#![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 ApexCore {
pub exchange: crate::exchange::Exchange,
}
impl ApexCore {
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 = ApexCore::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 ApexCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
ApexCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
ApexCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
ApexCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
ApexCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
ApexCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
ApexCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
ApexCore::parse_position(self, position, &[market])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
ApexCore::parse_transfer(self, transfer, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
ApexCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
ApexCore::parse_open_interest(self, interest, &[market])
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
ApexCore::parse_account(self, account)
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
ApexCore::parse_income(self, info, &[market])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
ApexCore::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 {
ApexCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for ApexCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"fetch_account" => self.fetch_account(&args[..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args[..]).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_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_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,
"get_account_id" => self.get_account_id().await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null),
args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"parse_account" => self.parse_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_market" => self.safe_market(&args[..]),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for ApexCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for ApexCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl ApexCore {
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("apex".into()));
m.insert("name".to_string(), Value::Str("Apex".into()));
m.insert("countries".to_string(), Value::from(vec![]));
m.insert("version".to_string(), Value::Str("v3".into()));
m.insert("rateLimit".to_string(), Value::Int(20));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("dex".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(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".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("cancelOrdersForSymbols".to_string(), Value::Bool(false));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(false));
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("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFee".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(false));
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(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
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("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(false));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1".into()));
m.insert("5m".to_string(), Value::Str("5".into()));
m.insert("15m".to_string(), Value::Str("15".into()));
m.insert("30m".to_string(), Value::Str("30".into()));
m.insert("1h".to_string(), Value::Str("60".into()));
m.insert("2h".to_string(), Value::Str("120".into()));
m.insert("4h".to_string(), Value::Str("240".into()));
m.insert("6h".to_string(), Value::Str("360".into()));
m.insert("12h".to_string(), Value::Str("720".into()));
m.insert("1d".to_string(), Value::Str("D".into()));
m.insert("1w".to_string(), Value::Str("W".into()));
m.insert("1M".to_string(), Value::Str("M".into()));
m
}));
m.insert("hostname".to_string(), Value::Str("omni.apex.exchange".into()));
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/8ba7fbfa-0dd0-4ab9-8b72-ff60abe08ac6".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://{hostname}/api".into()));
m.insert("private".to_string(), Value::Str("https://{hostname}/api".into()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://testnet.omni.apex.exchange/api".into()));
m.insert("private".to_string(), Value::Str("https://testnet.omni.apex.exchange/api".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://apex.exchange/".into()));
m.insert("doc".to_string(), Value::Str("https://api-docs.omni.apex.exchange".into()));
m.insert("fees".to_string(), Value::Str("https://apex-pro.gitbook.io/apex-pro/apex-omni-live-now/trading-perpetual-contracts/trading-fees".into()));
m.insert("referral".to_string(), Value::Str("https://omni.apex.exchange/trade".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("v3/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/history-funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/data/all-ticker-info".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("v3/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/account-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/order-fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/history-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/order-by-client-order-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/historical-pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/transfers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/stock/account".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("v3/delete-open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/delete-client-order-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/delete-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/set-initial-margin-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/contract-transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/contract-transfer-to".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/submit-withdraw-claim".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/stock/register-account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/stock/generate-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("httpExceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("403".to_string(), Value::Str("RateLimitExceeded".into()));
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("20006".to_string(), Value::Str("apikey sign error".into()));
m.insert("20016".to_string(), Value::Str("request para error".into()));
m.insert("10001".to_string(), Value::Str("BadRequest".into()));
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ORDER_PRICE_MUST_GREETER_ZERO".to_string(), Value::Str("InvalidOrder".into()));
m.insert("ORDER_POSSIBLE_LEAD_TO_ACCOUNT_LIQUIDATED".to_string(), Value::Str("InvalidOrder".into()));
m.insert("ORDER_WITH_THIS_PRICE_CANNOT_REDUCE_POSITION_ONLY".to_string(), Value::Str("InvalidOrder".into()));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0005".into()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".into()), &[]));
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.insert("walletAddress".to_string(), Value::Bool(false));
m.insert("privateKey".to_string(), Value::Bool(false));
m.insert("password".to_string(), Value::Bool(true));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("swap".into()));
m.insert("brokerId".to_string(), Value::Str("6956".into()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(true));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(500));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(200));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m
})]);
Value::Null
}
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_v3_time(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_integer_k(data, "time", &[]);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
let mut code: String = "USDT".to_string();
let mut account: indexmap::IndexMap<String, Value> = self.account().as_map().cloned().unwrap_or_default();
account.insert("free".into(), self.safe_string_k(response.clone(), "availableBalance", &[]));
account.insert("total".into(), self.safe_string_k(response, "totalEquityValue", &[]));
result.insert(code.clone(), Value::Map(account));
return self.safe_balance(Value::Map(result));
Value::Null
}
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_account_balance(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_balance(data);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
let mut accountId: Value = self.safe_string_k(account.clone(), "id", &[Value::Str("0".into())]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), accountId);
m.insert("type".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), account);
m
});
Value::Null
}
pub async fn fetch_account(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_account(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_account(data);
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 response: Value = self.public_get_v3_symbols(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotConfig: Value = self.safe_dict_k(data, "spotConfig", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut multiChain: Value = self.safe_dict_k(spotConfig.clone(), "multiChain", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rows: Value = self.safe_list_k(spotConfig, "assets", &[Value::from(vec![])]);
let mut chains: Value = self.safe_list_k(multiChain, "chains", &[Value::from(vec![])]);
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("_temp_currencies_chains".into(), chains); }
let mut result: Value = self.parse_currencies(rows);
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).shift_remove("_temp_currencies_chains"); }
return result;
Value::Null
}
pub fn parse_currency(&self, mut currency: Value) -> Value {
let mut currencyId: Value = self.safe_string_k(currency.clone(), "token", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut name: Option<String> = self.safe_string_k_opt(currency.clone(), "displayName", &[]);
let mut networks: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut chains: Value = self.safe_list_k(self.options.clone(), "_temp_currencies_chains", &[Value::from(vec![])]);
{
let mut j: i64 = 0;
let mut __for_first_226: bool = true;
while { if !__for_first_226 { j += 1; } __for_first_226 = false; j < (chains.len() as i64) } {
let mut chain: Value = self.safe_dict(chains.clone(), Value::Int(j), &[]);
let mut tokens: Value = self.safe_list_k(chain.clone(), "tokens", &[Value::from(vec![])]);
{
let mut f: i64 = 0;
let mut __for_first_225: bool = true;
while { if !__for_first_225 { f += 1; } __for_first_225 = false; f < (tokens.len() as i64) } {
let mut token: Value = self.safe_dict(tokens.clone(), Value::Int(f), &[]);
let mut tokenName: Value = self.safe_string_k(token.clone(), "token", &[]);
if (tokenName == currencyId) {
let mut networkId: Option<String> = self.safe_string_k_opt(chain.clone(), "chainId", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone().map(Value::from).unwrap_or(Value::Null), code.clone()]);
if (networkCode != Value::Null) {
networks.insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), networkId.map(Value::from).unwrap_or(Value::Null));
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool((!(self.safe_bool_k(chain.clone(), "depositDisable", &[Value::Bool(false)]).as_bool() == Some(true)))));
m.insert("withdraw".to_string(), self.safe_bool_k(token.clone(), "withdrawEnable", &[]));
m.insert("fee".to_string(), self.safe_number_k(token.clone(), "minFee", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(token.clone(), "decimals", &[])]), &[]));
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(token, "minWithdraw", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(chain.clone(), "minDeposit", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m
}));
}
}
}
}
}
}
let mut networkKeys: Vec<Value> = Value::Array(networks.keys().map(|__k| Value::Str(__k.clone().into())).collect()).as_array().cloned().unwrap_or_default();
let mut networksLength: f64 = ((networkKeys.len() as i64) as f64);
let mut emptyChains: bool = networksLength == 0.0; let mut valueForEmpty: Value = (if emptyChains { Value::Bool(false) } else { Value::Null });
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), currency);
m.insert("code".to_string(), code);
m.insert("id".to_string(), currencyId);
m.insert("type".to_string(), Value::Str("crypto".into()));
m.insert("name".to_string(), name.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), valueForEmpty.clone());
m.insert("withdraw".to_string(), valueForEmpty);
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
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
}));
m.insert("networks".to_string(), Value::Map(networks));
m
}));
Value::Null
}
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_v3_symbols(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractConfig: Value = self.safe_dict_k(data, "contractConfig", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut perpetualContract: Value = self.safe_list_k(contractConfig, "perpetualContract", &[Value::from(vec![])]);
return self.parse_markets(perpetualContract);
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 id2: Option<String> = self.safe_string_k_opt(market.clone(), "crossSymbolName", &[]);
let mut quoteId: Option<String> = self.safe_string_k_opt(market.clone(), "l2PairId", &[]);
let mut baseId: Option<String> = self.safe_string_k_opt(market.clone(), "baseTokenId", &[]);
let mut quote: Value = self.safe_string_k(market.clone(), "settleAssetId", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut settleId: Option<String> = self.safe_string_k_opt(market.clone(), "settleAssetId", &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
if (baseId.is_none()) || (quote == Value::Null) || (settle == Value::Null) {
return Value::Null;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", baseId.clone().map(Value::from).unwrap_or(Value::Null), Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), settle).into());
let mut expiry: Value = Value::Int(0);
let mut takerFee: Value = self.parse_number(Value::Str("0.0002".into()), &[]);
let mut makerFee: Value = self.parse_number(Value::Str("0.0005".into()), &[]);
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("id2".to_string(), id2.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.map(Value::from).unwrap_or(Value::Null));
m.insert("quoteId".to_string(), quoteId.map(Value::from).unwrap_or(Value::Null));
m.insert("settleId".to_string(), settleId.map(Value::from).unwrap_or(Value::Null));
m.insert("type".to_string(), Value::Str("swap".into()));
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Null);
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("active".to_string(), self.safe_bool_k(market.clone(), "enableTrade", &[]));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), Value::Bool(true));
m.insert("inverse".to_string(), Value::Bool(false));
m.insert("taker".to_string(), takerFee);
m.insert("maker".to_string(), makerFee);
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "minOrderSize", &[]));
m.insert("expiry".to_string(), (if (expiry.as_f64() == Some(0.0)) { Value::Null } else { expiry.clone() }));
m.insert("expiryDatetime".to_string(), (if (expiry.as_f64() == Some(0.0)) { Value::Null } else { self.iso8601(expiry) }));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(market.clone(), "stepSize", &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "tickSize", &[]));
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(), self.safe_number_k(market.clone(), "displayMinLeverage", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "displayMaxLeverage", &[]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minOrderSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxOrderSize", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(ticker.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone().map(Value::from).unwrap_or(Value::Null), market]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[marketResolved.clone()]);
let mut last: Option<String> = self.safe_string_k_opt(ticker.clone(), "lastPrice", &[]);
let mut percentage: Option<String> = self.safe_string_k_opt(ticker.clone(), "price24hPcnt", &[]);
let mut quoteVolume: Option<String> = self.safe_string_k_opt(ticker.clone(), "turnover24h", &[]);
let mut baseVolume: Option<String> = self.safe_string_k_opt(ticker.clone(), "volume24h", &[]);
let mut high: Option<String> = self.safe_string_k_opt(ticker.clone(), "highPrice24h", &[]);
let mut low: Option<String> = self.safe_string_k_opt(ticker.clone(), "lowPrice24h", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), high.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(), 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(), Value::Null);
m.insert("percentage".to_string(), percentage.map(Value::from).unwrap_or(Value::Null));
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(), self.safe_string_k(ticker.clone(), "markPrice", &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "indexPrice", &[]));
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id2", &[]));
m
});
let __ws_arg_0 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_v3_ticker(&[__ws_arg_0]).await;
let mut tickers: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut rawTicker: Value = self.safe_dict(tickers, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(rawTicker, &[market]);
Value::Null
}
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.public_get_v3_data_all_ticker_info(&[params]).await;
let mut tickers: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_tickers(tickers, &[symbols]);
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 market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id2", &[]));
m
});
let mut limitResolved: Value = (if ((limit == Value::Null) || limit.as_f64().unwrap_or(f64::NAN) > ((200i64) as f64)) { Value::Int(200) } else { limit });
request.insert("limit".into(), limitResolved.clone());
let requestUntilparamsUntilVariable: Vec<Value> = self.handle_until_option(Value::Str("end".into()), Value::Map(request), params, &[Value::Float(0.001)]).as_array().cloned().unwrap_or_default();
let mut requestUntil: Value = requestUntilparamsUntilVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.get(1).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("start".into(), ((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })).as_f64().map(|__x| Value::Float(__x.floor())).unwrap_or(Value::Null)); }
}
let __ws_arg_1 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_v3_klines(&[__ws_arg_1]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut OHLCVs: Value = self.safe_list(data, self.safe_string_k(market.clone(), "id2", &[]), &[Value::from(vec![])]);
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.safe_integer2(ohlcv.clone(), Value::Str("start".into()), Value::Str("t".into()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("open".into()), Value::Str("o".into()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("high".into()), Value::Str("h".into()), &[]), self.safe_number2(ohlcv.clone(),
Value::Str("low".into()), Value::Str("l".into()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("close".into()), Value::Str("c".into()), &[]), self.safe_number2(ohlcv, Value::Str("volume".into()), Value::Str("v".into()), &[])]);
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);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id2", &[]));
m
});
request.insert("limit".into(), (if (limit == Value::Null) { Value::Int(100) } else { limit })); let __ws_arg_2 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_v3_depth(&[__ws_arg_2]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.milliseconds();
let mut orderbook: indexmap::IndexMap<String, Value> = self.parse_order_book(data.clone(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), &[timestamp, Value::Str("b".into()), Value::Str("a".into())]).as_map().cloned().unwrap_or_default();
orderbook.insert("nonce".into(), self.safe_integer_k(data, "u", &[]));
return Value::Map(orderbook);
Value::Null
}
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id2", &[]));
m
});
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(500) } else { limit }); request.insert("limit".into(), limitResolved.clone());
let __ws_arg_3 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_v3_trades(&[__ws_arg_3]).await;
let mut trades: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_trades(trades, &[market, since, limitResolved]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("s".into()), Value::Str("symbol".into()), &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null), market]);
let mut id: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("i".into()), Value::Str("id".into()), &[]);
let mut timestamp: Option<i64> = self.safe_integer_n_opt(trade.clone(), Value::from(vec![Value::Str("t".into()), Value::Str("T".into()), Value::Str("createdAt".into())]), &[]);
let mut priceString: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("p".into()), Value::Str("price".into()), &[]);
let mut amountString: Option<String> = self.safe_string2_opt(trade.clone(), Value::Str("v".into()), Value::Str("size".into()), &[]);
let mut side: Value = self.safe_string_lower2(trade.clone(), Value::Str("S".into()), Value::Str("side".into()), &[]);
let mut type_var: Option<String> = self.safe_string_k_opt(trade.clone(), "type", &[]);
let mut fee: Option<String> = self.safe_string_k_opt(trade.clone(), "fee", &[]);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade);
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("order".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), type_var.map(Value::from).unwrap_or(Value::Null));
m.insert("takerOrMaker".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("price".to_string(), priceString.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amountString.map(Value::from).unwrap_or(Value::Null));
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee.map(Value::from).unwrap_or(Value::Null));
m
}), &[marketResolved]);
Value::Null
}
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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(), self.safe_string_k(market.clone(), "id2", &[]));
m
});
let __ws_arg_4 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_v3_ticker(&[__ws_arg_4]).await;
let mut tickers: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut rawTicker: Value = self.safe_dict(tickers, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_open_interest(rawTicker, &[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 marketId: Option<String> = self.safe_string_k_opt(interest.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()]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("openInterestAmount".to_string(), self.safe_string_k(interest.clone(), "openInterest", &[]));
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("info".to_string(), interest);
m
}), &[marketResolved]);
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 request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = self.market(symbol.clone());
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
if (since != Value::Null) {
request.insert("beginTimeInclusive".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let mut page: Value = self.safe_integer_k(params.clone(), "page", &[]);
if (page != Value::Null) {
request.insert("page".into(), page);
}
let mut endTimeExclusive: Value = self.safe_integer_n(params.clone(), Value::from(vec![Value::Str("endTime".into()), Value::Str("endTimeExclusive".into()), Value::Str("until".into())]), &[]);
if (endTimeExclusive != Value::Null) {
request.insert("endTimeExclusive".into(), endTimeExclusive);
}
let __ws_arg_5 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.public_get_v3_history_funding(&[__ws_arg_5]).await;
let mut rates: Vec<Value> = Vec::new();
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut resultList: Vec<Value> = self.safe_list_k(data, "historyFunds", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
{
let mut i: i64 = 0;
let mut __for_first_227: bool = true;
while { if !__for_first_227 { i += 1; } __for_first_227 = false; i < (resultList.len() as i64) } {
let mut entry: Value = resultList.get(i as usize).cloned().unwrap_or(Value::Null);
let mut timestamp: Option<i64> = self.safe_integer_k(entry.clone(), "fundingTimestamp", &[]).as_i64();
let mut marketId: Option<String> = self.safe_string_k_opt(entry.clone(), "symbol", &[]);
rates.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market.clone()]));
m.insert("fundingRate".to_string(), self.safe_number_k(entry, "rate", &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m
}));
}
}
let mut sorted: Value = self.sort_by(Value::from(rates), Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbol, 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 timestamp: Option<i64> = self.safe_integer_k(order.clone(), "createdAt", &[]).as_i64();
let mut orderId: Option<String> = self.safe_string_k_opt(order.clone(), "id", &[]);
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.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 price: Option<String> = self.safe_string_k_opt(order.clone(), "price", &[]);
let mut amount: Option<String> = self.safe_string_k_opt(order.clone(), "size", &[]);
let mut orderType: Option<String> = self.safe_string_k_opt(order.clone(), "type", &[]);
let mut status: Option<String> = self.safe_string_k_opt(order.clone(), "status", &[]);
let mut side: Option<String> = self.safe_string_lower_k_opt(order.clone(), "side", &[]);
let mut remaining: Value = self.omit_zero(self.safe_string_k(order.clone(), "remainingSize", &[]));
let mut lastUpdateTimestamp: Option<i64> = self.safe_integer_k(order.clone(), "updatedTime", &[]).as_i64();
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.map(Value::from).unwrap_or(Value::Null));
m.insert("clientOrderId".to_string(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), Value::from(lastUpdateTimestamp));
m.insert("status".to_string(), self.parse_order_status(status.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), self.parse_order_type(orderType.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null));
m.insert("timeInForce".to_string(), self.parse_time_in_force(self.safe_string_k(order.clone(), "timeInForce", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("postOnly".to_string(), self.safe_bool_k(order.clone(), "postOnly", &[]));
m.insert("reduceOnly".to_string(), self.safe_bool_k(order.clone(), "reduceOnly", &[]));
m.insert("side".to_string(), side.map(Value::from).unwrap_or(Value::Null));
m.insert("price".to_string(), price.map(Value::from).unwrap_or(Value::Null));
m.insert("triggerPrice".to_string(), self.safe_string_k(order.clone(), "triggerPrice", &[]));
m.insert("takeProfitPrice".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("amount".to_string(), amount.map(Value::from).unwrap_or(Value::Null));
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), remaining);
m.insert("cost".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "fee", &[]));
m.insert("currency".to_string(), marketResolved.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null));
m
}));
m.insert("info".to_string(), order);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Option<String> {
let mut timeInForces: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("GOOD_TIL_CANCEL".to_string(), Value::Str("GOOD_TIL_CANCEL".into()));
m.insert("FILL_OR_KILL".to_string(), Value::Str("FILL_OR_KILL".into()));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Str("IMMEDIATE_OR_CANCEL".into()));
m.insert("POST_ONLY".to_string(), Value::Str("POST_ONLY".into()));
m
});
return self.safe_string(Value::Map(timeInForces), timeInForce, &[]).as_str().map(str::to_owned);
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
if (status != Value::Null) {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("PENDING".to_string(), Value::Str("open".into()));
m.insert("OPEN".to_string(), Value::Str("open".into()));
m.insert("FILLED".to_string(), Value::Str("filled".into()));
m.insert("CANCELING".to_string(), Value::Str("canceled".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("UNTRIGGERED".to_string(), Value::Str("open".into()));
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
return None;
}
pub fn parse_order_type(&self, mut type_var: Value) -> Option<String> {
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("LIMIT".to_string(), Value::Str("limit".into()));
m.insert("MARKET".to_string(), Value::Str("market".into()));
m.insert("STOP_LIMIT".to_string(), Value::Str("limit".into()));
m.insert("STOP_MARKET".to_string(), Value::Str("market".into()));
m.insert("TAKE_PROFIT_LIMIT".to_string(), Value::Str("limit".into()));
m.insert("TAKE_PROFIT_MARKET".to_string(), Value::Str("market".into()));
m
});
return self.safe_string(Value::Map(types), type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn safe_market(&self, optional_args: &[Value]) -> Value {
let mut marketId = get_arg(optional_args, 0, Value::Null);
let mut market = get_arg(optional_args, 1, Value::Null);
let mut delimiter = get_arg(optional_args, 2, Value::Null);
let mut marketType = get_arg(optional_args, 3, Value::Null);
let mut marketResolved: Value = market.clone();
if (market == Value::Null) && (marketId != Value::Null) {
if (self.markets.clone() != Value::Null) && (matches!((&self.markets, &marketId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
marketResolved = (if let (Some(__m), Some(__k)) = (self.markets.as_map(), marketId.as_str()) { __m.get(__k).cloned().unwrap_or(Value::Null) } else { Value::Null });
} else if (self.markets_by_id.clone() != Value::Null) && (matches!((&self.markets_by_id, &marketId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
marketResolved = (if let (Some(__m), Some(__k)) = (self.markets_by_id.as_map(), marketId.as_str()) { __m.get(__k).cloned().unwrap_or(Value::Null) } else { Value::Null });
} else {
let mut newMarketId: Value = self.add_hyphen_before_usdt(marketId.clone()).map(Value::from).unwrap_or(Value::Null);
if (self.markets_by_id.clone() != Value::Null) && (matches!((&self.markets_by_id, &newMarketId), (Value::Dict(__d), Value::Str(__k)) if __d.contains_key(__k.as_ref()))) {
let mut markets: Value = (if let (Some(__m), Some(__k)) = (self.markets_by_id.as_map(), newMarketId.as_str()) { __m.get(__k).cloned().unwrap_or(Value::Null) } else { Value::Null });
let mut numMarkets: Value = get_array_length(&markets);
if numMarkets.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
if is_equal(&crate::value::get_value_k(&get_value(&markets, &Value::Int(0)), "id2"), &marketId) {
marketResolved = get_value(&markets, &Value::Int(0));
}
}
}
}
}
return self.super_safe_market(marketId, marketResolved, delimiter, marketType);
Value::Null
}
pub fn generate_random_client_id_omni(&self, mut _accountId: Value) -> Option<String> {
let mut accountId: Value = Value::Str("".into());
if (_accountId != Value::Null) && (_accountId.as_str() != Some("")) {
accountId = _accountId;
} else {
accountId = Value::Str(format!("{}", self.rand_number(Value::Int(12))).into());
}
return Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("apexomni-".into()), accountId).into()), Value::Str("-".into())).into()), Value::Str(format!("{}", self.milliseconds()).into())).into()), Value::Str("-".into())).into()), Value::Str(format!("{}",
self.rand_number(Value::Int(6))).into())).into()).as_str().map(str::to_owned);
}
pub fn add_hyphen_before_usdt(&self, mut symbol: Value) -> Option<String> {
let mut uppercaseSymbol: Value = (if let Some(__s) = symbol.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
let mut index: Value = Value::Int(uppercaseSymbol.as_str().and_then(|__s| __s.find("USDT")).map(|__i| __i as i64).unwrap_or(-1));
let mut symbolChar: Option<String> = self.safe_string(symbol.clone(), (match (&(index), &(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_str().map(str::to_owned);
if index.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) && (symbolChar.as_deref() != Some("-")) {
return Value::Str(format!("{}{}", Value::Str(format!("{}{}", (match (&(symbol), 0i64, (match &(index) { Value::Int(__n) => Some(*__n), Value::Float(__f) => Some(*__f as i64), Value::Str(__s) => __s.parse::<i64>().ok(), Value::Bool(__b) => Some(if *__b { 1 } else { 0 }), _ => None })) { (Value::Str(__sv), __b,
__e) => match (__sv.chars().count() as i64) { __l => match (if __b < 0 { (__l + __b).max(0) } else { __b.min(__l) }, match __e { None => __l, Some(__k) => if __k < 0 { (__l + __k).max(0) } else { __k.min(__l) } }) { (__i,
__j) => if __i <= __j { Value::Str(__sv.chars().skip(__i as usize).take((__j - __i) as usize).collect::<String>().into()) } else { Value::Str(String::new().into()) } } }, (Value::Arr(__a), __b, __e) => match (__a.len() as i64) { __l => match (if __b < 0 { (__l + __b).max(0) } else { __b.min(__l) }, match __e { None => __l,
Some(__k) => if __k < 0 { (__l + __k).max(0) } else { __k.min(__l) } }) { (__i, __j) => if __i <= __j { Value::Array(__a[__i as usize..__j as usize].to_vec()) } else { Value::Array(vec![]) } } }, _ => Value::Null }), Value::Str("-".into())).into()), (match (&(symbol), (match &(index) { Value::Int(__n) => Some(*__n),
Value::Float(__f) => Some(*__f as i64), Value::Str(__s) => __s.parse::<i64>().ok(), Value::Bool(__b) => Some(if *__b { 1 } else { 0 }), _ => None }).unwrap_or(0), (match &(Value::Null) { Value::Int(__n) => Some(*__n), Value::Float(__f) => Some(*__f as i64), Value::Str(__s) => __s.parse::<i64>().ok(),
Value::Bool(__b) => Some(if *__b { 1 } else { 0 }), _ => None })) { (Value::Str(__sv), __b, __e) => match (__sv.chars().count() as i64) { __l => match (if __b < 0 { (__l + __b).max(0) } else { __b.min(__l) }, match __e { None => __l, Some(__k) => if __k < 0 { (__l + __k).max(0) } else { __k.min(__l) } }) { (__i,
__j) => if __i <= __j { Value::Str(__sv.chars().skip(__i as usize).take((__j - __i) as usize).collect::<String>().into()) } else { Value::Str(String::new().into()) } } }, (Value::Arr(__a), __b, __e) => match (__a.len() as i64) { __l => match (if __b < 0 { (__l + __b).max(0) } else { __b.min(__l) }, match __e { None => __l,
Some(__k) => if __k < 0 { (__l + __k).max(0) } else { __k.min(__l) } }) { (__i, __j) => if __i <= __j { Value::Array(__a[__i as usize..__j as usize].to_vec()) } else { Value::Array(vec![]) } } }, _ => Value::Null })).into()).as_str().map(str::to_owned);
}
return symbol.as_str().map(str::to_owned);
}
pub fn get_seeds(&self) -> Option<String> {
let mut seeds: Option<String> = self.safe_string_k_opt(self.options.clone(), "seeds", &[]);
if (seeds.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" the \"seeds\" key is required in the options to access private endpoints. You can find it in API Management > Omni Key, and then set it as exchange.options[\"seeds\"] = XXXX".into()))));
}
return seeds.as_deref().map(str::to_owned);
}
pub async fn get_account_id(&mut self) -> Value {
let mut accountId: Option<String> = self.safe_string_k(self.options.clone(), "accountId", &[Value::Str("0".into())]).as_str().map(str::to_owned);
if (accountId.as_deref() == Some("0")) {
let mut accountData: Value = self.fetch_account(&[]).await;
{ let __be_tmp = self.safe_string_k(accountData, "id", &[Value::Str("0".into())]); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("accountId".into(), __be_tmp); } }
}
return self.safe_string_k(self.options.clone(), "accountId", &[]);
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 orderType: Value = (if let Some(__s) = type_var.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
self.check_required_argument(Value::Str("createOrder".into()), side.clone(), Value::Str("side".into()), &[]);
let mut orderSide: String = side.as_str().map(str::to_uppercase).unwrap_or_default();
let mut orderSize: Value = self.amount_to_precision(symbol.clone(), amount);
let mut orderPrice: Value = Value::Str("0".into());
if (price != Value::Null) {
orderPrice = self.price_to_precision(symbol.clone(), price.clone());
}
let mut fees: Value = self.safe_dict_k(self.fees.clone(), "swap", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut taker: Value = self.safe_string_k(fees.clone(), "taker", &[Value::Str("0.0005".into())]);
let mut maker: Value = self.safe_string_k(fees, "maker", &[Value::Str("0.0002".into())]);
let mut pricePrecision: Value = market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("price")).cloned().unwrap_or(Value::Null);
let mut limitFee: Value = self.decimal_to_precision(crate::precise::Precise::stringAdd(&crate::precise::Precise::stringMul(&crate::precise::Precise::stringMul(&orderPrice, &orderSize), &taker), &self.number_to_string(pricePrecision.clone())), Value::Int(crate::runtime::TRUNCATE), pricePrecision, &[self.precisionMode.clone(), self.paddingMode.clone()]);
let mut timeNow: Value = self.milliseconds();
let mut triggerPrice: Value = self.safe_string_k(params.clone(), "triggerPrice", &[]);
let mut stopLossPrice: Option<String> = self.safe_string_k_opt(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Option<String> = self.safe_string_k_opt(params.clone(), "takeProfitPrice", &[]);
if (stopLossPrice.is_some()) {
orderType = (if (orderType.as_str() == Some("MARKET")) { Value::Str("STOP_MARKET".into()) } else { Value::Str("STOP_LIMIT".into()) });
triggerPrice = stopLossPrice.map(Value::from).unwrap_or(Value::Null);
} else if (takeProfitPrice.is_some()) {
orderType = (if (orderType.as_str() == Some("MARKET")) { Value::Str("TAKE_PROFIT_MARKET".into()) } else { Value::Str("TAKE_PROFIT_LIMIT".into()) });
triggerPrice = takeProfitPrice.map(Value::from).unwrap_or(Value::Null);
}
let mut isMarket: bool = orderType.as_str() == Some("MARKET");
if isMarket && (price == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a price argument for market orders".into()))));
}
let mut timeInForce: Value = self.safe_string_upper_k(params.clone(), "timeInForce", &[]);
let mut postOnly: Value = self.is_post_only(Value::Bool(isMarket.clone()), Value::Null, &[params.clone()]);
if (timeInForce == Value::Null) {
timeInForce = Value::Str("GOOD_TIL_CANCEL".into());
}
if !(isMarket) {
if postOnly.as_bool() == Some(true) {
timeInForce = Value::Str("POST_ONLY".into());
} else if (timeInForce.as_str() == Some("ioc")) {
timeInForce = Value::Str("IMMEDIATE_OR_CANCEL".into());
}
}
let mut paramsOmitted: Value = self.omit(params, Value::Str("timeInForce".into()), &[]);
let mut paramsOmitted2: Value = self.omit(paramsOmitted, Value::Str("postOnly".into()), &[]);
let mut clientOrderId: Value = self.safe_string_n(paramsOmitted2.clone(), Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into())]), &[]);
let mut accountId: Value = self.get_account_id().await;
let mut finalClientOrderId: Value = (if (clientOrderId != Value::Null) { clientOrderId } else { self.generate_random_client_id_omni(accountId.clone()).map(Value::from).unwrap_or(Value::Null) });
let mut paramsOmitted3: Value = self.omit(paramsOmitted2, Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into()), Value::Str("stopLossPrice".into()), Value::Str("takeProfitPrice".into()), Value::Str("triggerPrice".into())]), &[]);
let mut finalOrderPrice: Value = orderPrice; let mut orderToSign: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("accountId".to_string(), accountId);
m.insert("slotId".to_string(), finalClientOrderId.clone());
m.insert("nonce".to_string(), finalClientOrderId.clone());
m.insert("pairId".to_string(), market.as_map().and_then(|__m| __m.get("quoteId")).cloned().unwrap_or(Value::Null));
m.insert("size".to_string(), orderSize.clone());
m.insert("price".to_string(), finalOrderPrice.clone());
m.insert("direction".to_string(), Value::from(orderSide.clone()));
m.insert("makerFeeRate".to_string(), maker);
m.insert("takerFeeRate".to_string(), taker);
m
});
if (triggerPrice != Value::Null) {
orderToSign.insert("triggerPrice".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
}
let mut signature: Value = self.get_zk_contract_signature_obj(self.remove0x_prefix(self.get_seeds().map(Value::from).unwrap_or(Value::Null)), &[Value::Map(orderToSign)]).await;
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(), Value::from(orderSide));
m.insert("type".to_string(), orderType);
m.insert("size".to_string(), orderSize);
m.insert("price".to_string(), finalOrderPrice);
m.insert("limitFee".to_string(), limitFee);
m.insert("expiration".to_string(), (match (&(self.parse_to_int((match ((timeNow).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))), &((match (&((match (&((match (&(Value::Int(30)), &(Value::Int(24))) { (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(60))) { (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(60))) { (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 }));
m.insert("timeInForce".to_string(), timeInForce);
m.insert("clientId".to_string(), finalClientOrderId);
m.insert("brokerId".to_string(), self.safe_string_k(self.options.clone(), "brokerId", &[Value::Str("6956".into())]));
m
});
if (triggerPrice != Value::Null) {
request.insert("triggerPrice".into(), self.price_to_precision(symbol, triggerPrice));
}
request.insert("signature".into(), signature);
let __ws_arg_6 = self.extend(Value::Map(request), &[paramsOmitted3]);
let mut response: Value = self.private_post_v3_order(&[__ws_arg_6]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[market]);
Value::Null
}
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut configResponse: Value = self.public_get_v3_symbols(&[params.clone()]).await;
let mut configData: Value = self.safe_dict_k(configResponse, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractConfig: Value = self.safe_dict_k(configData.clone(), "contractConfig", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotConfig: Value = self.safe_dict_k(configData, "spotConfig", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut globalConfig: Value = self.safe_dict_k(spotConfig.clone(), "global", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut receiverAddress: Value = self.safe_string_k(globalConfig.clone(), "contractAssetPoolEthAddress", &[Value::Str("".into())]);
let mut receiverZkAccountId: Value = self.safe_string_k(globalConfig.clone(), "contractAssetPoolZkAccountId", &[Value::Str("".into())]);
let mut receiverSubAccountId: Value = self.safe_string_k(globalConfig.clone(), "contractAssetPoolSubAccount", &[Value::Str("".into())]);
let mut receiverAccountId: Value = self.safe_string_k(globalConfig, "contractAssetPoolAccountId", &[Value::Str("".into())]);
let mut accountResponse: Value = self.private_get_v3_account(&[params.clone()]).await;
let mut accountData: Value = self.safe_dict_k(accountResponse, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotAccount: Value = self.safe_dict_k(accountData.clone(), "spotAccount", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut zkAccountId: Value = self.safe_string_k(spotAccount.clone(), "zkAccountId", &[Value::Str("".into())]);
let mut subAccountId: Value = self.safe_string_k(spotAccount.clone(), "defaultSubAccountId", &[Value::Str("0".into())]);
let mut subAccounts: Vec<Value> = self.safe_list_k(spotAccount, "subAccounts", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut nonce: Value = Value::Str("0".into());
if ((subAccounts.len() as i64) as f64) > ((0i64) as f64) {
nonce = self.safe_string_k(subAccounts.get(0).cloned().unwrap_or(Value::Null), "nonce", &[Value::Str("0".into())]);
}
let mut finalNonce: Value = nonce; let mut ethAddress: Value = self.safe_string_k(accountData.clone(), "ethereumAddress", &[Value::Str("".into())]);
let mut accountId: Value = self.safe_string_k(accountData, "id", &[Value::Str("".into())]);
let mut currency: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut isContract: bool = (if let Some(__s) = fromAccount.as_str() { Value::Str(__s.to_lowercase().into()) } else { Value::Null }).as_str() == Some("contract");
let mut assets: Value = self.safe_list_k(spotConfig, "assets", &[Value::from(vec![])]);
if isContract {
assets = self.safe_list_k(contractConfig, "assets", &[Value::from(vec![])]);
}
let mut numAssets: f64 = ((assets.len() as i64) as f64);
{
let mut i: Value = Value::Int(0);
let mut __for_first_228: bool = true;
while { if !__for_first_228 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_228 = false; i.as_f64().unwrap_or(f64::NAN) < numAssets } {
let mut asset: Value = self.safe_dict(assets.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (self.safe_string_k(asset.clone(), "token", &[Value::Str("".into())]).as_str() == code.as_str()) {
currency = asset;
}
}
}
let mut tokenId: Value = self.safe_string_k(currency.clone(), "tokenId", &[Value::Str("".into())]);
let mut decimalsNum: Value = self.safe_number_k(currency.clone(), "decimals", &[Value::Int(0)]);
let mut decimalsNumber: Value = (if (decimalsNum == Value::Null) { Value::Int(0) } else { decimalsNum });
let mut mathPowResult: Value = (crate::runtime::Math::pow(&Value::Int(10), &decimalsNumber));
let mut amountNum: Value = self.parse_number(amount.clone(), &[]);
let mut amountValue: Value = (if (amountNum == Value::Null) { Value::Int(0) } else { amountNum });
let mut amountNumber: Value = self.parse_to_int((match (&(amountValue), &(mathPowResult)) { (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 timestampSeconds: Value = self.parse_to_int((match ((self.milliseconds()).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
let mut clientOrderId: Value = self.safe_string_n(params.clone(), Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into())]), &[]);
let mut finalClientOrderId: Value = (if (clientOrderId != Value::Null) { clientOrderId } else { self.generate_random_client_id_omni(self.safe_string_k(self.options.clone(), "accountId", &[])).map(Value::from).unwrap_or(Value::Null) });
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into())]), &[]);
if isContract {
let mut formattedUint32: Value = Value::Str("4294967295".into());
let mut zkSignAccountId: Value = crate::precise::Precise::stringMod(&accountId, &formattedUint32);
let mut expireTime: Value = (match (&(timestampSeconds), &((match (&((match (&(Value::Int(3600)), &(Value::Int(24))) { (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(28))) { (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 });
let mut orderToSign: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("zkAccountId".to_string(), zkSignAccountId);
m.insert("receiverAddress".to_string(), ethAddress.clone());
m.insert("subAccountId".to_string(), subAccountId.clone());
m.insert("receiverSubAccountId".to_string(), subAccountId.clone());
m.insert("tokenId".to_string(), tokenId.clone());
m.insert("amount".to_string(), Value::Str(format!("{}", amountNumber).into()));
m.insert("fee".to_string(), Value::Str("0".into()));
m.insert("nonce".to_string(), finalClientOrderId.clone());
m.insert("timestampSeconds".to_string(), expireTime.clone());
m.insert("isContract".to_string(), Value::Bool(true));
m
});
let mut signature: Value = self.get_zk_transfer_signature_obj(self.remove0x_prefix(self.get_seeds().map(Value::from).unwrap_or(Value::Null)), &[orderToSign.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m.insert("expireTime".to_string(), expireTime);
m.insert("clientWithdrawId".to_string(), finalClientOrderId.clone());
m.insert("signature".to_string(), signature.clone());
m.insert("token".to_string(), code.clone());
m.insert("ethAddress".to_string(), ethAddress);
m
});
let __ws_arg_7 = self.extend(request.clone(), &[paramsOmitted.clone()]);
let mut response: Value = self.private_post_v3_contract_transfer_out(&[__ws_arg_7]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currentTime: Value = self.milliseconds();
let mut parsedAmount: Value = self.parse_number(amount.clone(), &[]);
let __ws_arg_8 = self.parse_transfer(data.clone(), &[self.currency(code.clone())]);
let __ws_arg_9 = self.iso8601(currentTime.clone());
return self.extend(__ws_arg_8, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), currentTime.clone());
m.insert("datetime".to_string(), __ws_arg_9);
m.insert("amount".to_string(), parsedAmount);
m.insert("fromAccount".to_string(), Value::Str("contract".into()));
m.insert("toAccount".to_string(), Value::Str("spot".into()));
m
})]);
} else {
let mut orderToSign: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("zkAccountId".to_string(), zkAccountId.clone());
m.insert("receiverAddress".to_string(), receiverAddress.clone());
m.insert("subAccountId".to_string(), subAccountId.clone());
m.insert("receiverSubAccountId".to_string(), receiverSubAccountId.clone());
m.insert("tokenId".to_string(), tokenId.clone());
m.insert("amount".to_string(), Value::Str(format!("{}", amountNumber).into()));
m.insert("fee".to_string(), Value::Str("0".into()));
m.insert("nonce".to_string(), finalNonce.clone());
m.insert("timestampSeconds".to_string(), timestampSeconds.clone());
m
});
let mut signature: Value = self.get_zk_transfer_signature_obj(self.remove0x_prefix(self.get_seeds().map(Value::from).unwrap_or(Value::Null)), &[orderToSign]).await;
let mut ts: Value = timestampSeconds; let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.number_to_string(amount.clone()));
m.insert("timestamp".to_string(), ts);
m.insert("clientTransferId".to_string(), finalClientOrderId);
m.insert("signature".to_string(), signature);
m.insert("zkAccountId".to_string(), zkAccountId);
m.insert("subAccountId".to_string(), subAccountId);
m.insert("fee".to_string(), Value::Str("0".into()));
m.insert("token".to_string(), code.clone());
m.insert("tokenId".to_string(), tokenId);
m.insert("receiverAccountId".to_string(), receiverAccountId);
m.insert("receiverZkAccountId".to_string(), receiverZkAccountId);
m.insert("receiverSubAccountId".to_string(), receiverSubAccountId);
m.insert("receiverAddress".to_string(), receiverAddress);
m.insert("nonce".to_string(), finalNonce);
m
});
let __ws_arg_10 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_post_v3_transfer_out(&[__ws_arg_10]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currentTime: Value = self.milliseconds();
let __ws_arg_11 = self.parse_transfer(data, &[self.currency(code)]);
let __ws_arg_12 = self.iso8601(currentTime.clone());
let __ws_arg_13 = self.parse_number(amount, &[]);
return self.extend(__ws_arg_11, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), currentTime);
m.insert("datetime".to_string(), __ws_arg_12);
m.insert("amount".to_string(), __ws_arg_13);
m.insert("fromAccount".to_string(), Value::Str("spot".into()));
m.insert("toAccount".to_string(), Value::Str("contract".into()));
m
})]);
}
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyId: Option<String> = self.safe_string_k_opt(transfer.clone(), "coin", &[]);
let mut timestamp: Option<i64> = self.safe_integer_k(transfer.clone(), "timestamp", &[]).as_i64();
let mut fromAccount: Option<String> = self.safe_string_k_opt(transfer.clone(), "fromAccount", &[]);
let mut toAccount: Option<String> = self.safe_string_k_opt(transfer.clone(), "toAccount", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), self.safe_string2(transfer.clone(), Value::Str("transferId".into()), Value::Str("id".into()), &[]));
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[currency]));
m.insert("amount".to_string(), self.safe_number_k(transfer.clone(), "amount", &[]));
m.insert("fromAccount".to_string(), fromAccount.map(Value::from).unwrap_or(Value::Null));
m.insert("toAccount".to_string(), toAccount.map(Value::from).unwrap_or(Value::Null));
m.insert("status".to_string(), self.safe_string_k(transfer, "status", &[]));
m
});
Value::Null
}
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
let __ws_arg_14 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_post_v3_delete_open_orders(&[__ws_arg_14]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return Value::from(vec![self.parse_order(data, &[market])]);
Value::Null
}
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Option<String> = self.safe_string_n_opt(params.clone(), Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into())]), &[]);
let mut response: Value = Value::Null;
if (clientOrderId.is_some()) {
request.insert("id".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
let __ws_arg_15 = self.extend(Value::Map(request.clone()), &[self.omit(params.clone(), Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into())]), &[])]);
response = self.private_post_v3_delete_client_order_id(&[__ws_arg_15]).await;
} else {
request.insert("id".into(), id);
let __ws_arg_16 = self.extend(Value::Map(request), &[params]);
response = self.private_post_v3_delete_order(&[__ws_arg_16]).await;
}
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_order(data, &[]);
Value::Null
}
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Option<String> = self.safe_string_n_opt(params.clone(), Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into())]), &[]);
let mut response: Value = Value::Null;
if (clientOrderId.is_some()) {
request.insert("id".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
let __ws_arg_17 = self.extend(Value::Map(request.clone()), &[self.omit(params.clone(), Value::from(vec![Value::Str("clientId".into()), Value::Str("clientOrderId".into()), Value::Str("client_order_id".into())]), &[])]);
response = self.private_get_v3_order_by_client_order_id(&[__ws_arg_17]).await;
} else {
request.insert("id".into(), id);
let __ws_arg_18 = self.extend(Value::Map(request), &[params]);
response = self.private_get_v3_order(&[__ws_arg_18]).await;
}
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data, &[]);
Value::Null
}
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_open_orders(&[params]).await;
let mut orders: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_orders(orders, &[Value::Null, since, limit]);
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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (since != Value::Null) {
request.insert("beginTimeInclusive".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let mut endTimeExclusive: Option<i64> = self.safe_integer_n_opt(params.clone(), Value::from(vec![Value::Str("endTime".into()), Value::Str("endTimeExclusive".into()), Value::Str("until".into())]), &[]);
if (endTimeExclusive.is_some()) {
request.insert("endTimeExclusive".into(), Value::from(endTimeExclusive));
}
let mut paramsOmitted: Value = (if (endTimeExclusive.is_some()) { self.omit(params.clone(), Value::from(vec![Value::Str("endTime".into()), Value::Str("endTimeExclusive".into()), Value::Str("until".into())]), &[]) } else { params });
let __ws_arg_19 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.private_get_v3_history_orders(&[__ws_arg_19]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data, "orders", &[Value::from(vec![])]);
return self.parse_orders(orders, &[market, since, limit]);
Value::Null
}
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (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 clientOrderId: Option<String> = self.safe_string2_opt(params.clone(), Value::Str("clientOrderId".into()), Value::Str("clientId".into()), &[]);
if (clientOrderId.is_some()) {
request.insert("clientOrderId".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
} else {
request.insert("orderId".into(), id);
}
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("clientOrderId".into()), Value::Str("clientId".into())]), &[]);
let __ws_arg_20 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.private_get_v3_order_fills(&[__ws_arg_20]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data, "orders", &[Value::from(vec![])]);
return self.parse_trades(orders, &[Value::Null, 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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (since != Value::Null) {
request.insert("beginTimeInclusive".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let mut endTimeExclusive: Option<i64> = self.safe_integer_n_opt(params.clone(), Value::from(vec![Value::Str("endTime".into()), Value::Str("endTimeExclusive".into()), Value::Str("until".into())]), &[]);
if (endTimeExclusive.is_some()) {
request.insert("endTimeExclusive".into(), Value::from(endTimeExclusive));
}
let mut paramsOmitted: Value = (if (endTimeExclusive.is_some()) { self.omit(params.clone(), Value::from(vec![Value::Str("endTime".into()), Value::Str("endTimeExclusive".into()), Value::Str("until".into())]), &[]) } else { params });
let __ws_arg_21 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.private_get_v3_fills(&[__ws_arg_21]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data, "orders", &[Value::from(vec![])]);
return self.parse_trades(orders, &[market, since, limit]);
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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (since != Value::Null) {
request.insert("beginTimeInclusive".into(), since.clone());
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
}
let mut endTimeExclusive: Option<i64> = self.safe_integer_n_opt(params.clone(), Value::from(vec![Value::Str("endTime".into()), Value::Str("endTimeExclusive".into()), Value::Str("until".into())]), &[]);
if (endTimeExclusive.is_some()) {
request.insert("endTimeExclusive".into(), Value::from(endTimeExclusive));
}
let mut paramsOmitted: Value = (if (endTimeExclusive.is_some()) { self.omit(params.clone(), Value::from(vec![Value::Str("endTime".into()), Value::Str("endTimeExclusive".into()), Value::Str("until".into())]), &[]) } else { params });
let __ws_arg_22 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.private_get_v3_funding(&[__ws_arg_22]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fundingValues: Value = self.safe_list_k(data, "fundingValues", &[Value::from(vec![])]);
return self.parse_incomes(fundingValues, &[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 marketResolved: Value = self.safe_market(&[marketId.clone().map(Value::from).unwrap_or(Value::Null), market, Value::Null, Value::Str("contract".into())]);
let mut code: String = "USDT".to_string();
let mut timestamp: Option<i64> = self.safe_integer_k(income.clone(), "fundingTime", &[]).as_i64();
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), income.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[marketResolved]));
m.insert("code".to_string(), Value::from(code));
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(income.clone(), "id", &[]));
m.insert("amount".to_string(), self.safe_number_k(income.clone(), "fundingValue", &[]));
m.insert("rate".to_string(), self.safe_number_k(income, "rate", &[]));
m
});
Value::Null
}
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol).as_map().cloned().unwrap_or_default();
let mut leverageString: Value = self.number_to_string(leverage);
let mut initialMarginRate: Value = crate::precise::Precise::stringDivPrec(&Value::Str("1".into()), &leverageString, &Value::Int(4));
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m.insert("initialMarginRate".to_string(), initialMarginRate);
m
});
let __ws_arg_23 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.private_post_v3_set_initial_margin_rate(&[__ws_arg_23]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return data;
Value::Null
}
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_account(&[params]).await;
let mut data: Value = self.safe_dict_k(response, "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positions: Value = self.safe_list_k(data, "positions", &[Value::from(vec![])]);
return self.parse_positions(positions, &[symbols]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(position.clone(), "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 side: Option<String> = self.safe_string_lower_k_opt(position.clone(), "side", &[]);
let mut quantity: Option<String> = self.safe_string_k_opt(position.clone(), "size", &[]);
let mut timestamp: Option<i64> = self.safe_integer_k(position.clone(), "updatedTime", &[]).as_i64();
let mut leverage: Value = Value::Int(20);
let mut customInitialMarginRate: Value = self.safe_string2(position.clone(), Value::Str("customInitialMarginRate".into()), Value::Str("customImr".into()), &[Value::Str("0".into())]);
if (self.precision_from_string(customInitialMarginRate.clone()).as_f64() != Some(0.0)) {
leverage = self.parse_to_int(crate::precise::Precise::stringDivPrec(&Value::Str("1".into()), &customInitialMarginRate, &Value::Int(4)));
}
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_k(position.clone(), "id", &[]));
m.insert("symbol".to_string(), symbol);
m.insert("entryPrice".to_string(), self.safe_number_k(position, "entryPrice", &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("notional".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), Value::Null);
m.insert("side".to_string(), side.map(Value::from).unwrap_or(Value::Null));
m.insert("contracts".to_string(), self.parse_number(quantity.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::from(timestamp));
m.insert("datetime".to_string(), self.iso8601(Value::from(timestamp)));
m.insert("hedged".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), leverage);
m.insert("liquidationPrice".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
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 baseApiUrl: Option<String> = self.safe_string_opt(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), apiName.clone(), &[]);
if (baseApiUrl.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.implode_hostname(baseApiUrl.map(Value::from).unwrap_or(Value::Null)), Value::Str("/".into())).into()), path).into());
let mut headersValue: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("User-Agent".to_string(), Value::Str("apex-CCXT".into()));
m.insert("Accept".to_string(), Value::Str("application/json".into()));
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".into()));
m
});
let mut signPath: Value = Value::Str(format!("{}{}", Value::Str("/api/".into()), path).into());
let mut signBody: Value = Value::Null;
if ((if let Some(__s) = method.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }).as_str() != Some("POST")) {
if ((Value::Array(params.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).len() as i64) as f64) > ((0i64) as f64) {
signPath = Value::Str(format!("{}{}", signPath, Value::Str(format!("{}{}", Value::Str("?".into()), self.rawencode(params.clone(), &[])).into())).into());
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), self.rawencode(params.clone(), &[])).into())).into());
}
} else {
let mut sortedQuery: Value = self.keysort(params, &[]);
signBody = self.rawencode(sortedQuery, &[]);
}
if (apiName.as_str() == Some("private")) {
self.check_required_credentials(&[]);
let mut timestamp: Value = Value::Str(format!("{}", self.milliseconds()).into());
let mut messageString: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", timestamp, (if let Some(__s) = method.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null })).into()), signPath).into());
if (signBody != Value::Null) {
messageString = Value::Str(format!("{}{}", messageString, signBody).into());
}
let mut signature: Value = self.hmac(self.encode(messageString), self.encode(self.string_to_base64(self.secret.clone(), &[])), Value::Str("sha256".into()), &[Value::Str("base64".into())]);
headersValue.insert("APEX-SIGNATURE".into(), signature);
headersValue.insert("APEX-API-KEY".into(), self.apiKey.clone());
headersValue.insert("APEX-TIMESTAMP".into(), timestamp);
headersValue.insert("APEX-PASSPHRASE".into(), self.password.clone());
}
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(), signBody);
m.insert("headers".to_string(), Value::Map(headersValue));
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
let mut errorCode: Option<i64> = self.safe_integer_k(response.clone(), "code", &[]).as_i64();
if (errorCode.is_some()) && (errorCode != Some(0)) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
let mut message: Option<String> = self.safe_string2_opt(response, Value::Str("key".into()), Value::Str("msg".into()), &[]);
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());
let mut status: Value = Value::Str(format!("{}", code).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), status, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}