// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
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);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for ApexCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_position(self, position, &[market.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_account(self, account)
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::parse_income(self, info, &[market.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on ApexCore.
ApexCore::sign(self, path, &[api.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
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 {
// Forward to the inherent method on ApexCore.
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 {
"add_hyphen_before_usdt" => self.add_hyphen_before_usdt(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).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.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_account" => self.fetch_account(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"generate_random_client_id_omni" => self.generate_random_client_id_omni(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"get_account_id" => self.get_account_id().await,
"get_seeds" => self.get_seeds(),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type" => self.parse_order_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_time_in_force" => self.parse_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"safe_market" => self.safe_market(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(4..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => 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".to_string()));
m.insert("name".to_string(), Value::Str("Apex".to_string()));
m.insert("countries".to_string(), Value::List(vec![]));
m.insert("version".to_string(), Value::Str("v3".to_string()));
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(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("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(true));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
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".to_string()));
m.insert("5m".to_string(), Value::Str("5".to_string()));
m.insert("15m".to_string(), Value::Str("15".to_string()));
m.insert("30m".to_string(), Value::Str("30".to_string()));
m.insert("1h".to_string(), Value::Str("60".to_string()));
m.insert("2h".to_string(), Value::Str("120".to_string()));
m.insert("4h".to_string(), Value::Str("240".to_string()));
m.insert("6h".to_string(), Value::Str("360".to_string()));
m.insert("12h".to_string(), Value::Str("720".to_string()));
m.insert("1d".to_string(), Value::Str("D".to_string()));
m.insert("1w".to_string(), Value::Str("W".to_string()));
m.insert("1M".to_string(), Value::Str("M".to_string()));
m
}));
m.insert("hostname".to_string(), Value::Str("omni.apex.exchange".to_string()));
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".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://{hostname}/api".to_string()));
m.insert("private".to_string(), Value::Str("https://{hostname}/api".to_string()));
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".to_string()));
m.insert("private".to_string(), Value::Str("https://testnet.omni.apex.exchange/api".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://apex.exchange/".to_string()));
m.insert("doc".to_string(), Value::Str("https://api-docs.omni.apex.exchange".to_string()));
m.insert("fees".to_string(), Value::Str("https://apex-pro.gitbook.io/apex-pro/apex-omni-live-now/trading-perpetual-contracts/trading-fees".to_string()));
m.insert("referral".to_string(), Value::Str("https://omni.apex.exchange/trade".to_string()));
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
}));
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
}));
m
}));
m
}));
m.insert("httpExceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("403".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
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".to_string()));
m.insert("20016".to_string(), Value::Str("request para error".to_string()));
m.insert("10001".to_string(), Value::Str("BadRequest".to_string()).clone());
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".to_string()).clone());
m.insert("ORDER_POSSIBLE_LEAD_TO_ACCOUNT_LIQUIDATED".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_WITH_THIS_PRICE_CANNOT_REDUCE_POSITION_ONLY".to_string(), Value::Str("InvalidOrder".to_string()).clone());
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".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
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".to_string()));
m.insert("brokerId".to_string(), Value::Str("6956".to_string()));
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".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name apex#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-system-time-v3
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
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.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_integer_k(data.clone(), "time", &[]);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
//
// {
// "totalEquityValue": "100.000000",
// "availableBalance": "100.000000",
// "initialMargin": "100.000000",
// "maintenanceMargin": "100.000000",
// "symbolToOraclePrice": {
// "BTC-USDC": {
// "oraclePrice": "20000",
// "createdTime": 124566
// }
// }
// }
//
let mut timestamp: Value = self.milliseconds();
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
let mut code: Value = Value::Str("USDT".to_string());
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(response.clone(), "availableBalance", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(response.clone(), "totalEquityValue", &[]));
add_element_to_object(&mut result, &code, account.clone());
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name apex#fetchBalance
* @description query for account info
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-retrieve-user-account-balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_account_balance(&[params.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_balance(data.clone());
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".to_string())]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), accountId.clone());
m.insert("type".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), account.clone());
m
});
Value::Null
}
/*
* @method
* @name apex#fetchAccount
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-retrieve-user-account-data
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_account(&[params.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_account(data.clone());
Value::Null
}
/*
* @method
* @name apex#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-all-config-data-v3
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
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.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotConfig: Value = self.safe_dict_k(data.clone(), "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
})]);
// "spotConfig": {
// "assets": [
// {
// "tokenId": "141",
// "token": "USDT",
// "displayName": "Tether USD Coin",
// "decimals": 18,
// "showStep": "0.01",
// "iconUrl": "https://static-omni.apex.exchange/chains/chain_tokens/Ethereum/Ethereum_USDT.svg",
// "l2WithdrawFee": "0",
// "enableCollateral": true,
// "enableCrossCollateral": false,
// "crossCollateralDiscountRate": null,
// "isGray": false
// }
// ],
// "multiChain": {
// "chains": [
// {
// "chain": "Arbitrum One",
// "chainId": "9",
// "chainType": "0",
// "l1ChainId": "42161",
// "chainIconUrl": "https://static-omni.apex.exchange/chains/chain_logos/Arbitrum.svg",
// "contractAddress": "0x3169844a120c0f517b4eb4a750c08d8518c8466a",
// "swapContractAddress": "0x9e07b6Aef1bbD9E513fc2Eb8873e311E80B4f855",
// "stopDeposit": false,
// "feeLess": false,
// "gasLess": false,
// "gasToken": "ETH",
// "dynamicFee": true,
// "gasTokenDecimals": 18,
// "feeGasLimit": 300000,
// "blockTimeSeconds": 2,
// "rpcUrl": "https://arb.omni.apex.exchange",
// "minSwapUsdtAmount": "",
// "maxSwapUsdtAmount": "",
// "webRpcUrl": "https://arb.omni.apex.exchange",
// "webTxUrl": "https://arbiscan.io/tx/",
// "backupRpcUrl": "https://arb-mainnet.g.alchemy.com/v2/rGlYUbRHtUav5mfeThCPtsV9GLPt2Xq5",
// "txConfirm": 20,
// "withdrawGasFeeLess": false,
// "tokens": [
// {
// "decimals": 6,
// "iconUrl": "https://static-omni.apex.exchange/chains/chain_tokens/Arbitrum/Arbitrum_USDT.svg",
// "token": "USDT",
// "tokenAddress": "0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9",
// "pullOff": false,
// "withdrawEnable": true,
// "slippage": "",
// "isDefaultToken": false,
// "displayToken": "USDT",
// "needResetApproval": true,
// "minFee": "2",
// "maxFee": "40",
// "feeRate": "0.0001",
// "maxWithdraw": "",
// "minDeposit": "",
// "minWithdraw": "",
// "maxFastWithdrawAmount": "40000",
// "minFastWithdrawAmount": "1",
// "isGray": false
// },
// {
// "decimals": 6,
// "iconUrl": "https://static-omni.apex.exchange/chains/chain_tokens/Arbitrum/Arbitrum_USDC.svg",
// "token": "USDC",
// "tokenAddress": "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
// "pullOff": false,
// "withdrawEnable": true,
// "slippage": "",
// "isDefaultToken": false,
// "displayToken": "USDC",
// "needResetApproval": true,
// "minFee": "2",
// "maxFee": "20",
// "feeRate": "0.0001",
// "maxWithdraw": "",
// "minDeposit": "",
// "minWithdraw": "",
// "maxFastWithdrawAmount": "1",
// "minFastWithdrawAmount": "1",
// "isGray": false
// }
// ]
// }
// ]
// }
let mut rows: Value = self.safe_list_k(spotConfig.clone(), "assets", &[Value::List(vec![])]);
let mut chains: Value = self.safe_list_k(multiChain.clone(), "chains", &[Value::List(vec![])]);
add_element_to_object(&mut self.options, &Value::Str("_temp_currencies_chains".to_string()), chains.clone());
let mut result: Value = self.parse_currencies(rows.clone());
remove(&mut self.options, &Value::Str("_temp_currencies_chains".to_string()));
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: Value = self.safe_string_k(currency.clone(), "displayName", &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut chains: Value = get_value(&self.options, &Value::Str("_temp_currencies_chains".to_string()));
{
let mut j: Value = Value::Int(0);
let mut __for_first_217: bool = true;
while { if !__for_first_217 { j = add(&j, &Value::Int(1)); } __for_first_217 = false; is_less_than(&j, &get_array_length(&chains)) } {
let mut chain: Value = get_value(&chains, &j);
let mut chain: Value = get_value(&chains, &j);
let mut tokens: Value = self.safe_list_k(chain.clone(), "tokens", &[Value::List(vec![])]);
{
let mut f: Value = Value::Int(0);
let mut __for_first_216: bool = true;
while { if !__for_first_216 { f = add(&f, &Value::Int(1)); } __for_first_216 = false; is_less_than(&f, &get_array_length(&tokens)) } {
let mut token: Value = get_value(&tokens, &f);
let mut token: Value = get_value(&tokens, &f);
let mut tokenName: Value = self.safe_string_k(token.clone(), "token", &[]);
if is_equal(&tokenName, ¤cyId) {
let mut networkId: Value = self.safe_string_k(chain.clone(), "chainId", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool((!is_equal(&self.safe_bool_k(chain.clone(), "depositDisable", &[]), &Value::Bool(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.clone(), "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: Value = object_keys(&networks);
let mut networksLength: Value = get_array_length(&networkKeys);
let mut emptyChains: bool = is_equal(&networksLength, &Value::Int(0)); // non-functional coins
let mut valueForEmpty: Value = ternary(is_true(&emptyChains), Value::Bool(false), Value::Null);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), currency.clone());
m.insert("code".to_string(), code.clone());
m.insert("id".to_string(), currencyId.clone());
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m.insert("name".to_string(), name.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), valueForEmpty.clone());
m.insert("withdraw".to_string(), valueForEmpty.clone());
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(), networks.clone());
m
}));
Value::Null
}
/*
* @method
* @name apex#fetchMarkets
* @description retrieves data on all markets for apex
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-all-config-data-v3
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
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.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractConfig: Value = self.safe_dict_k(data.clone(), "contractConfig", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut perpetualContract: Value = self.safe_list_k(contractConfig.clone(), "perpetualContract", &[Value::List(vec![])]);
return self.parse_markets(perpetualContract.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut id2: Value = self.safe_string_k(market.clone(), "crossSymbolName", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "l2PairId", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseTokenId", &[]);
let mut quote: Value = self.safe_string_k(market.clone(), "settleAssetId", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "settleAssetId", &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut symbol: Value = add(&add(&add(&add(&baseId, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
let mut expiry: Value = Value::Int(0);
let mut takerFee: Value = self.parse_number(Value::Str("0.0002".to_string()), &[]);
let mut makerFee: Value = self.parse_number(Value::Str("0.0005".to_string()), &[]);
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("id2".to_string(), id2.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), Value::Str("swap".to_string()));
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.clone());
m.insert("maker".to_string(), makerFee.clone());
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "minOrderSize", &[]));
m.insert("expiry".to_string(), ternary(is_true(&(is_equal(&expiry, &Value::Int(0)))), Value::Null, expiry.clone()));
m.insert("expiryDatetime".to_string(), ternary(is_true(&(is_equal(&expiry, &Value::Int(0)))), Value::Null, self.iso8601(expiry.clone())));
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.clone());
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);
//
// {
// "symbol": "BTCUSDT",
// "price24hPcnt": "0.450141",
// "lastPrice": "43511.50",
// "highPrice24h": "43513.50",
// "lowPrice24h": "29996.00",
// "markPrice": "43513.50",
// "indexPrice": "40828.94",
// "openInterest": "2036854775808",
// "turnover24h": "5626085.23749999",
// "volume24h": "169.317",
// "fundingRate": "0",
// "predictedFundingRate": "0",
// "nextFundingTime": "10:00:00",
// "tradeCount": 100
// }
//
let mut timestamp: Value = self.milliseconds();
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut last: Value = self.safe_string_k(ticker.clone(), "lastPrice", &[]);
let mut percentage: Value = self.safe_string_k(ticker.clone(), "price24hPcnt", &[]);
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "turnover24h", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "volume24h", &[]);
let mut high: Value = self.safe_string_k(ticker.clone(), "highPrice24h", &[]);
let mut low: Value = self.safe_string_k(ticker.clone(), "lowPrice24h", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), high.clone());
m.insert("low".to_string(), low.clone());
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());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), percentage.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
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.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-ticker-data-v3
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
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(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v3_ticker(&[__ws_arg_0]).await;
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rawTicker: Value = self.safe_dict(tickers.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(rawTicker.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchTickers
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-ticker-data-v3
* @param {string} symbols unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.public_get_v3_data_all_ticker_info(&[params.clone()]).await;
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_tickers(tickers.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-candlestick-chart-data-v3
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
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".to_string()));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
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
});
if is_equal(&limit, &Value::Null) {
limit = Value::Int(200); // default is 200 when requested with `since`
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // max 200, default 200
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[Value::Float(0.001)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), math_floor(÷(&since, &Value::Int(1000))));
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v3_klines(&[__ws_arg_1]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut OHLCVs: Value = self.safe_list(data.clone(), self.safe_string_k(market.clone(), "id2", &[]), &[Value::List(vec![])]);
return self.parse_ohlc_vs(OHLCVs.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
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::List(vec![self.safe_integer2(ohlcv.clone(), Value::Str("start".to_string()), Value::Str("t".to_string()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("open".to_string()), Value::Str("o".to_string()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("high".to_string()), Value::Str("h".to_string()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("low".to_string()), Value::Str("l".to_string()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("close".to_string()), Value::Str("c".to_string()), &[]), self.safe_number2(ohlcv.clone(), Value::Str("volume".to_string()), Value::Str("v".to_string()), &[])]);
Value::Null
}
/*
* @method
* @name apex#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-market-depth-v3
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id2", &[]));
m
});
if is_equal(&limit, &Value::Null) {
limit = Value::Int(100); // default is 200 when requested with `since`
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // max 100, default 100
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v3_depth(&[__ws_arg_2]).await;
//
// {
// "a": [
// [
// "96576.3",
// "0.399"
// ],
// [
// "96577.6",
// "0.106"
// ]
// ],
// "b": [
// [
// "96565.2",
// "0.131"
// ],
// [
// "96565.1",
// "0.038"
// ]
// ],
// "s": "BTCUSDT",
// "u": 18665465
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.milliseconds();
let mut orderbook: Value = self.parse_order_book(data.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone(), Value::Str("b".to_string()), Value::Str("a".to_string())]);
add_element_to_object(&mut orderbook, &Value::Str("nonce".to_string()), self.safe_integer_k(data.clone(), "u", &[]));
return orderbook;
Value::Null
}
/*
* @method
* @name apex#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-newest-trading-data-v3
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id2", &[]));
m
});
if is_equal(&limit, &Value::Null) {
limit = Value::Int(500); // default is 50
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v3_trades(&[__ws_arg_3]).await;
//
// [
// {
// "i": "993f7f85-9215-5723-9078-2186ae140847",
// "p": "96534.3",
// "S": "Sell",
// "v": "0.261",
// "s": "BTCUSDT",
// "T": 1739118072710
// },
// {
// "i": "c947c9cf-8c18-5784-89c3-91bdf86ddde8",
// "p": "96513.5",
// "S": "Sell",
// "v": "0.042",
// "s": "BTCUSDT",
// "T": 1739118075944
// }
// ]
//
let mut trades: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// {
// "i": "993f7f85-9215-5723-9078-2186ae140847",
// "p": "96534.3",
// "S": "Sell",
// "v": "0.261",
// "s": "BTCUSDT",
// "T": 1739118072710
// }
// ]
//
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("s".to_string()), Value::Str("symbol".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut id: Value = self.safe_string2(trade.clone(), Value::Str("i".to_string()), Value::Str("id".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_n(trade.clone(), Value::List(vec![Value::Str("t".to_string()), Value::Str("T".to_string()), Value::Str("createdAt".to_string())]), &[]);
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("p".to_string()), Value::Str("price".to_string()), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("v".to_string()), Value::Str("size".to_string()), &[]);
let mut side: Value = self.safe_string_lower2(trade.clone(), Value::Str("S".to_string()), Value::Str("side".to_string()), &[]);
let mut type_var: Value = self.safe_string_k(trade.clone(), "type", &[]);
let mut fee: Value = self.safe_string_k(trade.clone(), "fee", &[]);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), id.clone());
m.insert("order".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("takerOrMaker".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchOpenInterest
* @description retrieves the open interest of a contract trading pair
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-ticker-data-v3
* @param {string} symbol unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @returns {object} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
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(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v3_ticker(&[__ws_arg_4]).await;
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rawTicker: Value = self.safe_dict(tickers.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_open_interest(rawTicker.clone(), &[market.clone()]);
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);
//
// {
// "symbol": "BTCUSDT",
// "price24hPcnt": "0.450141",
// "lastPrice": "43511.50",
// "highPrice24h": "43513.50",
// "lowPrice24h": "29996.00",
// "markPrice": "43513.50",
// "indexPrice": "40828.94",
// "openInterest": "2036854775808",
// "turnover24h": "5626085.23749999",
// "volume24h": "169.317",
// "fundingRate": "0",
// "predictedFundingRate": "0",
// "nextFundingTime": "10:00:00",
// "tradeCount": 100
// }
//
let mut timestamp: Value = self.milliseconds();
let mut marketId: Value = self.safe_string_k(interest.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("openInterestAmount".to_string(), self.safe_string_k(interest.clone(), "openInterest", &[]));
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://api-docs.omni.apex.exchange/#publicapi-v3-for-omni-get-funding-rate-history-v3
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest funding rate
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("beginTimeInclusive".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut page: Value = self.safe_integer_k(params.clone(), "page", &[]);
if !is_equal(&page, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page".to_string()), page.clone());
}
let mut endTimeExclusive: Value = self.safe_integer_n(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("endTimeExclusive".to_string()), Value::Str("until".to_string())]), &[]);
if !is_equal(&endTimeExclusive, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTimeExclusive".to_string()), endTimeExclusive.clone());
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v3_history_funding(&[__ws_arg_5]).await;
//
// {
// "historyFunds": [
// {
// "symbol": "BTC-USD",
// "rate": "0.0000125000",
// "price": "31297.5000008009374142",
// "fundingTime": 12315555,
// "fundingTimestamp": 12315555
// }
// ],
// "totalSize": 11
// }
//
let mut rates: Value = Value::List(vec![]);
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut resultList: Value = self.safe_list_k(data.clone(), "historyFunds", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_218: bool = true;
while { if !__for_first_218 { i = add(&i, &Value::Int(1)); } __for_first_218 = false; is_less_than(&i, &get_array_length(&resultList)) } {
let mut entry: Value = get_value(&resultList, &i);
let mut entry: Value = get_value(&resultList, &i);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "fundingTimestamp", &[]);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
append_to_array(&mut rates, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "rate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": "1234",
// "clientId": "1234",
// "accountId": "12345",
// "symbol": "BTC-USD",
// "side": "SELL",
// "price": "18000",
// "limitFee": "100",
// "fee": "100",
// "triggerPrice": "1.2",
// "trailingPercent": "0.12",
// "size": "100",
// "remainingSize": "100",
// "type": "LIMIT",
// "createdAt": 1647502440973,
// "updatedTime": 1647502440973,
// "expiresAt": 1647502440973,
// "status": "PENDING",
// "timeInForce": "GOOD_TIL_CANCEL",
// "postOnly": false,
// "reduceOnly": false,
// "stopPnl": false,
// "latestMatchFillPrice": "reason",
// "cumMatchFillSize": "0.1",
// "cumMatchFillValue": "1000",
// "cumMatchFillFee": "1",
// "cumSuccessFillSize": "0.1",
// "cumSuccessFillValue": "1000",
// "cumSuccessFillFee": "1",
// "triggerPriceType": "INDEX",
// "isOpenTpslOrder": true,
// "isSetOpenTp": true,
// "isSetOpenSl": false,
// "openTpParam": {
// "side": "SELL",
// "price": "18000",
// "limitFee": "100",
// "clientOrderId": "111100",
// "triggerPrice": "1.2",
// "trailingPercent": "0.12",
// "size": "100"
// },
// "openSlParam": {
// "side": "SELL",
// "price": "18000",
// "limitFee": "100",
// "clientOrderId": "111100",
// "triggerPrice": "1.2",
// "trailingPercent": "0.12",
// "size": "100"
// }
// }
//
let mut timestamp: Value = self.safe_integer_k(order.clone(), "createdAt", &[]);
let mut orderId: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "clientId", &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut price: Value = self.safe_string_k(order.clone(), "price", &[]);
let mut amount: Value = self.safe_string_k(order.clone(), "size", &[]);
let mut orderType: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut status: Value = self.safe_string_k(order.clone(), "status", &[]);
let mut side: Value = self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]);
// const average = this.omitZero (this.safeString (order, 'avg_fill_price'));
let mut remaining: Value = self.omit_zero(self.safe_string_k(order.clone(), "remainingSize", &[]));
let mut lastUpdateTimestamp: Value = self.safe_integer_k(order.clone(), "updatedTime", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.clone());
m.insert("status".to_string(), self.parse_order_status(status.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), self.parse_order_type(orderType.clone()));
m.insert("timeInForce".to_string(), self.parse_time_in_force(self.safe_string_k(order.clone(), "timeInForce", &[])));
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.clone());
m.insert("price".to_string(), price.clone());
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.clone());
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), remaining.clone());
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(), get_value(&market, &Value::Str("settleId".to_string())));
m
}));
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GOOD_TIL_CANCEL".to_string(), Value::Str("GOOD_TIL_CANCEL".to_string()));
m.insert("FILL_OR_KILL".to_string(), Value::Str("FILL_OR_KILL".to_string()));
m.insert("IMMEDIATE_OR_CANCEL".to_string(), Value::Str("IMMEDIATE_OR_CANCEL".to_string()));
m.insert("POST_ONLY".to_string(), Value::Str("POST_ONLY".to_string()));
m
});
return self.safe_string(timeInForces.clone(), timeInForce.clone(), &[]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
if !is_equal(&status, &Value::Null) {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("PENDING".to_string(), Value::Str("open".to_string()));
m.insert("OPEN".to_string(), Value::Str("open".to_string()));
m.insert("FILLED".to_string(), Value::Str("filled".to_string()));
m.insert("CANCELING".to_string(), Value::Str("canceled".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("UNTRIGGERED".to_string(), Value::Str("open".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
}
return status;
Value::Null
}
pub fn parse_order_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("MARKET".to_string(), Value::Str("market".to_string()));
m.insert("STOP_LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("STOP_MARKET".to_string(), Value::Str("market".to_string()));
m.insert("TAKE_PROFIT_LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("TAKE_PROFIT_MARKET".to_string(), Value::Str("market".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
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);
if is_equal(&market, &Value::Null) && !is_equal(&marketId, &Value::Null) {
let mut marketsMap: Value = self.markets.clone();
let mut marketsById: Value = self.markets_by_id.clone();
if is_true(&(!is_equal(&marketsMap, &Value::Null))) && is_true(&(Value::Bool(in_op(&marketsMap, &marketId)))) {
market = get_value(&marketsMap, &marketId);
} else if is_true(&(!is_equal(&marketsById, &Value::Null))) && is_true(&(Value::Bool(in_op(&marketsById, &marketId)))) {
market = get_value(&marketsById, &marketId);
} else {
let mut newMarketId: Value = self.add_hyphen_before_usdt(marketId.clone());
if is_true(&(!is_equal(&marketsById, &Value::Null))) && is_true(&(Value::Bool(in_op(&marketsById, &newMarketId)))) {
let mut markets: Value = get_value(&marketsById, &newMarketId);
let mut markets: Value = get_value(&marketsById, &newMarketId);
let mut numMarkets: Value = get_array_length(&markets);
if is_greater_than(&numMarkets, &Value::Int(0)) {
if is_equal(&get_value(&get_value(&get_value(&marketsById, &newMarketId), &Value::Int(0)), &Value::Str("id2".to_string())), &marketId) {
market = get_value(&get_value(&marketsById, &newMarketId), &Value::Int(0));
}
}
}
}
}
return self.super_safe_market(marketId.clone(), market.clone(), delimiter.clone(), marketType.clone());
Value::Null
}
pub fn generate_random_client_id_omni(&self, mut _accountId: Value) -> Value {
let mut hasAccountId: bool = is_true(&(!is_equal(&_accountId, &Value::Null))) && is_true(&(!is_equal(&_accountId, &Value::Str("".to_string()))));
let mut accountId: Value = ternary(is_true(&hasAccountId), _accountId.clone(), to_string_val(&self.rand_number(Value::Int(12))));
return add(&add(&add(&add(&add(&Value::Str("apexomni-".to_string()), &accountId), &Value::Str("-".to_string())), &to_string_val(&self.milliseconds())), &Value::Str("-".to_string())), &to_string_val(&self.rand_number(Value::Int(6))));
Value::Null
}
pub fn add_hyphen_before_usdt(&self, mut symbol: Value) -> Value {
let mut uppercaseSymbol: Value = to_upper(&symbol);
let mut index: Value = get_index_of(&uppercaseSymbol, &Value::Str("USDT".to_string()));
let mut symbolChar: Value = self.safe_string(symbol.clone(), subtract(&index, &Value::Int(1)), &[]);
if is_greater_than(&index, &Value::Int(0)) && !is_equal(&symbolChar, &Value::Str("-".to_string())) {
return add(&add(&slice(&symbol, &Value::Int(0), &index), &Value::Str("-".to_string())), &slice(&symbol, &index, &Value::Null));
}
return symbol;
Value::Null
}
pub fn get_seeds(&self) -> Value {
let mut seeds: Value = self.safe_string_k(self.options.clone(), "seeds", &[]);
if is_equal(&seeds, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &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".to_string()))));
}
return seeds;
Value::Null
}
pub async fn get_account_id(&mut self) -> Value {
let mut accountId: Value = self.safe_string_k(self.options.clone(), "accountId", &[Value::Str("0".to_string())]);
if is_equal(&accountId, &Value::Str("0".to_string())) {
let mut accountData: Value = self.fetch_account(&[]).await;
{ let __be_tmp = self.safe_string_k(accountData.clone(), "id", &[Value::Str("0".to_string())]); add_element_to_object(&mut self.options, &Value::Str("accountId".to_string()), __be_tmp); };
}
return get_value(&self.options, &Value::Str("accountId".to_string()));
Value::Null
}
/*
* @method
* @name apex#createOrder
* @description create a trade order
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-post-creating-orders
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price a trigger order is triggered at
* @param {float} [params.stopLossPrice] The price a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] The price a take profit order is triggered at
* @param {string} [params.timeInForce] "GTC", "IOC", or "POST_ONLY"
* @param {bool} [params.postOnly] true or false
* @param {bool} [params.reduceOnly] Ensures that the executed order does not flip the opened position.
* @param {string} [params.clientOrderId] a unique id for the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut orderType: Value = to_upper(&type_var);
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a side argument".to_string()))));
}
let mut orderSide: Value = to_upper(&side);
let mut orderSize: Value = self.amount_to_precision(symbol.clone(), amount.clone());
let mut orderPrice: Value = Value::Str("0".to_string());
if !is_equal(&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".to_string())]);
let mut maker: Value = self.safe_string_k(fees.clone(), "maker", &[Value::Str("0.0002".to_string())]);
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(get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("price".to_string())))), Value::Int(crate::runtime::TRUNCATE), get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("price".to_string())), &[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: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
if !is_equal(&stopLossPrice, &Value::Null) {
orderType = ternary(is_true(&(is_equal(&orderType, &Value::Str("MARKET".to_string())))), Value::Str("STOP_MARKET".to_string()), Value::Str("STOP_LIMIT".to_string()));
triggerPrice = stopLossPrice.clone();
} else if !is_equal(&takeProfitPrice, &Value::Null) {
orderType = ternary(is_true(&(is_equal(&orderType, &Value::Str("MARKET".to_string())))), Value::Str("TAKE_PROFIT_MARKET".to_string()), Value::Str("TAKE_PROFIT_LIMIT".to_string()));
triggerPrice = takeProfitPrice.clone();
}
let mut isMarket: Value = Value::Bool(is_equal(&orderType, &Value::Str("MARKET".to_string())));
if is_true(&isMarket) && is_true(&(is_equal(&price, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a price argument for market orders".to_string()))));
}
let mut timeInForce: Value = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[]);
let mut postOnly: Value = self.is_post_only(isMarket.clone(), Value::Null, &[params.clone()]);
if is_equal(&timeInForce, &Value::Null) {
timeInForce = Value::Str("GOOD_TIL_CANCEL".to_string());
}
if !is_true(&isMarket) {
if is_true(&postOnly) {
timeInForce = Value::Str("POST_ONLY".to_string());
} else if is_equal(&timeInForce, &Value::Str("ioc".to_string())) {
timeInForce = Value::Str("IMMEDIATE_OR_CANCEL".to_string());
}
}
params = self.omit(params.clone(), Value::Str("timeInForce".to_string()), &[]);
params = self.omit(params.clone(), Value::Str("postOnly".to_string()), &[]);
let mut clientOrderId: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
let mut accountId: Value = self.get_account_id().await;
if is_equal(&clientOrderId, &Value::Null) {
clientOrderId = self.generate_random_client_id_omni(accountId.clone());
}
let mut finalClientOrderId: Value = clientOrderId.clone(); // java req
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("triggerPrice".to_string())]), &[]);
let mut finalOrderPrice: Value = orderPrice.clone(); // java req
let mut orderToSign: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountId".to_string(), accountId.clone());
m.insert("slotId".to_string(), finalClientOrderId.clone());
m.insert("nonce".to_string(), finalClientOrderId.clone());
m.insert("pairId".to_string(), get_value(&market, &Value::Str("quoteId".to_string())));
m.insert("size".to_string(), orderSize.clone());
m.insert("price".to_string(), finalOrderPrice.clone());
m.insert("direction".to_string(), orderSide.clone());
m.insert("makerFeeRate".to_string(), maker.clone());
m.insert("takerFeeRate".to_string(), taker.clone());
m
});
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut orderToSign, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
}
let mut signature: Value = self.get_zk_contract_signature_obj(self.remove0x_prefix(self.get_seeds()), &[orderToSign.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), orderSide.clone());
m.insert("type".to_string(), orderType.clone());
m.insert("size".to_string(), orderSize.clone());
m.insert("price".to_string(), finalOrderPrice.clone());
m.insert("limitFee".to_string(), limitFee.clone());
m.insert("expiration".to_string(), math_floor(&add(÷(&timeNow, &Value::Int(1000)), &multiply(&multiply(&multiply(&Value::Int(30), &Value::Int(24)), &Value::Int(60)), &Value::Int(60)))));
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("clientId".to_string(), finalClientOrderId.clone());
m.insert("brokerId".to_string(), self.safe_string_k(self.options.clone(), "brokerId", &[Value::Str("6956".to_string())]));
m
});
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
}
add_element_to_object(&mut request, &Value::Str("signature".to_string()), signature.clone());
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v3_order(&[__ws_arg_6]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name apex#transfer
* @description transfer currency internally between wallets on the same account
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.transferId] UUID, which is unique across the platform
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
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 is_equal(&self.markets, &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.clone(), "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 contractAssets: Value = self.safe_list_k(contractConfig.clone(), "assets", &[Value::List(vec![])]);
let mut spotConfig: Value = self.safe_dict_k(configData.clone(), "spotConfig", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotAssets: Value = self.safe_list_k(spotConfig.clone(), "assets", &[Value::List(vec![])]);
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("".to_string())]);
let mut receiverZkAccountId: Value = self.safe_string_k(globalConfig.clone(), "contractAssetPoolZkAccountId", &[Value::Str("".to_string())]);
let mut receiverSubAccountId: Value = self.safe_string_k(globalConfig.clone(), "contractAssetPoolSubAccount", &[Value::Str("".to_string())]);
let mut receiverAccountId: Value = self.safe_string_k(globalConfig.clone(), "contractAssetPoolAccountId", &[Value::Str("".to_string())]);
let mut accountResponse: Value = self.private_get_v3_account(&[params.clone()]).await;
let mut accountData: Value = self.safe_dict_k(accountResponse.clone(), "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("".to_string())]);
let mut subAccountId: Value = self.safe_string_k(spotAccount.clone(), "defaultSubAccountId", &[Value::Str("0".to_string())]);
let mut subAccounts: Value = self.safe_list_k(spotAccount.clone(), "subAccounts", &[Value::List(vec![])]);
let mut nonce: Value = Value::Str("0".to_string());
if is_greater_than(&get_array_length(&subAccounts), &Value::Int(0)) {
nonce = self.safe_string(get_value(&subAccounts, &Value::Int(0)), Value::Str("nonce".to_string()), &[Value::Str("0".to_string())]);
}
let mut finalNonce: Value = nonce.clone(); // java req
let mut ethAddress: Value = self.safe_string_k(accountData.clone(), "ethereumAddress", &[Value::Str("".to_string())]);
let mut accountId: Value = self.safe_string_k(accountData.clone(), "id", &[Value::Str("".to_string())]);
let mut currency: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut assets: Value = Value::List(vec![]);
if !is_equal(&fromAccount, &Value::Null) && is_equal(&to_lower(&fromAccount), &Value::Str("contract".to_string())) {
assets = contractAssets.clone();
} else {
assets = spotAssets.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_219: bool = true;
while { if !__for_first_219 { i = add(&i, &Value::Int(1)); } __for_first_219 = false; is_less_than(&i, &get_array_length(&assets)) } {
if is_equal(&self.safe_string_k(get_value(&assets, &i), "token", &[Value::Str("".to_string())]), &code) {
currency = get_value(&assets, &i);
}
}
}
let mut tokenId: Value = self.safe_string_k(currency.clone(), "tokenId", &[Value::Str("".to_string())]);
let mut decimalsNum: Value = self.safe_number_k(currency.clone(), "decimals", &[Value::Int(0)]);
let mut decimalsNumber: Value = ternary(is_true(&(is_equal(&decimalsNum, &Value::Null))), Value::Int(0), decimalsNum.clone());
let mut mathPowResult: Value = (crate::runtime::Math::pow(&Value::Int(10), &decimalsNumber));
let mut amountNumber: Value = self.parse_to_int(multiply(&amount, &mathPowResult));
let mut timestampSeconds: Value = self.parse_to_int(divide(&self.milliseconds(), &Value::Int(1000)));
let mut clientOrderId: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
if is_equal(&clientOrderId, &Value::Null) {
clientOrderId = self.generate_random_client_id_omni(self.safe_string_k(self.options.clone(), "accountId", &[]));
}
let mut finalClientOrderId: Value = clientOrderId.clone(); // java req
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
if !is_equal(&fromAccount, &Value::Null) && is_equal(&to_lower(&fromAccount), &Value::Str("contract".to_string())) {
let mut formattedUint32: Value = Value::Str("4294967295".to_string());
let mut zkSignAccountId: Value = crate::precise::Precise::stringMod(&accountId, &formattedUint32);
let mut expireTime: Value = add(×tampSeconds, &multiply(&multiply(&Value::Int(3600), &Value::Int(24)), &Value::Int(28)));
let mut orderToSign: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("zkAccountId".to_string(), zkSignAccountId.clone());
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(), to_string_val(&amountNumber));
m.insert("fee".to_string(), Value::Str("0".to_string()));
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()), &[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.clone());
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.clone());
m
});
let __ws_arg_7 = self.extend(request.clone(), &[params.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.clone());
m.insert("fromAccount".to_string(), Value::Str("contract".to_string()));
m.insert("toAccount".to_string(), Value::Str("spot".to_string()));
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(), to_string_val(&amountNumber));
m.insert("fee".to_string(), Value::Str("0".to_string()));
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()), &[orderToSign.clone()]).await;
let mut amountStr: Value = to_string_val(&amount);
let mut ts: Value = timestampSeconds.clone(); // java req
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amountStr.clone());
m.insert("timestamp".to_string(), ts.clone());
m.insert("clientTransferId".to_string(), finalClientOrderId.clone());
m.insert("signature".to_string(), signature.clone());
m.insert("zkAccountId".to_string(), zkAccountId.clone());
m.insert("subAccountId".to_string(), subAccountId.clone());
m.insert("fee".to_string(), Value::Str("0".to_string()));
m.insert("token".to_string(), code.clone());
m.insert("tokenId".to_string(), tokenId.clone());
m.insert("receiverAccountId".to_string(), receiverAccountId.clone());
m.insert("receiverZkAccountId".to_string(), receiverZkAccountId.clone());
m.insert("receiverSubAccountId".to_string(), receiverSubAccountId.clone());
m.insert("receiverAddress".to_string(), receiverAddress.clone());
m.insert("nonce".to_string(), finalNonce.clone());
m
});
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v3_transfer_out(&[__ws_arg_10]).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 __ws_arg_11 = self.parse_transfer(data.clone(), &[self.currency(code.clone())]);
let __ws_arg_12 = self.iso8601(currentTime.clone());
let __ws_arg_13 = self.parse_number(amount.clone(), &[]);
return self.extend(__ws_arg_11, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), currentTime.clone());
m.insert("datetime".to_string(), __ws_arg_12);
m.insert("amount".to_string(), __ws_arg_13);
m.insert("fromAccount".to_string(), Value::Str("spot".to_string()));
m.insert("toAccount".to_string(), Value::Str("contract".to_string()));
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: Value = self.safe_string_k(transfer.clone(), "coin", &[]);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "timestamp", &[]);
let mut fromAccount: Value = self.safe_string_k(transfer.clone(), "fromAccount", &[]);
let mut toAccount: Value = self.safe_string_k(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".to_string()), Value::Str("id".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("amount".to_string(), self.safe_number_k(transfer.clone(), "amount", &[]));
m.insert("fromAccount".to_string(), fromAccount.clone());
m.insert("toAccount".to_string(), toAccount.clone());
m.insert("status".to_string(), self.safe_string_k(transfer.clone(), "status", &[]));
m
});
Value::Null
}
/*
* @method
* @name apex#cancelAllOrders
* @description cancel all open orders in a market
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-post-cancel-all-open-orders
* @param {string} [symbol] unified market symbol of the market to cancel orders in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v3_delete_open_orders(&[__ws_arg_14]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return Value::List(vec![self.parse_order(data.clone(), &[market.clone()])]);
Value::Null
}
/*
* @method
* @name apex#cancelOrder
* @description cancels an open order
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-post-cancel-order
* @param {string} id order id
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
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: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
let mut response: Value = Value::Null;
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_v3_delete_client_order_id(&[__ws_arg_15]).await;
} else {
add_element_to_object(&mut request, &Value::Str("id".to_string()), id.clone());
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_v3_delete_order(&[__ws_arg_16]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_order(data.clone(), &[]);
Value::Null
}
/*
* @method
* @name apex#fetchOrder
* @description fetches information on an order made by the user
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-order-id
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-order-by-clientorderid
* @param {string} id the order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the order
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
let mut response: Value = Value::Null;
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v3_order_by_client_order_id(&[__ws_arg_17]).await;
} else {
add_element_to_object(&mut request, &Value::Str("id".to_string()), id.clone());
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v3_order(&[__ws_arg_18]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[]);
Value::Null
}
/*
* @method
* @name apex#fetchOpenOrders
* @description fetches information on multiple orders made by the user
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-open-orders
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_open_orders(&[params.clone()]).await;
let mut orders: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[Value::Null, since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchOrders
* @description fetches information on multiple orders made by the user *classic accounts only*
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-all-order-history
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve, default 100
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.until] end time, ms
* @param {boolean} [params.status] "PENDING", "OPEN", "FILLED", "CANCELED", "EXPIRED", "UNTRIGGERED"
* @param {boolean} [params.side] BUY or SELL
* @param {string} [params.type] "LIMIT", "MARKET","STOP_LIMIT", "STOP_MARKET", "TAKE_PROFIT_LIMIT","TAKE_PROFIT_MARKET"
* @param {string} [params.orderType] "ACTIVE","CONDITION","HISTORY"
* @param {boolean} [params.page] Page numbers start from 0
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("beginTimeInclusive".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut endTimeExclusive: Value = self.safe_integer_n(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("endTimeExclusive".to_string()), Value::Str("until".to_string())]), &[]);
if !is_equal(&endTimeExclusive, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTimeExclusive".to_string()), endTimeExclusive.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("endTimeExclusive".to_string()), Value::Str("until".to_string())]), &[]);
}
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v3_history_orders(&[__ws_arg_19]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-trade-history
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("clientId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOrderId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("clientId".to_string())]), &[]);
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v3_order_fills(&[__ws_arg_20]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
return self.parse_trades(orders.clone(), &[Value::Null, since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchMyTrades
* @description fetches information on multiple orders made by the user *classic accounts only*
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-trade-history
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve, default 100
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.until] end time
* @param {boolean} [params.side] BUY or SELL
* @param {string} [params.orderType] "LIMIT", "MARKET","STOP_LIMIT", "STOP_MARKET", "TAKE_PROFIT_LIMIT","TAKE_PROFIT_MARKET"
* @param {boolean} [params.page] Page numbers start from 0
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("beginTimeInclusive".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut endTimeExclusive: Value = self.safe_integer_n(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("endTimeExclusive".to_string()), Value::Str("until".to_string())]), &[]);
if !is_equal(&endTimeExclusive, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTimeExclusive".to_string()), endTimeExclusive.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("endTimeExclusive".to_string()), Value::Str("until".to_string())]), &[]);
}
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v3_fills(&[__ws_arg_21]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
return self.parse_trades(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name apex#fetchFundingHistory
* @description fetches information on multiple orders made by the user *classic accounts only*
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-funding-rate
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve, default 100
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.until] end time, ms
* @param {boolean} [params.side] BUY or SELL
* @param {boolean} [params.page] Page numbers start from 0
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("beginTimeInclusive".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut endTimeExclusive: Value = self.safe_integer_n(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("endTimeExclusive".to_string()), Value::Str("until".to_string())]), &[]);
if !is_equal(&endTimeExclusive, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("endTimeExclusive".to_string()), Value::Str("until".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("endTimeExclusive".to_string()), endTimeExclusive.clone());
}
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v3_funding(&[__ws_arg_22]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fundingValues: Value = self.safe_list_k(data.clone(), "fundingValues", &[Value::List(vec![])]);
return self.parse_incomes(fundingValues.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_income(&self, mut income: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": "1234",
// "symbol": "BTC-USDT",
// "fundingValue": "10000",
// "rate": "0.0000125000",
// "positionSize": "500",
// "price": "90",
// "side": "LONG",
// "status": "SUCCESS",
// "fundingTime": 1647502440973,
// "transactionId": "1234556"
// }
//
let mut marketId: Value = self.safe_string_k(income.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut code: Value = Value::Str("USDT".to_string());
let mut timestamp: Value = self.safe_integer_k(income.clone(), "fundingTime", &[]);
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.clone(), &[market.clone()]));
m.insert("code".to_string(), code.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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.clone(), "rate", &[]));
m
});
Value::Null
}
/*
* @method
* @name apex#setLeverage
* @description set the level of leverage for a market
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-post-sets-the-initial-margin-rate-of-a-contract
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut leverageString: Value = self.number_to_string(leverage.clone());
let mut initialMarginRate: Value = crate::precise::Precise::stringDivPrec(&Value::Str("1".to_string()), &leverageString, &Value::Int(4));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("initialMarginRate".to_string(), initialMarginRate.clone());
m
});
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return data;
Value::Null
}
/*
* @method
* @name apex#fetchPositions
* @description fetch all open positions
* @see https://api-docs.omni.apex.exchange/#privateapi-v3-for-omni-get-retrieve-user-account-data
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v3_account(&[params.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positions: Value = self.safe_list_k(data.clone(), "positions", &[Value::List(vec![])]);
return self.parse_positions(positions.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTC-USDT",
// "status": "",
// "side": "LONG",
// "size": "0.000",
// "entryPrice": "0.00",
// "exitPrice": "",
// "createdAt": 1690366452416,
// "updatedTime": 1690366452416,
// "fee": "0.000000",
// "fundingFee": "0.000000",
// "lightNumbers": "",
// "customInitialMarginRate": "0"
// }
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut side: Value = self.safe_string_lower(position.clone(), Value::Str("side".to_string()), &[]);
let mut quantity: Value = self.safe_string_k(position.clone(), "size", &[]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "updatedTime", &[]);
let mut leverage: Value = Value::Int(20);
let mut customInitialMarginRate: Value = self.safe_string2(position.clone(), Value::Str("customInitialMarginRate".to_string()), Value::Str("customImr".to_string()), &[Value::Str("0".to_string())]);
if !is_equal(&self.precision_from_string(customInitialMarginRate.clone()), &Value::Int(0)) {
leverage = self.parse_to_int(crate::precise::Precise::stringDivPrec(&Value::Str("1".to_string()), &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.clone());
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "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.clone());
m.insert("contracts".to_string(), self.parse_number(quantity.clone(), &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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.clone());
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::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut url: Value = add(&add(&self.implode_hostname(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api)), &Value::Str("/".to_string())), &path);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("User-Agent".to_string(), Value::Str("apex-CCXT".to_string()));
m.insert("Accept".to_string(), Value::Str("application/json".to_string()));
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".to_string()));
m
});
let mut signPath: Value = add(&Value::Str("/api/".to_string()), &path);
let mut signBody: Value = body.clone();
if !is_equal(&to_upper(&method), &Value::Str("POST".to_string())) {
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
signPath = add(&signPath, &add(&Value::Str("?".to_string()), &self.rawencode(params.clone(), &[])));
url = add(&url, &add(&Value::Str("?".to_string()), &self.rawencode(params.clone(), &[])));
}
} else {
let mut sortedQuery: Value = self.keysort(params.clone(), &[]);
signBody = self.rawencode(sortedQuery.clone(), &[]);
}
if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut timestamp: Value = to_string_val(&self.milliseconds());
let mut messageString: Value = add(&add(×tamp, &to_upper(&method)), &signPath);
if !is_equal(&signBody, &Value::Null) {
messageString = add(&messageString, &signBody);
}
let mut signature: Value = self.hmac(self.encode(messageString.clone()), self.encode(self.string_to_base64(self.secret.clone(), &[])), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
add_element_to_object(&mut headers, &Value::Str("APEX-SIGNATURE".to_string()), signature.clone());
add_element_to_object(&mut headers, &Value::Str("APEX-API-KEY".to_string()), self.apiKey.clone());
add_element_to_object(&mut headers, &Value::Str("APEX-TIMESTAMP".to_string()), timestamp.clone());
add_element_to_object(&mut headers, &Value::Str("APEX-PASSPHRASE".to_string()), self.password.clone());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), signBody.clone());
m.insert("headers".to_string(), headers.clone());
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 {
//
// {"code":3,"msg":"Order price must be greater than 0. Order price is 0.","key":"ORDER_PRICE_MUST_GREETER_ZERO","detail":{"price":"0"}}
// {"code":400,"msg":"strconv.ParseInt: parsing \"dsfdfsd\": invalid syntax","timeCost":5320995}
//
if is_equal(&response, &Value::Null) {
return Value::Null;
}
let mut errorCode: Value = self.safe_integer_k(response.clone(), "code", &[]);
if !is_equal(&errorCode, &Value::Null) && !is_equal(&errorCode, &Value::Int(0)) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
let mut message: Value = self.safe_string2(response.clone(), Value::Str("key".to_string()), Value::Str("msg".to_string()), &[]);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
let mut status: Value = to_string_val(&code);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), status.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}