// 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 NadoCore {
pub exchange: crate::exchange::Exchange,
}
impl NadoCore {
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 = NadoCore::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 NadoCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_order(self, order, &[market.clone()])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_position(self, position, &[market.clone()])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on NadoCore.
NadoCore::parse_transaction(self, transaction, &[currency.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 NadoCore.
NadoCore::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 NadoCore.
NadoCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for NadoCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders_request" => self.cancel_all_orders_request(&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,
"cancel_orders_request" => self.cancel_orders_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"convert_to_x18" => self.convert_to_x18(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_appendix" => self.create_order_appendix(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"create_order_nonce" => self.create_order_nonce(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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()[..]).await,
"create_subaccount" => self.create_subaccount(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"edit_order_request" => self.edit_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()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_canceled_and_closed_orders" => self.fetch_canceled_and_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_canceled_orders" => self.fetch_canceled_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interests" => self.fetch_open_interests(&args.get(0..).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_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_status" => self.fetch_status(&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_withdrawals" => self.fetch_withdrawals(&args.get(0..).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)),
"is_archive_order_closed" => self.is_archive_order_closed(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"order_verifying_contract" => self.order_verifying_contract(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"pad_hex" => self.pad_hex(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()[..]),
"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_history" => self.parse_funding_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_time_in_force" => self.parse_order_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(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_x18" => self.parse_x18(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"query_contracts" => self.query_contracts(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"query_transactions_by_event_type" => self.query_transactions_by_event_type(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,
"remove_market_suffix" => self.remove_market_suffix(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"sign_cancellation" => self.sign_cancellation(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)),
"sign_cancellation_products" => self.sign_cancellation_products(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)),
"sign_fetch_trigger_orders" => self.sign_fetch_trigger_orders(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)),
"sign_hash" => self.sign_hash(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"sign_order" => self.sign_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)),
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for NadoCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for NadoCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl NadoCore {
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("nado".to_string()));
m.insert("name".to_string(), Value::Str("Nado".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("KY".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(25));
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("dex".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterests".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(false));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/811f4e1a-a8b5-4b9e-84c2-0f88997bd274".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("gateway".to_string(), Value::Str("https://gateway.prod.nado.xyz/v1".to_string()));
m.insert("gatewayV2".to_string(), Value::Str("https://gateway.prod.nado.xyz/v2".to_string()));
m.insert("archive".to_string(), Value::Str("https://archive.prod.nado.xyz/v1".to_string()));
m.insert("archiveV2".to_string(), Value::Str("https://archive.prod.nado.xyz/v2".to_string()));
m.insert("trigger".to_string(), Value::Str("https://trigger.prod.nado.xyz/v1".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("gateway".to_string(), Value::Str("https://gateway.test.nado.xyz/v1".to_string()));
m.insert("gatewayV2".to_string(), Value::Str("https://gateway.test.nado.xyz/v2".to_string()));
m.insert("archive".to_string(), Value::Str("https://archive.test.nado.xyz/v1".to_string()));
m.insert("archiveV2".to_string(), Value::Str("https://archive.test.nado.xyz/v2".to_string()));
m.insert("trigger".to_string(), Value::Str("https://trigger.test.nado.xyz/v1".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://nado.xyz".to_string()));
m.insert("doc".to_string(), Value::Str("https://docs.nado.xyz/".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("gateway".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("edge/query".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("query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("execute".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("gatewayV2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("pairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("archiveV2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contracts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("trigger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("execute".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m
}));
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("walletAddress".to_string(), Value::Bool(true));
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("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("swap".to_string()));
m.insert("recvWindow".to_string(), Value::Int(5000));
m.insert("expiration".to_string(), Value::Str("4294967295".to_string()));
m.insert("subaccount".to_string(), Value::Str("default".to_string()));
m.insert("editOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("placeRequiresUnfilled".to_string(), Value::Bool(true));
m
}));
m.insert("builderFee".to_string(), Value::Bool(true));
m.insert("builder".to_string(), Value::Str("4500".to_string()));
m.insert("feeRate".to_string(), Value::Str("10".to_string()));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Int(60));
m.insert("5m".to_string(), Value::Int(300));
m.insert("15m".to_string(), Value::Int(900));
m.insert("1h".to_string(), Value::Int(3600));
m.insert("2h".to_string(), Value::Int(7200));
m.insert("4h".to_string(), Value::Int(14400));
m.insert("1d".to_string(), Value::Int(86400));
m.insert("1w".to_string(), Value::Int(604800));
m.insert("4w".to_string(), Value::Int(2419200));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1000".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("1015".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("1001".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("1002".to_string(), Value::Str("RestrictedLocation".to_string()).clone());
m.insert("1003".to_string(), Value::Str("RestrictedLocation".to_string()).clone());
m.insert("1004".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("2000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2005".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2006".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2008".to_string(), Value::Str("OrderImmediatelyFillable".to_string()).clone());
m.insert("2009".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("InvalidNonce".to_string()).clone());
m.insert("2012".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("2013".to_string(), Value::Str("DuplicateOrderId".to_string()).clone());
m.insert("2014".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("2015".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("2016".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("2017".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2019".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2020".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("2021".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("2022".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("2023".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2024".to_string(), Value::Str("InvalidAddress".to_string()).clone());
m.insert("2025".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2026".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2027".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2028".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("2029".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2030".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("2031".to_string(), Value::Str("OrderNotFillable".to_string()).clone());
m.insert("2033".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("2034".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("2035".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("2036".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2037".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2038".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2039".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2040".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2041".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2042".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2043".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2044".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2045".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2046".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2047".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2048".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2049".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("2050".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("2051".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2052".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2053".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("2054".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2055".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2056".to_string(), Value::Str("OrderNotFillable".to_string()).clone());
m.insert("2057".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2058".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("2059".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2060".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("2061".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2062".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("2063".to_string(), Value::Str("BadResponse".to_string()).clone());
m.insert("2064".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2065".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2066".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2067".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2068".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("2069".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2070".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2071".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2072".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2073".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2074".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2075".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2076".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2077".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2078".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("2079".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2080".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2081".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2082".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("2083".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2084".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2085".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2086".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2087".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("2088".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2089".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2090".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2091".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2092".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2093".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("2094".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2095".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2096".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2097".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2098".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2099".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2100".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2101".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2102".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2103".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2104".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2105".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2106".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2107".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2108".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2109".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2110".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2111".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2112".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2113".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2114".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2115".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("2117".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2118".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2119".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2120".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("2121".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("2122".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2123".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2124".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("2125".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("3000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3002".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("3003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3005".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("4000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("4001".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("4002".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("4003".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("4004".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("5000".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name nado#createOrder
* @description create a trade order
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/place-order
* @see https://docs.nado.xyz/developer-resources/api/trigger/executes/place-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type must be 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string|int} [params.expiration] order expiration timestamp in seconds, defaults to 4294967295
* @param {string|int} [params.appendix] pre-encoded order appendix
* @param {boolean} [params.reduceOnly] true if the order should only reduce position
* @param {boolean} [params.postOnly] true to create a post-only order
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', or 'PO'
* @param {boolean} [params.spotLeverage] whether leverage should be used for spot, defaults to true, exchange-specific alias params.spot_leverage
* @param {float} [params.triggerPrice] *swap only* The price at which a trigger order is triggered at
* @param {float} [params.stopLossPrice] *swap only* The price at which a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] *swap only* The price at which a take profit order is triggered at
* @param {string} [params.triggerDirection] trigger direction, above, below
* @param {int} [params.id] client-provided request id, returned by the exchange in the response
* @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.check_required_credentials(&[]);
self.load_markets(&[]).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()]).await;
let mut placeOrder: Value = self.safe_dict_k(request.clone(), "place_order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut isTriggerOrder: Value = (Value::Bool(in_op(&placeOrder, &Value::Str("trigger".to_string()))));
let mut response: Value = Value::Null;
if is_true(&isTriggerOrder) {
response = self.trigger_private_post_execute(&[request.clone()]).await;
} else {
response = self.gateway_private_post_execute(&[request.clone()]).await;
}
let __ws_arg_0 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("place_order".to_string(), placeOrder.clone());
m
}), &[response.clone()]);
return self.parse_order(__ws_arg_0, &[market.clone()]);
Value::Null
}
/*
* @method
* @ignore
* @name nado#createOrderRequest
* @description build and sign the place_order execute payload
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type must be 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the request payload for the place_order execute
*/
pub async fn create_order_request(&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
}));
let mut market: Value = self.market(symbol.clone());
if !is_equal(&type_var, &Value::Str("limit".to_string())) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() supports limit orders only".to_string()))));
}
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a price argument".to_string()))));
}
let mut productId: Value = self.parse_to_int(get_value(&market, &Value::Str("id".to_string())));
let mut priceString: Value = self.price_to_precision(symbol.clone(), price.clone());
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount.clone());
let mut priceX18: Value = self.convert_to_x18(priceString.clone());
let mut amountX18: Value = self.convert_to_x18(amountString.clone());
if is_equal(&side, &Value::Str("sell".to_string())) {
amountX18 = crate::precise::Precise::stringMul(&amountX18, &Value::Str("-1".to_string()));
}
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut expiration: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("expiration".to_string()), &[Value::Str("4294967295".to_string())]); expiration = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut recvWindow: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("recvWindow".to_string()), &[Value::Int(5000)]); recvWindow = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut nonce: Value = self.create_order_nonce(recvWindow.clone());
let mut requestId: Value = self.safe_integer_k(params.clone(), "id", &[]);
let mut spotLeverage: Value = self.safe_bool2(params.clone(), Value::Str("spotLeverage".to_string()), Value::Str("spot_leverage".to_string()), &[]);
let mut sender: Value = self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]);
let mut order: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sender".to_string(), sender.clone());
m.insert("priceX18".to_string(), priceX18.clone());
m.insert("amount".to_string(), amountX18.clone());
m.insert("expiration".to_string(), expiration.clone());
m.insert("nonce".to_string(), nonce.clone());
m
});
let mut placeOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), productId.clone());
m
});
if !is_equal(&requestId, &Value::Null) {
add_element_to_object(&mut placeOrder, &Value::Str("id".to_string()), requestId.clone());
}
if !is_equal(&spotLeverage, &Value::Null) {
add_element_to_object(&mut placeOrder, &Value::Str("spot_leverage".to_string()), spotLeverage.clone());
}
let mut isBuy: bool = is_equal(&side, &Value::Str("buy".to_string()));
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossTriggerPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitTriggerPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut isStopLossOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
let mut isStopOrder: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isTriggerOrder: Value = Value::Bool(is_true(&isStopOrder) || is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder));
if is_true(&isStopOrder) {
let mut triggerDirection: Value = self.safe_string_lower(params.clone(), Value::Str("triggerDirection".to_string()), &[]);
if is_equal(&triggerDirection, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires triggerDirection for trigger order".to_string()))));
}
let mut triggerPriceX18: Value = self.convert_to_x18(triggerPrice.clone());
let mut priceRequirement: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut priceRequirement, &add(&Value::Str("oracle_price_".to_string()), &triggerDirection), triggerPriceX18.clone());
let mut trigger: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price_trigger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price_requirement".to_string(), priceRequirement.clone());
m
}));
m
});
add_element_to_object(&mut placeOrder, &Value::Str("trigger".to_string()), trigger.clone());
} else if is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder) {
let mut triggerDirection: Value = Value::Str("".to_string());
if is_true(&isBuy) {
triggerDirection = ternary(is_true(&isStopLossOrder), Value::Str("above".to_string()), Value::Str("below".to_string()));
} else {
triggerDirection = ternary(is_true(&isStopLossOrder), Value::Str("below".to_string()), Value::Str("above".to_string()));
}
triggerPrice = ternary(is_true(&isStopLossOrder), stopLossTriggerPrice.clone(), takeProfitTriggerPrice.clone());
let mut triggerPriceX18: Value = self.convert_to_x18(triggerPrice.clone());
let mut priceRequirement: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut priceRequirement, &add(&Value::Str("oracle_price_".to_string()), &triggerDirection), triggerPriceX18.clone());
let mut trigger: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price_trigger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price_requirement".to_string(), priceRequirement.clone());
m
}));
m
});
add_element_to_object(&mut placeOrder, &Value::Str("trigger".to_string()), trigger.clone());
}
let mut appendix: Value = self.safe_string_k(params.clone(), "appendix", &[]);
if is_equal(&appendix, &Value::Null) {
appendix = self.create_order_appendix(isTriggerOrder.clone(), &[params.clone()]);
}
add_element_to_object(&mut order, &Value::Str("appendix".to_string()), appendix.clone());
let mut contracts: Value = self.query_contracts(&[]).await;
let mut chainId: Value = self.safe_string_k(contracts.clone(), "chain_id", &[]);
let mut signature: Value = self.sign_order(order.clone(), productId.clone(), chainId.clone());
add_element_to_object(&mut placeOrder, &Value::Str("order".to_string()), order.clone());
add_element_to_object(&mut placeOrder, &Value::Str("signature".to_string()), signature.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("expiration".to_string()), Value::Str("nonce".to_string()), Value::Str("appendix".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("postOnly".to_string()), Value::Str("timeInForce".to_string()), Value::Str("id".to_string()), Value::Str("spotLeverage".to_string()), Value::Str("spot_leverage".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerDirection".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("place_order".to_string(), placeOrder.clone());
m
});
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name nado#editOrder
* @description edit a trade order
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-and-place
* @param {string} id order id
* @param {string} symbol unified symbol of the market to edit an order in
* @param {string} type must be 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string|int} [params.expiration] order expiration timestamp in seconds, defaults to 4294967295
* @param {string|int} [params.appendix] pre-encoded order appendix
* @param {boolean} [params.reduceOnly] true if the order should only reduce position
* @param {boolean} [params.postOnly] true to create a post-only order
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', or 'PO'
* @param {boolean} [params.spotLeverage] whether leverage should be used for spot, defaults to true, exchange-specific alias params.spot_leverage
* @param {boolean} [params.placeRequiresUnfilled] when true, aborts the new order if the canceled order had partial fills or the cancel failed, exchange-specific alias params.place_requires_unfilled, defaults to true
* @param {int} [params.id] client-provided request id, returned by the exchange in the response
* @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_required_credentials(&[]);
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.edit_order_request(id.clone(), symbol.clone(), type_var.clone(), side.clone(), &[amount.clone(), price.clone(), params.clone()]).await;
let mut response: Value = self.gateway_private_post_execute(&[request.clone()]).await;
//
// {
// "status": "success",
// "signature": "0x...",
// "data": {
// "digest": "0x..."
// },
// "request_type": "execute_cancel_and_place"
// }
//
let mut cancelAndPlace: Value = self.safe_dict_k(request.clone(), "cancel_and_place", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut placeOrder: Value = self.safe_dict_k(cancelAndPlace.clone(), "place_order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let __ws_arg_1 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("place_order".to_string(), placeOrder.clone());
m
}), &[response.clone()]);
return self.parse_order(__ws_arg_1, &[market.clone()]);
Value::Null
}
/*
* @method
* @ignore
* @name nado#editOrderRequest
* @description build and sign the cancel_and_place execute payload
* @param {string} id order id
* @param {string} symbol unified symbol of the market to edit an order in
* @param {string} type must be 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the request payload for the cancel_and_place execute
*/
pub async fn edit_order_request(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut market: Value = self.market(symbol.clone());
if !is_equal(&type_var, &Value::Str("limit".to_string())) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" editOrder() supports limit orders only".to_string()))));
}
if is_equal(&amount, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires an amount argument".to_string()))));
}
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires a price argument".to_string()))));
}
let mut productId: Value = self.parse_to_int(get_value(&market, &Value::Str("id".to_string())));
let mut priceString: Value = self.price_to_precision(symbol.clone(), price.clone());
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount.clone());
let mut priceX18: Value = self.convert_to_x18(priceString.clone());
let mut amountX18: Value = self.convert_to_x18(amountString.clone());
if is_equal(&side, &Value::Str("sell".to_string())) {
amountX18 = crate::precise::Precise::stringMul(&amountX18, &Value::Str("-1".to_string()));
}
let mut editOrderOptions: Value = self.safe_dict_k(self.options.clone(), "editOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("editOrder".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut expiration: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("editOrder".to_string()), Value::Str("expiration".to_string()), &[Value::Str("4294967295".to_string())]); expiration = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut recvWindow: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("editOrder".to_string()), Value::Str("recvWindow".to_string()), &[Value::Int(5000)]); recvWindow = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut cancelNonce: Value = self.create_order_nonce(recvWindow.clone());
let mut orderNonce: Value = crate::precise::Precise::stringAdd(&cancelNonce, &Value::Str("1".to_string()));
let mut appendix: Value = self.safe_string_k(params.clone(), "appendix", &[]);
if is_equal(&appendix, &Value::Null) {
appendix = self.create_order_appendix(Value::Bool(false), &[params.clone()]);
}
let mut requestId: Value = self.safe_integer_k(params.clone(), "id", &[]);
let mut spotLeverage: Value = self.safe_bool2(params.clone(), Value::Str("spotLeverage".to_string()), Value::Str("spot_leverage".to_string()), &[]);
let mut placeRequiresUnfilled: Value = self.safe_bool2(params.clone(), Value::Str("placeRequiresUnfilled".to_string()), Value::Str("place_requires_unfilled".to_string()), &[self.safe_bool_k(editOrderOptions.clone(), "placeRequiresUnfilled", &[Value::Bool(true)])]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("expiration".to_string()), Value::Str("nonce".to_string()), Value::Str("appendix".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("postOnly".to_string()), Value::Str("timeInForce".to_string()), Value::Str("id".to_string()), Value::Str("spotLeverage".to_string()), Value::Str("spot_leverage".to_string()), Value::Str("placeRequiresUnfilled".to_string()), Value::Str("place_requires_unfilled".to_string())]), &[]);
let mut sender: Value = self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]);
let mut cancelTx: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sender".to_string(), sender.clone());
m.insert("productIds".to_string(), Value::List(vec![productId.clone()]));
m.insert("digests".to_string(), Value::List(vec![id.clone()]));
m.insert("nonce".to_string(), cancelNonce.clone());
m
});
let mut order: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sender".to_string(), sender.clone());
m.insert("priceX18".to_string(), priceX18.clone());
m.insert("amount".to_string(), amountX18.clone());
m.insert("expiration".to_string(), expiration.clone());
m.insert("nonce".to_string(), orderNonce.clone());
m.insert("appendix".to_string(), appendix.clone());
m
});
let mut contracts: Value = self.query_contracts(&[]).await;
let mut chainId: Value = self.safe_string_k(contracts.clone(), "chain_id", &[]);
let mut endpointAddress: Value = self.safe_string_k(contracts.clone(), "endpoint_addr", &[]);
if is_equal(&endpointAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" editOrder() requires endpoint_addr from contracts query".to_string()))));
}
let mut cancelSignature: Value = self.sign_cancellation(cancelTx.clone(), chainId.clone(), endpointAddress.clone());
let mut orderSignature: Value = self.sign_order(order.clone(), productId.clone(), chainId.clone());
let mut placeOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), productId.clone());
m.insert("order".to_string(), order.clone());
m.insert("signature".to_string(), orderSignature.clone());
m
});
if !is_equal(&requestId, &Value::Null) {
add_element_to_object(&mut placeOrder, &Value::Str("id".to_string()), requestId.clone());
}
if !is_equal(&spotLeverage, &Value::Null) {
add_element_to_object(&mut placeOrder, &Value::Str("spot_leverage".to_string()), spotLeverage.clone());
}
let mut cancelAndPlace: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cancel_tx".to_string(), cancelTx.clone());
m.insert("cancel_signature".to_string(), cancelSignature.clone());
m.insert("place_order".to_string(), placeOrder.clone());
m.insert("place_requires_unfilled".to_string(), placeRequiresUnfilled.clone());
m
});
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cancel_and_place".to_string(), cancelAndPlace.clone());
m
});
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name nado#cancelOrder
* @description cancels an open order
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-orders
* @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
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string} [params.requiredUnfilledAmount] cancel only if the order's absolute remaining unfilled amount matches this amount, exchange-specific raw x18 alias params.required_unfilled_amount
* @param {int} [params.id] client-provided request id, returned by the exchange in the response
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut orders: Value = self.cancel_orders(Value::List(vec![id.clone()]), &[symbol.clone(), params.clone()]).await;
return self.safe_dict(orders.clone(), Value::Int(0), &[]);
Value::Null
}
/*
* @method
* @name nado#cancelAllOrders
* @description cancel all open orders
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-product-orders
* @param {string} [symbol] unified market symbol, when undefined all orders for all products are canceled
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {int} [params.id] client-provided request id, returned by the exchange in the response
* @param {boolean} [params.trigger] set to true if you would like to fetch portfolio margin account trigger or conditional orders
* @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
}));
self.check_required_credentials(&[]);
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut request: Value = self.cancel_all_orders_request(&[symbol.clone(), params.clone()]).await;
let mut response: Value = Value::Null;
if is_equal(&trigger, &Value::Bool(true)) {
response = self.trigger_private_post_execute(&[request.clone()]).await;
} else {
response = self.gateway_private_post_execute(&[request.clone()]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cancelledOrders: Value = self.safe_list_k(data.clone(), "cancelled_orders", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_961: bool = true;
while { if !__for_first_961 { i = add(&i, &Value::Int(1)); } __for_first_961 = false; is_less_than(&i, &get_array_length(&cancelledOrders)) } {
let __ws_arg_2 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m
}), &[get_value(&cancelledOrders, &i)]);
append_to_array(&mut result, self.parse_order(__ws_arg_2, &[market.clone()]));
}
}
return result;
Value::Null
}
/*
* @method
* @ignore
* @name nado#cancelAllOrdersRequest
* @description build and sign the cancel_product_orders execute payload
* @param {string} [symbol] unified market symbol, when undefined all orders for all products are canceled
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the request payload for the cancel_product_orders execute
*/
pub async fn cancel_all_orders_request(&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 productIds: Value = Value::List(vec![]);
if !is_equal(&symbol, &Value::Null) {
let mut market: Value = self.market(symbol.clone());
append_to_array(&mut productIds, self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
}
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelAllOrders".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut sender: Value = self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]);
let mut recvWindow: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelAllOrders".to_string()), Value::Str("recvWindow".to_string()), &[Value::Int(5000)]); recvWindow = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut nonce: Value = self.create_order_nonce(recvWindow.clone());
let mut tx: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sender".to_string(), sender.clone());
m.insert("productIds".to_string(), productIds.clone());
m.insert("nonce".to_string(), nonce.clone());
m
});
let mut contracts: Value = self.query_contracts(&[]).await;
let mut chainId: Value = self.safe_string_k(contracts.clone(), "chain_id", &[]);
let mut endpointAddress: Value = self.safe_string_k(contracts.clone(), "endpoint_addr", &[]);
if is_equal(&endpointAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" cancelAllOrders() requires endpoint_addr from contracts query".to_string()))));
}
let mut signature: Value = self.sign_cancellation_products(tx.clone(), chainId.clone(), endpointAddress.clone());
let mut requestId: Value = self.safe_integer_k(params.clone(), "id", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("id".to_string())]), &[]);
let mut cancelProductOrders: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx".to_string(), tx.clone());
m.insert("signature".to_string(), signature.clone());
m
});
if !is_equal(&requestId, &Value::Null) {
add_element_to_object(&mut cancelProductOrders, &Value::Str("id".to_string()), requestId.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cancel_product_orders".to_string(), cancelProductOrders.clone());
m
});
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name nado#cancelOrders
* @description cancel multiple orders
* @see https://docs.nado.xyz/developer-resources/api/gateway/executes/cancel-orders
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {string} [params.requiredUnfilledAmount] cancel only if the order's absolute remaining unfilled amount matches this amount, exchange-specific raw x18 alias params.required_unfilled_amount
* @param {int} [params.id] client-provided request id, returned by the exchange in the response
* @param {boolean} [params.trigger] set to true if you would like to fetch portfolio margin account trigger or conditional orders
* @returns {object[]} a 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
}));
self.check_required_credentials(&[]);
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(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut request: Value = self.cancel_orders_request(ids.clone(), &[symbol.clone(), params.clone()]).await;
let mut response: Value = Value::Null;
if is_equal(&trigger, &Value::Bool(true)) {
response = self.trigger_private_post_execute(&[request.clone()]).await;
} else {
response = self.gateway_private_post_execute(&[request.clone()]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cancelledOrders: Value = self.safe_list_k(data.clone(), "cancelled_orders", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_962: bool = true;
while { if !__for_first_962 { i = add(&i, &Value::Int(1)); } __for_first_962 = false; is_less_than(&i, &get_array_length(&cancelledOrders)) } {
let __ws_arg_3 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m
}), &[get_value(&cancelledOrders, &i)]);
append_to_array(&mut result, self.parse_order(__ws_arg_3, &[market.clone()]));
}
}
return result;
Value::Null
}
/*
* @method
* @ignore
* @name nado#cancelOrdersRequest
* @description build and sign the cancel_orders execute payload
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the request payload for the cancel_orders execute
*/
pub async fn cancel_orders_request(&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
}));
let mut market: Value = self.market(symbol.clone());
let mut productId: Value = self.parse_to_int(get_value(&market, &Value::Str("id".to_string())));
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelOrders".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut sender: Value = self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]);
let mut productIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_963: bool = true;
while { if !__for_first_963 { i = add(&i, &Value::Int(1)); } __for_first_963 = false; is_less_than(&i, &get_array_length(&ids)) } {
append_to_array(&mut productIds, productId.clone());
}
}
let mut recvWindow: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelOrders".to_string()), Value::Str("recvWindow".to_string()), &[Value::Int(5000)]); recvWindow = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut nonce: Value = self.create_order_nonce(recvWindow.clone());
let mut tx: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sender".to_string(), sender.clone());
m.insert("productIds".to_string(), productIds.clone());
m.insert("digests".to_string(), ids.clone());
m.insert("nonce".to_string(), nonce.clone());
m
});
let mut contracts: Value = self.query_contracts(&[]).await;
let mut chainId: Value = self.safe_string_k(contracts.clone(), "chain_id", &[]);
let mut endpointAddress: Value = self.safe_string_k(contracts.clone(), "endpoint_addr", &[]);
if is_equal(&endpointAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" cancelOrders() requires endpoint_addr from contracts query".to_string()))));
}
let mut signature: Value = self.sign_cancellation(tx.clone(), chainId.clone(), endpointAddress.clone());
let mut requestId: Value = self.safe_integer_k(params.clone(), "id", &[]);
let mut requiredUnfilledAmountRaw: Value = self.safe_string_k(params.clone(), "required_unfilled_amount", &[]);
let mut requiredUnfilledAmount: Value = self.safe_string_k(params.clone(), "requiredUnfilledAmount", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("id".to_string()), Value::Str("requiredUnfilledAmount".to_string()), Value::Str("required_unfilled_amount".to_string())]), &[]);
let mut cancelOrders: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx".to_string(), tx.clone());
m.insert("signature".to_string(), signature.clone());
m
});
if !is_equal(&requiredUnfilledAmountRaw, &Value::Null) {
add_element_to_object(&mut cancelOrders, &Value::Str("required_unfilled_amount".to_string()), requiredUnfilledAmountRaw.clone());
} else if !is_equal(&requiredUnfilledAmount, &Value::Null) {
add_element_to_object(&mut cancelOrders, &Value::Str("required_unfilled_amount".to_string()), self.convert_to_x18(requiredUnfilledAmount.clone()));
}
if !is_equal(&requestId, &Value::Null) {
add_element_to_object(&mut cancelOrders, &Value::Str("id".to_string()), requestId.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cancel_orders".to_string(), cancelOrders.clone());
m
});
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchOrder
* @description fetches information on an order made by the user
* @see https://docs.nado.xyz/developer-resources/api/gateway/queries/order
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn 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(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("order".to_string()));
m.insert("product_id".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m.insert("digest".to_string(), id.clone());
m
});
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_public_get_query(&[__ws_arg_4]).await;
//
// {
// "status": "success",
// "data": {
// "product_id": 1,
// "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
// "price_x18": "1000000000000000000",
// "amount": "1000000000000000000",
// "expiration": "2000000000",
// "nonce": "1",
// "unfilled_amount": "1000000000000000000",
// "digest": "0x0000000000000000000000000000000000000000000000000000000000000000",
// "placed_at": 1681951347,
// "appendix": "1537",
// "order_type": "ioc"
// },
// "request_type": "query_order"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://docs.nado.xyz/developer-resources/api/archive-indexer/orders
* @see https://docs.nado.xyz/developer-resources/api/trigger/queries/list-trigger-orders
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true if you would like to fetch portfolio margin account trigger or conditional orders
* @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
}));
self.load_markets(&[]).await;
let mut productIds: Value = Value::List(vec![]);
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
append_to_array(&mut productIds, self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
}
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrders".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut sender: Value = self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
if !is_equal(&trigger, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrders only support trigger".to_string()))));
}
let mut recvWindow: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrders".to_string()), Value::Str("recvWindow".to_string()), &[Value::Int(5000)]); recvWindow = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut tx: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sender".to_string(), sender.clone());
m.insert("recvTime".to_string(), self.number_to_string(add(&self.milliseconds(), &recvWindow)));
m
});
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tx".to_string(), tx.clone());
m.insert("type".to_string(), Value::Str("list_trigger_orders".to_string()));
m.insert("product_ids".to_string(), productIds.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut contracts: Value = self.query_contracts(&[]).await;
let mut chainId: Value = self.safe_string_k(contracts.clone(), "chain_id", &[]);
let mut endpointAddress: Value = self.safe_string_k(contracts.clone(), "endpoint_addr", &[]);
let mut signature: Value = self.sign_fetch_trigger_orders(tx.clone(), chainId.clone(), endpointAddress.clone());
add_element_to_object(&mut request, &Value::Str("signature".to_string()), signature.clone());
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.trigger_private_post_query(&[__ws_arg_5]).await;
//
// {
// "status": "success",
// "data": {
// "orders": [{
// "order": {
// "order": {
// "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
// "priceX18": "1000000000000000000",
// "amount": "1000000000000000000",
// "expiration": "2000000000",
// "nonce": "1",
// },
// "signature": "0x...",
// "product_id": 1,
// "spot_leverage": true,
// "trigger": {
// "price_above": "1000000000000000000"
// },
// "digest": "0x..."
// },
// "status": "pending",
// "placed_at": 1688768157000,
// "updated_at": 1688768157050
// }]
// },
// "request_type": "query_list_trigger_orders"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://docs.nado.xyz/developer-resources/api/gateway/queries/orders
* @see https://docs.nado.xyz/developer-resources/api/trigger/queries/list-trigger-orders
* @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 order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {boolean} [params.trigger] whether the order is a trigger order
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOpenOrders() requires walletAddress".to_string()))));
}
self.load_markets(&[]).await;
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOpenOrders".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut sender: Value = self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_6 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status_types".to_string(), Value::List(vec![Value::Str("waiting_price".to_string()), Value::Str("waiting_dependency".to_string())]));
m
})]);
return self.fetch_orders(&[symbol.clone(), since.clone(), Value::Null, __ws_arg_6]).await;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOpenOrders() requires a symbol argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sender".to_string(), sender.clone());
m.insert("type".to_string(), Value::Str("subaccount_orders".to_string()));
m.insert("product_id".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m
});
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_public_get_query(&[__ws_arg_7]).await;
//
// single product
//
// {
// "status": "success",
// "data": {
// "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
// "product_id": 1,
// "orders": [
// {
// "product_id": 1,
// "sender": "0x7a5ec2748e9065794491a8d29dcf3f9edb8d7c43000000000000000000000000",
// "price_x18": "1000000000000000000",
// "amount": "1000000000000000000",
// "expiration": "2000000000",
// "nonce": "1",
// "unfilled_amount": "1000000000000000000",
// "digest": "0x0000000000000000000000000000000000000000000000000000000000000000",
// "placed_at": 1682437739,
// "appendix": "1537",
// "order_type": "ioc"
// }
// ]
// },
// "request_type": "query_subaccount_orders"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("open".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name nado#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://docs.nado.xyz/developer-resources/api/archive-indexer/orders
* @see https://docs.nado.xyz/developer-resources/api/trigger/queries/list-trigger-orders
* @param {string} [symbol] unified market symbol of the market orders were made in
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the maximum number of orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {int} [params.until] timestamp in ms of the latest order to fetch
* @param {boolean} [params.trigger] whether the order is a trigger order
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchClosedOrders() requires walletAddress".to_string()))));
}
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchClosedOrders".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut sender: Value = self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_8 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status_types".to_string(), Value::List(vec![Value::Str("triggered".to_string()), Value::Str("triggering".to_string()), Value::Str("twap_executing".to_string()), Value::Str("twap_completed".to_string())]));
m
})]);
return self.fetch_orders(&[symbol.clone(), since.clone(), Value::Null, __ws_arg_8]).await;
}
let mut ordersRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subaccounts".to_string(), Value::List(vec![sender.clone()]));
m
});
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut ordersRequest, &Value::Str("product_ids".to_string()), Value::List(vec![self.parse_to_int(get_value(&market, &Value::Str("id".to_string())))]));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("max_time".to_string()), ordersRequest.clone(), params.clone(), &[Value::Float(0.001)]); ordersRequest = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut ordersRequest, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(500)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), ordersRequest.clone());
m
});
let mut response: Value = self.archive_post(&[self.deep_extend(request.clone(), &[params.clone()])]).await;
//
// {
// "orders": [
// {
// "digest": "0xf4f7a8767faf0c7f72251a1f9e5da590f708fd9842bf8fcdeacbaa0237958fff",
// "subaccount": "0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000",
// "product_id": 1,
// "submission_idx": "563024",
// "amount": "20000000000000000000",
// "price_x18": "1751900000000000000000",
// "base_filled": "20000000000000000000",
// "quote_filled": "-35038000000000000000000",
// "fee": "7007600000000000000",
// "first_fill_timestamp": "1679728133",
// "last_fill_timestamp": "1679728133"
// }
// ]
// }
//
let mut closedOrders: Value = Value::List(vec![]);
let mut orders: Value = self.safe_list_k(response.clone(), "orders", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_964: bool = true;
while { if !__for_first_964 { i = add(&i, &Value::Int(1)); } __for_first_964 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = get_value(&orders, &i);
let mut order: Value = get_value(&orders, &i);
if is_true(&self.is_archive_order_closed(order.clone())) {
append_to_array(&mut closedOrders, self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("closed".to_string()));
m
}), &[order.clone()]));
}
}
}
return self.parse_orders(closedOrders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://docs.nado.xyz/developer-resources/api/trigger/queries/list-trigger-orders
* @param {string} symbol unified market symbol of the market the 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 {boolean} [params.trigger] set to true if you would like to fetch portfolio margin account trigger or conditional orders
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_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
}));
let __ws_arg_9 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status_types".to_string(), Value::List(vec![Value::Str("cancelled".to_string()), Value::Str("internal_error".to_string())]));
m
})]);
return self.fetch_orders(&[symbol.clone(), since.clone(), Value::Null, __ws_arg_9]).await;
Value::Null
}
/*
* @method
* @name nado#fetchCanceledAndClosedOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://docs.nado.xyz/developer-resources/api/trigger/queries/list-trigger-orders
* @param {string} symbol unified market symbol of the market the 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 {boolean} [params.trigger] set to true if you would like to fetch portfolio margin account trigger or conditional orders
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_and_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __ws_arg_10 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status_types".to_string(), Value::List(vec![Value::Str("cancelled".to_string()), Value::Str("internal_error".to_string()), Value::Str("triggered".to_string()), Value::Str("triggering".to_string()), Value::Str("twap_executing".to_string()), Value::Str("twap_completed".to_string())]));
m
})]);
return self.fetch_orders(&[symbol.clone(), since.clone(), Value::Null, __ws_arg_10]).await;
Value::Null
}
/*
* @method
* @name nado#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.nado.xyz/developer-resources/api/archive-indexer/matches
* @param {string} [symbol] unified market symbol
* @param {int} [since] timestamp in ms of the earliest trade
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {int} [params.until] timestamp in ms of the latest trade to fetch
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires walletAddress".to_string()))));
}
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut matchesRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subaccounts".to_string(), Value::List(vec![self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()])]));
m
});
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut matchesRequest, &Value::Str("product_ids".to_string()), Value::List(vec![self.parse_to_int(get_value(&market, &Value::Str("id".to_string())))]));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("max_time".to_string()), matchesRequest.clone(), params.clone(), &[Value::Float(0.001)]); matchesRequest = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut matchesRequest, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(500)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("matches".to_string(), matchesRequest.clone());
m
});
let mut response: Value = self.archive_post(&[self.deep_extend(request.clone(), &[params.clone()])]).await;
//
// {
// "matches": [
// {
// "digest": "0x80ce789702b670b7d33f2aa67e12c85f124395c3f9acdb422dde3b4973ccd50c",
// "order": {
// "sender": "0x12a0b4888021576eb10a67616dd3dd3d9ce206b664656661756c740000000000",
// "priceX18": "27544000000000000000000",
// "amount": "2000000000000000000",
// "expiration": "4611686020107119633",
// "nonce": "1761322608857448448"
// },
// "base_filled": "736000000000000000",
// "quote_filled": "-20276464287857571514302",
// "fee": "4055287857571514302",
// "submission_idx": "563012",
// "is_taker": true
// }
// ],
// "txs": [
// {
// "submission_idx": "563012",
// "product_id": 2,
// "timestamp": "1679728133"
// }
// ]
// }
//
let mut matches: Value = self.safe_list_k(response.clone(), "matches", &[Value::List(vec![])]);
let mut txs: Value = self.safe_list_k(response.clone(), "txs", &[Value::List(vec![])]);
let mut txsBySubmission: Value = self.index_by(txs.clone(), Value::Str("submission_idx".to_string()));
let mut trades: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_965: bool = true;
while { if !__for_first_965 { i = add(&i, &Value::Int(1)); } __for_first_965 = false; is_less_than(&i, &get_array_length(&matches)) } {
let mut match_val: Value = get_value(&matches, &i);
let mut match_val: Value = get_value(&matches, &i);
let mut submissionIdx: Value = self.safe_string_k(match_val.clone(), "submission_idx", &[]);
let mut tx: Value = self.safe_dict(txsBySubmission.clone(), submissionIdx.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
append_to_array(&mut trades, self.extend(tx.clone(), &[match_val.clone()]));
}
}
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.nado.xyz/developer-resources/api/gateway/queries/subaccount-info
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchBalance() requires walletAddress".to_string()))));
}
self.load_markets(&[]).await;
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("subaccount_info".to_string()));
m.insert("subaccount".to_string(), self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]));
m
});
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_public_get_query(&[__ws_arg_11]).await;
//
// {
// "status": "success",
// "data": {
// "subaccount": "0x8d7d64d6cf1d4f018dd101482ac71ad49e30c56064656661756c740000000000",
// "exists": true,
// "spot_balances": [
// {
// "product_id": 0,
// "balance": {
// "amount": "456895621098158389211471"
// }
// }
// ],
// "perp_balances": []
// },
// "request_type": "query_subaccount_info"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_balance(data.clone());
Value::Null
}
/*
* @method
* @name nado#fetchDeposits
* @description fetch all deposits made to an account
* @see https://docs.nado.xyz/developer-resources/api/archive-indexer/events
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {int} [params.until] timestamp in ms of the latest deposit to fetch
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
*/
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.query_transactions_by_event_type(Value::Str("deposit_collateral".to_string()), Value::Str("deposit".to_string()), Value::Str("fetchDeposits".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name nado#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://docs.nado.xyz/developer-resources/api/archive-indexer/events
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @param {int} [params.until] timestamp in ms of the latest withdrawal to fetch
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
*/
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.query_transactions_by_event_type(Value::Str("withdraw_collateral".to_string()), Value::Str("withdrawal".to_string()), Value::Str("fetchWithdrawals".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
pub async fn query_transactions_by_event_type(&mut self, mut eventType: Value, mut transactionType: Value, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires walletAddress".to_string()))));
}
self.load_markets(&[]).await;
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut eventsRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subaccounts".to_string(), Value::List(vec![self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()])]));
m.insert("event_types".to_string(), Value::List(vec![eventType.clone()]));
m.insert("limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("raw".to_string(), ternary(is_true(&(is_equal(&limit, &Value::Null))), Value::Int(100), crate::runtime::Math::min(&limit, &Value::Int(500))));
m
}));
m
});
if !is_equal(¤cy, &Value::Null) {
add_element_to_object(&mut eventsRequest, &Value::Str("product_ids".to_string()), Value::List(vec![self.parse_to_int(get_value(¤cy, &Value::Str("id".to_string())))]));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("max_time".to_string()), eventsRequest.clone(), params.clone(), &[Value::Float(0.001)]); eventsRequest = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("events".to_string(), eventsRequest.clone());
m
});
let mut response: Value = self.archive_post(&[self.deep_extend(request.clone(), &[params.clone()])]).await;
//
// {
// "events": [
// {
// "subaccount": "0x...",
// "product_id": 5,
// "submission_idx": "563011",
// "event_type": "deposit_collateral",
// "pre_balance": {
// "spot": {
// "balance": {
// "amount": "1000000000000000000"
// }
// }
// },
// "post_balance": {
// "spot": {
// "balance": {
// "amount": "2000000000000000000"
// }
// }
// }
// }
// ],
// "txs": [
// {
// "submission_idx": "563011",
// "timestamp": "1679728127"
// }
// ]
// }
//
let mut events: Value = self.safe_list_k(response.clone(), "events", &[Value::List(vec![])]);
let mut txs: Value = self.safe_list_k(response.clone(), "txs", &[Value::List(vec![])]);
let mut transactions: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_967: bool = true;
while { if !__for_first_967 { i = add(&i, &Value::Int(1)); } __for_first_967 = false; is_less_than(&i, &get_array_length(&events)) } {
let mut event: Value = get_value(&events, &i);
let mut event: Value = get_value(&events, &i);
let mut submissionIdx: Value = self.safe_string_k(event.clone(), "submission_idx", &[]);
let mut tx: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_966: bool = true;
while { if !__for_first_966 { j = add(&j, &Value::Int(1)); } __for_first_966 = false; is_less_than(&j, &get_array_length(&txs)) } {
let mut rawTx: Value = get_value(&txs, &j);
let mut rawTx: Value = get_value(&txs, &j);
let mut txSubmissionIdx: Value = self.safe_string_k(rawTx.clone(), "submission_idx", &[]);
if is_equal(&txSubmissionIdx, &submissionIdx) {
tx = rawTx.clone();
break;
}
}
}
let mut transaction: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[tx.clone()]);
transaction = self.extend(transaction.clone(), &[event.clone()]);
add_element_to_object(&mut transaction, &Value::Str("transaction_type".to_string()), transactionType.clone());
append_to_array(&mut transactions, self.parse_transaction(transaction.clone(), &[currency.clone()]));
}
}
return self.filter_by_currency_since_limit(transactions.clone(), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchPositions
* @description fetch all open positions
* @see https://docs.nado.xyz/developer-resources/api/gateway/queries/subaccount-info
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @returns {Position[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchPositions() requires walletAddress".to_string()))));
}
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPositions".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("subaccount_info".to_string()));
m.insert("subaccount".to_string(), self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]));
m
});
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_public_get_query(&[__ws_arg_12]).await;
//
// {
// "status": "success",
// "data": {
// "perp_balances": [
// {
// "product_id": 2,
// "balance": {
// "amount": "100000000000000000",
// "v_quote_balance": "3033500000000000000000",
// "last_cumulative_funding_x18": "-394223711772447555304"
// }
// }
// ],
// "perp_products": [
// {
// "product_id": 2,
// "oracle_price_x18": "115596528090565357611177",
// "risk": {
// "price_x18": "115596528090565357611177"
// }
// }
// ]
// },
// "request_type": "query_subaccount_info"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positions: Value = self.safe_list_k(data.clone(), "perp_balances", &[Value::List(vec![])]);
let mut products: Value = self.safe_list_k(data.clone(), "perp_products", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_969: bool = true;
while { if !__for_first_969 { i = add(&i, &Value::Int(1)); } __for_first_969 = 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 balance: Value = self.safe_dict_k(position.clone(), "balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amount: Value = self.safe_string_k(balance.clone(), "amount", &[]);
if is_true(&(is_equal(&amount, &Value::Null))) || is_true(&crate::precise::Precise::stringEquals(&amount, &Value::Str("0".to_string()))) {
continue;
}
let mut productId: Value = self.safe_string_k(position.clone(), "product_id", &[]);
let mut product: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_968: bool = true;
while { if !__for_first_968 { j = add(&j, &Value::Int(1)); } __for_first_968 = false; is_less_than(&j, &get_array_length(&products)) } {
let mut rawProduct: Value = get_value(&products, &j);
let mut rawProduct: Value = get_value(&products, &j);
let mut rawProductId: Value = self.safe_string_k(rawProduct.clone(), "product_id", &[]);
if is_equal(&rawProductId, &productId) {
product = rawProduct.clone();
break;
}
}
}
let __ws_arg_13 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("product".to_string(), product.clone());
m
}), &[position.clone()]);
append_to_array(&mut result, self.parse_position(__ws_arg_13, &[]));
}
}
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
/*
* @method
* @name nado#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://docs.nado.xyz/developer-resources/api/gateway/edge#control-messages
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("time".to_string()));
m
});
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_public_get_edge_query(&[__ws_arg_14]).await;
return self.safe_integer_k(response.clone(), "server_time", &[]);
Value::Null
}
/*
* @method
* @name nado#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://docs.nado.xyz/developer-resources/api/gateway/queries/status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("status".to_string()));
m
});
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_public_get_query(&[__ws_arg_15]).await;
//
// {
// "status": "success",
// "data": "active",
// "request_type": "query_status"
// }
//
let mut status: Value = self.safe_string_k(response.clone(), "data", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), ternary(is_true(&(is_equal(&status, &Value::Str("active".to_string())))), Value::Str("ok".to_string()), Value::Str("error".to_string())));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
m
});
Value::Null
}
/*
* @method
* @name nado#fetchMarkets
* @description retrieves data on all markets for nado
* @see https://docs.nado.xyz/developer-resources/api/gateway/queries/symbols
* @see https://docs.nado.xyz/developer-resources/api/v2/pairs
* @see https://docs.nado.xyz/developer-resources/api/v2/assets
* @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 symbolsRequest: Value = self.gateway_public_get_symbols(&[params.clone()]).await;
let mut pairsRequest: Value = self.gateway_v2_public_get_pairs(&[params.clone()]).await;
let mut assetsRequest: Value = self.gateway_v2_public_get_assets(&[params.clone()]).await;
let mut responses: Value = promise_all(&Value::List(vec![symbolsRequest.clone(), pairsRequest.clone(), assetsRequest.clone()])).await;
let mut symbols: Value = self.safe_list(responses.clone(), Value::Int(0), &[Value::List(vec![])]);
let mut pairs: Value = self.safe_list(responses.clone(), Value::Int(1), &[Value::List(vec![])]);
let mut assets: Value = self.safe_list(responses.clone(), Value::Int(2), &[Value::List(vec![])]);
// product_id is a JSON number: JS object keys are always strings but a Python
// dict keeps int keys, so indexBy would never match the safeString lookups below
let mut pairsById: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_970: bool = true;
while { if !__for_first_970 { i = add(&i, &Value::Int(1)); } __for_first_970 = false; is_less_than(&i, &get_array_length(&pairs)) } {
let mut rawPair: Value = get_value(&pairs, &i);
let mut rawPair: Value = get_value(&pairs, &i);
let mut pairProductId: Value = self.safe_string_k(rawPair.clone(), "product_id", &[]);
if !is_equal(&pairProductId, &Value::Null) {
add_element_to_object(&mut pairsById, &pairProductId, rawPair.clone());
}
}
}
let mut assetsById: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_971: bool = true;
while { if !__for_first_971 { i = add(&i, &Value::Int(1)); } __for_first_971 = false; is_less_than(&i, &get_array_length(&assets)) } {
let mut rawAsset: Value = get_value(&assets, &i);
let mut rawAsset: Value = get_value(&assets, &i);
let mut assetProductId: Value = self.safe_string_k(rawAsset.clone(), "product_id", &[]);
if !is_equal(&assetProductId, &Value::Null) {
add_element_to_object(&mut assetsById, &assetProductId, rawAsset.clone());
}
}
}
let mut assetsByCode: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_972: bool = true;
while { if !__for_first_972 { i = add(&i, &Value::Int(1)); } __for_first_972 = false; is_less_than(&i, &get_array_length(&assets)) } {
let mut rawAsset: Value = get_value(&assets, &i);
let mut rawAsset: Value = get_value(&assets, &i);
let mut assetSymbol: Value = self.safe_string_k(rawAsset.clone(), "symbol", &[]);
let mut assetCode: Value = self.safe_currency_code(self.remove_market_suffix(assetSymbol.clone()), &[]);
if is_equal(&assetCode, &Value::Null) {
continue;
}
let mut previous: Value = self.safe_dict(assetsByCode.clone(), assetCode.clone(), &[]);
if is_equal(&previous, &Value::Null) {
add_element_to_object(&mut assetsByCode, &assetCode, rawAsset.clone());
} else {
let mut previousDeposit: Value = self.safe_bool_k(previous.clone(), "can_deposit", &[Value::Bool(false)]);
let mut previousWithdraw: Value = self.safe_bool_k(previous.clone(), "can_withdraw", &[Value::Bool(false)]);
let mut currentDeposit: Value = self.safe_bool_k(rawAsset.clone(), "can_deposit", &[Value::Bool(false)]);
let mut currentWithdraw: Value = self.safe_bool_k(rawAsset.clone(), "can_withdraw", &[Value::Bool(false)]);
if is_true(&(!is_equal(&previousDeposit, &Value::Bool(true)))) && is_true(&(!is_equal(&previousWithdraw, &Value::Bool(true)))) && is_true(&(is_true(&(is_equal(¤tDeposit, &Value::Bool(true)))) || is_true(&(is_equal(¤tWithdraw, &Value::Bool(true)))))) {
add_element_to_object(&mut assetsByCode, &assetCode, rawAsset.clone());
}
}
}
}
let mut markets: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_973: bool = true;
while { if !__for_first_973 { i = add(&i, &Value::Int(1)); } __for_first_973 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut market: Value = get_value(&symbols, &i);
let mut market: Value = get_value(&symbols, &i);
let mut id: Value = self.safe_string_k(market.clone(), "product_id", &[]);
let mut pair: Value = self.safe_dict(pairsById.clone(), id.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut asset: Value = self.safe_dict(assetsById.clone(), id.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rawType: Value = self.safe_string_k(market.clone(), "type", &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&rawType, &Value::Str("perp".to_string())))), Value::Str("swap".to_string()), rawType.clone());
let mut contract: Value = Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string())));
let mut tickerId: Value = self.safe_string2(pair.clone(), Value::Str("ticker_id".to_string()), Value::Str("tickerId".to_string()), &[]);
if is_equal(&tickerId, &Value::Null) {
continue;
}
let mut rawBaseId: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut rawQuoteId: Value = self.safe_string_k(pair.clone(), "quote", &[Value::Str("USDT0".to_string())]);
let mut base: Value = self.safe_currency_code(self.remove_market_suffix(rawBaseId.clone()), &[]);
let mut quote: Value = self.safe_currency_code(rawQuoteId.clone(), &[]);
let mut baseAsset: Value = self.safe_dict(assetsByCode.clone(), base.clone(), &[asset.clone()]);
let mut quoteAsset: Value = self.safe_dict(assetsByCode.clone(), quote.clone(), &[]);
let mut baseId: Value = self.safe_string_k(baseAsset.clone(), "product_id", &[rawBaseId.clone()]);
let mut quoteId: Value = self.safe_string_k(quoteAsset.clone(), "product_id", &[rawQuoteId.clone()]);
let mut settleId: Value = ternary(is_true(&contract), quoteId.clone(), Value::Null);
let mut settle: Value = ternary(is_true(&contract), quote.clone(), Value::Null);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
if is_true(&contract) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &settle));
}
let mut tradingStatus: Value = self.safe_string_k(market.clone(), "trading_status", &[]);
let mut active: Value = Value::Bool(!is_equal(&tradingStatus, &Value::Str("not_tradable".to_string())));
let mut priceIncrement: Value = self.parse_x18(self.safe_string_k(market.clone(), "price_increment_x18", &[]));
let mut amountIncrement: Value = self.parse_x18(self.safe_string_k(market.clone(), "size_increment", &[]));
let mut minCost: Value = self.parse_x18(self.safe_string_k(market.clone(), "min_size", &[]));
append_to_array(&mut markets, self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("lowercaseId".to_string(), Value::Null);
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(), type_var.clone());
m.insert("spot".to_string(), Value::Bool((is_equal(&type_var, &Value::Str("spot".to_string())))));
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), contract.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(), contract.clone());
m.insert("linear".to_string(), ternary(is_true(&contract), Value::Bool(true), Value::Null));
m.insert("inverse".to_string(), ternary(is_true(&contract), Value::Bool(false), Value::Null));
m.insert("taker".to_string(), self.parse_x18(self.safe_string_k(market.clone(), "taker_fee_rate_x18", &[])));
m.insert("maker".to_string(), self.parse_x18(self.safe_string_k(market.clone(), "maker_fee_rate_x18", &[])));
m.insert("contractSize".to_string(), ternary(is_true(&contract), Value::Int(1), Value::Null));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amountIncrement.clone());
m.insert("price".to_string(), priceIncrement.clone());
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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minCost.clone());
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
let __ws_arg_16 = self.safe_string_k(asset.clone(), "name", &[]);
m.insert("info".to_string(), self.extend(market.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ticker_id".to_string(), tickerId.clone());
m.insert("name".to_string(), __ws_arg_16);
m.insert("v2Pair".to_string(), pair.clone());
m.insert("v2Asset".to_string(), asset.clone());
m
})]));
m
})]));
}
}
return markets;
Value::Null
}
/*
* @method
* @name nado#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://docs.nado.xyz/developer-resources/api/v2/assets
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.gateway_v2_public_get_assets(&[params.clone()]).await;
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut assets: Value = self.to_array(response.clone());
{
let mut i: Value = Value::Int(0);
let mut __for_first_974: bool = true;
while { if !__for_first_974 { i = add(&i, &Value::Int(1)); } __for_first_974 = false; is_less_than(&i, &get_array_length(&assets)) } {
let mut currency: Value = get_value(&assets, &i);
let mut currency: Value = get_value(&assets, &i);
let mut parsed: Value = self.parse_currency(currency.clone());
let mut code: Value = self.safe_string_k(parsed.clone(), "code", &[]);
if is_equal(&code, &Value::Null) {
continue;
}
let mut previous: Value = self.safe_dict(result.clone(), code.clone(), &[]);
let mut canDeposit: Value = self.safe_bool_k(currency.clone(), "can_deposit", &[Value::Bool(false)]);
let mut canWithdraw: Value = self.safe_bool_k(currency.clone(), "can_withdraw", &[Value::Bool(false)]);
if is_equal(&previous, &Value::Null) {
add_element_to_object(&mut result, &code, parsed.clone());
} else {
let mut previousDeposit: Value = self.safe_bool_k(previous.clone(), "deposit", &[Value::Bool(false)]);
let mut previousWithdraw: Value = self.safe_bool_k(previous.clone(), "withdraw", &[Value::Bool(false)]);
if is_true(&(!is_equal(&previousDeposit, &Value::Bool(true)))) && is_true(&(!is_equal(&previousWithdraw, &Value::Bool(true)))) && is_true(&(is_true(&(is_equal(&canDeposit, &Value::Bool(true)))) || is_true(&(is_equal(&canWithdraw, &Value::Bool(true)))))) {
add_element_to_object(&mut result, &code, parsed.clone());
}
}
}
}
return result;
Value::Null
}
/*
* @method
* @name nado#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://docs.nado.xyz/developer-resources/api/v2/tickers
* @param {string[]|undefined} 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
* @returns {object} a dictionary 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
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.archive_v2_public_get_tickers(&[params.clone()]).await;
//
// {
// "BTC-PERP_USDT0": {
// "product_id": 2,
// "ticker_id": "BTC-PERP_USDT0",
// "base_currency": "BTC",
// "quote_currency": "USDT0",
// "last_price": 25728.0,
// "base_volume": 552.048,
// "quote_volume": 14238632.207250029,
// "price_change_percent_24h": -0.6348599635253989
// }
// }
//
let mut tickers: Value = self.to_array(response.clone());
return self.parse_tickers(tickers.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://docs.nado.xyz/developer-resources/api/v2/tickers
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut tickers: Value = self.fetch_tickers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
let mut ticker: Value = self.safe_dict(tickers.clone(), symbol.clone(), &[]);
if is_equal(&ticker, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&add(&self.id, &Value::Str(" fetchTicker() ticker not found for ".to_string())), &symbol)));
}
return self.safe_ticker(ticker.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchFundingRate
* @description fetch the current funding rate
* @see https://docs.nado.xyz/developer-resources/api/v2/contracts
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.edge] whether to retrieve volume and open interest metrics for all chains, defaults to true
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" fetchFundingRate() supports swap contracts only".to_string()))));
}
let mut tickerId: Value = self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("ticker_id".to_string()), &[]);
let mut response: Value = self.archive_v2_public_get_contracts(&[params.clone()]).await;
//
// {
// "BTC-PERP_USDT0": {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "base_currency": "BTC-PERP",
// "quote_currency": "USDT0",
// "last_price": 25744.0,
// "base_volume": 794.154,
// "quote_volume": 20475749.367766097,
// "product_type": "perpetual",
// "contract_price": 25830.738843799172,
// "contract_price_currency": "USD",
// "open_interest": 3059.325,
// "open_interest_usd": 79024625.11330591,
// "index_price": 25878.913320746455,
// "mark_price": 25783.996946729356,
// "funding_rate": -0.003664562348812546,
// "next_funding_rate_timestamp": 1694379600,
// "price_change_percent_24h": -0.6348599635253989
// }
// }
//
let mut data: Value = self.safe_dict(response.clone(), tickerId.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://docs.nado.xyz/developer-resources/api/archive-indexer/interest-and-funding-payments
* @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 {string} [params.subaccount] the 12-byte subaccount identifier, defaults to 'default'
* @returns {object[]} a list of [funding history structures]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
pub async fn fetch_funding_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingHistory() requires walletAddress".to_string()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" fetchFundingHistory() supports swap contracts only".to_string()))));
}
let mut subaccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingHistory".to_string()), Value::Str("subaccount".to_string()), &[Value::Str("default".to_string())]); subaccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("interest_and_funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subaccount".to_string(), self.create_subaccount(self.walletAddress.clone(), &[subaccount.clone()]));
m.insert("product_ids".to_string(), Value::List(vec![self.parse_to_int(get_value(&market, &Value::Str("id".to_string())))]));
m.insert("limit".to_string(), ternary(is_true(&(is_equal(&limit, &Value::Null))), Value::Int(100), crate::runtime::Math::min(&limit, &Value::Int(100))));
m
}));
m
});
let mut response: Value = self.archive_post(&[self.deep_extend(request.clone(), &[params.clone()])]).await;
//
// {
// "interest_payments": [],
// "funding_payments": [
// {
// "product_id": 2,
// "idx": "5968022",
// "timestamp": "1701698400",
// "amount": "-12273223338657163",
// "balance_amount": "1000000000000000000",
// "rate_x18": "47928279191008320",
// "oracle_price_x18": "2243215034242228224820"
// }
// ],
// "next_idx": "1314805"
// }
//
let mut fundingPayments: Value = self.safe_list_k(response.clone(), "funding_payments", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_975: bool = true;
while { if !__for_first_975 { i = add(&i, &Value::Int(1)); } __for_first_975 = false; is_less_than(&i, &get_array_length(&fundingPayments)) } {
append_to_array(&mut result, self.parse_funding_history(get_value(&fundingPayments, &i), &[market.clone()]));
}
}
let mut sorted: Value = self.sort_by(result.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchFundingRates
* @description fetch the funding rate for multiple markets
* @see https://docs.nado.xyz/developer-resources/api/v2/contracts
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.edge] whether to retrieve volume and open interest metrics for all chains, defaults to true
* @returns {object} a dictionary of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rates-structure}, indexed by market symbols
*/
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
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone(), Value::Str("swap".to_string()), Value::Bool(true)]);
let mut response: Value = self.archive_v2_public_get_contracts(&[params.clone()]).await;
//
// {
// "BTC-PERP_USDT0": {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "base_currency": "BTC-PERP",
// "quote_currency": "USDT0",
// "last_price": 25744.0,
// "base_volume": 794.154,
// "quote_volume": 20475749.367766097,
// "product_type": "perpetual",
// "contract_price": 25830.738843799172,
// "contract_price_currency": "USD",
// "open_interest": 3059.325,
// "open_interest_usd": 79024625.11330591,
// "index_price": 25878.913320746455,
// "mark_price": 25783.996946729356,
// "funding_rate": -0.003664562348812546,
// "next_funding_rate_timestamp": 1694379600,
// "price_change_percent_24h": -0.6348599635253989
// }
// }
//
let mut tickers: Value = object_keys(&response);
let mut rates: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_976: bool = true;
while { if !__for_first_976 { i = add(&i, &Value::Int(1)); } __for_first_976 = false; is_less_than(&i, &get_array_length(&tickers)) } {
let mut ticker: Value = get_value(&tickers, &i);
let mut ticker: Value = get_value(&tickers, &i);
append_to_array(&mut rates, self.safe_dict(response.clone(), ticker.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]));
}
}
return self.parse_funding_rates(rates.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchOpenInterest
* @description retrieves the open interest of a contract trading pair
* @see https://docs.nado.xyz/developer-resources/api/v2/contracts
* @param {string} symbol unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @param {boolean} [params.edge] whether to retrieve volume and open interest metrics for all chains, defaults to true
* @returns {object} an [open interest structure]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" fetchOpenInterest() supports swap contracts only".to_string()))));
}
let mut tickerId: Value = self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("ticker_id".to_string()), &[]);
let mut response: Value = self.archive_v2_public_get_contracts(&[params.clone()]).await;
//
// {
// "BTC-PERP_USDT0": {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "base_currency": "BTC-PERP",
// "quote_currency": "USDT0",
// "last_price": 25744.0,
// "base_volume": 794.154,
// "quote_volume": 20475749.367766097,
// "product_type": "perpetual",
// "contract_price": 25830.738843799172,
// "contract_price_currency": "USD",
// "open_interest": 3059.325,
// "open_interest_usd": 79024625.11330591,
// "index_price": 25878.913320746455,
// "mark_price": 25783.996946729356,
// "funding_rate": -0.003664562348812546,
// "next_funding_rate_timestamp": 1694379600,
// "price_change_percent_24h": -0.6348599635253989
// }
// }
//
let mut data: Value = self.safe_dict(response.clone(), tickerId.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_open_interest(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchOpenInterests
* @description retrieves the open interests of some currencies
* @see https://docs.nado.xyz/developer-resources/api/v2/contracts
* @param {string[]} [symbols] unified CCXT market symbols
* @param {object} [params] exchange specific parameters
* @param {boolean} [params.edge] whether to retrieve volume and open interest metrics for all chains, defaults to true
* @returns {object} a dictionary of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interests(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone(), Value::Str("swap".to_string()), Value::Bool(true)]);
let mut response: Value = self.archive_v2_public_get_contracts(&[params.clone()]).await;
//
// {
// "BTC-PERP_USDT0": {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "base_currency": "BTC-PERP",
// "quote_currency": "USDT0",
// "last_price": 25744.0,
// "base_volume": 794.154,
// "quote_volume": 20475749.367766097,
// "product_type": "perpetual",
// "contract_price": 25830.738843799172,
// "contract_price_currency": "USD",
// "open_interest": 3059.325,
// "open_interest_usd": 79024625.11330591,
// "index_price": 25878.913320746455,
// "mark_price": 25783.996946729356,
// "funding_rate": -0.003664562348812546,
// "next_funding_rate_timestamp": 1694379600,
// "price_change_percent_24h": -0.6348599635253989
// }
// }
//
let mut tickers: Value = object_keys(&response);
let mut interests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_977: bool = true;
while { if !__for_first_977 { i = add(&i, &Value::Int(1)); } __for_first_977 = false; is_less_than(&i, &get_array_length(&tickers)) } {
let mut ticker: Value = get_value(&tickers, &i);
let mut ticker: Value = get_value(&tickers, &i);
append_to_array(&mut interests, self.safe_dict(response.clone(), ticker.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]));
}
}
return self.parse_open_interests(interests.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.nado.xyz/developer-resources/api/v2/orderbook
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut tickerId: Value = self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("ticker_id".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ticker_id".to_string(), tickerId.clone());
m.insert("depth".to_string(), ternary(is_true(&(is_equal(&limit, &Value::Null))), Value::Int(100), limit.clone()));
m
});
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_v2_public_get_orderbook(&[__ws_arg_17]).await;
//
// {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "bids": [
// [ 116215.0, 0.128 ],
// [ 116214.0, 0.172 ]
// ],
// "asks": [
// [ 116225.0, 0.043 ],
// [ 116226.0, 0.172 ]
// ],
// "timestamp": 1757913317944
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "timestamp", &[]);
return self.parse_order_book(response.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchTrades
* @description get the list of the most recent trades for a particular symbol
* @see https://docs.nado.xyz/developer-resources/api/v2/trades
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.max_trade_id] max trade id to include in the result for pagination
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut tickerId: Value = self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("ticker_id".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ticker_id".to_string(), tickerId.clone());
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(500)));
}
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.archive_v2_public_get_trades(&[__ws_arg_18]).await;
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name nado#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://docs.nado.xyz/developer-resources/api/archive-indexer/candlesticks
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).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("candlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), self.parse_to_int(get_value(&market, &Value::Str("id".to_string()))));
m.insert("granularity".to_string(), self.safe_integer(self.timeframes.clone(), timeframe.clone(), &[self.parse_timeframe(timeframe.clone())]));
m
}));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("candlesticks".to_string())), &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&until, &Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("candlesticks".to_string())), &Value::Str("max_time".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
let mut response: Value = self.archive_post(&[self.deep_extend(request.clone(), &[params.clone()])]).await;
//
// {
// "candlesticks": [
// {
// "product_id": 1,
// "granularity": 60,
// "submission_idx": "627709",
// "timestamp": "1680118140",
// "open_x18": "27235000000000000000000",
// "high_x18": "27298000000000000000000",
// "low_x18": "27235000000000000000000",
// "close_x18": "27298000000000000000000",
// "volume": "1999999999999999998"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "candlesticks", &[Value::List(vec![])]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_timestamp(ohlcv.clone(), Value::Str("timestamp".to_string()), &[]), self.parse_x18(self.safe_string_k(ohlcv.clone(), "open_x18", &[])), self.parse_x18(self.safe_string_k(ohlcv.clone(), "high_x18", &[])), self.parse_x18(self.safe_string_k(ohlcv.clone(), "low_x18", &[])), self.parse_x18(self.safe_string_k(ohlcv.clone(), "close_x18", &[])), self.parse_x18(self.safe_string_k(ohlcv.clone(), "volume", &[]))]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "trade_id": 6351,
// "price": 112029.5896,
// "base_filled": -0.388,
// "quote_filled": 43467.4807648,
// "timestamp": 1757335618,
// "trade_type": "sell"
// }
//
// archive match
//
// {
// "submission_idx": "563012",
// "product_id": 2,
// "timestamp": "1679728133",
// "digest": "0x80ce789702b670b7d33f2aa67e12c85f124395c3f9acdb422dde3b4973ccd50c",
// "order": {
// "priceX18": "27544000000000000000000",
// "amount": "2000000000000000000"
// },
// "base_filled": "736000000000000000",
// "quote_filled": "-20276464287857571514302",
// "fee": "4055287857571514302",
// "is_taker": true
// }
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_timestamp(trade.clone(), Value::Str("timestamp".to_string()), &[]);
let mut rawOrder: Value = self.safe_dict_k(trade.clone(), "order", &[]);
let mut isArchiveMatch: bool = !is_equal(&rawOrder, &Value::Null);
let mut order: Value = ternary(is_true(&(is_equal(&rawOrder, &Value::Null))), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), rawOrder.clone());
let mut amountString: Value = self.safe_string_k(trade.clone(), "base_filled", &[]);
let mut costString: Value = self.safe_string_k(trade.clone(), "quote_filled", &[]);
let mut rawOrderAmount: Value = self.safe_string_k(order.clone(), "amount", &[]);
let mut side: Value = self.safe_string_k(trade.clone(), "trade_type", &[]);
if is_true(&(is_equal(&side, &Value::Null))) && is_true(&(!is_equal(&rawOrderAmount, &Value::Null))) {
if is_true(&crate::precise::Precise::stringLt(&rawOrderAmount, &Value::Str("0".to_string()))) {
side = Value::Str("sell".to_string());
} else {
side = Value::Str("buy".to_string());
}
}
let mut price: Value = self.safe_string_k(trade.clone(), "price", &[]);
if is_equal(&price, &Value::Null) {
let mut parsedPrice: Value = self.parse_x18(self.safe_string_k(order.clone(), "priceX18", &[]));
price = ternary(is_true(&(is_equal(&parsedPrice, &Value::Null))), Value::Null, self.number_to_string(parsedPrice.clone()));
}
let mut takerOrMaker: Value = Value::Null;
let mut isTaker: Value = self.safe_bool_k(trade.clone(), "is_taker", &[]);
if !is_equal(&isTaker, &Value::Null) {
if is_true(&isTaker) {
takerOrMaker = Value::Str("taker".to_string());
} else {
takerOrMaker = Value::Str("maker".to_string());
}
}
let mut feeString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
let mut feeCost: Value = Value::Null;
if is_true(&isArchiveMatch) {
feeCost = self.parse_x18(feeString.clone());
} else {
feeCost = self.parse_number(feeString.clone(), &[]);
}
let mut fee: Value = Value::Null;
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), get_value(&market, &Value::Str("quote".to_string())));
m
});
}
let mut parsedAmount: Value = Value::Null;
if !is_equal(&amountString, &Value::Null) {
let mut absoluteAmount: Value = crate::precise::Precise::stringAbs(&amountString);
if is_true(&isArchiveMatch) {
parsedAmount = self.parse_x18(absoluteAmount.clone());
} else {
parsedAmount = absoluteAmount.clone();
}
}
let mut parsedCost: Value = Value::Null;
if !is_equal(&costString, &Value::Null) {
let mut absoluteCost: Value = crate::precise::Precise::stringAbs(&costString);
if is_true(&isArchiveMatch) {
parsedCost = self.parse_x18(absoluteCost.clone());
} else {
parsedCost = absoluteCost.clone();
}
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("trade_id".to_string()), Value::Str("submission_idx".to_string()), &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "digest", &[]));
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(), price.clone());
m.insert("amount".to_string(), parsedAmount.clone());
m.insert("cost".to_string(), parsedCost.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.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);
//
// {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "base_currency": "BTC-PERP",
// "quote_currency": "USDT0",
// "last_price": 25744.0,
// "base_volume": 794.154,
// "quote_volume": 20475749.367766097,
// "product_type": "perpetual",
// "contract_price": 25830.738843799172,
// "contract_price_currency": "USD",
// "open_interest": 3059.325,
// "open_interest_usd": 79024625.11330591,
// "index_price": 25878.913320746455,
// "mark_price": 25783.996946729356,
// "funding_rate": -0.003664562348812546,
// "next_funding_rate_timestamp": 1694379600,
// "price_change_percent_24h": -0.6348599635253989
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut fundingTimestamp: Value = self.safe_timestamp(contract.clone(), Value::Str("next_funding_rate_timestamp".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("markPrice".to_string(), self.safe_number_k(contract.clone(), "mark_price", &[]));
m.insert("indexPrice".to_string(), self.safe_number_k(contract.clone(), "index_price", &[]));
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "funding_rate", &[]));
m.insert("fundingTimestamp".to_string(), fundingTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTimestamp.clone()));
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), Value::Null);
m.insert("nextFundingDatetime".to_string(), Value::Null);
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), Value::Str("24h".to_string()));
m
});
Value::Null
}
pub fn parse_funding_history(&self, mut funding: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "product_id": 2,
// "idx": "5968022",
// "timestamp": "1701698400",
// "amount": "-12273223338657163",
// "balance_amount": "1000000000000000000",
// "rate_x18": "47928279191008320",
// "oracle_price_x18": "2243215034242228224820"
// }
//
let mut marketId: Value = self.safe_string_k(funding.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_timestamp(funding.clone(), Value::Str("timestamp".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), funding.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("code".to_string(), self.safe_string_k(market.clone(), "settle", &[]));
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(funding.clone(), "idx", &[]));
m.insert("amount".to_string(), self.parse_x18(self.safe_string_k(funding.clone(), "amount", &[])));
m
});
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "product_id": 1,
// "ticker_id": "BTC-PERP_USDT0",
// "base_currency": "BTC-PERP",
// "quote_currency": "USDT0",
// "last_price": 25744.0,
// "base_volume": 794.154,
// "quote_volume": 20475749.367766097,
// "product_type": "perpetual",
// "contract_price": 25830.738843799172,
// "contract_price_currency": "USD",
// "open_interest": 3059.325,
// "open_interest_usd": 79024625.11330591,
// "index_price": 25878.913320746455,
// "mark_price": 25783.996946729356,
// "funding_rate": -0.003664562348812546,
// "next_funding_rate_timestamp": 1694379600,
// "price_change_percent_24h": -0.6348599635253989
// }
//
let mut marketId: Value = self.safe_string_k(interest.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("openInterestAmount".to_string(), self.safe_number_k(interest.clone(), "open_interest", &[]));
m.insert("openInterestValue".to_string(), self.safe_number_k(interest.clone(), "open_interest_usd", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = Value::Null;
let mut last: Value = self.safe_string_k(ticker.clone(), "last_price", &[]);
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(), Value::Null);
m.insert("low".to_string(), Value::Null);
m.insert("bid".to_string(), Value::Null);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), Value::Null);
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
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(), self.safe_string_k(ticker.clone(), "price_change_percent_24h", &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "base_volume", &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "quote_volume", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut canDeposit: Value = self.safe_bool_k(rawCurrency.clone(), "can_deposit", &[Value::Bool(false)]);
let mut canWithdraw: Value = self.safe_bool_k(rawCurrency.clone(), "can_withdraw", &[Value::Bool(false)]);
let mut id: Value = self.safe_string_k(rawCurrency.clone(), "product_id", &[]);
let mut currencyId: Value = self.safe_string_k(rawCurrency.clone(), "symbol", &[]);
let mut code: Value = self.safe_currency_code(self.remove_market_suffix(currencyId.clone()), &[]);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("name".to_string(), self.safe_string_k(rawCurrency.clone(), "name", &[]));
m.insert("code".to_string(), code.clone());
m.insert("precision".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("deposit".to_string(), canDeposit.clone());
m.insert("withdraw".to_string(), canWithdraw.clone());
m.insert("type".to_string(), Value::Str("crypto".to_string()));
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
}));
m.insert("info".to_string(), rawCurrency.clone());
m
}));
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
//
// {
// "subaccount": "0x8d7d64d6cf1d4f018dd101482ac71ad49e30c56064656661756c740000000000",
// "exists": true,
// "spot_balances": [
// {
// "product_id": 0,
// "balance": {
// "amount": "456895621098158389211471"
// }
// }
// ],
// "perp_balances": []
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut balances: Value = self.safe_list_k(response.clone(), "spot_balances", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_978: bool = true;
while { if !__for_first_978 { i = add(&i, &Value::Int(1)); } __for_first_978 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut rawBalance: Value = get_value(&balances, &i);
let mut rawBalance: Value = get_value(&balances, &i);
let mut currencyId: Value = self.safe_string_k(rawBalance.clone(), "product_id", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
if is_equal(&code, &Value::Str("0".to_string())) {
code = Value::Str("USDT0".to_string());
} else if is_equal(&code, ¤cyId) {
let mut market: Value = self.safe_market(&[currencyId.clone(), Value::Null, Value::Null, Value::Str("spot".to_string())]);
if is_equal(&self.safe_bool_k(market.clone(), "spot", &[]), &Value::Bool(true)) {
code = self.safe_string_k(market.clone(), "base", &[code.clone()]);
}
}
let mut balance: Value = self.safe_dict_k(rawBalance.clone(), "balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amount: Value = crate::precise::Precise::stringDiv(&self.safe_string_k(balance.clone(), "amount", &[]), &Value::Str("1000000000000000000".to_string()));
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), amount.clone());
// the subaccount balance carries no locked/reserved breakdown, the whole amount is spendable
add_element_to_object(&mut account, &Value::Str("free".to_string()), amount.clone());
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.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);
//
// {
// "submission_idx": "563011",
// "timestamp": "1679728127",
// "subaccount": "0x...",
// "product_id": 5,
// "event_type": "deposit_collateral",
// "transaction_type": "deposit",
// "pre_balance": {
// "spot": {
// "balance": {
// "amount": "1000000000000000000"
// }
// }
// },
// "post_balance": {
// "spot": {
// "balance": {
// "amount": "2000000000000000000"
// }
// }
// }
// }
//
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "product_id", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_timestamp(transaction.clone(), Value::Str("timestamp".to_string()), &[]);
let mut preBalance: Value = self.safe_dict_k(transaction.clone(), "pre_balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut postBalance: Value = self.safe_dict_k(transaction.clone(), "post_balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut preSpot: Value = self.safe_dict_k(preBalance.clone(), "spot", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut postSpot: Value = self.safe_dict_k(postBalance.clone(), "spot", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut preSpotBalance: Value = self.safe_dict_k(preSpot.clone(), "balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut postSpotBalance: Value = self.safe_dict_k(postSpot.clone(), "balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut preAmount: Value = self.safe_string_k(preSpotBalance.clone(), "amount", &[Value::Str("0".to_string())]);
let mut postAmount: Value = self.safe_string_k(postSpotBalance.clone(), "amount", &[Value::Str("0".to_string())]);
let mut amount: Value = self.parse_x18(crate::precise::Precise::stringAbs(&crate::precise::Precise::stringSub(&postAmount, &preAmount)));
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(), "submission_idx", &[]));
m.insert("txid".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("address".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("addressTo".to_string(), Value::Null);
m.insert("tag".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("type".to_string(), self.safe_string_k(transaction.clone(), "transaction_type", &[]));
m.insert("amount".to_string(), amount.clone());
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), Value::Str("ok".to_string()));
m.insert("updated".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("network".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "product_id": 2,
// "balance": {
// "amount": "100000000000000000",
// "v_quote_balance": "3033500000000000000000",
// "last_cumulative_funding_x18": "-394223711772447555304"
// },
// "product": {
// "product_id": 2,
// "oracle_price_x18": "115596528090565357611177",
// "risk": {
// "price_x18": "115596528090565357611177"
// }
// }
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut balance: Value = self.safe_dict_k(position.clone(), "balance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amountString: Value = self.safe_string_k(balance.clone(), "amount", &[]);
let mut product: Value = self.safe_dict_k(position.clone(), "product", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut risk: Value = self.safe_dict_k(product.clone(), "risk", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut markPriceX18: Value = self.safe_string2(risk.clone(), Value::Str("price_x18".to_string()), Value::Str("oracle_price_x18".to_string()), &[]);
let mut vQuoteBalance: Value = self.safe_string_k(balance.clone(), "v_quote_balance", &[]);
let mut side: Value = Value::Null;
let mut contracts: Value = Value::Null;
let mut entryPrice: Value = Value::Null;
let mut markPrice: Value = Value::Null;
let mut notional: Value = Value::Null;
if !is_equal(&amountString, &Value::Null) {
if is_true(&crate::precise::Precise::stringGt(&amountString, &Value::Str("0".to_string()))) {
side = Value::Str("long".to_string());
} else if is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".to_string()))) {
side = Value::Str("short".to_string());
}
let mut absoluteAmount: Value = crate::precise::Precise::stringAbs(&amountString);
contracts = self.parse_x18(absoluteAmount.clone());
if is_true(&(!is_equal(&vQuoteBalance, &Value::Null))) && !is_true(&crate::precise::Precise::stringEquals(&absoluteAmount, &Value::Str("0".to_string()))) {
entryPrice = self.parse_number(crate::precise::Precise::stringDiv(&crate::precise::Precise::stringAbs(&vQuoteBalance), &absoluteAmount), &[]);
}
if !is_equal(&markPriceX18, &Value::Null) {
markPrice = self.parse_x18(markPriceX18.clone());
let mut notionalX36: Value = crate::precise::Precise::stringMul(&absoluteAmount, &markPriceX18);
notional = self.parse_number(crate::precise::Precise::stringDiv(¬ionalX36, &Value::Str("1000000000000000000000000000000000000".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(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("isolated".to_string(), Value::Null);
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("side".to_string(), side.clone());
m.insert("contracts".to_string(), contracts.clone());
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("entryPrice".to_string(), entryPrice.clone());
m.insert("markPrice".to_string(), markPrice.clone());
m.insert("notional".to_string(), notional.clone());
m.insert("leverage".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn is_archive_order_closed(&self, mut order: Value) -> Value {
let mut amount: Value = self.safe_string_k(order.clone(), "amount", &[]);
let mut filled: Value = self.safe_string_k(order.clone(), "base_filled", &[]);
if is_true(&(is_equal(&amount, &Value::Null))) || is_true(&(is_equal(&filled, &Value::Null))) {
return Value::Bool(false);
}
return crate::precise::Precise::stringGe(&crate::precise::Precise::stringAbs(&filled), &crate::precise::Precise::stringAbs(&amount));
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// create order
//
// {
// "status": "success",
// "signature": "0x...",
// "data": {
// "digest": "0x..."
// },
// "request_type": "execute_place_order",
// "id": 100,
// "place_order": {
// "product_id": 2,
// "order": {
// "sender": "0x...",
// "priceX18": "1000000000000000000",
// "amount": "1000000000000000000",
// "expiration": "4294967295",
// "nonce": "1757062078359666688",
// "appendix": "1"
// },
// "signature": "0x..."
// }
// }
//
// open/cancel order
//
// {
// "product_id": 2,
// "sender": "0x...",
// "price_x18": "20000000000000000000000",
// "amount": "-100000000000000000",
// "expiration": "1686332748",
// "order_type": "post_only",
// "nonce": "1768248100142339392",
// "unfilled_amount": "-100000000000000000",
// "digest": "0x...",
// "appendix": "1537",
// "placed_at": 1686332708
// }
//
// trigger order
//
// {
// order: {
// order: {
// sender: '',
// priceX18: '100000000000000000000',
// amount: '-1000000000000000000',
// expiration: '4294967295',
// nonce: '',
// appendix: '4097'
// },
// signature: '',
// product_id: '8',
// spot_leverage: null,
// borrow_margin: null,
// trigger: { price_trigger: [Object] },
// digest: '',
// id: null
// },
// status: 'waiting_price',
// placed_at: '1783347360',
// updated_at: '1783347360'
// }
//
let mut id: Value = Value::Null;
let mut timestamp: Value = Value::Null;
let mut timeInForce: Value = Value::Null;
let mut postOnly: Value = Value::Null;
let mut side: Value = Value::Null;
let mut price: Value = Value::Null;
let mut amount: Value = Value::Null;
let mut filled: Value = Value::Null;
let mut remaining: Value = Value::Null;
let mut cost: Value = Value::Null;
let mut average: Value = Value::Null;
let mut fee: Value = Value::Null;
let mut lastTradeTimestamp: Value = Value::Null;
let mut lastUpdateTimestamp: Value = Value::Null;
let mut status: Value = Value::Null;
let mut cancelOrderDigest: Value = self.safe_string_k(order.clone(), "digest", &[]);
let mut archiveFilled: Value = self.safe_string_k(order.clone(), "base_filled", &[]);
if !is_equal(&archiveFilled, &Value::Null) {
id = cancelOrderDigest.clone();
let mut marketId: Value = self.safe_string_k(order.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut amountString: Value = self.safe_string_k(order.clone(), "amount", &[]);
if !is_equal(&amountString, &Value::Null) {
side = ternary(is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".to_string()))), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
amount = self.parse_x18(crate::precise::Precise::stringAbs(&amountString));
}
filled = self.parse_x18(crate::precise::Precise::stringAbs(&archiveFilled));
let mut costString: Value = self.safe_string_k(order.clone(), "quote_filled", &[]);
cost = ternary(is_true(&(is_equal(&costString, &Value::Null))), Value::Null, self.parse_x18(crate::precise::Precise::stringAbs(&costString)));
if is_true(&(!is_equal(&filled, &Value::Null))) && is_true(&(!is_equal(&cost, &Value::Null))) {
average = crate::precise::Precise::stringDiv(&self.number_to_string(cost.clone()), &self.number_to_string(filled.clone()));
}
if is_true(&(!is_equal(&amountString, &Value::Null))) && is_true(&(!is_equal(&archiveFilled, &Value::Null))) {
remaining = self.parse_x18(crate::precise::Precise::stringMax(&crate::precise::Precise::stringSub(&crate::precise::Precise::stringAbs(&amountString), &crate::precise::Precise::stringAbs(&archiveFilled)), &Value::Str("0".to_string())));
}
timestamp = self.safe_timestamp(order.clone(), Value::Str("first_fill_timestamp".to_string()), &[]);
lastTradeTimestamp = self.safe_timestamp(order.clone(), Value::Str("last_fill_timestamp".to_string()), &[]);
price = self.parse_x18(self.safe_string_k(order.clone(), "price_x18", &[]));
status = self.safe_string_k(order.clone(), "status", &[]);
if is_equal(&status, &Value::Null) {
if is_true(&self.is_archive_order_closed(order.clone())) {
status = Value::Str("closed".to_string());
}
}
let mut feeCost: Value = self.parse_x18(self.safe_string_k(order.clone(), "fee", &[]));
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), get_value(&market, &Value::Str("quote".to_string())));
m
});
}
} else if !is_equal(&cancelOrderDigest, &Value::Null) {
id = cancelOrderDigest.clone();
let mut marketId: Value = self.safe_string_k(order.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut amountString: Value = self.safe_string_k(order.clone(), "amount", &[]);
if !is_equal(&amountString, &Value::Null) {
side = ternary(is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".to_string()))), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
amount = self.parse_x18(crate::precise::Precise::stringAbs(&amountString));
}
let mut unfilledAmount: Value = self.safe_string_k(order.clone(), "unfilled_amount", &[]);
if !is_equal(&unfilledAmount, &Value::Null) {
remaining = self.parse_x18(crate::precise::Precise::stringAbs(&unfilledAmount));
}
timestamp = self.safe_timestamp(order.clone(), Value::Str("placed_at".to_string()), &[]);
let mut orderType: Value = self.safe_string_k(order.clone(), "order_type", &[]);
timeInForce = self.parse_order_time_in_force(orderType.clone());
postOnly = Value::Bool(is_equal(&orderType, &Value::Str("post_only".to_string())));
price = self.parse_x18(self.safe_string_k(order.clone(), "price_x18", &[]));
status = self.safe_string_k(order.clone(), "status", &[Value::Str("open".to_string())]);
} else {
let mut placeOrder: Value = self.safe_dict2(order.clone(), Value::Str("place_order".to_string()), Value::Str("order".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rawOrder: Value = self.safe_dict_k(placeOrder.clone(), "order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(placeOrder.clone(), "product_id", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut data: Value = self.safe_dict_k(order.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
id = self.safe_string_k(data.clone(), "digest", &[]);
if is_equal(&id, &Value::Null) {
id = self.safe_string_k(placeOrder.clone(), "digest", &[]);
timestamp = self.safe_timestamp(order.clone(), Value::Str("placed_at".to_string()), &[]);
lastUpdateTimestamp = self.safe_timestamp(order.clone(), Value::Str("updated_at".to_string()), &[]);
}
let mut amountString: Value = self.safe_string_k(rawOrder.clone(), "amount", &[]);
if !is_equal(&amountString, &Value::Null) {
side = ternary(is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".to_string()))), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
amount = self.parse_x18(crate::precise::Precise::stringAbs(&amountString));
}
let mut triggerStatus: Value = self.safe_dict_k(order.clone(), "status", &[]);
if !is_equal(&triggerStatus, &Value::Null) {
let mut triggered: Value = self.safe_dict_k(triggerStatus.clone(), "triggered", &[]);
if !is_equal(&triggered, &Value::Null) {
status = Value::Str("closed".to_string());
} else {
status = Value::Str("canceled".to_string());
}
} else {
status = self.safe_string_k(order.clone(), "status", &[Value::Str("rejected".to_string())]);
if is_true(&(is_equal(&status, &Value::Str("success".to_string())))) || is_true(&(is_greater_than_or_equal(&get_index_of(&status, &Value::Str("waiting".to_string())), &Value::Int(0)))) {
status = Value::Str("open".to_string());
}
}
price = self.parse_x18(self.safe_string_k(rawOrder.clone(), "priceX18", &[]));
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), lastTradeTimestamp.clone());
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), Value::Str("limit".to_string()));
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("stopPrice".to_string(), Value::Null);
m.insert("triggerPrice".to_string(), Value::Null);
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("average".to_string(), average.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), remaining.clone());
m.insert("status".to_string(), status.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_order_time_in_force(&self, mut timeInForce: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Str("GTC".to_string()));
m.insert("ioc".to_string(), Value::Str("IOC".to_string()));
m.insert("fok".to_string(), Value::Str("FOK".to_string()));
m.insert("post_only".to_string(), Value::Str("PO".to_string()));
m
});
return self.safe_string(timeInForces.clone(), timeInForce.clone(), &[timeInForce.clone()]);
Value::Null
}
pub fn convert_to_x18(&self, mut value: Value) -> Value {
if is_equal(&value, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" convertToX18() requires a value".to_string()))));
}
return crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringMul(&value, &Value::Str("1000000000000000000".to_string())), &Value::Str("1".to_string()), &Value::Int(0));
Value::Null
}
pub fn parse_x18(&self, mut value: Value) -> Value {
if is_equal(&value, &Value::Null) {
return Value::Null;
}
return self.parse_number(crate::precise::Precise::stringDiv(&value, &Value::Str("1000000000000000000".to_string())), &[]);
Value::Null
}
pub fn create_order_nonce(&self, mut recvWindow: Value) -> Value {
let mut expires: Value = self.sum(&[self.milliseconds(), recvWindow.clone()]);
return crate::precise::Precise::stringMul(&self.number_to_string(expires.clone()), &Value::Str("1048576".to_string()));
Value::Null
}
pub fn create_order_appendix(&self, mut isTriggerOrder: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// | value | builder | builder fee rate | reserved | trigger | reduce only | order type | isolated | version |
// | 64 bits | 16 bits | 10 bits | 24 bits | 2 bits | 1 bit | 2 bits | 1 bit | 8 bits |
// | 127..64 | 63..48 | 47..38 | 37..14 | 13..12 | 11 | 10..9 | 8 | 7..0 |
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut postOnly: Value = self.is_post_only(Value::Bool(false), Value::Null, &[params.clone()]);
let mut timeInForce: Value = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[]);
let mut orderType: Value = Value::Int(0);
if is_equal(&timeInForce, &Value::Str("IOC".to_string())) {
orderType = Value::Int(1);
} else if is_equal(&timeInForce, &Value::Str("FOK".to_string())) {
orderType = Value::Int(2);
} else if is_true(&postOnly) || is_true(&(is_equal(&timeInForce, &Value::Str("PO".to_string())))) {
orderType = Value::Int(3);
} else if is_true(&(!is_equal(&timeInForce, &Value::Null))) && is_true(&(!is_equal(&timeInForce, &Value::Str("GTC".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() only supports timeInForce values GTC, IOC, FOK, or PO".to_string()))));
}
let mut appendix: Value = Value::Str("1".to_string()); // version
if !is_equal(&orderType, &Value::Int(0)) {
appendix = crate::precise::Precise::stringAdd(&appendix, &crate::precise::Precise::stringMul(&self.number_to_string(orderType.clone()), &Value::Str("512".to_string())));
}
if is_equal(&reduceOnly, &Value::Bool(true)) {
appendix = crate::precise::Precise::stringAdd(&appendix, &Value::Str("2048".to_string()));
}
let mut buildFee: Value = self.safe_bool_k(self.options.clone(), "builderFee", &[Value::Bool(true)]);
if is_equal(&buildFee, &Value::Bool(true)) {
let mut builder: Value = self.safe_string_k(self.options.clone(), "builder", &[Value::Str("4500".to_string())]);
let mut builderFeeRate: Value = self.safe_string_k(self.options.clone(), "feeRate", &[Value::Str("10".to_string())]); // 10 units = 0.01%
appendix = crate::precise::Precise::stringAdd(&appendix, &crate::precise::Precise::stringMul(&builder, &Value::Str("281474976710656".to_string()))); // 1<<48
appendix = crate::precise::Precise::stringAdd(&appendix, &crate::precise::Precise::stringMul(&builderFeeRate, &Value::Str("274877906944".to_string()))); // 1<<32
}
if is_equal(&isTriggerOrder, &Value::Bool(true)) {
appendix = crate::precise::Precise::stringAdd(&appendix, &Value::Str("4096".to_string()));
}
return appendix;
Value::Null
}
pub fn create_subaccount(&self, mut walletAddress: Value, optional_args: &[Value]) -> Value {
let mut subaccount = get_arg(optional_args, 0, Value::Str("default".to_string()));
if is_equal(&walletAddress, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createSubaccount() requires walletAddress".to_string()))));
}
if is_equal(&subaccount, &Value::Null) {
subaccount = Value::Str("default".to_string());
}
let mut address: Value = to_lower(&self.remove0x_prefix(walletAddress.clone()));
if !is_equal(&get_array_length(&address), &Value::Int(40)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() requires a 20-byte walletAddress".to_string()))));
}
let mut encoded: Value = self.remove0x_prefix(self.string_to_base16(subaccount.clone()));
if is_greater_than(&get_array_length(&encoded), &Value::Int(24)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() subaccount must fit in 12 bytes".to_string()))));
}
return add(&add(&Value::Str("0x".to_string()), &address), &self.pad_hex(encoded.clone(), Value::Int(24), &[Value::Bool(false)]));
Value::Null
}
pub async fn query_contracts(&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 cachedContracts: Value = self.safe_dict_k(self.options.clone(), "gatewayContracts", &[]);
if !is_equal(&cachedContracts, &Value::Null) {
return cachedContracts;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("contracts".to_string()));
m
});
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.gateway_public_get_query(&[__ws_arg_19]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
add_element_to_object(&mut self.options, &Value::Str("gatewayContracts".to_string()), data.clone());
return data;
Value::Null
}
pub fn order_verifying_contract(&self, mut productId: Value) -> Value {
return add(&Value::Str("0x".to_string()), &self.pad_hex(self.int_to_base16(productId.clone(), &[]), Value::Int(40), &[]));
Value::Null
}
pub fn pad_hex(&self, mut value: Value, mut length: Value, optional_args: &[Value]) -> Value {
let mut left = get_arg(optional_args, 0, Value::Bool(true));
if is_equal(&length, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" padHex() requires length".to_string()))));
}
let mut zeros: Value = Value::Str("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000".to_string());
let mut padded: Value = ternary(is_true(&left), (add(&zeros, &value)), (add(&value, &zeros)));
if is_true(&left) {
let mut start: Value = subtract(&get_array_length(&padded), &length);
return slice(&padded, &start, &get_array_length(&padded));
}
return slice(&padded, &Value::Int(0), &length);
Value::Null
}
pub fn sign_order(&self, mut order: Value, mut productId: Value, mut chainId: Value) -> Value {
let mut domain: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("Nado".to_string()));
m.insert("version".to_string(), Value::Str("0.0.1".to_string()));
m.insert("chainId".to_string(), chainId.clone());
m.insert("verifyingContract".to_string(), self.order_verifying_contract(productId.clone()));
m
});
let mut messageTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Order".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("sender".to_string()));
m.insert("type".to_string(), Value::Str("bytes32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("priceX18".to_string()));
m.insert("type".to_string(), Value::Str("int128".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("int128".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("expiration".to_string()));
m.insert("type".to_string(), Value::Str("uint64".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("uint64".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("appendix".to_string()));
m.insert("type".to_string(), Value::Str("uint128".to_string()));
m
})]));
m
});
let mut encoded: Value = self.eth_encode_structured_data(domain.clone(), messageTypes.clone(), order.clone());
let mut hash: Value = add(&Value::Str("0x".to_string()), &self.hash(encoded.clone(), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
return self.sign_hash(hash.clone(), self.privateKey.clone());
Value::Null
}
pub fn sign_cancellation(&self, mut cancellation: Value, mut chainId: Value, mut endpointAddress: Value) -> Value {
let mut domain: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("Nado".to_string()));
m.insert("version".to_string(), Value::Str("0.0.1".to_string()));
m.insert("chainId".to_string(), chainId.clone());
m.insert("verifyingContract".to_string(), endpointAddress.clone());
m
});
let mut messageTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Cancellation".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("sender".to_string()));
m.insert("type".to_string(), Value::Str("bytes32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("productIds".to_string()));
m.insert("type".to_string(), Value::Str("uint32[]".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("digests".to_string()));
m.insert("type".to_string(), Value::Str("bytes32[]".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("uint64".to_string()));
m
})]));
m
});
let mut encoded: Value = self.eth_encode_structured_data(domain.clone(), messageTypes.clone(), cancellation.clone());
let mut hash: Value = add(&Value::Str("0x".to_string()), &self.hash(encoded.clone(), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
return self.sign_hash(hash.clone(), self.privateKey.clone());
Value::Null
}
pub fn sign_cancellation_products(&self, mut cancellation: Value, mut chainId: Value, mut endpointAddress: Value) -> Value {
let mut domain: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("Nado".to_string()));
m.insert("version".to_string(), Value::Str("0.0.1".to_string()));
m.insert("chainId".to_string(), chainId.clone());
m.insert("verifyingContract".to_string(), endpointAddress.clone());
m
});
let mut messageTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CancellationProducts".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("sender".to_string()));
m.insert("type".to_string(), Value::Str("bytes32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("productIds".to_string()));
m.insert("type".to_string(), Value::Str("uint32[]".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("uint64".to_string()));
m
})]));
m
});
let mut encoded: Value = self.eth_encode_structured_data(domain.clone(), messageTypes.clone(), cancellation.clone());
let mut hash: Value = add(&Value::Str("0x".to_string()), &self.hash(encoded.clone(), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
return self.sign_hash(hash.clone(), self.privateKey.clone());
Value::Null
}
pub fn sign_fetch_trigger_orders(&self, mut tx: Value, mut chainId: Value, mut endpointAddress: Value) -> Value {
let mut domain: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("Nado".to_string()));
m.insert("version".to_string(), Value::Str("0.0.1".to_string()));
m.insert("chainId".to_string(), chainId.clone());
m.insert("verifyingContract".to_string(), endpointAddress.clone());
m
});
let mut messageTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ListTriggerOrders".to_string(), Value::List(vec![Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("sender".to_string()));
m.insert("type".to_string(), Value::Str("bytes32".to_string()));
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("name".to_string(), Value::Str("recvTime".to_string()));
m.insert("type".to_string(), Value::Str("uint64".to_string()));
m
})]));
m
});
let mut encoded: Value = self.eth_encode_structured_data(domain.clone(), messageTypes.clone(), tx.clone());
let mut hash: Value = add(&Value::Str("0x".to_string()), &self.hash(encoded.clone(), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
return self.sign_hash(hash.clone(), self.privateKey.clone());
Value::Null
}
pub fn sign_hash(&self, mut hash: Value, mut privateKey: Value) -> Value {
if is_equal(&privateKey, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" signHash() requires privateKey".to_string()))));
}
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 = to_lower(&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()), &self.pad_hex(r.clone(), Value::Int(64), &[])), &self.pad_hex(s.clone(), Value::Int(64), &[])), &v);
Value::Null
}
pub fn remove_market_suffix(&self, mut marketId: Value) -> Value {
if is_equal(&marketId, &Value::Null) {
return Value::Null;
}
if is_true(&Value::Bool(ends_with(&marketId, &Value::Str("-PERP".to_string())))) {
return slice(&marketId, &Value::Int(0), &negate(&Value::Int(5)));
}
return marketId;
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::List(vec![]));
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 endpoint: Value = get_value(&api, &Value::Int(0));
if is_string(&api) {
endpoint = api.clone();
}
let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &endpoint);
if !is_equal(&path, &Value::Str("".to_string())) {
url = add(&url, &add(&Value::Str("/".to_string()), &self.implode_params(path.clone(), params.clone())));
}
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_true(&(is_equal(&endpoint, &Value::Str("gateway".to_string())))) || is_true(&(is_equal(&endpoint, &Value::Str("archive".to_string())))) {
add_element_to_object(&mut headers, &Value::Str("Accept-Encoding".to_string()), Value::Str("gzip, br, deflate".to_string()));
}
if is_equal(&method, &Value::Str("GET".to_string())) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
} else {
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
body = self.json(query.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 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_true(&(is_equal(&response, &Value::Null))) || is_true(&(is_equal(&response, &Value::Null))) {
return Value::Null;
}
//
// {
// "status": "failure",
// "signature": "0x...",
// "error_code": 2007,
// "error": "Order price must be within a range of 80% to 120% of oracle price.",
// "request_type": "execute_place_order"
// }
//
let mut status: Value = self.safe_string_k(response.clone(), "status", &[]);
let mut errorCode: Value = self.safe_string_k(response.clone(), "error_code", &[]);
let mut error: Value = self.safe_string_k(response.clone(), "error", &[]);
if is_true(&(is_equal(&status, &Value::Str("failure".to_string())))) || is_true(&(!is_equal(&errorCode, &Value::Null))) || is_true(&(!is_equal(&error, &Value::Null))) {
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())), errorCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), error.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}