// 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 AsterCore {
pub exchange: crate::exchange::Exchange,
}
impl AsterCore {
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 = AsterCore::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 AsterCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_balance(self, response)
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_last_price(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_last_price(self, entry, &[market.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_ledger_entry(self, entry, &[currency.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_currency(self, currency)
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_funding_rate_history(self, entry, &[market.clone()])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_income(self, info, &[market.clone()])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_margin_mode(self, margin_mode, &[market.clone()])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on AsterCore.
AsterCore::parse_leverage(self, leverage, &[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 AsterCore.
AsterCore::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 AsterCore.
AsterCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for AsterCore {
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_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"capitalize_keys" => self.capitalize_keys(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"encode_values_with_json" => self.encode_values_with_json(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"fetch_account_positions" => self.fetch_account_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&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_intervals" => self.fetch_funding_intervals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_last_prices" => self.fetch_last_prices(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverages" => self.fetch_leverages(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_adjustment_history" => self.fetch_margin_adjustment_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_modes" => self.fetch_margin_modes(&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_order" => self.fetch_open_order(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_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position_mode" => self.fetch_position_mode(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_risk" => self.fetch_positions_risk(&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,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"hash_message" => self.hash_message(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"initialize_client" => self.initialize_client(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"is_inverse" => self.is_inverse(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"is_linear" => self.is_linear(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"keccak_message" => self.keccak_message(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"load_leverage_brackets" => self.load_leverage_brackets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"load_markets_and_sign_in" => self.load_markets_and_sign_in().await,
"modify_margin_helper" => self.modify_margin_helper(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..).unwrap_or(&[]).to_vec()[..]).await,
"parse_account_position" => self.parse_account_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_account_positions" => self.parse_account_positions(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_income" => self.parse_income(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_last_price" => self.parse_last_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_mode" => self.parse_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(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_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_risk" => self.parse_position_risk(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_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(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()[..]),
"parse_transfer_status" => self.parse_transfer_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_position_mode" => self.set_position_mode(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()[..]),
"sign_hash" => self.sign_hash(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"sign_in" => self.sign_in(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"sign_message" => self.sign_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"sign_withdraw_payload" => self.sign_withdraw_payload(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"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,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).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 AsterCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for AsterCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl AsterCore {
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("aster".to_string()));
m.insert("name".to_string(), Value::Str("Aster".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("US".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(333));
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("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/5e5909d6-c4de-4435-992f-4339c80edbd7".to_string()));
m.insert("www".to_string(), Value::Str("https://www.asterdex.com/en".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fapiPublic".to_string(), Value::Str("https://fapi.asterdex.com/fapi".to_string()));
m.insert("fapiPrivate".to_string(), Value::Str("https://fapi.asterdex.com/fapi".to_string()));
m.insert("sapiPublic".to_string(), Value::Str("https://sapi.asterdex.com/api".to_string()));
m.insert("sapiPrivate".to_string(), Value::Str("https://sapi.asterdex.com/api".to_string()));
m
}));
m.insert("doc".to_string(), Value::Str("https://github.com/asterdex/api-docs".to_string()));
m.insert("fees".to_string(), Value::Str("https://docs.asterdex.com/product/asterex-simple/fees-and-slippage".to_string()));
m.insert("referral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Str("https://www.asterdex.com/en/referral/aA1c2B".to_string()));
m.insert("discount".to_string(), Value::Float(0.1));
m
}));
m
}));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createConvertTrade".to_string(), Value::Bool(false));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createLimitBuyOrder".to_string(), Value::Bool(false));
m.insert("createLimitSellOrder".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrder".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrder".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(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopLimitOrder".to_string(), Value::Bool(false));
m.insert("createStopLossOrder".to_string(), Value::Bool(false));
m.insert("createStopMarketOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(false));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(false));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(false));
m.insert("editOrder".to_string(), Value::Bool(false));
m.insert("editOrders".to_string(), Value::Bool(false));
m.insert("fetchAccounts".to_string(), Value::Null);
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchCanceledOrders".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(false));
m.insert("fetchConvertQuote".to_string(), Value::Bool(false));
m.insert("fetchConvertTrade".to_string(), Value::Bool(false));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposit".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(false));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingInterval".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(true));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchL3OrderBook".to_string(), Value::Bool(false));
m.insert("fetchLastPrices".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchLeverages".to_string(), Value::Bool(true));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(true));
m.insert("fetchMarginMode".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchMarginModes".to_string(), Value::Bool(true));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMarkPrice".to_string(), Value::Bool(false));
m.insert("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenOrder".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTradingLimits".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchTransactionFee".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawAddresses".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("signIn".to_string(), Value::Bool(true));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fapiPublic".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("v1/ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/time".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("v1/exchangeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/exchangeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/depth".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(2));
m
}));
m.insert("v1/trades".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("v1/historicalTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/historicalTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v1/aggTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/aggTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v1/klines".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("v1/indexPriceKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/indexPriceKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markPriceKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/markPriceKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/premiumIndex".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/premiumIndex".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/fundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/fundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/fundingInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/fundingInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/adlQuantile".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/forceOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/indexreferences".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("fapiPrivate".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("v1/positionSide/dual".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/positionSide/dual".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("v1/multiAssetsMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/multiAssetsMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/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("v1/openOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/openOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
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("v1/positionMargin/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/positionMargin/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/positionRisk".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/positionRisk".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v1/income".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/income".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/leverageBracket".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/leverageBracket".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/adlQuantile".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/forceOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/accountWithJoinMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v4/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/agent".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/builder".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("v1/positionSide/dual".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/positionSide/dual".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/multiAssetsMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/multiAssetsMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/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("v1/order/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/order/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/asset/wallet/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/asset/wallet/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/countdownCancelAll".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/countdownCancelAll".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/positionMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/positionMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/mmpReset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/noop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/approveAgent".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/updateAgent".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/approveBuilder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/updateBuilder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1/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("v1/allOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/allOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/agent".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/builder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("sapiPublic".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("v1/ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/exchangeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/historicalTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/aggTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/aster/withdraw/estimateFee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/ping".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/exchangeInfo".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(2));
m.insert("byLimit".to_string(), Value::List(vec![Value::List(vec![Value::Int(50), Value::Int(2)]), Value::List(vec![Value::Int(100), Value::Int(5)]), Value::List(vec![Value::Int(500), Value::Int(10)]), Value::List(vec![Value::Int(1000), Value::Int(20)])]));
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/historicalTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/aggTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m.insert("byLimit".to_string(), Value::List(vec![Value::List(vec![Value::Int(99), Value::Int(1)]), Value::List(vec![Value::Int(499), Value::Int(2)]), Value::List(vec![Value::Int(1000), Value::Int(5)]), Value::List(vec![Value::Int(10000), Value::Int(10)])]));
m
}));
m.insert("v3/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m.insert("noSymbol".to_string(), Value::Int(40));
m
}));
m.insert("v3/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m.insert("noSymbol".to_string(), Value::Int(2));
m
}));
m.insert("v3/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m.insert("noSymbol".to_string(), Value::Int(2));
m
}));
m.insert("v3/aster/withdraw/estimateFee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("sapiPrivate".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("v1/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/transactionHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m.insert("noSymbol".to_string(), Value::Int(2));
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/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v3/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v3/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v3/openOrder".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("v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/asset/wallet/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v1/asset/sendToAddress".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/listenKey".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/asset/wallet/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v3/aster/user-withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/allOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/allOpenOrders".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/listenKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("3m".to_string(), Value::Str("3m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("8h".to_string(), Value::Str("8h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("3d".to_string(), Value::Str("3d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(false));
m.insert("secret".to_string(), Value::Bool(false));
m.insert("privateKey".to_string(), Value::Bool(true));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.00035".to_string()), &[]));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".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(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("symbolRequired".to_string(), Value::Bool(true));
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(true));
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(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".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(true));
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(1500));
m
}));
m
}));
m.insert("forDerivs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(false));
m
}));
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(true));
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("selfTradePrevention".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(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("symbolRequired".to_string(), Value::Bool(true));
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(true));
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(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".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(true));
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(1500));
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("forDerivs".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("spot".to_string()));
m.insert("recvWindow".to_string(), multiply(&Value::Int(10), &Value::Int(1000)));
m.insert("zeroAddress".to_string(), Value::Str("0x0000000000000000000000000000000000000000".to_string()));
m.insert("v3ChainId".to_string(), Value::Int(1666));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeInForce".to_string(), Value::Str("GTC".to_string()));
m.insert("quoteOrderQty".to_string(), Value::Bool(true));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("swap".to_string(), Value::Str("FUTURE".to_string()));
m.insert("future".to_string(), Value::Str("FUTURE".to_string()));
m.insert("linear".to_string(), Value::Str("FUTURE".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("Arbitrum".to_string()));
m
}));
m.insert("networksToChainId".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ETH".to_string(), Value::Int(1));
m.insert("BSC".to_string(), Value::Int(56));
m.insert("Arbitrum".to_string(), Value::Int(42161));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("warnIfNoSymbol".to_string(), Value::Bool(true));
m
}));
m.insert("builderFee".to_string(), Value::Bool(true));
m.insert("builder".to_string(), Value::Str("0x1F5877C19e3777Cfd15F9d57253eA4aA5254Ec39".to_string()));
m.insert("builderRate".to_string(), Value::Str("0.001".to_string()));
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("-1000".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1001".to_string(), Value::Str("NetworkError".to_string()).clone());
m.insert("-1002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1003".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-1004".to_string(), Value::Str("DuplicateOrderId".to_string()).clone());
m.insert("-1005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1006".to_string(), Value::Str("BadResponse".to_string()).clone());
m.insert("-1007".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("-1010".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1011".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1013".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1014".to_string(), Value::Str("OrderNotFillable".to_string()).clone());
m.insert("-1015".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-1016".to_string(), Value::Str("ExchangeClosedByUser".to_string()).clone());
m.insert("-1020".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-1021".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("-1022".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1023".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1100".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1101".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1102".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("-1103".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1104".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1105".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("-1106".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1108".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1109".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1110".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-1111".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1112".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1113".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1114".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1115".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1116".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1117".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1118".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1119".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1120".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1121".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-1125".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1127".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1128".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1130".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1136".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-2010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-2011".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("-2013".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("-2014".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-2015".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-2016".to_string(), Value::Str("MarketClosed".to_string()).clone());
m.insert("-2018".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-2019".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-2020".to_string(), Value::Str("OrderNotFillable".to_string()).clone());
m.insert("-2021".to_string(), Value::Str("OrderImmediatelyFillable".to_string()).clone());
m.insert("-2022".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2023".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("-2024".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-2025".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-2026".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-2027".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2028".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4012".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-4013".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4015".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4018".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4019".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4020".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4021".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4022".to_string(), Value::Str("MarketClosed".to_string()).clone());
m.insert("-4023".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4024".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4025".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4026".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4027".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4028".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4029".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4030".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4031".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4032".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-4033".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-4044".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4045".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-4046".to_string(), Value::Str("NoChange".to_string()).clone());
m.insert("-4047".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4048".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4049".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4050".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-4051".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-4052".to_string(), Value::Str("NoChange".to_string()).clone());
m.insert("-4053".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4054".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4055".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("-4056".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-4057".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-4058".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4059".to_string(), Value::Str("NoChange".to_string()).clone());
m.insert("-4060".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4061".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4062".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4063".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4064".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4065".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4066".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4067".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4068".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4069".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4070".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4071".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4072".to_string(), Value::Str("NoChange".to_string()).clone());
m.insert("-4073".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4074".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4075".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4076".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4077".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-4078".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4079".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4080".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4081".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4082".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-4083".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-4084".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-4085".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4086".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4087".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-4088".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-4104".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-4114".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4115".to_string(), Value::Str("DuplicateOrderId".to_string()).clone());
m.insert("-4118".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-4131".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4135".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4137".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4138".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4139".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4140".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4141".to_string(), Value::Str("MarketClosed".to_string()).clone());
m.insert("-4142".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4144".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-4161".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4164".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4165".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4183".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-4184".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-5060".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-5076".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-4168".to_string(), Value::Str("OperationRejected".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
})]);
Value::Null
}
pub fn is_inverse(&self, mut type_var: Value, optional_args: &[Value]) -> Value {
let mut subType = get_arg(optional_args, 0, Value::Null);
if is_equal(&subType, &Value::Null) {
return Value::Bool(is_equal(&type_var, &Value::Str("delivery".to_string())));
} else {
return Value::Bool(is_equal(&subType, &Value::Str("inverse".to_string())));
}
Value::Null
}
pub fn is_linear(&self, mut type_var: Value, optional_args: &[Value]) -> Value {
let mut subType = get_arg(optional_args, 0, Value::Null);
if is_equal(&subType, &Value::Null) {
return Value::Bool(is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))));
} else {
return Value::Bool(is_equal(&subType, &Value::Str("linear".to_string())));
}
Value::Null
}
/*
* @method
* @name aster#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#trading-specification-information
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#exchange-information
* @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 sapiResult: Value = self.sapi_public_get_v3_exchange_info(&[params.clone()]).await;
let mut sapiRows: Value = self.safe_list_k(sapiResult.clone(), "assets", &[Value::List(vec![])]);
return self.parse_currencies(sapiRows.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut currencyId: Value = self.safe_string_k(rawCurrency.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rawCurrency.clone());
m.insert("code".to_string(), code.clone());
m.insert("id".to_string(), currencyId.clone());
m.insert("name".to_string(), code.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("margin".to_string(), self.safe_bool_k(rawCurrency.clone(), "marginAvailable", &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m
}));
Value::Null
}
/*
* @method
* @name aster#fetchMarkets
* @description retrieves data on all markets for bigone
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#trading-specification-information
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#exchange-information
* @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 promises: Value = Value::List(vec![self.sapi_public_get_v3_exchange_info(&[params.clone()]).await, self.fapi_public_get_v3_exchange_info(&[params.clone()]).await]);
append_to_array(&mut promises, self.sign_in(&[]).await);
let mut results: Value = promise_all(&promises).await;
let mut sapiResult: Value = self.safe_dict(results.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut sapiRows: Value = self.safe_list_k(sapiResult.clone(), "symbols", &[Value::List(vec![])]);
let mut fapiResult: Value = self.safe_dict(results.clone(), Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fapiRows: Value = self.safe_list_k(fapiResult.clone(), "symbols", &[Value::List(vec![])]);
//
// example:
//
// [
// {
// symbol: "TESTUSDT",
// status: "TRADING",
// baseAsset: "TEST",
// quoteAsset: "USDT",
// pricePrecision: "2",
// quantityPrecision: "5",
// baseAssetPrecision: "8",
// quotePrecision: "8",
// listingTime: "1756289680210", // only in SPOT
// baseAssetAddress: null, // only in SPOT
// ocoAllowed: false, // only in SPOT
// pair: "ASTERUSDT", // only in PERP
// contractType: "PERPETUAL", // only in PERP
// deliveryDate: "4133404800000", // only in PERP
// onboardDate: "1758178800000", // only in PERP
// maintMarginPercent: "12.5000", // only in PERP
// requiredMarginPercent: "25.0000", // only in PERP
// marginAsset: "USDT", // only in PERP
// underlyingType: "COIN", // only in PERP
// underlyingSubType: [ "Top", ], // only in PERP
// symbolType: "0", // only in PERP
// tradingMode: "0", // only in PERP
// name: "", // only in PERP
// channel: "{}", // only in PERP
// sequenceNo: "100", // only in PERP
// twapMinNotional: "1000", // only in PERP
// imn: "4000.00", // only in PERP
// tags: [], // only in PERP
// settlePlan: "0", // only in PERP
// triggerProtect: "0.1500", // only in PERP
// liquidationFee: "0.025000", // only in PERP
// marketTakeBound: "0.05", // only in PERP
// createTime: "1758215451058", // only in PERP
// filters: [
// {
// minPrice: "0.01",
// maxPrice: "1000000",
// filterType: "PRICE_FILTER",
// tickSize: "0.01",
// },
// {
// stepSize: "0.00001",
// filterType: "LOT_SIZE",
// maxQty: "9000",
// minQty: "0.00001",
// },
// {
// stepSize: "0.00001",
// filterType: "MARKET_LOT_SIZE",
// maxQty: "9000",
// minQty: "0.00001",
// },
// {
// limit: "200",
// filterType: "MAX_NUM_ORDERS",
// },
// {
// minNotional: "5",
// filterType: "MIN_NOTIONAL",
// },
// {
// minNotional: "5",
// avgPriceMins: "5",
// applyMinToMarket: true,
// filterType: "NOTIONAL", // only in SPOT
// applyMaxToMarket: true,
// },
// {
// multiplierDown: "0.2",
// multiplierUp: "5",
// multiplierDecimal: "1",
// filterType: "PERCENT_PRICE",
// },
// {
// bidMultiplierUp: "5",
// askMultiplierUp: "5",
// bidMultiplierDown: "0.2",
// avgPriceMins: "5",
// multiplierDecimal: "1",
// filterType: "PERCENT_PRICE_BY_SIDE", // only in SPOT
// askMultiplierDown: "0.2",
// },
// ],
// orderTypes: [ "LIMIT", "MARKET", "STOP", "STOP_MARKET", "TAKE_PROFIT", "TAKE_PROFIT_MARKET", "TRAILING_STOP_MARKET", ],
// timeInForce: [ "GTC", "IOC", "FOK", "GTX", "HIDDEN", ],
// }
// ]
//
//
let mut fapiRowsFiltered: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_220: bool = true;
while { if !__for_first_220 { i = add(&i, &Value::Int(1)); } __for_first_220 = false; is_less_than(&i, &get_array_length(&fapiRows)) } {
let mut market: Value = get_value(&fapiRows, &i);
let mut market: Value = get_value(&fapiRows, &i);
// tmp skip some markets with base = undefined
if !is_equal(&self.safe_string_k(market.clone(), "baseAsset", &[]), &Value::Null) {
append_to_array(&mut fapiRowsFiltered, market.clone());
}
}
}
let mut rows: Value = self.array_concat(sapiRows.clone(), fapiRowsFiltered.clone());
return self.parse_markets(rows.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 baseId: Value = self.safe_string_k(market.clone(), "baseAsset", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteAsset", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut active: Value = Value::Bool(is_equal(&self.safe_string_k(market.clone(), "status", &[]), &Value::Str("TRADING".to_string())));
let mut spot: Value = Value::Null;
let mut symbol: Value = Value::Null;
let mut settle: Value = Value::Null;
let mut settleId: Value = Value::Null;
let mut swap: Value = Value::Null;
let mut linear: Value = Value::Null;
let mut inverse: Value = Value::Null;
let mut contractSize: Value = Value::Null;
let mut contractType: Value = self.safe_string_k(market.clone(), "contractType", &[]);
let mut isContract: Value = Value::Bool(!is_equal(&contractType, &Value::Null));
if is_true(&isContract) {
// currently, there is only perpetuals, not futures
spot = Value::Bool(false);
swap = Value::Bool(true);
settleId = self.safe_string_k(market.clone(), "marginAsset", &[]);
settle = self.safe_currency_code(settleId.clone(), &[]);
symbol = add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
linear = Value::Bool(is_equal(&settle, "e));
inverse = Value::Bool(is_equal(&settle, &base));
contractSize = self.safe_number2(market.clone(), Value::Str("contractSize".to_string()), Value::Str("unit".to_string()), &[self.parse_number(Value::Str("1".to_string()), &[])]);
} else {
spot = Value::Bool(true);
swap = Value::Bool(false);
symbol = add(&add(&base, &Value::Str("/".to_string())), "e);
}
// filters
let mut filters: Value = self.safe_list_k(market.clone(), "filters", &[Value::List(vec![])]);
let mut filtersByType: Value = self.index_by(filters.clone(), Value::Str("filterType".to_string()));
let mut filterNotional: Value = self.safe_dict2(filtersByType.clone(), Value::Str("MIN_NOTIONAL".to_string()), Value::Str("NOTIONAL".to_string()), &[]);
let mut filterPrice: Value = self.safe_dict_k(filtersByType.clone(), "PRICE_FILTER", &[]);
let mut filterLotSize: Value = self.safe_dict_k(filtersByType.clone(), "LOT_SIZE", &[]);
let mut filterMarketLotSize: Value = self.safe_dict_k(filtersByType.clone(), "MARKET_LOT_SIZE", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut pricePrecision: Value = self.safe_number_k(filterPrice.clone(), "tickSize", &[]);
if is_equal(&pricePrecision, &Value::Null) {
pricePrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "pricePrecision", &[])]), &[]);
}
let mut amountPrecision: Value = ternary(is_true(&(!is_equal(&filterLotSize, &Value::Null))), self.safe_number_k(filterLotSize.clone(), "stepSize", &[]), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quantityPrecision", &[])]), &[]));
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.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(), ternary(is_true(&isContract), Value::Str("swap".to_string()), Value::Str("spot".to_string())));
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active.clone());
m.insert("contract".to_string(), isContract.clone());
m.insert("linear".to_string(), linear.clone());
m.insert("inverse".to_string(), inverse.clone());
m.insert("taker".to_string(), get_value(&get_value(&self.fees, &Value::Str("trading".to_string())), &Value::Str("taker".to_string())));
m.insert("maker".to_string(), get_value(&get_value(&self.fees, &Value::Str("trading".to_string())), &Value::Str("maker".to_string())));
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amountPrecision.clone());
m.insert("price".to_string(), pricePrecision.clone());
m.insert("base".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "baseAssetPrecision", &[])]), &[]));
m.insert("quote".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quotePrecision", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(filterLotSize.clone(), "minQty", &[]));
m.insert("max".to_string(), self.safe_number_k(filterLotSize.clone(), "maxQty", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(filterPrice.clone(), "minPrice", &[]));
m.insert("max".to_string(), self.safe_number_k(filterPrice.clone(), "maxPrice", &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number2(filterNotional.clone(), Value::Str("notional".to_string()), Value::Str("minNotional".to_string()), &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(filterMarketLotSize.clone(), "minQty", &[]));
m.insert("max".to_string(), self.safe_number_k(filterMarketLotSize.clone(), "maxQty", &[]));
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer2(market.clone(), Value::Str("listingTime".to_string()), Value::Str("createTime".to_string()), &[]));
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name aster#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#get-server-time
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#check-server-time
* @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 marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTime".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.fapi_public_get_v3_time(&[params.clone()]).await;
} else {
response = self.sapi_public_get_v3_time(&[params.clone()]).await;
}
return self.safe_integer_k(response.clone(), "serverTime", &[]);
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_integer(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name aster#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#k-line-data
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#klinecandlestick-data
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#index-price-klinecandlestick-data
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#mark-price-klinecandlestick-data
* @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 {string} [params.price] "mark" or "index" for mark price and index price candles
* @param {int} [params.until] the latest time in ms to fetch orders for
* @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
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1500)));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("interval".to_string()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
let mut price: Value = self.safe_string_k(params.clone(), "price", &[]);
let mut isMark: bool = is_equal(&price, &Value::Str("mark".to_string()));
let mut isIndex: bool = is_equal(&price, &Value::Str("index".to_string()));
params = self.omit(params.clone(), Value::Str("price".to_string()), &[]);
let mut response: Value = Value::Null;
if is_true(&isMark) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_public_get_v3_mark_price_klines(&[__ws_arg_0]).await;
} else if is_true(&isIndex) {
add_element_to_object(&mut request, &Value::Str("pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_public_get_v3_index_price_klines(&[__ws_arg_1]).await;
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_public_get_v3_klines(&[__ws_arg_2]).await;
} else {
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_public_get_v3_klines(&[__ws_arg_3]).await;
}
}
return self.parse_ohlc_vs(self.to_array(response.clone()), &[market.clone(), timeframe.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);
//
// fetchTrades
//
// recent trades:
//
// {
// "id": 3913206,
// "price": "644.100",
// "qty": "0.08",
// "quoteQty": "51.528", // present in PERP
// "baseQty": "4.95049505", // present in SPOT
// "time": 1749784506633,
// "isBuyerMaker": true
// }
//
// aggrTrades
//
// {
// "a": 26129, // Aggregate tradeId
// "p": "0.01633102", // Price
// "q": "4.70443515", // Quantity
// "f": 27781, // First tradeId
// "l": 27781, // Last tradeId
// "T": 1498793709153, // Timestamp
// "m": true, // Was the buyer the maker?
// }
//
// fetchMyTrades (SPOT & PERP have similar format)
//
// {
// "symbol": "ETHUSDT",
// "id": 2583152,
// "orderId": 418588675,
// "side": "SELL",
// "price": "2330.04",
// "qty": "0.0030",
// "quoteQty": "6.99000000",
// "commission": "0.00279605",
// "commissionAsset": "USDT",
// "time": 1776409179230,
// "counterpartyId": 5143150, // only in SPOT
// "createUpdateId": null, // only in SPOT
// "maker": false, // only in SPOT
// "buyer": false, // only in SPOT
// "realizedPnl": "0.00029999", // only in PERP
// "marginAsset": "USDT", // only in PERP
// "positionSide": "BOTH", // only in PERP
// }
//
let mut id: Value = self.safe_string2(trade.clone(), Value::Str("id".to_string()), Value::Str("a".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
let mut marketType: Value = ternary(is_true(&(Value::Bool(in_op(&trade, &Value::Str("positionSide".to_string()))))), Value::Str("swap".to_string()), Value::Str("spot".to_string()));
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut currencyId: Value = self.safe_string2(trade.clone(), Value::Str("commissionAsset".to_string()), Value::Str("marginAsset".to_string()), &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("qty".to_string()), Value::Str("q".to_string()), &[]);
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("price".to_string()), Value::Str("p".to_string()), &[]);
let mut costString: Value = self.safe_string2(trade.clone(), Value::Str("quoteQty".to_string()), Value::Str("baseQty".to_string()), &[]);
let mut timestamp: Value = self.safe_integer2(trade.clone(), Value::Str("time".to_string()), Value::Str("T".to_string()), &[]);
let mut side: Value = self.safe_string_lower(trade.clone(), Value::Str("side".to_string()), &[]);
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "maker", &[]);
let mut takerOrMaker: Value = Value::Null;
if !is_equal(&isMaker, &Value::Null) {
takerOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
if is_equal(&side, &Value::Null) {
let mut isBuyer: Value = self.safe_bool_k(trade.clone(), "buyer", &[]);
if !is_equal(&isBuyer, &Value::Null) {
side = ternary(is_true(&isBuyer), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
}
}
}
let mut isBuyerMaker: Value = self.safe_bool2(trade.clone(), Value::Str("isBuyerMaker".to_string()), Value::Str("m".to_string()), &[]);
if !is_equal(&isBuyerMaker, &Value::Null) {
side = ternary(is_true(&isBuyerMaker), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("info".to_string(), trade.clone());
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("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), costString.clone());
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&self.safe_string_k(trade.clone(), "commission", &[])), &[]));
m.insert("currency".to_string(), currencyCode.clone());
m
}));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#recent-trades-list
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#recent-trades-aggregated
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#recent-trades-list
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#compressedaggregate-trades-list
* @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
* @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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
let mut response: Value = Value::Null;
let mut sinceDefined: bool = !is_equal(&since, &Value::Null);
let mut untilDefined: Value = (Value::Bool(in_op(¶ms, &Value::Str("until".to_string()))));
if is_true(&sinceDefined) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if is_true(&untilDefined) {
request = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]);
}
// use historical endpoint for targeted requests
if is_true(&Value::Bool(in_op(&request, &Value::Str("startTime".to_string())))) {
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_public_get_v3_agg_trades(&[__ws_arg_4]).await;
} else {
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_public_get_v3_agg_trades(&[__ws_arg_5]).await;
}
} else {
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_public_get_v3_trades(&[__ws_arg_6]).await;
} else {
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_public_get_v3_trades(&[__ws_arg_7]).await;
}
}
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchMyTrades
* @description fetch all trades made by the user
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#account-trade-history-user_data
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#account-trade-list-user_data
* @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 structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is undefined
* @returns {object[]} 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
}));
self.load_markets_and_sign_in().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())));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); marketType = 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("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_get_v3_user_trades(&[__ws_arg_8]).await;
} else {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_get_v3_user_trades(&[__ws_arg_9]).await;
}
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#depth-information
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#order-book
* @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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), self.find_nearest_ceiling(Value::List(vec![Value::Int(5), Value::Int(10), Value::Int(20), Value::Int(50), Value::Int(100), Value::Int(500), Value::Int(1000)]), limit.clone()));
}
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_public_get_v3_depth(&[__ws_arg_10]).await;
} else {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_public_get_v3_depth(&[__ws_arg_11]).await;
}
//
// both SPOT & PERP has same format
//
// {
// "lastUpdateId": 1027024,
// "E": 1589436922972, // Message output time
// "T": 1589436922959, // Transaction time
// "bids": [
// [
// "4.00000000", // PRICE
// "431.00000000" // QTY
// ]
// ],
// "asks": [
// [
// "4.00000200",
// "12.00000000"
// ]
// ]
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "T", &[]);
return self.parse_order_book(response.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string())]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTicker & fetchTickers: both SPOT & PERP has similar format
//
// {
// "symbol": "ETHUSDT",
// "priceChange": "6.54",
// "priceChangePercent": "0.279",
// "weightedAvgPrice": "2330.70",
// "lastPrice": "2350.00",
// "lastQty": "4.437",
// "openPrice": "2343.46",
// "highPrice": "2363.20",
// "lowPrice": "2283.86",
// "volume": "267154.248",
// "quoteVolume": "622657018.70",
// "openTime": "1776329400000",
// "closeTime": "1776415832593",
// "firstId": "73520536",
// "lastId": "73630176",
// "count": "109640",
// "baseAsset": "BTC", // only in SPOT
// "quoteAsset": "USDT", // only in SPOT
// "bidPrice": "71125.98", // only in SPOT
// "bidQty": "0.00737", // only in SPOT
// "askPrice": "71152.10", // only in SPOT
// "askQty": "0.32399" // only in SPOT
// }
//
//
// fetchBidsAsks: SPOT & PERP have only one field difference
//
// [
// {
// "symbol": "BMTUSDT",
// "bidPrice": "0.004000",
// "bidQty": "1250.0",
// "askPrice": "0.000000",
// "askQty": "0.0",
// "time": "1776411276072",
// "lastUpdateId": "453174307613" // only in PERP
// }, ...
//
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "closeTime", &[]);
let mut last: Value = self.safe_string_k(ticker.clone(), "lastPrice", &[]);
let mut open: Value = self.safe_string_k(ticker.clone(), "openPrice", &[]);
let mut percentage: Value = self.safe_string_k(ticker.clone(), "priceChangePercent", &[]);
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "quoteVolume", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "volume", &[]);
let mut high: Value = self.safe_string_k(ticker.clone(), "highPrice", &[]);
let mut low: Value = self.safe_string_k(ticker.clone(), "lowPrice", &[]);
let mut isTickerResponse: Value = (Value::Bool(in_op(&ticker, &Value::Str("priceChange".to_string()))));
let mut marketType: Value = Value::Null;
if is_true(&isTickerResponse) {
marketType = ternary(is_true(&(Value::Bool(in_op(&ticker, &Value::Str("baseAsset".to_string()))))), Value::Str("spot".to_string()), Value::Str("swap".to_string()));
} else {
marketType = ternary(is_true(&(Value::Bool(in_op(&ticker, &Value::Str("lastUpdateId".to_string()))))), Value::Str("swap".to_string()), Value::Str("spot".to_string()));
}
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
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(), self.safe_string_k(ticker.clone(), "bidPrice", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bidQty", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "askPrice", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "askQty", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), open.clone());
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(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#24h-price-change
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#24hr-ticker-price-change-statistics
* @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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_public_get_v3_ticker24hr(&[__ws_arg_12]).await;
} else {
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_public_get_v3_ticker24hr(&[__ws_arg_13]).await;
}
return self.parse_ticker(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#24h-price-change
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#24hr-ticker-price-change-statistics
* @param {string[]} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] "linear" or "inverse"
* @param {string} [params.type] 'spot', 'option', use params["subType"] for swap and future markets
* @returns {object} an array of [ticker structures]{@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;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.fapi_public_get_v3_ticker24hr(&[params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.sapi_public_get_v3_ticker24hr(&[params.clone()]).await;
}
return self.parse_tickers(response.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchLastPrices
* @description fetches the last price for multiple markets
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#latest-price
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#symbol-price-ticker
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the last prices
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] "linear" or "inverse"
* @returns {object} a dictionary of lastprices structures
*/
pub async fn fetch_last_prices(&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;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLastPrices".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.fapi_public_get_v3_ticker_price(&[params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.sapi_public_get_v3_ticker_price(&[params.clone()]).await;
}
//
// both SPOT & SWAP has same format
//
// [
// {
// "symbol": "LTCBTC",
// "price": "4.00000200"
// "time": "1649666690902"
// },
// ...
// ]
//
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" fetchLastPrices() returned empty response".to_string()))));
}
let mut rows: Value = self.to_array(response.clone());
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_221: bool = true;
while { if !__for_first_221 { i = add(&i, &Value::Int(1)); } __for_first_221 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut marketId: Value = self.safe_string_k(get_value(&rows, &i), "symbol", &[]);
let mut safeMarket: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
let __ws_arg_14 = self.parse_last_price(get_value(&rows, &i), &[safeMarket.clone()]);
let mut priceData: Value = self.extend(__ws_arg_14, &[params.clone()]);
append_to_array(&mut results, priceData.clone());
}
}
symbols = self.market_symbols(&[symbols.clone()]);
return self.filter_by_array(results.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub fn parse_last_price(&self, mut entry: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// spot & swap
//
// {
// "symbol": "LTCBTC",
// "price": "4.00000200"
// "time": "1649666690902"
// }
//
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "time", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("price".to_string(), self.safe_number_omit_zero(entry.clone(), Value::Str("price".to_string()), &[]));
m.insert("side".to_string(), Value::Null);
m.insert("info".to_string(), entry.clone());
m
});
Value::Null
}
/*
* @method
* @name aster#fetchBidsAsks
* @description fetches the bid and ask price and volume for multiple markets
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#current-best-order
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#symbol-order-book-ticker
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] "linear" or "inverse"
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_bids_asks(&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;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBidsAsks".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.fapi_public_get_v3_ticker_book_ticker(&[params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.sapi_public_get_v3_ticker_book_ticker(&[params.clone()]).await;
}
return self.parse_tickers(response.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fundingRate
//
// {
// "symbol": "BTCUSDT",
// "markPrice": "106729.84047826",
// "indexPrice": "106775.72673913",
// "estimatedSettlePrice": "106708.84997006",
// "lastFundingRate": "0.00010000",
// "interestRate": "0.00010000",
// "nextFundingTime": 1750147200000,
// "time": 1750146970000
// }
//
// funding interval
//
// {
// "symbol": "INJUSDT",
// "interestRate": "0.00010000",
// "time": 1756197479000,
// "fundingIntervalHours": 8,
// "fundingFeeCap": 0.03,
// "fundingFeeFloor": -0.03
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut nextFundingTimestamp: Value = self.safe_integer_k(contract.clone(), "nextFundingTime", &[]);
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "time", &[]);
let mut interval: Value = self.safe_string_k(contract.clone(), "fundingIntervalHours", &[]);
let mut intervalString: Value = Value::Null;
if !is_equal(&interval, &Value::Null) {
intervalString = add(&interval, &Value::Str("h".to_string()));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("markPrice".to_string(), self.safe_number_k(contract.clone(), "markPrice", &[]));
m.insert("indexPrice".to_string(), self.safe_number_k(contract.clone(), "indexPrice", &[]));
m.insert("interestRate".to_string(), self.safe_number_k(contract.clone(), "interestRate", &[]));
m.insert("estimatedSettlePrice".to_string(), self.safe_number_k(contract.clone(), "estimatedSettlePrice", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "lastFundingRate", &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), intervalString.clone());
m
});
Value::Null
}
/*
* @method
* @name aster#fetchFundingRate
* @description fetch the current funding rate
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#symbol-price-ticker
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRate() 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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_public_get_v3_premium_index(&[__ws_arg_15]).await;
return self.parse_funding_rate(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchFundingRates
* @description fetch the current funding rate for multiple symbols
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#symbol-price-ticker
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let __ws_arg_16 = self.extend(params.clone(), &[]);
let mut response: Value = self.fapi_public_get_v3_premium_index(&[__ws_arg_16]).await;
return self.parse_funding_rates(response.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchFundingIntervals
* @description fetch the funding rate interval for multiple markets
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#get-funding-rate-config
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_intervals(&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;
}
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
}
let mut response: Value = self.fapi_public_get_v3_funding_info(&[params.clone()]).await;
return self.parse_funding_rates(response.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://asterdex.github.io/aster-api-website/futures-v3/market-data/#get-funding-rate-history
* @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
* @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(&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("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_public_get_v3_funding_rate(&[__ws_arg_17]).await;
return self.parse_funding_rate_histories(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_funding_rate_history(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTCUSDT",
// "fundingRate": "0.00063521",
// "fundingTime": "1621267200000",
// }
//
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "fundingTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(self.safe_string_k(contract.clone(), "symbol", &[]), &[Value::Null, Value::Null, Value::Str("swap".to_string())]));
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "fundingRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name aster#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#account-information-user_data
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#futures-account-balance-v3-user_data
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] "linear" or "inverse"
* @param {string} [params.type] 'spot', 'option', use params["subType"] for swap and future markets
* @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
}));
self.load_markets_and_sign_in().await;
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut data: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
data = self.fapi_private_get_v3_balance(&[params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.sapi_private_get_v3_account(&[params.clone()]).await;
data = self.safe_list_k(response.clone(), "balances", &[Value::List(vec![])]);
}
return self.parse_balance(data.clone());
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_222: bool = true;
while { if !__for_first_222 { i = add(&i, &Value::Int(1)); } __for_first_222 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut balance: Value = get_value(&response, &i);
let mut balance: Value = get_value(&response, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string2(balance.clone(), Value::Str("free".to_string()), Value::Str("availableBalance".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "locked", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "balance", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name aster#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#change-margin-type-trade
* @param {string} marginMode 'cross' or 'isolated'
* @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_margin_mode(&mut self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a symbol argument".to_string()))));
}
marginMode = to_upper(&marginMode);
if is_equal(&marginMode, &Value::Str("CROSS".to_string())) {
marginMode = Value::Str("CROSSED".to_string());
}
if is_true(&(!is_equal(&marginMode, &Value::Str("ISOLATED".to_string())))) && is_true(&(!is_equal(&marginMode, &Value::Str("CROSSED".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" marginMode must be either isolated or cross".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("marginType".to_string(), marginMode.clone());
m
});
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_post_v3_margin_type(&[__ws_arg_18]).await;
return response;
Value::Null
}
/*
* @method
* @name aster#fetchPositionMode
* @description fetchs the position mode, hedged or one way, hedged for aster is set identically for all linear markets or all inverse markets
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#get-current-position-modeuser_data
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an object detailing whether the market is in hedged or one-way mode
*/
pub async fn fetch_position_mode(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.fapi_private_get_v3_position_side_dual(&[params.clone()]).await;
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("hedged".to_string(), self.safe_bool_k(response.clone(), "dualSidePosition", &[]));
m
});
Value::Null
}
/*
* @method
* @name aster#setPositionMode
* @description set hedged to true or false for a market
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#change-position-modetrade
* @param {bool} hedged set to true to use dualSidePosition
* @param {string} symbol not used by setPositionMode ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut strValue: Value = ternary(is_true(&hedged), Value::Str("true".to_string()), Value::Str("false".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("dualSidePosition".to_string(), strValue.clone());
m
});
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
return self.fapi_private_post_v3_position_side_dual(&[__ws_arg_19]).await;
Value::Null
}
pub fn parse_trading_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(fee.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), self.safe_number_k(fee.clone(), "makerCommissionRate", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee.clone(), "takerCommissionRate", &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m.insert("tierBased".to_string(), Value::Bool(false));
m
});
Value::Null
}
/*
* @method
* @name aster#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://asterdex.github.io/aster-api-website/spot-v3/market-data/#get-symbol-fees
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#user-commission-rate-user_data
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_trading_fee(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_get_v3_commission_rate(&[__ws_arg_20]).await;
} else {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_get_v3_commission_rate(&[__ws_arg_21]).await;
}
return self.parse_trading_fee(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("NEW".to_string(), Value::Str("open".to_string()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".to_string()));
m.insert("FILLED".to_string(), Value::Str("closed".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("REJECTED".to_string(), Value::Str("canceled".to_string()));
m.insert("EXPIRED".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
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".to_string(), Value::Str("limit".to_string()));
m.insert("STOP_MARKET".to_string(), Value::Str("market".to_string()));
m.insert("TAKE_PROFIT".to_string(), Value::Str("limit".to_string()));
m.insert("TAKE_PROFIT_MARKET".to_string(), Value::Str("market".to_string()));
m.insert("TRAILING_STOP_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 parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// swap
// {
// "avgPrice": "0.00000",
// "clientOrderId": "abc",
// "cumQuote": "0",
// "executedQty": "0",
// "orderId": 1917641,
// "origQty": "0.40",
// "origType": "TRAILING_STOP_MARKET",
// "price": "0",
// "reduceOnly": false,
// "side": "BUY",
// "positionSide": "SHORT",
// "status": "NEW",
// "stopPrice": "9300",
// "closePosition": false,
// "symbol": "BTCUSDT",
// "time": 1579276756075,
// "timeInForce": "GTC",
// "type": "TRAILING_STOP_MARKET",
// "activatePrice": "9020",
// "priceRate": "0.3",
// "updateTime": 1579276756075,
// "workingType": "CONTRACT_PRICE",
// "priceProtect": false
// }
//
// spot
//
// fetchOrders, fetchOpenOrders, fetchOpenOrder, fetchOrder, cancelOrder, createOrder
//
// {
// "orderId": "417594542",
// "symbol": "ETHUSDT",
// "status": "FILLED",
// "clientOrderId": "web_qnvMAhOJsiVbSyu0BdKG",
// "price": "0", // value set for unfilled
// "avgPrice": "2351.580000", // value zero for unfilled
// "origQty": "0.0054",
// "executedQty": "0.0054", // value zero for unfilled
// "cumQuote": "12.69853200", // value zero for unfilled
// "timeInForce": "GTC",
// "type": "MARKET",
// "side": "SELL",
// "stopPrice": "0",
// "origType": "MARKET",
// "time": "1776274219582",
// "updateTime": "1776274219609",
// "orderListId": "-1"
// }
//
let mut info: Value = order.clone();
let mut positionSide: Value = self.safe_string_k(order.clone(), "positionSide", &[]);
let mut defaultType: Value = ternary(is_true(&(!is_equal(&positionSide, &Value::Null))), Value::Str("swap".to_string()), Value::Str("spot".to_string()));
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, defaultType.clone()]);
let mut side: Value = self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_k(order.clone(), "time", &[]);
let mut statusId: Value = self.safe_string_upper(order.clone(), Value::Str("status".to_string()), &[]);
let mut rawType: Value = self.safe_string_upper(order.clone(), Value::Str("type".to_string()), &[]);
let mut stopPriceString: Value = self.safe_string_k(order.clone(), "stopPrice", &[]);
let mut triggerPrice: Value = self.parse_number(self.omit_zero(stopPriceString.clone()), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("id".to_string(), self.safe_string_k(order.clone(), "orderId", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "clientOrderId", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.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(), self.safe_integer_k(order.clone(), "updateTime", &[]));
m.insert("type".to_string(), self.parse_order_type(rawType.clone()));
m.insert("timeInForce".to_string(), self.safe_string_k(order.clone(), "timeInForce", &[]));
m.insert("postOnly".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.safe_string_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("average".to_string(), self.safe_string_k(order.clone(), "avgPrice", &[]));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "cumQuote", &[]));
m.insert("amount".to_string(), self.safe_string_k(order.clone(), "origQty", &[]));
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "executedQty", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_order_status(statusId.clone()));
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), self.safe_bool2(order.clone(), Value::Str("reduceOnly".to_string()), Value::Str("ro".to_string()), &[]));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchOrder
* @description fetches information on an order made by the user
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#query-order-user_data
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#query-order-user_data
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("clientOid".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("clientOid".to_string())]), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("origClientOrderId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_get_v3_order(&[__ws_arg_22]).await;
} else {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_get_v3_order(&[__ws_arg_23]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchOpenOrder
* @description fetch an open order by the id
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#query-current-open-order-user_data
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#query-current-open-order-user_data
* @param {string} id order id
* @param {string} symbol unified market symbol
* @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 fetch_open_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOpenOrder() requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("clientOid".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("clientOid".to_string())]), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("origClientOrderId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_get_v3_open_order(&[__ws_arg_24]).await;
} else {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_get_v3_open_order(&[__ws_arg_25]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#query-all-orders-user_data
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#all-orders-user_data
* @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
* @param {int} [params.until] the latest time in ms to fetch orders for
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrders() requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_get_v3_all_orders(&[__ws_arg_26]).await;
} else {
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_get_v3_all_orders(&[__ws_arg_27]).await;
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#current-open-orders-user_data
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#current-all-open-orders-user_data
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] "linear" or "inverse"
* @param {string} [params.type] 'spot', 'option', use params["subType"] for swap and future markets
* @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
}));
self.load_markets_and_sign_in().await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
let mut marketType: 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(&symbol, &Value::Null) {
if is_equal(&get_value(&get_value(&self.options, &Value::Str("fetchOpenOrders".to_string())), &Value::Str("warnIfNoSymbol".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&add(&self.id, &Value::Str(" fetchOpenOrders(): WARNING - this method without providing \"symbol\" argument uses 40 times more rate-limit quota. If you acknowledge this warning, set ".to_string())), &self.id), &Value::Str(".options[\"fetchOpenOrders\"][\"warnIfNoSymbol\"] = false to suppress this warning message.".to_string()))));
}
} else {
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 __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&self.is_linear(marketType.clone(), &[subType.clone()])) {
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_get_v3_open_orders(&[__ws_arg_28]).await;
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_get_v3_open_orders(&[__ws_arg_29]).await;
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name aster#createOrder
* @description create a trade order
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#place-order-trade
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#new-order-trade
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit' or 'STOP' or 'STOP_MARKET' or 'TAKE_PROFIT' or 'TAKE_PROFIT_MARKET' or 'TRAILING_STOP_MARKET'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.reduceOnly] for swap and future reduceOnly is a string 'true' or 'false' that cant be sent with close position set to true or in hedge mode. For spot margin and option reduceOnly is a boolean.
* @param {boolean} [params.test] whether to use the test endpoint or not, default is false
* @param {float} [params.trailingPercent] the percent to trail away from the current market price
* @param {float} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
* @param {string} [params.positionSide] "BOTH" for one-way mode, "LONG" for buy side of hedged mode, "SHORT" for sell side of hedged mode
* @param {float} [params.triggerPrice] the price that a trigger order is triggered at
* @param {float} [params.stopLossPrice] the price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] the price that a take profit order is triggered at
* @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
}));
self.load_markets_and_sign_in().await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
response = self.fapi_private_post_v3_order(&[request.clone()]).await;
} else {
response = self.sapi_private_post_v3_order(&[request.clone()]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#createOrders
* @description create a list of trade orders
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#new-order-trade
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @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 create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut ordersRequests: Value = Value::List(vec![]);
let mut orderSymbols: Value = Value::List(vec![]);
if is_greater_than(&get_array_length(&orders), &Value::Int(5)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrders() order list max 5 orders".to_string()))));
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_223: bool = true;
while { if !__for_first_223 { i = add(&i, &Value::Int(1)); } __for_first_223 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
let mut currentMarket: Value = self.market(marketId.clone());
append_to_array(&mut orderSymbols, get_value(¤tMarket, &Value::Str("symbol".to_string())));
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
orderSymbols = self.market_symbols(&[orderSymbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.market(get_value(&orderSymbols, &Value::Int(0)));
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" createOrders() does not support ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" orders".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("batchOrders".to_string(), ordersRequests.clone());
m
});
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_post_v3_batch_orders(&[__ws_arg_30]).await;
return self.parse_orders(response.clone(), &[]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
/*
* @method
* @ignore
* @name aster#createOrderRequest
* @description helper function to build the request
* @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 you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} request to be sent to the exchange
*/
let mut market: Value = self.market(symbol.clone());
let mut initialUppercaseType: Value = to_upper(&type_var);
let mut isMarketOrder: Value = Value::Bool(is_equal(&initialUppercaseType, &Value::Str("MARKET".to_string())));
let mut isLimitOrder: bool = is_equal(&initialUppercaseType, &Value::Str("LIMIT".to_string()));
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(), to_upper(&side));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("newClientOrderId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("newClientOrderId".to_string()), clientOrderId.clone());
}
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[triggerPrice.clone()]);
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut trailingDelta: Value = self.safe_string_k(params.clone(), "trailingDelta", &[]);
let mut trailingTriggerPrice: Value = self.safe_string2(params.clone(), Value::Str("trailingTriggerPrice".to_string()), Value::Str("activationPrice".to_string()), &[]);
let mut trailingPercent: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("trailingPercent".to_string()), Value::Str("callbackRate".to_string()), Value::Str("trailingDelta".to_string())]), &[]);
let mut isTrailingPercentOrder: bool = !is_equal(&trailingPercent, &Value::Null);
let mut isStopLoss: bool = !is_equal(&stopLossPrice, &Value::Null) || !is_equal(&trailingDelta, &Value::Null);
let mut isTakeProfit: bool = !is_equal(&takeProfitPrice, &Value::Null);
let mut uppercaseType: Value = initialUppercaseType.clone();
let mut stopPrice: Value = Value::Null;
if is_true(&isTrailingPercentOrder) {
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
uppercaseType = Value::Str("TRAILING_STOP_MARKET".to_string());
add_element_to_object(&mut request, &Value::Str("callbackRate".to_string()), trailingPercent.clone());
if !is_equal(&trailingTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("activationPrice".to_string()), self.price_to_precision(symbol.clone(), trailingTriggerPrice.clone()));
}
}
} else if is_true(&isStopLoss) {
stopPrice = stopLossPrice.clone();
if is_true(&isMarketOrder) {
uppercaseType = Value::Str("STOP_MARKET".to_string());
} else if is_true(&isLimitOrder) {
uppercaseType = Value::Str("STOP".to_string());
}
} else if is_true(&isTakeProfit) {
stopPrice = takeProfitPrice.clone();
if is_true(&isMarketOrder) {
uppercaseType = Value::Str("TAKE_PROFIT_MARKET".to_string());
} else if is_true(&isLimitOrder) {
uppercaseType = Value::Str("TAKE_PROFIT".to_string());
}
}
let mut postOnly: Value = self.is_post_only(isMarketOrder.clone(), Value::Null, &[params.clone()]);
if is_true(&postOnly) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("GTX".to_string()));
}
//
// spot
// LIMIT timeInForce, quantity, price
// MARKET quantity or quoteOrderQty
// STOP and TAKE_PROFIT quantity, price, stopPrice
// STOP_MARKET and TAKE_PROFIT_MARKET quantity, stopPrice
// future
// LIMIT timeInForce, quantity, price
// MARKET quantity
// STOP/TAKE_PROFIT quantity, price, stopPrice
// STOP_MARKET/TAKE_PROFIT_MARKET stopPrice
// TRAILING_STOP_MARKET callbackRate
//
// additional required fields depending on the order type
let mut closePosition: Value = self.safe_bool_k(params.clone(), "closePosition", &[Value::Bool(false)]);
let mut timeInForceIsRequired: bool = false;
let mut priceIsRequired: bool = false;
let mut triggerPriceIsRequired: bool = false;
let mut quantityIsRequired: bool = false;
add_element_to_object(&mut request, &Value::Str("type".to_string()), uppercaseType.clone());
if is_equal(&uppercaseType, &Value::Str("MARKET".to_string())) {
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let mut quoteOrderQty: Value = self.handle_option(Value::Str("createOrder".to_string()), Value::Str("quoteOrderQty".to_string()), &[Value::Bool(true)]);
if is_equal("eOrderQty, &Value::Bool(true)) {
let mut quoteOrderQtyNew: Value = self.safe_string2(params.clone(), Value::Str("quoteOrderQty".to_string()), Value::Str("cost".to_string()), &[]);
let mut precision: Value = get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("price".to_string()));
if !is_equal("eOrderQtyNew, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("quoteOrderQty".to_string()), self.decimal_to_precision(quoteOrderQtyNew.clone(), Value::Int(crate::runtime::TRUNCATE), precision.clone(), &[self.precisionMode.clone()]));
} else if !is_equal(&price, &Value::Null) {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
let mut quoteOrderQuantity: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
add_element_to_object(&mut request, &Value::Str("quoteOrderQty".to_string()), self.decimal_to_precision(quoteOrderQuantity.clone(), Value::Int(crate::runtime::TRUNCATE), precision.clone(), &[self.precisionMode.clone()]));
} else {
quantityIsRequired = true;
}
} else {
quantityIsRequired = true;
}
} else {
quantityIsRequired = true;
}
} else if is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())) {
timeInForceIsRequired = true;
quantityIsRequired = true;
priceIsRequired = true;
} else if is_true(&(is_equal(&uppercaseType, &Value::Str("STOP".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT".to_string())))) {
quantityIsRequired = true;
priceIsRequired = true;
triggerPriceIsRequired = true;
} else if is_true(&(is_equal(&uppercaseType, &Value::Str("STOP_MARKET".to_string())))) || is_true(&(is_equal(&uppercaseType, &Value::Str("TAKE_PROFIT_MARKET".to_string())))) {
if !is_equal(&closePosition, &Value::Bool(true)) {
quantityIsRequired = true;
}
triggerPriceIsRequired = true;
} else if is_equal(&uppercaseType, &Value::Str("TRAILING_STOP_MARKET".to_string())) {
add_element_to_object(&mut request, &Value::Str("callbackRate".to_string()), trailingPercent.clone());
if !is_equal(&trailingTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("activationPrice".to_string()), self.price_to_precision(symbol.clone(), trailingTriggerPrice.clone()));
}
}
if is_true(&quantityIsRequired) {
let mut marketAmountPrecision: Value = self.safe_string(get_value(&market, &Value::Str("precision".to_string())), Value::Str("amount".to_string()), &[]);
let mut isPrecisionAvailable: bool = !is_equal(&marketAmountPrecision, &Value::Null);
if is_true(&isPrecisionAvailable) {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.parse_to_numeric(amount.clone()));
}
}
if is_true(&priceIsRequired) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&self.id, &Value::Str(" createOrder() requires a price argument for a ".to_string())), &type_var), &Value::Str(" order".to_string()))));
}
let mut pricePrecision: Value = self.safe_string(get_value(&market, &Value::Str("precision".to_string())), Value::Str("price".to_string()), &[]);
let mut isPricePrecisionAvailable: bool = !is_equal(&pricePrecision, &Value::Null);
if is_true(&isPricePrecisionAvailable) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.parse_to_numeric(price.clone()));
}
}
if is_true(&triggerPriceIsRequired) {
if is_equal(&stopPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&self.id, &Value::Str(" createOrder() requires a stopPrice extra param for a ".to_string())), &type_var), &Value::Str(" order".to_string()))));
}
if !is_equal(&stopPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), stopPrice.clone()));
}
}
if is_true(&timeInForceIsRequired) && is_true(&(is_equal(&self.safe_string_k(params.clone(), "timeInForce", &[]), &Value::Null))) && is_true(&(is_equal(&self.safe_string_k(request.clone(), "timeInForce", &[]), &Value::Null))) {
let mut tif: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("timeInForce".to_string()), &[]); tif = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), tif.clone());
}
let mut requestParams: Value = self.omit(params.clone(), Value::List(vec![Value::Str("newClientOrderId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("trailingTriggerPrice".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("trailingDelta".to_string()), Value::Str("stopPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string())]), &[]);
if is_true(&(is_equal(&self.safe_bool_k(self.options.clone(), "builderFee", &[]), &Value::Bool(true)))) && is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("builder".to_string()), self.safe_string_k(self.options.clone(), "builder", &[]));
add_element_to_object(&mut request, &Value::Str("feeRate".to_string()), self.safe_string_k(self.options.clone(), "builderRate", &[]));
}
return self.extend(request.clone(), &[requestParams.clone()]);
Value::Null
}
/*
* @method
* @name aster#cancelAllOrders
* @description cancel all open orders in a market
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#cancel-all-open-orders-trade
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#current-all-open-orders-user_data
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_delete_v3_all_open_orders(&[__ws_arg_31]).await;
} else {
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_delete_v3_all_open_orders(&[__ws_arg_32]).await;
}
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[])]);
Value::Null
}
/*
* @method
* @name aster#cancelOrder
* @description cancels an open order
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#cancel-order-trade
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#cancel-order-trade
* @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
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("origClientOrderId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("origClientOrderId".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("origClientOrderId".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_delete_v3_order(&[__ws_arg_33]).await;
} else {
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_delete_v3_order(&[__ws_arg_34]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#cancelOrders
* @description cancel multiple orders
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#cancel-all-open-orders-trade
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#cancel-multiple-orders-trade
* @param {string[]} ids order ids
* @param {string} [symbol] unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {string[]} [params.origClientOrderIdList] max length 10 e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma
* @param {int[]} [params.recvWindow]
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut clientOrderIdList: Value = self.safe_list_k(params.clone(), "origClientOrderIdList", &[]);
if !is_equal(&clientOrderIdList, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("origClientOrderIdList".to_string()), clientOrderIdList.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderIdList".to_string()), ids.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
response = self.fapi_private_delete_v3_batch_orders(&[__ws_arg_35]).await;
} else {
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
response = self.sapi_private_delete_v3_all_open_orders(&[__ws_arg_36]).await;
}
return self.parse_orders(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name aster#setLeverage
* @description set the level of leverage for a market
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#change-initial-leverage-trade
* @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_true(&(is_less_than(&leverage, &Value::Int(1)))) || is_true(&(is_greater_than(&leverage, &Value::Int(125)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" leverage should be between 1 and 125".to_string()))));
}
self.load_markets_and_sign_in().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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("leverage".to_string(), leverage.clone());
m
});
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_post_v3_leverage(&[__ws_arg_37]).await;
return response;
Value::Null
}
/*
* @method
* @name aster#fetchLeverages
* @description fetch the set leverage for all markets
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#position-information-v3-user_data
* @param {string[]} [symbols] a list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverages(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut response: Value = self.fapi_private_get_v3_position_risk(&[params.clone()]).await;
return self.parse_leverages(self.to_array(response.clone()), &[symbols.clone(), Value::Str("symbol".to_string())]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "INJUSDT",
// "positionAmt": "0.0",
// "entryPrice": "0.0",
// "markPrice": "0.00000000",
// "unRealizedProfit": "0.00000000",
// "liquidationPrice": "0",
// "leverage": "20",
// "maxNotionalValue": "25000",
// "marginType": "cross",
// "isolatedMargin": "0.00000000",
// "isAutoAddMargin": "false",
// "positionSide": "BOTH",
// "notional": "0",
// "isolatedWallet": "0",
// "updateTime": 0
// }
//
let mut marketId: Value = self.safe_string_k(leverage.clone(), "symbol", &[]);
let mut marginMode: Value = self.safe_string_lower(leverage.clone(), Value::Str("marginType".to_string()), &[]);
let mut side: Value = self.safe_string_lower(leverage.clone(), Value::Str("positionSide".to_string()), &[]);
let mut longLeverage: Value = Value::Null;
let mut shortLeverage: Value = Value::Null;
let mut leverageValue: Value = self.safe_integer_k(leverage.clone(), "leverage", &[]);
if is_true(&(is_equal(&side, &Value::Null))) || is_true(&(is_equal(&side, &Value::Str("both".to_string())))) {
longLeverage = leverageValue.clone();
shortLeverage = leverageValue.clone();
} else if is_equal(&side, &Value::Str("long".to_string())) {
longLeverage = leverageValue.clone();
} else if is_equal(&side, &Value::Str("short".to_string())) {
shortLeverage = leverageValue.clone();
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("longLeverage".to_string(), longLeverage.clone());
m.insert("shortLeverage".to_string(), shortLeverage.clone());
m
});
Value::Null
}
/*
* @method
* @name aster#fetchMarginModes
* @description fetches margin mode of the user
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#position-information-v3-user_data
* @param {string[]} symbols unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [margin mode structures]{@link https://docs.ccxt.com/?id=margin-mode-structure}
*/
pub async fn fetch_margin_modes(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut response: Value = self.fapi_private_get_v3_position_risk(&[params.clone()]).await;
return self.parse_margin_modes(self.to_array(response.clone()), &[symbols.clone(), Value::Str("symbol".to_string()), Value::Str("swap".to_string())]);
Value::Null
}
pub fn parse_margin_mode(&self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "INJUSDT",
// "positionAmt": "0.0",
// "entryPrice": "0.0",
// "markPrice": "0.00000000",
// "unRealizedProfit": "0.00000000",
// "liquidationPrice": "0",
// "leverage": "20",
// "maxNotionalValue": "25000",
// "marginType": "cross",
// "isolatedMargin": "0.00000000",
// "isAutoAddMargin": "false",
// "positionSide": "BOTH",
// "notional": "0",
// "isolatedWallet": "0",
// "updateTime": 0
// }
//
let mut marketId: Value = self.safe_string_k(marginMode.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), marginMode.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("marginMode".to_string(), self.safe_string_lower(marginMode.clone(), Value::Str("marginType".to_string()), &[]));
m
});
Value::Null
}
/*
* @method
* @name aster#fetchMarginAdjustmentHistory
* @description fetches the history of margin added or reduced from contract isolated positions
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#get-position-margin-change-history-trade
* @param {string} symbol unified market symbol
* @param {string} [type] "add" or "reduce"
* @param {int} [since] timestamp in ms of the earliest change to fetch
* @param {int} [limit] the maximum amount of changes to fetch
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest change to fetch
* @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn fetch_margin_adjustment_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut type_var = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, 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(" fetchMarginAdjustmentHistory () requires a symbol argument".to_string()))));
}
self.load_markets_and_sign_in().await;
let mut market: Value = self.market(symbol.clone());
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
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
});
if !is_equal(&type_var, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), ternary(is_true(&(is_equal(&type_var, &Value::Str("add".to_string())))), Value::Int(1), Value::Int(2)));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_get_v3_position_margin_history(&[__ws_arg_38]).await;
//
// [
// {
// "amount": "23.36332311",
// "asset": "USDT",
// "symbol": "BTCUSDT",
// "time": 1578047897182,
// "type": 1,
// "positionSide": "BOTH"
// }
// ]
//
let mut modifications: Value = self.parse_margin_modifications(self.to_array(response.clone()), &[]);
return self.filter_by_symbol_since_limit(modifications.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "amount": "100",
// "asset": "USDT",
// "symbol": "BTCUSDT",
// "time": 1578047900425,
// "type": 1,
// "positionSide": "LONG"
// }
//
// {
// "amount": 100.0,
// "code": 200,
// "msg": "Successfully modify position margin.",
// "type": 1
// }
//
let mut rawType: Value = self.safe_integer_k(data.clone(), "type", &[]);
let mut errorCode: Value = self.safe_string_k(data.clone(), "code", &[]);
let mut marketId: Value = self.safe_string_k(data.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "time", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut noErrorCode: bool = is_equal(&errorCode, &Value::Null);
let mut success: bool = is_equal(&errorCode, &Value::Str("200".to_string()));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), ternary(is_true(&(is_equal(&rawType, &Value::Int(1)))), Value::Str("add".to_string()), Value::Str("reduce".to_string())));
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), self.safe_number_k(data.clone(), "amount", &[]));
m.insert("code".to_string(), self.safe_string_k(data.clone(), "asset", &[]));
m.insert("total".to_string(), Value::Null);
m.insert("status".to_string(), ternary(is_true(&(is_true(&success) || is_true(&noErrorCode))), Value::Str("ok".to_string()), Value::Str("failed".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
pub async fn modify_margin_helper(&mut self, mut symbol: Value, mut amount: Value, mut addOrReduce: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut market: Value = self.market(symbol.clone());
amount = self.amount_to_precision(symbol.clone(), amount.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), addOrReduce.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("amount".to_string(), amount.clone());
m
});
let mut code: Value = get_value(&market, &Value::Str("quote".to_string()));
let __ws_arg_39 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_post_v3_position_margin(&[__ws_arg_39]).await;
let __ws_arg_40 = self.parse_margin_modification(response.clone(), &[market.clone()]);
return self.extend(__ws_arg_40, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("code".to_string(), code.clone());
m
})]);
Value::Null
}
/*
* @method
* @name aster#reduceMargin
* @description remove margin from a position
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#modify-isolated-position-margin-trade
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=reduce-margin-structure}
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Int(2), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name aster#addMargin
* @description add margin
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#modify-isolated-position-margin-trade
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=add-margin-structure}
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Int(1), &[params.clone()]).await;
Value::Null
}
pub fn parse_income(&self, mut income: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETHUSDT",
// "incomeType": "FUNDING_FEE",
// "income": "0.00134317",
// "asset": "USDT",
// "time": "1621584000000",
// "info": "FUNDING_FEE",
// "tranId": "4480321991774044580",
// "tradeId": ""
// }
//
let mut marketId: Value = self.safe_string_k(income.clone(), "symbol", &[]);
let mut currencyId: Value = self.safe_string_k(income.clone(), "asset", &[]);
let mut timestamp: Value = self.safe_integer_k(income.clone(), "time", &[]);
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(), Value::Null, Value::Str("swap".to_string())]));
m.insert("code".to_string(), self.safe_currency_code(currencyId.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(), "tranId", &[]));
m.insert("amount".to_string(), self.safe_number_k(income.clone(), "income", &[]));
m
});
Value::Null
}
/*
* @method
* @name aster#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#get-income-historyuser_data
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch funding history for
* @param {int} [limit] the maximum number of funding history structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest funding history entry
* @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the funding history for a portfolio margin account
* @param {string} [params.subType] "linear" or "inverse"
* @returns {object} a [funding history structure]{@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
}));
self.load_markets_and_sign_in().await;
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("incomeType".to_string(), Value::Str("FUNDING_FEE".to_string()));
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 __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); 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("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000))); // max 1000
}
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_get_v3_income(&[__ws_arg_41]).await;
return self.parse_incomes(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "",
// "incomeType": "TRANSFER",
// "income": "10.00000000",
// "asset": "USDT",
// "time": 1677645250000,
// "info": "TRANSFER",
// "tranId": 131001573082,
// "tradeId": ""
// }
//
let mut amount: Value = self.safe_string_k(item.clone(), "income", &[]);
let mut direction: Value = Value::Null;
if is_true(&crate::precise::Precise::stringLe(&amount, &Value::Str("0".to_string()))) {
direction = Value::Str("out".to_string());
amount = crate::precise::Precise::stringMul(&Value::Str("-1".to_string()), &amount);
} else {
direction = Value::Str("in".to_string());
}
let mut currencyId: Value = self.safe_string_k(item.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_k(item.clone(), "time", &[]);
let mut type_var: Value = self.safe_string_k(item.clone(), "incomeType", &[]);
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string_k(item.clone(), "tranId", &[]));
m.insert("direction".to_string(), direction.clone());
m.insert("account".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("referenceId".to_string(), self.safe_string_k(item.clone(), "tradeId", &[]));
m.insert("type".to_string(), self.parse_ledger_entry_type(type_var.clone()));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut ledgerType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TRANSFER".to_string(), Value::Str("transfer".to_string()));
m.insert("WELCOME_BONUS".to_string(), Value::Str("cashback".to_string()));
m.insert("REALIZED_PNL".to_string(), Value::Str("trade".to_string()));
m.insert("FUNDING_FEE".to_string(), Value::Str("fee".to_string()));
m.insert("COMMISSION".to_string(), Value::Str("commission".to_string()));
m.insert("INSURANCE_CLEAR".to_string(), Value::Str("settlement".to_string()));
m.insert("MARKET_MERCHANT_RETURN_REWARD".to_string(), Value::Str("cashback".to_string()));
m
});
return self.safe_string(ledgerType.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name aster#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#get-income-historyuser_data
* @param {string} [code] unified currency code
* @param {int} [since] timestamp in ms of the earliest ledger entry
* @param {int} [limit] max number of ledger entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest ledger entry
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000))); // max 1000
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_get_v3_income(&[__ws_arg_42]).await;
return self.parse_ledger(response.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_position_risk(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "entryPrice": "6563.66500",
// "marginType": "isolated",
// "isAutoAddMargin": "false",
// "isolatedMargin": "15517.54150468",
// "leverage": "10",
// "liquidationPrice": "5930.78",
// "markPrice": "6679.50671178",
// "maxNotionalValue": "20000000",
// "positionSide": "LONG",
// "positionAmt": "20.000",
// "symbol": "BTCUSDT",
// "unRealizedProfit": "2316.83423560",
// "updateTime": 1625474304765
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut isolatedMarginString: Value = self.safe_string_k(position.clone(), "isolatedMargin", &[]);
let mut leverageBrackets: Value = self.safe_dict_k(self.options.clone(), "leverageBrackets", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut leverageBracket: Value = self.safe_list(leverageBrackets.clone(), symbol.clone(), &[Value::List(vec![])]);
let mut notionalString: Value = self.safe_string2(position.clone(), Value::Str("notional".to_string()), Value::Str("notionalValue".to_string()), &[]);
let mut notionalStringAbs: Value = crate::precise::Precise::stringAbs(¬ionalString);
let mut maintenanceMarginPercentageString: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_224: bool = true;
while { if !__for_first_224 { i = add(&i, &Value::Int(1)); } __for_first_224 = false; is_less_than(&i, &get_array_length(&leverageBracket)) } {
let mut bracket: Value = get_value(&leverageBracket, &i);
let mut bracket: Value = get_value(&leverageBracket, &i);
if is_true(&crate::precise::Precise::stringLt(¬ionalStringAbs, &get_value(&bracket, &Value::Int(0)))) {
break;
}
maintenanceMarginPercentageString = get_value(&bracket, &Value::Int(1));
}
}
let mut notional: Value = self.parse_number(notionalStringAbs.clone(), &[]);
let mut contractsAbs: Value = crate::precise::Precise::stringAbs(&self.safe_string_k(position.clone(), "positionAmt", &[]));
let mut contracts: Value = self.parse_number(contractsAbs.clone(), &[]);
let mut unrealizedPnlString: Value = self.safe_string_k(position.clone(), "unRealizedProfit", &[]);
let mut unrealizedPnl: Value = self.parse_number(unrealizedPnlString.clone(), &[]);
let mut liquidationPriceString: Value = self.omit_zero(self.safe_string_k(position.clone(), "liquidationPrice", &[]));
let mut liquidationPrice: Value = self.parse_number(liquidationPriceString.clone(), &[]);
let mut collateralString: Value = Value::Null;
let mut marginMode: Value = self.safe_string_k(position.clone(), "marginType", &[]);
if is_equal(&marginMode, &Value::Null) && !is_equal(&isolatedMarginString, &Value::Null) {
marginMode = ternary(is_true(&crate::precise::Precise::stringEq(&isolatedMarginString, &Value::Str("0".to_string()))), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
}
let mut side: Value = Value::Null;
if is_true(&crate::precise::Precise::stringGt(¬ionalString, &Value::Str("0".to_string()))) {
side = Value::Str("long".to_string());
} else if is_true(&crate::precise::Precise::stringLt(¬ionalString, &Value::Str("0".to_string()))) {
side = Value::Str("short".to_string());
}
let mut entryPriceString: Value = self.safe_string_k(position.clone(), "entryPrice", &[]);
let mut entryPrice: Value = self.parse_number(entryPriceString.clone(), &[]);
let mut contractSize: Value = self.safe_value_k(market.clone(), "contractSize", &[]);
let mut contractSizeString: Value = self.number_to_string(contractSize.clone());
// as oppose to notionalValue
let mut linear: Value = (Value::Bool(in_op(&position, &Value::Str("notional".to_string()))));
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
// calculate collateral
let mut precision: Value = self.safe_dict_k(market.clone(), "precision", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut basePrecisionValue: Value = self.safe_string_k(precision.clone(), "base", &[]);
let mut quotePrecisionValue: Value = self.safe_string2(precision.clone(), Value::Str("quote".to_string()), Value::Str("price".to_string()), &[]);
let mut precisionIsUndefined: bool = is_true(&(is_equal(&basePrecisionValue, &Value::Null))) && is_true(&(is_equal("ePrecisionValue, &Value::Null)));
if !is_true(&precisionIsUndefined) {
if is_true(&linear) {
// walletBalance = (liquidationPrice * (±1 + mmp) ± entryPrice) * contracts
let mut onePlusMaintenanceMarginPercentageString: Value = Value::Null;
let mut entryPriceSignString: Value = entryPriceString.clone();
if is_equal(&side, &Value::Str("short".to_string())) {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringAdd(&Value::Str("1".to_string()), &maintenanceMarginPercentageString);
entryPriceSignString = crate::precise::Precise::stringMul(&Value::Str("-1".to_string()), &entryPriceSignString);
} else {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringAdd(&Value::Str("-1".to_string()), &maintenanceMarginPercentageString);
}
let mut inner: Value = crate::precise::Precise::stringMul(&liquidationPriceString, &onePlusMaintenanceMarginPercentageString);
let mut leftSide: Value = crate::precise::Precise::stringAdd(&inner, &entryPriceSignString);
let mut quotePrecision: Value = self.precision_from_string(self.safe_string2(precision.clone(), Value::Str("quote".to_string()), Value::Str("price".to_string()), &[]));
if !is_equal("ePrecision, &Value::Null) {
collateralString = crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringMul(&leftSide, &contractsAbs), &Value::Str("1".to_string()), "ePrecision);
}
} else {
// walletBalance = (contracts * contractSize) * (±1/entryPrice - (±1 - mmp) / liquidationPrice)
let mut onePlusMaintenanceMarginPercentageString: Value = Value::Null;
let mut entryPriceSignString: Value = entryPriceString.clone();
if is_equal(&side, &Value::Str("short".to_string())) {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringSub(&Value::Str("1".to_string()), &maintenanceMarginPercentageString);
} else {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringSub(&Value::Str("-1".to_string()), &maintenanceMarginPercentageString);
entryPriceSignString = crate::precise::Precise::stringMul(&Value::Str("-1".to_string()), &entryPriceSignString);
}
let mut leftSide: Value = crate::precise::Precise::stringMul(&contractsAbs, &contractSizeString);
let mut rightSide: Value = crate::precise::Precise::stringSub(&crate::precise::Precise::stringDiv(&Value::Str("1".to_string()), &entryPriceSignString), &crate::precise::Precise::stringDiv(&onePlusMaintenanceMarginPercentageString, &liquidationPriceString));
let mut basePrecision: Value = self.precision_from_string(self.safe_string_k(precision.clone(), "base", &[]));
if !is_equal(&basePrecision, &Value::Null) {
collateralString = crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringMul(&leftSide, &rightSide), &Value::Str("1".to_string()), &basePrecision);
}
}
}
} else {
collateralString = self.safe_string_k(position.clone(), "isolatedMargin", &[]);
}
collateralString = ternary(is_true(&(is_equal(&collateralString, &Value::Null))), Value::Str("0".to_string()), collateralString.clone());
let mut collateral: Value = self.parse_number(collateralString.clone(), &[]);
let mut markPrice: Value = self.parse_number(self.omit_zero(self.safe_string_k(position.clone(), "markPrice", &[])), &[]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "updateTime", &[]);
if is_equal(×tamp, &Value::Int(0)) {
timestamp = Value::Null;
}
let mut maintenanceMarginPercentage: Value = self.parse_number(maintenanceMarginPercentageString.clone(), &[]);
let mut maintenanceMarginString: Value = crate::precise::Precise::stringMul(&maintenanceMarginPercentageString, ¬ionalStringAbs);
if is_equal(&maintenanceMarginString, &Value::Null) {
// for a while, this new value was a backup to the existing calculations, but in future we might prioritize this
maintenanceMarginString = self.safe_string_k(position.clone(), "maintMargin", &[]);
}
let mut maintenanceMargin: Value = self.parse_number(maintenanceMarginString.clone(), &[]);
let mut initialMarginString: Value = Value::Null;
let mut initialMarginPercentageString: Value = Value::Null;
let mut leverageString: Value = self.safe_string_k(position.clone(), "leverage", &[]);
if !is_equal(&leverageString, &Value::Null) {
let mut leverage: Value = crate::runtime::parse_int(&leverageString);
let mut rational: Value = self.is_round_number(mod_val(&Value::Int(1000), &leverage));
initialMarginPercentageString = crate::precise::Precise::stringDivPrec(&Value::Str("1".to_string()), &leverageString, &Value::Int(8));
if !is_true(&rational) {
initialMarginPercentageString = crate::precise::Precise::stringAdd(&initialMarginPercentageString, &Value::Str("1e-8".to_string()));
}
let mut unrounded: Value = crate::precise::Precise::stringMul(¬ionalStringAbs, &initialMarginPercentageString);
initialMarginString = crate::precise::Precise::stringDivPrec(&unrounded, &Value::Str("1".to_string()), &Value::Int(8));
} else {
initialMarginString = self.safe_string_k(position.clone(), "initialMargin", &[]);
let mut unrounded: Value = crate::precise::Precise::stringMul(&initialMarginString, &Value::Str("1".to_string()));
initialMarginPercentageString = crate::precise::Precise::stringDivPrec(&unrounded, ¬ionalStringAbs, &Value::Int(8));
}
let mut marginRatio: Value = Value::Null;
let mut percentage: Value = Value::Null;
if !is_true(&crate::precise::Precise::stringEquals(&collateralString, &Value::Str("0".to_string()))) {
marginRatio = self.parse_number(crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringAdd(&crate::precise::Precise::stringDiv(&maintenanceMarginString, &collateralString), &Value::Str("5e-5".to_string())), &Value::Str("1".to_string()), &Value::Int(4)), &[]);
percentage = self.parse_number(crate::precise::Precise::stringMul(&crate::precise::Precise::stringDivPrec(&unrealizedPnlString, &initialMarginString, &Value::Int(4)), &Value::Str("100".to_string())), &[]);
}
let mut positionSide: Value = self.safe_string_k(position.clone(), "positionSide", &[]);
let mut hedged: Value = Value::Bool(!is_equal(&positionSide, &Value::Str("BOTH".to_string())));
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol.clone());
m.insert("contracts".to_string(), contracts.clone());
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("unrealizedPnl".to_string(), unrealizedPnl.clone());
m.insert("leverage".to_string(), self.parse_number(leverageString.clone(), &[]));
m.insert("liquidationPrice".to_string(), liquidationPrice.clone());
m.insert("collateral".to_string(), collateral.clone());
m.insert("notional".to_string(), notional.clone());
m.insert("markPrice".to_string(), markPrice.clone());
m.insert("entryPrice".to_string(), entryPrice.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("initialMargin".to_string(), self.parse_number(initialMarginString.clone(), &[]));
m.insert("initialMarginPercentage".to_string(), self.parse_number(initialMarginPercentageString.clone(), &[]));
m.insert("maintenanceMargin".to_string(), maintenanceMargin.clone());
m.insert("maintenanceMarginPercentage".to_string(), maintenanceMarginPercentage.clone());
m.insert("marginRatio".to_string(), marginRatio.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("side".to_string(), side.clone());
m.insert("hedged".to_string(), hedged.clone());
m.insert("percentage".to_string(), percentage.clone());
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name aster#fetchPositionsRisk
* @description fetch positions risk
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#position-information-v3-user_data
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} data on the positions risk
*/
pub async fn fetch_positions_risk(&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(&symbols, &Value::Null) {
if !is_true(&Value::Bool(is_array(&symbols))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchPositionsRisk() requires an array argument for symbols".to_string()))));
}
}
self.load_markets_and_sign_in().await;
self.load_leverage_brackets(&[Value::Bool(false), params.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.fapi_private_get_v3_position_risk(&[__ws_arg_43]).await;
//
// [
// {
// "entryPrice": "6563.66500",
// "marginType": "isolated",
// "isAutoAddMargin": "false",
// "isolatedMargin": "15517.54150468",
// "leverage": "10",
// "liquidationPrice": "5930.78",
// "markPrice": "6679.50671178",
// "maxNotionalValue": "20000000",
// "positionSide": "LONG",
// "positionAmt": "20.000", // negative value for 'SHORT'
// "symbol": "BTCUSDT",
// "unRealizedProfit": "2316.83423560",
// "updateTime": 1625474304765
// }
// ]
//
let mut rawPositions: Value = self.to_array(response.clone());
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_225: bool = true;
while { if !__for_first_225 { i = add(&i, &Value::Int(1)); } __for_first_225 = false; is_less_than(&i, &get_array_length(&rawPositions)) } {
let mut rawPosition: Value = get_value(&rawPositions, &i);
let mut rawPosition: Value = get_value(&rawPositions, &i);
let mut entryPriceString: Value = self.safe_string_k(rawPosition.clone(), "entryPrice", &[]);
if is_true(&crate::precise::Precise::stringGt(&entryPriceString, &Value::Str("0".to_string()))) {
append_to_array(&mut result, self.parse_position_risk(rawPosition.clone(), &[]));
}
}
}
symbols = self.market_symbols(&[symbols.clone()]);
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
/*
* @method
* @name aster#fetchPositions
* @description fetch all open positions
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#position-information-v3-user_data
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.method] method name to call, "positionRisk", "account" or "option", default is "positionRisk"
* @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
}));
let mut defaultMethod: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPositions".to_string()), Value::Str("method".to_string()), &[]); defaultMethod = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&defaultMethod, &Value::Null) {
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchPositions", &[]);
if is_equal(&options, &Value::Null) {
defaultMethod = self.safe_string_k(self.options.clone(), "fetchPositions", &[Value::Str("positionRisk".to_string())]);
} else {
defaultMethod = Value::Str("positionRisk".to_string());
}
}
if is_equal(&defaultMethod, &Value::Str("positionRisk".to_string())) {
return self.fetch_positions_risk(&[symbols.clone(), params.clone()]).await;
} else if is_equal(&defaultMethod, &Value::Str("account".to_string())) {
return self.fetch_account_positions(&[symbols.clone(), params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(".options[\"fetchPositions\"][\"method\"] or params[\"method\"] = \"".to_string())), &defaultMethod), &Value::Str("\" is invalid, please choose between \"account\" and \"positionRisk\"".to_string()))));
}
Value::Null
}
pub fn parse_account_positions(&self, mut account: Value, optional_args: &[Value]) -> Value {
let mut filterClosed = get_arg(optional_args, 0, Value::Bool(false));
let mut positions: Value = self.safe_list_k(account.clone(), "positions", &[Value::List(vec![])]);
let mut assets: Value = self.safe_list_k(account.clone(), "assets", &[Value::List(vec![])]);
let mut balances: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_226: bool = true;
while { if !__for_first_226 { i = add(&i, &Value::Int(1)); } __for_first_226 = false; is_less_than(&i, &get_array_length(&assets)) } {
let mut entry: Value = get_value(&assets, &i);
let mut entry: Value = get_value(&assets, &i);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut crossWalletBalance: Value = self.safe_string_k(entry.clone(), "crossWalletBalance", &[]);
let mut crossUnPnl: Value = self.safe_string_k(entry.clone(), "crossUnPnl", &[]);
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut balances, &code, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("crossMargin".to_string(), crate::precise::Precise::stringAdd(&crossWalletBalance, &crossUnPnl));
m.insert("crossWalletBalance".to_string(), crossWalletBalance.clone());
m
}));
}
}
}
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_227: bool = true;
while { if !__for_first_227 { i = add(&i, &Value::Int(1)); } __for_first_227 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut position: Value = get_value(&positions, &i);
let mut position: Value = get_value(&positions, &i);
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, Value::Str("contract".to_string())]);
let mut code: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))), get_value(&market, &Value::Str("quote".to_string())), get_value(&market, &Value::Str("base".to_string())));
let mut maintenanceMargin: Value = self.safe_string_k(position.clone(), "maintMargin", &[]);
// check for maintenance margin so empty positions are not returned
let mut isPositionOpen: bool = is_true(&(!is_equal(&maintenanceMargin, &Value::Str("0".to_string())))) && is_true(&(!is_equal(&maintenanceMargin, &Value::Str("0.00000000".to_string()))));
if !is_true(&filterClosed) || is_true(&isPositionOpen) {
// sometimes not all the codes are correctly returned...
if is_true(&Value::Bool(in_op(&balances, &code))) {
let __ws_arg_44 = self.extend(position.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("crossMargin".to_string(), get_value(&get_value(&balances, &code), &Value::Str("crossMargin".to_string())));
m.insert("crossWalletBalance".to_string(), get_value(&get_value(&balances, &code), &Value::Str("crossWalletBalance".to_string())));
m
})]);
let mut parsed: Value = self.parse_account_position(__ws_arg_44, &[market.clone()]);
append_to_array(&mut result, parsed.clone());
}
}
}
}
return result;
Value::Null
}
pub fn parse_account_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut leverageString: Value = self.safe_string_k(position.clone(), "leverage", &[]);
let mut leverage: Value = ternary(is_true(&(!is_equal(&leverageString, &Value::Null))), crate::runtime::parse_int(&leverageString), Value::Null);
let mut initialMarginString: Value = self.safe_string_k(position.clone(), "initialMargin", &[]);
let mut initialMargin: Value = self.parse_number(initialMarginString.clone(), &[]);
let mut initialMarginPercentageString: Value = Value::Null;
if !is_equal(&leverageString, &Value::Null) {
initialMarginPercentageString = crate::precise::Precise::stringDivPrec(&Value::Str("1".to_string()), &leverageString, &Value::Int(8));
if is_equal(&leverage, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseAccountPosition() missing leverage".to_string()))));
}
let mut rational: Value = self.is_round_number(mod_val(&Value::Int(1000), &leverage));
if !is_true(&rational) {
initialMarginPercentageString = crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringAdd(&initialMarginPercentageString, &Value::Str("1e-8".to_string())), &Value::Str("1".to_string()), &Value::Int(8));
}
}
// as oppose to notionalValue
let mut usdm: Value = (Value::Bool(in_op(&position, &Value::Str("notional".to_string()))));
let mut maintenanceMarginString: Value = self.safe_string_k(position.clone(), "maintMargin", &[]);
let mut maintenanceMargin: Value = self.parse_number(maintenanceMarginString.clone(), &[]);
let mut entryPriceString: Value = self.safe_string_k(position.clone(), "entryPrice", &[]);
let mut entryPrice: Value = self.parse_number(entryPriceString.clone(), &[]);
let mut notionalString: Value = self.safe_string2(position.clone(), Value::Str("notional".to_string()), Value::Str("notionalValue".to_string()), &[]);
let mut notionalStringAbs: Value = crate::precise::Precise::stringAbs(¬ionalString);
let mut notional: Value = self.parse_number(notionalStringAbs.clone(), &[]);
let mut contractsString: Value = self.safe_string_k(position.clone(), "positionAmt", &[]);
let mut contractsStringAbs: Value = crate::precise::Precise::stringAbs(&contractsString);
if is_equal(&contractsString, &Value::Null) {
let mut entryNotional: Value = crate::precise::Precise::stringMul(&crate::precise::Precise::stringMul(&leverageString, &initialMarginString), &entryPriceString);
let mut contractSizeNew: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
contractsString = crate::precise::Precise::stringDiv(&entryNotional, &contractSizeNew);
contractsStringAbs = crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringAdd(&contractsString, &Value::Str("0.5".to_string())), &Value::Str("1".to_string()), &Value::Int(0));
}
let mut contracts: Value = self.parse_number(contractsStringAbs.clone(), &[]);
let mut leverageBrackets: Value = self.safe_dict_k(self.options.clone(), "leverageBrackets", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut leverageBracket: Value = self.safe_list(leverageBrackets.clone(), symbol.clone(), &[Value::List(vec![])]);
let mut maintenanceMarginPercentageString: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_228: bool = true;
while { if !__for_first_228 { i = add(&i, &Value::Int(1)); } __for_first_228 = false; is_less_than(&i, &get_array_length(&leverageBracket)) } {
let mut bracket: Value = get_value(&leverageBracket, &i);
let mut bracket: Value = get_value(&leverageBracket, &i);
if is_true(&crate::precise::Precise::stringLt(¬ionalStringAbs, &get_value(&bracket, &Value::Int(0)))) {
break;
}
maintenanceMarginPercentageString = get_value(&bracket, &Value::Int(1));
}
}
let mut maintenanceMarginPercentage: Value = self.parse_number(maintenanceMarginPercentageString.clone(), &[]);
let mut unrealizedPnlString: Value = self.safe_string_k(position.clone(), "unrealizedProfit", &[]);
let mut unrealizedPnl: Value = self.parse_number(unrealizedPnlString.clone(), &[]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "updateTime", &[]);
if is_equal(×tamp, &Value::Int(0)) {
timestamp = Value::Null;
}
let mut isolated: Value = self.safe_bool_k(position.clone(), "isolated", &[]);
if is_equal(&isolated, &Value::Null) {
let mut isolatedMarginRaw: Value = self.safe_string_k(position.clone(), "isolatedMargin", &[]);
isolated = Value::Bool(!is_true(&crate::precise::Precise::stringEq(&isolatedMarginRaw, &Value::Str("0".to_string()))));
}
let mut marginMode: Value = Value::Null;
let mut collateralString: Value = Value::Null;
let mut walletBalance: Value = Value::Null;
if is_true(&isolated) {
marginMode = Value::Str("isolated".to_string());
walletBalance = self.safe_string_k(position.clone(), "isolatedWallet", &[]);
collateralString = crate::precise::Precise::stringAdd(&walletBalance, &unrealizedPnlString);
} else {
marginMode = Value::Str("cross".to_string());
walletBalance = self.safe_string_k(position.clone(), "crossWalletBalance", &[]);
collateralString = self.safe_string_k(position.clone(), "crossMargin", &[]);
}
let mut collateral: Value = self.parse_number(collateralString.clone(), &[]);
let mut marginRatio: Value = Value::Null;
let mut side: Value = Value::Null;
let mut percentage: Value = Value::Null;
let mut liquidationPriceStringRaw: Value = Value::Null;
let mut liquidationPrice: Value = Value::Null;
let mut contractSize: Value = self.safe_value_k(market.clone(), "contractSize", &[]);
let mut contractSizeString: Value = self.number_to_string(contractSize.clone());
if is_true(&crate::precise::Precise::stringEquals(¬ionalString, &Value::Str("0".to_string()))) {
entryPrice = Value::Null;
} else {
side = ternary(is_true(&crate::precise::Precise::stringLt(¬ionalString, &Value::Str("0".to_string()))), Value::Str("short".to_string()), Value::Str("long".to_string()));
marginRatio = self.parse_number(crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringAdd(&crate::precise::Precise::stringDiv(&maintenanceMarginString, &collateralString), &Value::Str("5e-5".to_string())), &Value::Str("1".to_string()), &Value::Int(4)), &[]);
percentage = self.parse_number(crate::precise::Precise::stringMul(&crate::precise::Precise::stringDivPrec(&unrealizedPnlString, &initialMarginString, &Value::Int(4)), &Value::Str("100".to_string())), &[]);
if is_true(&usdm) {
// calculate liquidation price
//
// liquidationPrice = (walletBalance / (contracts * (±1 + mmp))) + (±entryPrice / (±1 + mmp))
//
// mmp = maintenanceMarginPercentage
// where ± is negative for long and positive for short
// TODO: calculate liquidation price for coinm contracts
let mut onePlusMaintenanceMarginPercentageString: Value = Value::Null;
let mut entryPriceSignString: Value = entryPriceString.clone();
if is_equal(&side, &Value::Str("short".to_string())) {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringAdd(&Value::Str("1".to_string()), &maintenanceMarginPercentageString);
} else {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringAdd(&Value::Str("-1".to_string()), &maintenanceMarginPercentageString);
entryPriceSignString = crate::precise::Precise::stringMul(&Value::Str("-1".to_string()), &entryPriceSignString);
}
let mut leftSide: Value = crate::precise::Precise::stringDiv(&walletBalance, &crate::precise::Precise::stringMul(&contractsStringAbs, &onePlusMaintenanceMarginPercentageString));
let mut rightSide: Value = crate::precise::Precise::stringDiv(&entryPriceSignString, &onePlusMaintenanceMarginPercentageString);
liquidationPriceStringRaw = crate::precise::Precise::stringAdd(&leftSide, &rightSide);
} else {
// calculate liquidation price
//
// liquidationPrice = (contracts * contractSize(±1 - mmp)) / (±1/entryPrice * contracts * contractSize - walletBalance)
//
let mut onePlusMaintenanceMarginPercentageString: Value = Value::Null;
let mut entryPriceSignString: Value = entryPriceString.clone();
if is_equal(&side, &Value::Str("short".to_string())) {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringSub(&Value::Str("1".to_string()), &maintenanceMarginPercentageString);
} else {
onePlusMaintenanceMarginPercentageString = crate::precise::Precise::stringSub(&Value::Str("-1".to_string()), &maintenanceMarginPercentageString);
entryPriceSignString = crate::precise::Precise::stringMul(&Value::Str("-1".to_string()), &entryPriceSignString);
}
let mut size: Value = crate::precise::Precise::stringMul(&contractsStringAbs, &contractSizeString);
let mut leftSide: Value = crate::precise::Precise::stringMul(&size, &onePlusMaintenanceMarginPercentageString);
let mut rightSide: Value = crate::precise::Precise::stringSub(&crate::precise::Precise::stringMul(&crate::precise::Precise::stringDiv(&Value::Str("1".to_string()), &entryPriceSignString), &size), &walletBalance);
liquidationPriceStringRaw = crate::precise::Precise::stringDiv(&leftSide, &rightSide);
}
let mut pricePrecision: Value = self.precision_from_string(self.safe_string(get_value(&market, &Value::Str("precision".to_string())), Value::Str("price".to_string()), &[]));
let mut pricePrecisionPlusOne: Value = add(&pricePrecision, &Value::Int(1));
let mut pricePrecisionPlusOneString: Value = to_string_val(&pricePrecisionPlusOne);
// round half up
let mut rounder = Precise::new(add(&Value::Str("5e-".to_string()), &pricePrecisionPlusOneString));
let mut rounderString: Value = to_string_val(&rounder);
let mut liquidationPriceRoundedString: Value = crate::precise::Precise::stringAdd(&rounderString, &liquidationPriceStringRaw);
let mut truncatedLiquidationPrice: Value = crate::precise::Precise::stringDivPrec(&liquidationPriceRoundedString, &Value::Str("1".to_string()), &pricePrecision);
if is_equal(&truncatedLiquidationPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing truncatedLiquidationPrice".to_string()))));
}
if is_equal(&get_value(&truncatedLiquidationPrice, &Value::Int(0)), &Value::Str("-".to_string())) {
// user cannot be liquidated
// since he has more collateral than the size of the position
truncatedLiquidationPrice = Value::Null;
}
liquidationPrice = self.parse_number(truncatedLiquidationPrice.clone(), &[]);
}
let mut positionSide: Value = self.safe_string_k(position.clone(), "positionSide", &[]);
let mut hedged: Value = Value::Bool(!is_equal(&positionSide, &Value::Str("BOTH".to_string())));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
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("initialMargin".to_string(), initialMargin.clone());
m.insert("initialMarginPercentage".to_string(), self.parse_number(initialMarginPercentageString.clone(), &[]));
m.insert("maintenanceMargin".to_string(), maintenanceMargin.clone());
m.insert("maintenanceMarginPercentage".to_string(), maintenanceMarginPercentage.clone());
m.insert("entryPrice".to_string(), entryPrice.clone());
m.insert("notional".to_string(), notional.clone());
m.insert("leverage".to_string(), self.parse_number(leverageString.clone(), &[]));
m.insert("unrealizedPnl".to_string(), unrealizedPnl.clone());
m.insert("contracts".to_string(), contracts.clone());
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("marginRatio".to_string(), marginRatio.clone());
m.insert("liquidationPrice".to_string(), liquidationPrice.clone());
m.insert("markPrice".to_string(), Value::Null);
m.insert("collateral".to_string(), collateral.clone());
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("side".to_string(), side.clone());
m.insert("hedged".to_string(), hedged.clone());
m.insert("percentage".to_string(), percentage.clone());
m
});
Value::Null
}
/*
* @method
* @name aster#fetchAccountPositions
* @ignore
* @description fetch account positions
https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#position-information-v3-user_data
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} data on account positions
*/
pub async fn fetch_account_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(&symbols, &Value::Null) {
if !is_true(&Value::Bool(is_array(&symbols))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchPositions() requires an array argument for symbols".to_string()))));
}
}
self.load_markets_and_sign_in().await;
self.load_leverage_brackets(&[Value::Bool(false), params.clone()]).await;
let mut response: Value = self.fapi_private_get_v4_account(&[params.clone()]).await;
let mut filterClosed: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchAccountPositions".to_string()), Value::Str("filterClosed".to_string()), &[Value::Bool(false)]); filterClosed = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut result: Value = self.parse_account_positions(response.clone(), &[filterClosed.clone()]);
symbols = self.market_symbols(&[symbols.clone()]);
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
pub async fn load_leverage_brackets(&mut self, optional_args: &[Value]) -> Value {
let mut reload = get_arg(optional_args, 0, Value::Bool(false));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets_and_sign_in().await;
// by default cache the leverage bracket
// it contains useful stuff like the maintenance margin and initial margin for positions
let mut leverageBrackets: Value = self.safe_dict_k(self.options.clone(), "leverageBrackets", &[]);
if is_true(&(is_equal(&leverageBrackets, &Value::Null))) || is_true(&(reload)) {
let mut response: Value = self.fapi_private_get_v3_leverage_bracket(&[params.clone()]).await;
//
// [
// {
// "symbol": "TRUTHUSDT",
// "brackets": [
// {
// "bracket": "1",
// "initialLeverage": "50",
// "notionalCap": "5000",
// "notionalFloor": "0",
// "maintMarginRatio": "0.01",
// "cum": "0.0"
// },
// {
// "bracket": "2",
// "initialLeverage": "20",
// "notionalCap": "10000",
// "notionalFloor": "5000",
// "maintMarginRatio": "0.025",
// "cum": "75.0"
// },
// ...
//
{ let __be_tmp = self.create_safe_dictionary(&[]); add_element_to_object(&mut self.options, &Value::Str("leverageBrackets".to_string()), __be_tmp); };
let mut entries: Value = self.to_array(response.clone());
{
let mut i: Value = Value::Int(0);
let mut __for_first_230: bool = true;
while { if !__for_first_230 { i = add(&i, &Value::Int(1)); } __for_first_230 = false; is_less_than(&i, &get_array_length(&entries)) } {
let mut entry: Value = get_value(&entries, &i);
let mut entry: Value = get_value(&entries, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[Value::Null, Value::Null, Value::Str("contract".to_string())]);
let mut brackets: Value = self.safe_list_k(entry.clone(), "brackets", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_229: bool = true;
while { if !__for_first_229 { j = add(&j, &Value::Int(1)); } __for_first_229 = false; is_less_than(&j, &get_array_length(&brackets)) } {
let mut bracket: Value = get_value(&brackets, &j);
let mut bracket: Value = get_value(&brackets, &j);
let mut floorValue: Value = self.safe_string_k(bracket.clone(), "notionalFloor", &[]);
let mut maintenanceMarginPercentage: Value = self.safe_string_k(bracket.clone(), "maintMarginRatio", &[]);
append_to_array(&mut result, Value::List(vec![floorValue.clone(), maintenanceMarginPercentage.clone()]));
}
}
add_element_to_object(get_value_mut(&mut self.options, &Value::Str("leverageBrackets".to_string())), &symbol, result.clone());
}
}
}
return get_value(&self.options, &Value::Str("leverageBrackets".to_string()));
Value::Null
}
pub fn keccak_message(&self, mut message: Value) -> Value {
return add(&Value::Str("0x".to_string()), &self.hash(message.clone(), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
Value::Null
}
pub fn sign_message(&self, mut message: Value, mut privateKey: Value) -> Value {
return self.sign_hash(self.keccak_message(message.clone()), slice(&privateKey, &negate(&Value::Int(64)), &Value::Null));
Value::Null
}
pub fn sign_withdraw_payload(&self, mut withdrawPayload: Value, mut network: Value) -> Value {
let mut chainId: Value = self.safe_integer_k(withdrawPayload.clone(), "chainId", &[]);
let mut domain: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("chainId".to_string(), chainId.clone());
m.insert("name".to_string(), Value::Str("Aster".to_string()));
m.insert("verifyingContract".to_string(), self.safe_string_k(self.options.clone(), "zeroAddress", &[]));
m.insert("version".to_string(), Value::Str("1".to_string()));
m
});
let mut messageTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Action".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("type".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("destination".to_string()));
m.insert("type".to_string(), Value::Str("address".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("destination Chain".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("token".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("amount".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("fee".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint256".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("aster chain".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
})]));
m
});
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("Withdraw".to_string()));
m.insert("destination".to_string(), self.safe_string_k(withdrawPayload.clone(), "receiver", &[]));
m.insert("destination Chain".to_string(), network.clone());
m.insert("token".to_string(), self.safe_string_k(withdrawPayload.clone(), "asset", &[]));
m.insert("amount".to_string(), self.safe_string_k(withdrawPayload.clone(), "amount", &[]));
m.insert("fee".to_string(), self.safe_string_k(withdrawPayload.clone(), "fee", &[]));
m.insert("nonce".to_string(), self.safe_integer_k(withdrawPayload.clone(), "userNonce", &[]));
m.insert("aster chain".to_string(), Value::Str("Mainnet".to_string()));
m
});
let mut msg: Value = self.eth_encode_structured_data(domain.clone(), messageTypes.clone(), request.clone());
let mut signature: Value = self.sign_message(msg.clone(), self.privateKey.clone());
return signature;
Value::Null
}
/*
* @method
* @name aster#withdraw
* @description make a withdrawal
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#withdraw-user_data
* @see https://asterdex.github.io/aster-api-website/futures-v3/deposit%26withdrawal/#withdraw-by-fapiv3-evm-futures
* @see https://asterdex.github.io/aster-api-website/futures-v3/deposit%26withdrawal/#withdraw-by-fapiv3-evm-spot
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = 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 __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
self.check_address(&[address.clone()]);
self.load_markets_and_sign_in().await;
let mut currency: Value = self.currency(code.clone());
let mut nonce: Value = multiply(&self.milliseconds(), &Value::Int(1000));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("receiver".to_string(), address.clone());
m.insert("userNonce".to_string(), to_string_val(&nonce));
m
});
let mut chainId: Value = self.safe_integer_k(params.clone(), "chainId", &[]);
// TODO: check how ARBI signature would work
let mut networks: Value = self.safe_dict_k(self.options.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut network: Value = self.safe_string_upper(params.clone(), Value::Str("network".to_string()), &[]);
network = self.safe_string(networks.clone(), network.clone(), &[network.clone()]);
if is_true(&(is_equal(&chainId, &Value::Null))) && is_true(&(!is_equal(&network, &Value::Null))) {
let mut chainIds: Value = self.safe_dict_k(self.options.clone(), "networksToChainId", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
chainId = self.safe_integer(chainIds.clone(), network.clone(), &[]);
}
if is_equal(&chainId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" withdraw require chainId or network parameter".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("chainId".to_string()), chainId.clone());
let mut fee: Value = self.safe_string_k(params.clone(), "fee", &[]);
if is_equal(&fee, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" withdraw require fee parameter".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("fee".to_string()), fee.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("chainId".to_string()), Value::Str("network".to_string()), Value::Str("fee".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.currency_to_precision(code.clone(), amount.clone(), &[network.clone()]));
{ let __be_tmp = self.sign_withdraw_payload(request.clone(), network.clone()); add_element_to_object(&mut request, &Value::Str("userSignature".to_string()), __be_tmp); };
let __ws_arg_45 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.sapi_private_post_v3_aster_user_withdraw(&[__ws_arg_45]).await;
return self.parse_transaction(response.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string_k(transaction.clone(), "withdrawId", &[]));
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "hash", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), Value::Null);
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("withdrawal".to_string()));
m.insert("amount".to_string(), Value::Null);
m.insert("currency".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m.insert("updated".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name aster#transfer
* @description transfer currency internally between wallets on the same account
* @see https://asterdex.github.io/aster-api-website/spot-v3/account%26trades/#perp-spot-transfer-trade
* @see https://asterdex.github.io/aster-api-website/futures-v3/account%26trades/#transfer-between-futures-and-spot-transfer
* @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
* @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
}));
self.load_markets_and_sign_in().await;
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let mut type_var: Value = Value::Null;
let mut fromId: Value = Value::Null;
if !is_equal(&fromAccount, &Value::Null) {
fromId = to_upper(&self.convert_type_to_account(fromAccount.clone()));
}
let mut toId: Value = Value::Null;
if !is_equal(&toAccount, &Value::Null) {
toId = to_upper(&self.convert_type_to_account(toAccount.clone()));
}
if is_equal(&fromId, &Value::Str("SPOT".to_string())) && is_equal(&toId, &Value::Str("FUTURE".to_string())) {
type_var = Value::Str("SPOT_FUTURE".to_string());
} else if is_equal(&fromId, &Value::Str("FUTURE".to_string())) && is_equal(&toId, &Value::Str("SPOT".to_string())) {
type_var = Value::Str("FUTURE_SPOT".to_string());
}
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" transfer() requires fromAccount and toAccount parameters to be either SPOT or FUTURE".to_string()))));
}
let mut defaultClientTranId: Value = self.number_to_string(self.milliseconds());
let mut clientTranId: Value = self.safe_string_k(params.clone(), "clientTranId", &[defaultClientTranId.clone()]);
add_element_to_object(&mut request, &Value::Str("kindType".to_string()), type_var.clone());
add_element_to_object(&mut request, &Value::Str("clientTranId".to_string()), clientTranId.clone());
let __ws_arg_46 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.sapi_private_post_v3_asset_wallet_transfer(&[__ws_arg_46]).await;
return self.parse_transfer(response.clone(), &[currency.clone()]);
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(), "code", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "tranId", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_transfer_status(self.safe_string_k(transfer.clone(), "status", &[])));
m
});
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SUCCESS".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn hash_message(&self, mut binaryMessage: Value) -> Value {
// const binaryMessage = this.encode (message);
let mut binaryMessageLength: Value = self.binary_length(binaryMessage.clone(), &[]);
let mut x19: Value = self.base16_to_binary(Value::Str("19".to_string()), &[]);
let mut newline: Value = self.base16_to_binary(Value::Str("0a".to_string()), &[]);
let mut prefix: Value = self.binary_concat(x19.clone(), &[self.encode(Value::Str("Ethereum Signed Message:".to_string())), newline.clone(), self.encode(self.number_to_string(binaryMessageLength.clone()))]);
return add(&Value::Str("0x".to_string()), &self.hash(self.binary_concat(prefix.clone(), &[binaryMessage.clone()]), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
Value::Null
}
pub fn sign_hash(&self, mut hash: Value, mut privateKey: Value) -> Value {
self.check_required_credentials(&[]);
let mut signature: Value = ecdsa(slice(&hash, &negate(&Value::Int(64)), &Value::Null), slice(&privateKey, &negate(&Value::Int(64)), &Value::Null), Value::Str("secp256k1".to_string()), Value::Null);
let mut r: Value = get_value(&signature, &Value::Str("r".to_string()));
let mut s: Value = get_value(&signature, &Value::Str("s".to_string()));
let mut v: Value = self.int_to_base16(self.sum(&[Value::Int(27), get_value(&signature, &Value::Str("v".to_string()))]), &[]);
return add(&add(&add(&Value::Str("0x".to_string()), &pad_start(&r, &Value::Int(64), &Value::Str("0".to_string()))), &pad_start(&s, &Value::Int(64), &Value::Str("0".to_string()))), &v);
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(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &path);
if is_equal(&api, &Value::Str("fapiPublic".to_string())) || is_equal(&api, &Value::Str("sapiPublic".to_string())) {
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.rawencode(params.clone(), &[])));
}
} else if is_equal(&api, &Value::Str("fapiPrivate".to_string())) || is_equal(&api, &Value::Str("sapiPrivate".to_string())) {
self.check_required_credentials(&[]);
let mut nonce: Value = multiply(&self.milliseconds(), &Value::Int(1000));
// Sign using EIP-712 typed data per the AsterSignTransaction spec
let mut zeroAddress: Value = self.safe_string_k(self.options.clone(), "zeroAddress", &[Value::Str("0x0000000000000000000000000000000000000000".to_string())]);
let mut v3ChainId: Value = self.safe_integer_k(self.options.clone(), "v3ChainId", &[Value::Int(1666)]);
let mut walletAddress: Value = self.safe_string_k(self.options.clone(), "cachedWalletAddress", &[]);
let mut privateKeyHash: Value = self.hash(self.encode(self.privateKey.clone()), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]);
let mut cachedPrivateKeyHash: Value = self.safe_string_k(self.options.clone(), "privateKeyHashForCachedWalletAddress", &[]);
if is_true(&(is_equal(&walletAddress, &Value::Null))) || is_true(&(!is_equal(&cachedPrivateKeyHash, &privateKeyHash))) {
walletAddress = self.eth_get_address_from_private_key(self.privateKey.clone(), &[]);
add_element_to_object(&mut self.options.clone(), &Value::Str("cachedWalletAddress".to_string()), walletAddress.clone());
add_element_to_object(&mut self.options.clone(), &Value::Str("privateKeyHashForCachedWalletAddress".to_string()), privateKeyHash.clone());
}
let mut signerAddress: Value = self.safe_string_k(self.options.clone(), "signerAddress", &[walletAddress.clone()]); // default to user's wallet
if is_equal(&signerAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires signerAddress in options when use v3 api".to_string()))));
}
let mut domain: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("AsterSignTransaction".to_string()));
m.insert("version".to_string(), Value::Str("1".to_string()));
m.insert("chainId".to_string(), v3ChainId.clone());
m.insert("verifyingContract".to_string(), zeroAddress.clone());
m
});
let mut messageTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Message".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("msg".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
})]));
m
});
// Build v3 params: original endpoint params + nonce (microseconds) + user + signer
// Note: timestamp and recvWindow are not used for v3; nonce replaces timestamp
let mut finalParams: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("nonce".to_string(), to_string_val(&nonce));
m.insert("user".to_string(), walletAddress.clone());
m.insert("signer".to_string(), signerAddress.clone());
m
}), &[params.clone()]);
let mut paramString: Value = Value::Null;
let mut paramsToEncode: Value = Value::Null;
let mut isApproveBuilder: bool = is_greater_than_or_equal(&get_index_of(&path, &Value::Str("/approveBuilder".to_string())), &Value::Int(0));
if is_true(&isApproveBuilder) {
// domain['name'] = 'Aster';
messageTypes = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ApproveBuilder".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("Builder".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("MaxFeeRate".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("BuilderName".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("AsterChain".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("User".to_string()));
m.insert("type".to_string(), Value::Str("string".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("Nonce".to_string()));
m.insert("type".to_string(), Value::Str("uint256".to_string()));
m
})]));
m
});
remove(&mut finalParams, &Value::Str("signer".to_string())); // signer is not needed for approveBuilder endpoint
paramString = self.encode_values_with_json(finalParams.clone());
paramsToEncode = self.capitalize_keys(finalParams.clone());
} else {
paramString = self.encode_values_with_json(finalParams.clone());
paramsToEncode = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("msg".to_string(), paramString.clone());
m
});
}
let mut encodedMessage: Value = self.eth_encode_structured_data(domain.clone(), messageTypes.clone(), paramsToEncode.clone());
let mut signature: Value = self.sign_message(encodedMessage.clone(), self.privateKey.clone());
let mut queryString: Value = add(&add(&add(¶mString, &Value::Str("&".to_string())), &Value::Str("signature=".to_string())), &signature);
if is_equal(&method, &Value::Str("GET".to_string())) {
url = add(&url, &add(&Value::Str("?".to_string()), &queryString));
} else {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/x-www-form-urlencoded".to_string()));
body = queryString.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(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn encode_values_with_json(&self, mut values: Value) -> Value {
let mut encodedString: Value = Value::Str("".to_string());
let mut keys: Value = object_keys(&values);
{
let mut i: Value = Value::Int(0);
let mut __for_first_231: bool = true;
while { if !__for_first_231 { i = add(&i, &Value::Int(1)); } __for_first_231 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
let mut value: Value = get_value(&values, &key);
let mut value: Value = get_value(&values, &key);
let mut isObj: bool = is_true(&Value::Bool(is_array(&value))) || is_true(&self.is_dictionary(value.clone()));
let mut valueJsonified: Value = ternary(is_true(&isObj), self.json(value.clone()), to_string_val(&value));
let mut encoded: Value = self.encode_uri_component(valueJsonified.clone());
encodedString = add(&encodedString, &add(&add(&add(&key, &Value::Str("=".to_string())), &encoded), &Value::Str("&".to_string())));
}
}
return slice(&encodedString, &Value::Int(0), &negate(&Value::Int(1)));
Value::Null
}
pub fn capitalize_keys(&self, mut dict: Value) -> Value {
let mut capitalized: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut keys: Value = object_keys(&dict);
{
let mut i: Value = Value::Int(0);
let mut __for_first_232: bool = true;
while { if !__for_first_232 { i = add(&i, &Value::Int(1)); } __for_first_232 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
let mut value: Value = get_value(&dict, &key);
let mut value: Value = get_value(&dict, &key);
let mut capitalizedKey: Value = self.capitalize(key.clone());
add_element_to_object(&mut capitalized, &capitalizedKey, value.clone());
}
}
return capitalized;
Value::Null
}
pub async fn load_markets_and_sign_in(&mut self) -> Value {
promise_all(&Value::List(vec![self.load_markets(&[]).await, self.sign_in(&[]).await])).await;
Value::Null
}
/*
* @method
* @name aster#signIn
* @description sign in, must be called prior to using other authenticated methods
* @see https://asterdex.github.io/aster-api-website/asterCode/integration-flow/
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns response from exchange
*/
pub async fn sign_in(&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_true(&self.is_empty_string(self.privateKey.clone())) {
if !is_true(&self.is_empty_string(self.apiKey.clone())) || !is_true(&self.is_empty_string(self.secret.clone())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str("after the latest upgrade (v4.5.52), CCXT now expects the l1 private key to be provided in the credentials.".to_string()))));
}
return Value::Bool(false);
}
if is_greater_than(&get_array_length(&self.privateKey), &Value::Int(66)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" after the latest update (v4.5.52), CCXT now expects the l1 private key to be provided in the credentials.".to_string()))));
}
self.initialize_client(&[params.clone()]).await;
return Value::Bool(true);
Value::Null
}
pub async fn initialize_client(&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 builderFee: Value = self.safe_bool_k(params.clone(), "builderFee", &[self.safe_bool(self.options.clone(), Value::Str("builderFee".to_string()), &[Value::Bool(true)])]); // we shouldn't omit here
if !is_equal(&builderFee, &Value::Bool(true)) {
return Value::Bool(false);
}
let mut approvedBuilderFee: Value = self.safe_bool_k(self.options.clone(), "approvedBuilderFee", &[Value::Bool(false)]);
if is_equal(&approvedBuilderFee, &Value::Bool(true)) {
return Value::Bool(true);
}
let mut result: Value = self.fapi_private_get_v3_builder(&[]).await;
//
// [
// {
// "userAddress": "0x35a5B33Be664B09F78b5089eb6185f71c8a7f11f",
// "builderAddress": "0x1F5877C19e3777Cfd15F9d57253eA4aA5254Ec39",
// "maxFeeRate": "0.001",
// "builderName": "ccxt"
// }
// ]
//
let mut approvedBuilders: Value = result.clone();
let mut length: Value = get_array_length(&approvedBuilders);
let mut found: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_233: bool = true;
while { if !__for_first_233 { i = add(&i, &Value::Int(1)); } __for_first_233 = false; is_less_than(&i, &length) } {
let mut builderInfo: Value = self.safe_dict(approvedBuilders.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut builderAccountId: Value = self.safe_string_k(builderInfo.clone(), "builderAddress", &[]);
if is_equal(&builderAccountId, &self.safe_string_k(self.options.clone(), "builder", &[])) {
found = true;
break;
}
}
}
if !is_true(&found) {
add_element_to_object(&mut self.options, &Value::Str("approvedBuilderFee".to_string()), Value::Bool(true));
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("builder".to_string(), self.safe_string_k(self.options.clone(), "builder", &[]));
m.insert("builderName".to_string(), self.safe_string_k(self.options.clone(), "builderName", &[Value::Str("ccxt".to_string())]));
m.insert("maxFeeRate".to_string(), self.safe_string_k(self.options.clone(), "builderRate", &[]));
m.insert("signatureChainId".to_string(), self.safe_integer_k(self.options.clone(), "v3ChainId", &[Value::Int(1666)]));
m.insert("asterChain".to_string(), Value::Str("Mainnet".to_string()));
m
});
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
let mut authResponse: Value = self.fapi_private_post_v3_approve_builder(&[__ws_arg_47]).await;
//
// {"code": 200,"msg": "success"}
//
let mut codeRes: Value = self.safe_integer_k(authResponse.clone(), "code", &[]);
if !is_equal(&codeRes, &Value::Int(200)) {
panic!("{}", crate::exchange_errors::exchange_error(add(&Value::Str("Builder authorization failed, ".to_string()), &self.json(authResponse.clone()))));
}
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
add_element_to_object(&mut self.options, &Value::Str("approvedBuilderFee".to_string()), Value::Bool(false));
add_element_to_object(&mut self.options, &Value::Str("builderFee".to_string()), Value::Bool(false)); // disable if err
}
}
return Value::Null;
Value::Null
}
pub fn handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
//
// {
// "code": -1121,
// "msg": "Invalid symbol.",
// }
//
let mut code: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut message: Value = self.safe_string_k(response.clone(), "msg", &[]);
if !is_equal(&code, &Value::Null) && !is_equal(&code, &Value::Str("200".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}