// 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 DeriveCore {
pub exchange: crate::exchange::Exchange,
}
impl DeriveCore {
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 = DeriveCore::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 DeriveCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_market(self, market)
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::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 DeriveCore.
DeriveCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_currency(self, currency)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::parse_income(self, info, &[market.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on DeriveCore.
DeriveCore::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 DeriveCore.
DeriveCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for DeriveCore {
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_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"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,
"fetch_balance" => self.fetch_balance(&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_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option_markets" => self.fetch_option_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_swap_markets" => self.fetch_swap_markets(&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_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_derive_subaccount_id" => self.handle_derive_subaccount_id(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_derive_wallet_address" => self.handle_derive_wallet_address(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"hash_message" => self.hash_message(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"hash_order_message" => self.hash_order_message(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_income" => self.parse_income(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_time_in_force" => self.parse_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trades" => self.parse_trades(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_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_units" => self.parse_units(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"sign_hash" => self.sign_hash(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"sign_message" => self.sign_message(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)),
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for DeriveCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for DeriveCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl DeriveCore {
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("derive".to_string()));
m.insert("name".to_string(), Value::Str("Derive".to_string()));
m.insert("countries".to_string(), Value::List(vec![]));
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("rateLimit".to_string(), Value::Int(50));
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(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(true));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("cancelOrdersForSymbols".to_string(), Value::Bool(false));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(false));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Null);
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(false));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(false));
m.insert("fetchOrderBook".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(false));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(false));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("3m".to_string(), Value::Str("3m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("8h".to_string(), Value::Str("8h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("3d".to_string(), Value::Str("3d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/9e640700-c870-41f9-8907-fba58e120fed".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.lyra.finance/public".to_string()));
m.insert("private".to_string(), Value::Str("https://api.lyra.finance/private".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api-demo.lyra.finance/public".to_string()));
m.insert("private".to_string(), Value::Str("https://api-demo.lyra.finance/private".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.derive.xyz/".to_string()));
m.insert("doc".to_string(), Value::Str("https://docs.derive.xyz/docs/".to_string()));
m.insert("fees".to_string(), Value::Str("https://docs.derive.xyz/reference/fees-1/".to_string()));
m.insert("referral".to_string(), Value::Str("https://www.derive.xyz/invite/3VB0B".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get_all_currencies".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("build_register_session_key_tx".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("register_session_key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deregister_session_key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("login".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("statistics".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_all_currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_instrument".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_all_instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_latest_signed_feeds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_option_settlement_prices".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_spot_feed_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_spot_feed_history_candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_funding_rate_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_option_settlement_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_liquidation_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_interest_rate_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_transaction".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin_watch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("validate_invite_code".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_points".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_all_points".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_points_leaderboard".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_descendant_tree".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_tree_roots".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_swell_percent_points".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_vault_assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_etherfi_effective_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_kelp_effective_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_bridge_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_ethena_participants".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_vault_share".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_vault_statistics".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_vault_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("estimate_integrator_points".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("create_subaccount_debug".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposit_debug".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdraw_debug".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("send_quote_debug".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("execute_quote_debug".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_invite_code".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("register_invite".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_live_incidents".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_maker_programs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_maker_program_scores".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("get_account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("create_subaccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_subaccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_subaccounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_all_portfolios".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("change_subaccount_label".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_notificationsv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("update_notifications".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfer_erc20".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfer_position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfer_positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("replace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order_debug".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_open_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_by_label".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_by_nonce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_by_instrument".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_trigger_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_order_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_deposit_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_withdrawal_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("send_rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_batch_rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("poll_rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("send_quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cancel_batch_quotes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_quotes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("poll_quotes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("execute_quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("rfq_get_best_quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_collaterals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_option_settlement_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_subaccount_value_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("expired_and_cancelled_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_funding_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_interest_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_erc20_transfer_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_liquidation_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("liquidate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_liquidator_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("session_keys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("edit_session_key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("register_scoped_session_key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_mmp_config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("set_mmp_config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("reset_mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("set_cancel_on_disconnect".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("get_invite_code".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("register_invite".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("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("-32000".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-32100".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("-32700".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-32600".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-32601".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-32602".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-32603".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("9000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10009".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10011".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("10012".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("10013".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("10014".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("11000".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("11002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11006".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("11007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11012".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11013".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11015".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11018".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11019".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11020".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("11021".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11022".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11023".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11024".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11025".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11026".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("11027".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11028".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11050".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11051".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11052".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11053".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11054".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11055".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11100".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11101".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11102".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11103".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11104".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11105".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11106".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11107".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11200".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11201".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11202".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("11203".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("12000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("12001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("12002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("12003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("13000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("14002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14009".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14010".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14011".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14012".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14013".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("14015".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14016".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14019".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14020".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14021".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14022".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("14023".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("14024".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14025".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14026".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14027".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("14028".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14029".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("14030".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("14031".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("14032".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("16000".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("16001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("16100".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("17000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("17001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("17002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("17003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("17004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("17005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("17006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("17007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("18007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("19000".to_string(), Value::Str("BadRequest".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deriveWalletAddress".to_string(), Value::Str("".to_string()));
m.insert("id".to_string(), Value::Str("0x0ad42b8e602c2d3d475ae52d678cf63d84ab2749".to_string()));
m
}));
m
})]);
Value::Null
}
pub fn set_sandbox_mode(&mut self, mut enable: Value) {
self.super_set_sandbox_mode(enable.clone());
add_element_to_object(&mut self.options, &Value::Str("sandboxMode".to_string()), enable.clone());
}
/*
* @method
* @name derive#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://docs.derive.xyz/reference/post_public-get-time
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_post_get_time(&[params.clone()]).await;
return self.safe_integer_k(response.clone(), "result", &[]);
Value::Null
}
/*
* @method
* @name derive#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://docs.derive.xyz/reference/post_public-get-all-currencies
* @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 tokenResponse: Value = self.public_get_get_all_currencies(&[params.clone()]).await;
//
// {
// "result": [
// {
// "currency": "SEI",
// "instrument_types": [
// "perp"
// ],
// "protocol_asset_addresses": {
// "perp": "0x7225889B75fd34C68eA3098dAE04D50553C09840",
// "option": null,
// "spot": null,
// "underlying_erc20": null
// },
// "managers": [
// {
// "address": "0x28c9ddF9A3B29c2E6a561c1BC520954e5A33de5D",
// "margin_type": "SM",
// "currency": null
// }
// ],
// "srm_im_discount": "0",
// "srm_mm_discount": "0",
// "pm2_collateral_discounts": [],
// "borrow_apy": "0",
// "supply_apy": "0",
// "total_borrow": "0",
// "total_supply": "0",
// "asset_cap_and_supply_per_manager": {
// "perp": {
// "SM": [
// {
// "current_open_interest": "0",
// "interest_cap": "2000000",
// "manager_currency": null
// }
// ]
// },
// "option": {},
// "erc20": {}
// },
// "market_type": "SRM_PERP_ONLY",
// "spot_price": "0.2193542905042081",
// "spot_price_24h": "0.238381655533635830"
// },
// "id": "7e07fe1d-0ab4-4d2b-9e22-b65ce9e232dc"
// }
//
let mut currencies: Value = self.safe_list_k(tokenResponse.clone(), "result", &[Value::List(vec![])]);
return self.parse_currencies(currencies.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut currencyId: Value = self.safe_string_k(rawCurrency.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId.clone());
m.insert("name".to_string(), Value::Null);
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::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("info".to_string(), rawCurrency.clone());
m
}));
Value::Null
}
/*
* @method
* @name derive#fetchMarkets
* @description retrieves data on all markets for bybit
* @see https://docs.derive.xyz/reference/post_public-get-all-instruments
* @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 spotMarketsPromise: Value = self.fetch_spot_markets(&[params.clone()]).await;
let mut swapMarketsPromise: Value = self.fetch_swap_markets(&[params.clone()]).await;
let mut optionMarketsPromise: Value = self.fetch_option_markets(&[params.clone()]).await;
let mut spotMarketsswapMarketsoptionMarketsVariable = promise_all(&Value::List(vec![spotMarketsPromise.clone(), swapMarketsPromise.clone(), optionMarketsPromise.clone()])).await;
let mut spotMarkets: Value = get_value(&spotMarketsswapMarketsoptionMarketsVariable, &Value::Int(0));
let mut swapMarkets: Value = get_value(&spotMarketsswapMarketsoptionMarketsVariable, &Value::Int(1));
let mut optionMarkets: Value = get_value(&spotMarketsswapMarketsoptionMarketsVariable, &Value::Int(2));
//
// {
// "result": {
// "instruments": [
// {
// "instrument_type": "perp",
// "instrument_name": "BTC-PERP",
// "scheduled_activation": 1701840228,
// "scheduled_deactivation": 9223372036854776000,
// "is_active": true,
// "tick_size": "0.1",
// "minimum_amount": "0.01",
// "maximum_amount": "10000",
// "amount_step": "0.001",
// "mark_price_fee_rate_cap": "0",
// "maker_fee_rate": "0.00005",
// "taker_fee_rate": "0.0003",
// "base_fee": "0.1",
// "base_currency": "BTC",
// "quote_currency": "USD",
// "option_details": null,
// "perp_details": {
// "index": "BTC-USD",
// "max_rate_per_hour": "0.004",
// "min_rate_per_hour": "-0.004",
// "static_interest_rate": "0.0000125",
// "aggregate_funding": "10538.574363381759146829",
// "funding_rate": "0.0000125"
// },
// "erc20_details": null,
// "base_asset_address": "0xDBa83C0C654DB1cd914FA2710bA743e925B53086",
// "base_asset_sub_id": "0",
// "pro_rata_fraction": "0",
// "fifo_min_allocation": "0",
// "pro_rata_amount_step": "0.1"
// }
// ],
// "pagination": {
// "num_pages": 1,
// "count": 1
// }
// },
// "id": "a06bc0b2-8e78-4536-a21f-f785f225b5a5"
// }
//
let mut result: Value = self.array_concat(spotMarkets.clone(), swapMarkets.clone());
result = self.array_concat(result.clone(), optionMarkets.clone());
return result;
Value::Null
}
pub async fn fetch_spot_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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("expired".to_string(), Value::Bool(false));
m.insert("instrument_type".to_string(), Value::Str("erc20".to_string()));
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_post_get_all_instruments(&[__ws_arg_0]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "instruments", &[Value::List(vec![])]);
return self.parse_markets(data.clone());
Value::Null
}
pub async fn fetch_swap_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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("expired".to_string(), Value::Bool(false));
m.insert("instrument_type".to_string(), Value::Str("perp".to_string()));
m
});
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_post_get_all_instruments(&[__ws_arg_1]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "instruments", &[Value::List(vec![])]);
return self.parse_markets(data.clone());
Value::Null
}
pub async fn fetch_option_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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("expired".to_string(), Value::Bool(false));
m.insert("instrument_type".to_string(), Value::Str("option".to_string()));
m
});
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_post_get_all_instruments(&[__ws_arg_2]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "instruments", &[Value::List(vec![])]);
return self.parse_markets(data.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut type_var: Value = self.safe_string_k(market.clone(), "instrument_type", &[]);
let mut marketType: Value = Value::Null;
let mut spot: Value = Value::Bool(false);
let mut margin: Value = Value::Bool(true);
let mut swap: Value = Value::Bool(false);
let mut option: Value = Value::Bool(false);
let mut linear: Value = Value::Null;
let mut inverse: Value = Value::Null;
let mut baseId: Value = self.safe_string_k(market.clone(), "base_currency", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quote_currency", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut marketId: Value = self.safe_string_k(market.clone(), "instrument_name", &[]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut settleId: Value = Value::Null;
let mut settle: Value = Value::Null;
let mut expiry: Value = Value::Null;
let mut strike: Value = Value::Null;
let mut optionType: Value = Value::Null;
let mut optionLetter: Value = Value::Null;
if is_equal(&type_var, &Value::Str("erc20".to_string())) {
spot = Value::Bool(true);
marketType = Value::Str("spot".to_string());
} else if is_equal(&type_var, &Value::Str("perp".to_string())) {
margin = Value::Bool(false);
settleId = Value::Str("USDC".to_string());
settle = self.safe_currency_code(settleId.clone(), &[]);
symbol = add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
swap = Value::Bool(true);
linear = Value::Bool(true);
inverse = Value::Bool(false);
marketType = Value::Str("swap".to_string());
} else if is_equal(&type_var, &Value::Str("option".to_string())) {
settleId = Value::Str("USDC".to_string());
settle = self.safe_currency_code(settleId.clone(), &[]);
margin = Value::Bool(false);
option = Value::Bool(true);
marketType = Value::Str("option".to_string());
let mut optionDetails: Value = self.safe_dict_k(market.clone(), "option_details", &[]);
expiry = self.safe_timestamp(optionDetails.clone(), Value::Str("expiry".to_string()), &[]);
strike = self.safe_integer_k(optionDetails.clone(), "strike", &[]);
optionLetter = self.safe_string_k(optionDetails.clone(), "option_type", &[]);
symbol = add(&add(&add(&add(&add(&add(&add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle), &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[])), &Value::Str("-".to_string())), &self.number_to_string(strike.clone())), &Value::Str("-".to_string())), &optionLetter);
if is_equal(&optionLetter, &Value::Str("P".to_string())) {
optionType = Value::Str("put".to_string());
} else {
optionType = Value::Str("call".to_string());
}
linear = Value::Bool(true);
inverse = Value::Bool(false);
}
let mut contractSize: Value = ternary(is_true(&(spot)), Value::Null, Value::Int(1));
let mut isContract: Value = Value::Bool(is_true(&swap) || is_true(&option));
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), marketType.clone());
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), margin.clone());
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), option.clone());
m.insert("active".to_string(), self.safe_bool_k(market.clone(), "is_active", &[]));
m.insert("contract".to_string(), isContract.clone());
m.insert("linear".to_string(), linear.clone());
m.insert("inverse".to_string(), inverse.clone());
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "taker_fee_rate", &[]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "maker_fee_rate", &[]));
m.insert("strike".to_string(), strike.clone());
m.insert("optionType".to_string(), optionType.clone());
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(market.clone(), "amount_step", &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "tick_size", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minimum_amount", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maximum_amount", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name derive#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.derive.xyz/reference/post_public-get-ticker
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_post_get_ticker(&[__ws_arg_3]).await;
//
// spot
//
// {
// "result": {
// "instrument_type": "perp",
// "instrument_name": "BTC-PERP",
// "scheduled_activation": 1701840228,
// "scheduled_deactivation": 9223372036854776000,
// "is_active": true,
// "tick_size": "0.1",
// "minimum_amount": "0.01",
// "maximum_amount": "10000",
// "amount_step": "0.001",
// "mark_price_fee_rate_cap": "0",
// "maker_fee_rate": "0.00005",
// "taker_fee_rate": "0.0003",
// "base_fee": "0.1",
// "base_currency": "BTC",
// "quote_currency": "USD",
// "option_details": null,
// "perp_details": {
// "index": "BTC-USD",
// "max_rate_per_hour": "0.004",
// "min_rate_per_hour": "-0.004",
// "static_interest_rate": "0.0000125",
// "aggregate_funding": "10512.580833189805742522",
// "funding_rate": "-0.000022223906766867"
// },
// "erc20_details": null,
// "base_asset_address": "0xDBa83C0C654DB1cd914FA2710bA743e925B53086",
// "base_asset_sub_id": "0",
// "pro_rata_fraction": "0",
// "fifo_min_allocation": "0",
// "pro_rata_amount_step": "0.1",
// "best_ask_amount": "0.012",
// "best_ask_price": "99567.9",
// "best_bid_amount": "0.129",
// "best_bid_price": "99554.5",
// "five_percent_bid_depth": "11.208",
// "five_percent_ask_depth": "11.42",
// "option_pricing": null,
// "index_price": "99577.2",
// "mark_price": "99543.642926357933902181684970855712890625",
// "stats": {
// "contract_volume": "464.712",
// "num_trades": "10681",
// "open_interest": "72.804739389481989861",
// "high": "99519.1",
// "low": "97254.1",
// "percent_change": "0.0128",
// "usd_change": "1258.1"
// },
// "timestamp": 1736140984000,
// "min_price": "97591.2",
// "max_price": "101535.1"
// },
// "id": "bbd7c271-c2be-48f7-b93a-26cf6d4cb79f"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(data.clone(), &[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);
//
// {
// "instrument_type": "perp",
// "instrument_name": "BTC-PERP",
// "scheduled_activation": 1701840228,
// "scheduled_deactivation": 9223372036854776000,
// "is_active": true,
// "tick_size": "0.1",
// "minimum_amount": "0.01",
// "maximum_amount": "10000",
// "amount_step": "0.001",
// "mark_price_fee_rate_cap": "0",
// "maker_fee_rate": "0.00005",
// "taker_fee_rate": "0.0003",
// "base_fee": "0.1",
// "base_currency": "BTC",
// "quote_currency": "USD",
// "option_details": null,
// "perp_details": {
// "index": "BTC-USD",
// "max_rate_per_hour": "0.004",
// "min_rate_per_hour": "-0.004",
// "static_interest_rate": "0.0000125",
// "aggregate_funding": "10512.580833189805742522",
// "funding_rate": "-0.000022223906766867"
// },
// "erc20_details": null,
// "base_asset_address": "0xDBa83C0C654DB1cd914FA2710bA743e925B53086",
// "base_asset_sub_id": "0",
// "pro_rata_fraction": "0",
// "fifo_min_allocation": "0",
// "pro_rata_amount_step": "0.1",
// "best_ask_amount": "0.012",
// "best_ask_price": "99567.9",
// "best_bid_amount": "0.129",
// "best_bid_price": "99554.5",
// "five_percent_bid_depth": "11.208",
// "five_percent_ask_depth": "11.42",
// "option_pricing": null,
// "index_price": "99577.2",
// "mark_price": "99543.642926357933902181684970855712890625",
// "stats": {
// "contract_volume": "464.712",
// "num_trades": "10681",
// "open_interest": "72.804739389481989861",
// "high": "99519.1",
// "low": "97254.1",
// "percent_change": "0.0128",
// "usd_change": "1258.1"
// },
// "timestamp": 1736140984000,
// "min_price": "97591.2",
// "max_price": "101535.1"
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instrument_name", &[]);
let mut timestamp: Value = self.safe_integer_omit_zero(ticker.clone(), Value::Str("timestamp".to_string()), &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut stats: Value = self.safe_dict_k(ticker.clone(), "stats", &[]);
let mut change: Value = self.safe_string_k(stats.clone(), "percent_change", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string_k(stats.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_string_k(stats.clone(), "low", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "best_bid_price", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "best_bid_amount", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "best_ask_price", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "best_ask_amount", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), Value::Null);
m.insert("last".to_string(), Value::Null);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), change.clone());
m.insert("percentage".to_string(), crate::precise::Precise::stringMul(&change, &Value::Str("100".to_string())));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), Value::Null);
m.insert("quoteVolume".to_string(), Value::Null);
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "index_price", &[]));
m.insert("markPrice".to_string(), self.safe_string_k(ticker.clone(), "mark_price", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name derive#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://docs.derive.xyz/reference/post_public-get-trade-history
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades for
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
if is_greater_than(&limit, &Value::Int(1000)) {
limit = Value::Int(1000);
}
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone()); // default 100, max 1000
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from_timestamp".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("to_timestamp".to_string()), until.clone());
}
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_post_get_trade_history(&[__ws_arg_4]).await;
//
// {
// "result": {
// "trades": [
// {
// "trade_id": "9dbc88b0-f0c4-4439-9cc1-4e6409d4eafb",
// "instrument_name": "BTC-PERP",
// "timestamp": 1736153910930,
// "trade_price": "98995.3",
// "trade_amount": "0.033",
// "mark_price": "98990.875914388161618263",
// "index_price": "99038.050611100001501184",
// "direction": "sell",
// "quote_id": null,
// "wallet": "0x88B6BB87fbFac92a34F8155aaA35c87B5b166fA9",
// "subaccount_id": 8250,
// "tx_status": "settled",
// "tx_hash": "0x020bd735b312f867f17f8cc254946d87cfe9f2c8ff3605035d8129082eb73723",
// "trade_fee": "0.980476701049890015",
// "liquidity_role": "taker",
// "realized_pnl": "-2.92952402688793509",
// "realized_pnl_excl_fees": "-1.949047325838045075"
// }
// ],
// "pagination": {
// "num_pages": 598196,
// "count": 598196
// }
// },
// "id": "b8539544-6975-4497-8163-5e51a38e4aa7"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "trades", &[Value::List(vec![])]);
return self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_trades(&self, mut trades: Value, optional_args: &[Value]) -> Value {
let mut market = 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 mut tradesArray: Value = self.to_array(trades.clone());
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_632: bool = true;
while { if !__for_first_632 { i = add(&i, &Value::Int(1)); } __for_first_632 = false; is_less_than(&i, &get_array_length(&tradesArray)) } {
let mut rawTrade: Value = get_value(&tradesArray, &i);
let mut rawTrade: Value = get_value(&tradesArray, &i);
let mut isFetchTrades: bool = !is_true(&(Value::Bool(in_op(&rawTrade, &Value::Str("order_id".to_string())))));
let mut liquidityRole: Value = self.safe_string_k(rawTrade.clone(), "liquidity_role", &[]);
if is_true(&isFetchTrades) && is_true(&(is_equal(&liquidityRole, &Value::Str("maker".to_string())))) {
continue;
}
let mut parsed: Value = self.parse_trade(rawTrade.clone(), &[market.clone()]);
let mut trade: Value = self.extend(parsed.clone(), &[params.clone()]);
append_to_array(&mut result, trade.clone());
}
}
result = self.sort_by2(result.clone(), Value::Str("timestamp".to_string()), Value::Str("id".to_string()), &[]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[]);
return self.filter_by_symbol_since_limit(result.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades & fetchMyTrades
//
// {
// "subaccount_id": 130837,
// "instrument_name": "BTC-PERP",
// "direction": "sell",
// "quote_id": null,
// "trade_id": "f8a30740-488c-4c2d-905d-e17057bafde1",
// "timestamp": 1738065303708,
// "mark_price": "102740.137375457314192317",
// "index_price": "102741.553409299981533184",
// "trade_price": "102700.6",
// "trade_amount": "0.01",
// "liquidity_role": "taker",
// "realized_pnl": "0",
// "realized_pnl_excl_fees": "0",
// "tx_status": "settled",
// "trade_fee": "1.127415534092999815",
// "tx_hash": "0xc55df1f07330faf86579bd8a6385391fbe9e73089301149d8550e9d29c9ead74",
// "label": "test1234", // only fetchMyTrades
// "order_id": "30c48194-8d48-43ac-ad00-0d5ba29eddc9", // only fetchMyTrades
// "is_transfer": false, // only fetchMyTrades
// "transaction_id": "e18b9426-3fa5-41bb-99d3-8b54fb4d11bb", // only fetchMyTrades
// "rfq_id": null, // only fetchTrades
// "wallet": "0x353Bf69715DdbF7A2b0C6Deba8EAC1F1D160c123", // only fetchTrades
// "expected_rebate": "0", // only fetchTrades
// "extra_fee": "0", // only fetchTrades
// }
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "instrument_name", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), Value::Str("USDC".to_string()));
m.insert("cost".to_string(), self.safe_string_k(trade.clone(), "trade_fee", &[]));
m
});
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string_k(trade.clone(), "trade_id", &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "order_id", &[]));
m.insert("symbol".to_string(), symbol.clone());
m.insert("side".to_string(), self.safe_string_lower(trade.clone(), Value::Str("direction".to_string()), &[]));
m.insert("type".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), self.safe_string_k(trade.clone(), "liquidity_role", &[]));
m.insert("price".to_string(), self.safe_string_k(trade.clone(), "trade_price", &[]));
m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "trade_amount", &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name derive#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://docs.derive.xyz/reference/post_public-get-funding-rate-history
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of funding rate structures to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_timestamp".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("to_timestamp".to_string()), until.clone());
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_post_get_funding_rate_history(&[__ws_arg_5]).await;
//
// {
// "result": {
// "funding_rate_history": [
// {
// "timestamp": 1736215200000,
// "funding_rate": "-0.000020014"
// }
// ]
// },
// "id": "3200ab8d-0080-42f0-8517-c13e3d9201d8"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "funding_rate_history", &[Value::List(vec![])]);
let mut rates: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_633: bool = true;
while { if !__for_first_633 { i = add(&i, &Value::Int(1)); } __for_first_633 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "timestamp", &[]);
append_to_array(&mut rates, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "funding_rate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name derive#fetchFundingRate
* @description fetch the current funding rate
* @see https://docs.derive.xyz/reference/post_public-get-funding-rate-history
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.fetch_funding_rate_history(&[symbol.clone(), Value::Null, Value::Int(1), params.clone()]).await;
//
// [
// {
// "info": {
// "timestamp": 1736157600000,
// "funding_rate": "-0.000008872"
// },
// "symbol": "BTC/USD:USDC",
// "fundingRate": -0.000008872,
// "timestamp": 1736157600000,
// "datetime": "2025-01-06T10:00:00.000Z"
// }
// ]
//
let mut data: Value = self.safe_dict(response.clone(), Value::Int(0), &[]);
return self.parse_funding_rate(data.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);
let mut symbol: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut fundingTimestamp: Value = self.safe_integer_k(contract.clone(), "timestamp", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
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(), "fundingRate", &[]));
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::Null);
m
});
Value::Null
}
pub fn hash_order_message(&self, mut order: Value) -> Value {
let mut accountHash: Value = self.hash(self.eth_abi_encode(Value::List(vec![Value::Str("bytes32".to_string()), Value::Str("uint256".to_string()), Value::Str("uint256".to_string()), Value::Str("address".to_string()), Value::Str("bytes32".to_string()), Value::Str("uint256".to_string()), Value::Str("address".to_string()), Value::Str("address".to_string())]), order.clone()), Value::Str("keccak".to_string()), &[Value::Str("binary".to_string())]);
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut DOMAIN_SEPARATOR: Value = ternary(is_true(&(is_equal(&sandboxMode, &Value::Bool(true)))), Value::Str("9bcf4dc06df5d8bf23af818d5716491b995020f377d3b7b64c29ed14e3dd1105".to_string()), Value::Str("d96e5f90797da7ec8dc4e276260c7f3f87fedf68775fbe1ef116e996fc60441b".to_string()));
let mut binaryDomainSeparator: Value = self.base16_to_binary(DOMAIN_SEPARATOR.clone(), &[]);
let mut prefix: Value = self.base16_to_binary(Value::Str("1901".to_string()), &[]);
return self.hash(self.binary_concat(prefix.clone(), &[binaryDomainSeparator.clone(), accountHash.clone()]), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]);
Value::Null
}
pub fn sign_order(&self, mut order: Value, mut privateKey: Value) -> Value {
let mut hashOrder: Value = self.hash_order_message(order.clone());
return self.sign_hash(slice(&hashOrder, &negate(&Value::Int(64)), &Value::Null), slice(&privateKey, &negate(&Value::Int(64)), &Value::Null));
Value::Null
}
pub fn hash_message(&self, mut message: Value) -> Value {
let mut binaryMessage: Value = self.encode(message.clone());
let mut binaryMessageLength: Value = self.binary_length(binaryMessage.clone(), &[]);
let mut x19: Value = self.base16_to_binary(Value::Str("19".to_string()), &[]);
let mut newline: Value = self.base16_to_binary(Value::Str("0a".to_string()), &[]);
let mut prefix: Value = self.binary_concat(x19.clone(), &[self.encode(Value::Str("Ethereum Signed Message:".to_string())), newline.clone(), self.encode(self.number_to_string(binaryMessageLength.clone()))]);
return add(&Value::Str("0x".to_string()), &self.hash(self.binary_concat(prefix.clone(), &[binaryMessage.clone()]), Value::Str("keccak".to_string()), &[Value::Str("hex".to_string())]));
Value::Null
}
pub fn sign_hash(&self, mut hash: Value, mut privateKey: Value) -> Value {
self.check_required_credentials(&[]);
let mut signature: Value = ecdsa(slice(&hash, &negate(&Value::Int(64)), &Value::Null), slice(&privateKey, &negate(&Value::Int(64)), &Value::Null), Value::Str("secp256k1".to_string()), Value::Null);
let mut r: Value = get_value(&signature, &Value::Str("r".to_string()));
let mut s: Value = get_value(&signature, &Value::Str("s".to_string()));
let mut v: Value = self.int_to_base16(self.sum(&[Value::Int(27), get_value(&signature, &Value::Str("v".to_string()))]), &[]);
return add(&add(&add(&Value::Str("0x".to_string()), &pad_start(&r, &Value::Int(64), &Value::Str("0".to_string()))), &pad_start(&s, &Value::Int(64), &Value::Str("0".to_string()))), &v);
Value::Null
}
pub fn sign_message(&self, mut message: Value, mut privateKey: Value) -> Value {
return self.sign_hash(self.hash_message(message.clone()), slice(&privateKey, &negate(&Value::Int(64)), &Value::Null));
Value::Null
}
pub fn parse_units(&self, mut num: Value, optional_args: &[Value]) -> Value {
let mut dec = get_arg(optional_args, 0, Value::Str("1000000000000000000".to_string()));
return crate::precise::Precise::stringMul(&num, &dec);
Value::Null
}
/*
* @method
* @name derive#createOrder
* @description create a trade order
* @see https://docs.derive.xyz/reference/post_private-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount_id] *required* the subaccount id
* @param {float} [params.triggerPrice] The price a trigger order is triggered at
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered (perpetual swap markets only)
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered (perpetual swap markets only)
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {float} [params.max_fee] *required* the maximum fee you are willing to pay for the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
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 subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("createOrder".to_string()), params.clone()); subaccountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut test: Value = self.safe_bool_k(params.clone(), "test", &[Value::Bool(false)]);
let mut reduceOnly: Value = self.safe_bool2(params.clone(), Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), &[]);
let mut timeInForce: Value = self.safe_string_lower2(params.clone(), Value::Str("timeInForce".to_string()), Value::Str("time_in_force".to_string()), &[]);
let mut postOnly: Value = self.safe_bool_k(params.clone(), "postOnly", &[]);
let mut orderType: Value = to_lower(&type_var);
let mut orderSide: Value = to_lower(&side);
let mut orderSideIsBuy: Value = Value::Bool(is_equal(&orderSide, &Value::Str("buy".to_string()))); // extracted to a named local: the Rust transpiler can't lower a bare `===` bool inside a list literal (ethAbiEncode args)
let mut nonce: Value = self.milliseconds();
// Order signature expiry must be between 2592000 and 7776000 sec from now
let mut signatureExpiry: Value = self.safe_integer_k(params.clone(), "signature_expiry_sec", &[add(&self.seconds(), &Value::Int(7776000))]);
let mut ACTION_TYPEHASH: Value = self.base16_to_binary(Value::Str("4d7a9f27c403ff9c0f19bce61d76d82f9aa29f8d6d4b0c5474607d9770d1af17".to_string()), &[]);
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut TRADE_MODULE_ADDRESS: Value = ternary(is_true(&(is_equal(&sandboxMode, &Value::Bool(true)))), Value::Str("0x87F2863866D85E3192a35A73b388BD625D83f2be".to_string()), Value::Str("0xB8D20c2B7a1Ad2EE33Bc50eF10876eD3035b5e7b".to_string()));
let mut priceString: Value = self.number_to_string(price.clone());
let mut maxFee: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("max_fee".to_string()), &[]); maxFee = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&maxFee, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a max_fee argument in params".to_string()))));
}
let mut maxFeeString: Value = self.number_to_string(maxFee.clone());
let mut amountString: Value = self.number_to_string(amount.clone());
let mut tradeModuleDataHash: Value = self.hash(self.eth_abi_encode(Value::List(vec![Value::Str("address".to_string()), Value::Str("uint".to_string()), Value::Str("int".to_string()), Value::Str("int".to_string()), Value::Str("uint".to_string()), Value::Str("uint".to_string()), Value::Str("bool".to_string())]), Value::List(vec![get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("base_asset_address".to_string())), self.parse_to_numeric(get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("base_asset_sub_id".to_string()))), self.convert_to_big_int(self.parse_units(priceString.clone(), &[])), self.convert_to_big_int(self.parse_units(self.amount_to_precision(symbol.clone(), amountString.clone()), &[])), self.convert_to_big_int(self.parse_units(maxFeeString.clone(), &[])), subaccountId.clone(), orderSideIsBuy.clone()])), Value::Str("keccak".to_string()), &[Value::Str("binary".to_string())]);
let mut deriveWalletAddress: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_wallet_address(Value::Str("createOrder".to_string()), params.clone()); deriveWalletAddress = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut signature: Value = self.sign_order(Value::List(vec![ACTION_TYPEHASH.clone(), subaccountId.clone(), nonce.clone(), TRADE_MODULE_ADDRESS.clone(), tradeModuleDataHash.clone(), signatureExpiry.clone(), deriveWalletAddress.clone(), self.walletAddress.clone()]), self.privateKey.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("direction".to_string(), orderSide.clone());
m.insert("order_type".to_string(), orderType.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("limit_price".to_string(), priceString.clone());
m.insert("max_fee".to_string(), maxFeeString.clone());
m.insert("subaccount_id".to_string(), subaccountId.clone());
m.insert("signature_expiry_sec".to_string(), signatureExpiry.clone());
m.insert("referral_code".to_string(), self.safe_string_k(self.options.clone(), "id", &[Value::Str("0x0ad42b8e602c2d3d475ae52d678cf63d84ab2749".to_string())]));
m.insert("signer".to_string(), self.walletAddress.clone());
m
});
if !is_equal(&reduceOnly, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("reduce_only".to_string()), reduceOnly.clone());
if is_true(&reduceOnly) && is_true(&(is_equal(&postOnly, &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" cannot use reduce only with post only time in force".to_string()))));
}
}
if !is_equal(&postOnly, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("post_only".to_string()));
} else if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), timeInForce.clone());
}
let mut stopLoss: Value = self.safe_value_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_value_k(params.clone(), "takeProfit", &[]);
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "trigger_price_type", &[Value::Str("mark".to_string())]);
if !is_equal(&stopLoss, &Value::Null) {
let mut stopLossPrice: Value = self.safe_string_k(stopLoss.clone(), "triggerPrice", &[stopLoss.clone()]);
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), stopLossPrice.clone());
add_element_to_object(&mut request, &Value::Str("trigger_type".to_string()), Value::Str("stoploss".to_string()));
add_element_to_object(&mut request, &Value::Str("trigger_price_type".to_string()), triggerPriceType.clone());
} else if !is_equal(&takeProfit, &Value::Null) {
let mut takeProfitPrice: Value = self.safe_string_k(takeProfit.clone(), "triggerPrice", &[takeProfit.clone()]);
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), takeProfitPrice.clone());
add_element_to_object(&mut request, &Value::Str("trigger_type".to_string()), Value::Str("takeprofit".to_string()));
add_element_to_object(&mut request, &Value::Str("trigger_price_type".to_string()), triggerPriceType.clone());
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("label".to_string()), clientOrderId.clone());
}
add_element_to_object(&mut request, &Value::Str("signature".to_string()), signature.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), Value::Str("timeInForce".to_string()), Value::Str("time_in_force".to_string()), Value::Str("postOnly".to_string()), Value::Str("test".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("trigger_price".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string()), Value::Str("trigger_price_type".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&test, &Value::Bool(true)) {
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_order_debug(&[__ws_arg_6]).await;
} else {
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_order(&[__ws_arg_7]).await;
}
//
// {
// "result": {
// "raw_data": {
// "subaccount_id": 130837,
// "nonce": 1736923517552,
// "module": "0x87F2863866D85E3192a35A73b388BD625D83f2be",
// "expiry": 86400,
// "owner": "0x108b9aF9279a525b8A8AeAbE7AC2bA925Bc50075",
// "signer": "0x108b9aF9279a525b8A8AeAbE7AC2bA925Bc50075",
// "signature": "0xaa4f42b2f3da33c668fa703ea872d4c3a6b55aca66025b5119e3bebb6679fe2e2794638db51dcace21fc39a498047835994f07eb59f311bb956ce057e66793d1c",
// "data": {
// "asset": "0xAFB6Bb95cd70D5367e2C39e9dbEb422B9815339D",
// "sub_id": 0,
// "limit_price": "10000",
// "desired_amount": "0.001",
// "worst_fee": "0",
// "recipient_id": 130837,
// "is_bid": true,
// "trade_id": ""
// }
// },
// "encoded_data": "0x000000000000000000000000afb6bb95cd70d5367e2c39e9dbeb422b9815339d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000021e19e0c9bab240000000000000000000000000000000000000000000000000000000038d7ea4c680000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001ff150000000000000000000000000000000000000000000000000000000000000001",
// "encoded_data_hashed": "0xe88fb416bc54dba2d288988f1a82fee40fd792ed555b3471b5f6b4b810d279b4",
// "action_hash": "0x273a0befb3751fa991edc7ed73582456c3b50ae964d458c8f472e932fb6a0069",
// "typed_data_hash": "0x123e2d2f3d5b2473b4e260f51c6459d6bf904e5db8f042a3ea63be8d55329ce9"
// },
// "id": "f851c8c4-dddf-4b77-93cf-aeddd0966f29"
// }
// {
// "result": {
// "order": {
// "subaccount_id": 130837,
// "order_id": "96349ebb-7d46-43ae-81c7-7ab390444293",
// "instrument_name": "BTC-PERP",
// "direction": "buy",
// "label": "",
// "quote_id": null,
// "creation_timestamp": 1737467576257,
// "last_update_timestamp": 1737467576257,
// "limit_price": "10000",
// "amount": "0.01",
// "filled_amount": "0",
// "average_price": "0",
// "order_fee": "0",
// "order_type": "limit",
// "time_in_force": "gtc",
// "order_status": "open",
// "max_fee": "210",
// "signature_expiry_sec": 1737468175989,
// "nonce": 1737467575989,
// "signer": "0x30CB7B06AdD6749BbE146A6827502B8f2a79269A",
// "signature": "0xd1ca49df1fa06bd805bb59b132ff6c0de29bf973a3e01705abe0a01cc956e4945ed9eb99ab68f3df4c037908113cac5a5bfc3a954a0b7103cdab285962fa6a51c",
// "cancel_reason": "",
// "mmp": false,
// "is_transfer": false,
// "replaced_order_id": null,
// "trigger_type": null,
// "trigger_price_type": null,
// "trigger_price": null,
// "trigger_reject_message": null
// },
// "trades": []
// },
// "id": "397087fa-0125-42af-bfc3-f66166f9fb55"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
let mut rawOrder: Value = self.safe_dict_k(result.clone(), "raw_data", &[]);
if is_equal(&rawOrder, &Value::Null) {
rawOrder = self.safe_dict_k(result.clone(), "order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
let mut order: Value = self.parse_order(rawOrder.clone(), &[market.clone()]);
add_element_to_object(&mut order, &Value::Str("type".to_string()), type_var.clone());
return order;
Value::Null
}
/*
* @method
* @name derive#editOrder
* @description edit a trade order
* @see https://docs.derive.xyz/reference/post_private-replace
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount_id] *required* the subaccount id
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("editOrder".to_string()), params.clone()); subaccountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut reduceOnly: Value = self.safe_bool2(params.clone(), Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), &[]);
let mut timeInForce: Value = self.safe_string_lower2(params.clone(), Value::Str("timeInForce".to_string()), Value::Str("time_in_force".to_string()), &[]);
let mut postOnly: Value = self.safe_bool_k(params.clone(), "postOnly", &[]);
let mut orderType: Value = to_lower(&type_var);
let mut orderSide: Value = to_lower(&side);
let mut orderSideIsBuy: Value = Value::Bool(is_equal(&orderSide, &Value::Str("buy".to_string()))); // extracted to a named local: the Rust transpiler can't lower a bare `===` bool inside a list literal (ethAbiEncode args)
let mut nonce: Value = self.milliseconds();
let mut signatureExpiry: Value = self.safe_number_k(params.clone(), "signature_expiry_sec", &[add(&self.seconds(), &Value::Int(7776000))]);
// TODO: subaccount id / trade module address
let mut ACTION_TYPEHASH: Value = self.base16_to_binary(Value::Str("4d7a9f27c403ff9c0f19bce61d76d82f9aa29f8d6d4b0c5474607d9770d1af17".to_string()), &[]);
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut TRADE_MODULE_ADDRESS: Value = ternary(is_true(&(is_equal(&sandboxMode, &Value::Bool(true)))), Value::Str("0x87F2863866D85E3192a35A73b388BD625D83f2be".to_string()), Value::Str("0xB8D20c2B7a1Ad2EE33Bc50eF10876eD3035b5e7b".to_string()));
let mut priceString: Value = self.number_to_string(price.clone());
let mut maxFeeString: Value = self.safe_string_k(params.clone(), "max_fee", &[Value::Str("0".to_string())]);
let mut amountString: Value = self.number_to_string(amount.clone());
let mut tradeModuleDataHash: Value = self.hash(self.eth_abi_encode(Value::List(vec![Value::Str("address".to_string()), Value::Str("uint".to_string()), Value::Str("int".to_string()), Value::Str("int".to_string()), Value::Str("uint".to_string()), Value::Str("uint".to_string()), Value::Str("bool".to_string())]), Value::List(vec![get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("base_asset_address".to_string())), self.parse_to_numeric(get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("base_asset_sub_id".to_string()))), self.convert_to_big_int(self.parse_units(priceString.clone(), &[])), self.convert_to_big_int(self.parse_units(self.amount_to_precision(symbol.clone(), amountString.clone()), &[])), self.convert_to_big_int(self.parse_units(maxFeeString.clone(), &[])), subaccountId.clone(), orderSideIsBuy.clone()])), Value::Str("keccak".to_string()), &[Value::Str("binary".to_string())]);
let mut deriveWalletAddress: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_wallet_address(Value::Str("editOrder".to_string()), params.clone()); deriveWalletAddress = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut signature: Value = self.sign_order(Value::List(vec![ACTION_TYPEHASH.clone(), subaccountId.clone(), nonce.clone(), TRADE_MODULE_ADDRESS.clone(), tradeModuleDataHash.clone(), signatureExpiry.clone(), deriveWalletAddress.clone(), self.walletAddress.clone()]), self.privateKey.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("order_id_to_cancel".to_string(), id.clone());
m.insert("direction".to_string(), orderSide.clone());
m.insert("order_type".to_string(), orderType.clone());
m.insert("nonce".to_string(), nonce.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("limit_price".to_string(), priceString.clone());
m.insert("max_fee".to_string(), maxFeeString.clone());
m.insert("subaccount_id".to_string(), subaccountId.clone());
m.insert("signature_expiry_sec".to_string(), signatureExpiry.clone());
m.insert("signer".to_string(), self.walletAddress.clone());
m
});
if !is_equal(&reduceOnly, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("reduce_only".to_string()), reduceOnly.clone());
if is_true(&reduceOnly) && is_true(&(is_equal(&postOnly, &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" cannot use reduce only with post only time in force".to_string()))));
}
}
if !is_equal(&postOnly, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), Value::Str("post_only".to_string()));
} else if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), timeInForce.clone());
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("label".to_string()), clientOrderId.clone());
}
add_element_to_object(&mut request, &Value::Str("signature".to_string()), signature.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), Value::Str("timeInForce".to_string()), Value::Str("time_in_force".to_string()), Value::Str("postOnly".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_replace(&[__ws_arg_8]).await;
//
// {
// "result":
// {
// "cancelled_order":
// {
// "subaccount_id": 130837,
// "order_id": "c2337704-f1af-437d-91c8-dddb9d6bac59",
// "instrument_name": "BTC-PERP",
// "direction": "buy",
// "label": "test1234",
// "quote_id": null,
// "creation_timestamp": 1737539743959,
// "last_update_timestamp": 1737539764234,
// "limit_price": "10000",
// "amount": "0.01",
// "filled_amount": "0",
// "average_price": "0",
// "order_fee": "0",
// "order_type": "limit",
// "time_in_force": "post_only",
// "order_status": "cancelled",
// "max_fee": "211",
// "signature_expiry_sec": 1737540343631,
// "nonce": 1737539743631,
// "signer": "0x30CB7B06AdD6749BbE146A6827502B8f2a79269A",
// "signature": "0xdb669e18f407a3efa816b79c0dd3bac1c651d4dbf3caad4db67678ce9b81c76378d787a08143a30707eb0827ce4626640767c9f174358df1b90611bd6d1391711b",
// "cancel_reason": "user_request",
// "mmp": false,
// "is_transfer": false,
// "replaced_order_id": null,
// "trigger_type": null,
// "trigger_price_type": null,
// "trigger_price": null,
// "trigger_reject_message": null,
// },
// "order":
// {
// "subaccount_id": 130837,
// "order_id": "97af0902-813f-4892-a54b-797e5689db05",
// "instrument_name": "BTC-PERP",
// "direction": "buy",
// "label": "test1234",
// "quote_id": null,
// "creation_timestamp": 1737539764154,
// "last_update_timestamp": 1737539764154,
// "limit_price": "10000",
// "amount": "0.01",
// "filled_amount": "0",
// "average_price": "0",
// "order_fee": "0",
// "order_type": "limit",
// "time_in_force": "post_only",
// "order_status": "open",
// "max_fee": "211",
// "signature_expiry_sec": 1737540363890,
// "nonce": 1737539763890,
// "signer": "0x30CB7B06AdD6749BbE146A6827502B8f2a79269A",
// "signature": "0xef2c459ab4797cbbd7d97b47678ff172542af009bac912bf53e7879cf92eb1aa6b1a6cf40bf0928684f5394942fb424cc2db71eac0eaf7226a72480034332f291c",
// "cancel_reason": "",
// "mmp": false,
// "is_transfer": false,
// "replaced_order_id": "c2337704-f1af-437d-91c8-dddb9d6bac59",
// "trigger_type": null,
// "trigger_price_type": null,
// "trigger_price": null,
// "trigger_reject_message": null,
// },
// "trades": [],
// "create_order_error": null,
// },
// "id": "fb19e991-15f6-4c80-a20c-917e762a1a38",
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
let mut rawOrder: Value = self.safe_dict_k(result.clone(), "order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(rawOrder.clone(), &[market.clone()]);
return order;
Value::Null
}
/*
* @method
* @name derive#cancelOrder
* @see https://docs.derive.xyz/reference/post_private-cancel
* @description cancels an open 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
* @param {boolean} [params.trigger] whether the order is a trigger/algo order
* @param {string} [params.subaccount_id] *required* the subaccount id
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("cancelOrder".to_string()), params.clone()); subaccountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instrument_name".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("subaccount_id".to_string(), subaccountId.clone());
m
});
let mut clientOrderIdUnified: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
let mut clientOrderIdExchangeSpecific: Value = self.safe_string_k(params.clone(), "label", &[clientOrderIdUnified.clone()]);
let mut isByClientOrder: bool = !is_equal(&clientOrderIdExchangeSpecific, &Value::Null);
let mut response: Value = Value::Null;
if is_true(&isByClientOrder) {
add_element_to_object(&mut request, &Value::Str("label".to_string()), clientOrderIdExchangeSpecific.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("label".to_string())]), &[]);
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cancel_by_label(&[__ws_arg_9]).await;
} else {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), id.clone());
if is_equal(&isTrigger, &Value::Bool(true)) {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cancel_trigger_order(&[__ws_arg_10]).await;
} else {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cancel(&[__ws_arg_11]).await;
}
}
//
// {
// "result": {
// "subaccount_id": 130837,
// "order_id": "de4f30b6-0dcb-4df6-9222-c1a27f1ad80d",
// "instrument_name": "BTC-PERP",
// "direction": "buy",
// "label": "test1234",
// "quote_id": null,
// "creation_timestamp": 1737540100989,
// "last_update_timestamp": 1737540574696,
// "limit_price": "10000",
// "amount": "0.01",
// "filled_amount": "0",
// "average_price": "0",
// "order_fee": "0",
// "order_type": "limit",
// "time_in_force": "post_only",
// "order_status": "cancelled",
// "max_fee": "211",
// "signature_expiry_sec": 1737540700726,
// "nonce": 1737540100726,
// "signer": "0x30CB7B06AdD6749BbE146A6827502B8f2a79269A",
// "signature": "0x9cd1a6e32a0699929e4e090c08c548366b1353701ec56e02d5cdf37fc89bd19b7b29e00e57e8383bb6336d73019027a7e2a4364f40859e7a949115024c7f199a1b",
// "cancel_reason": "user_request",
// "mmp": false,
// "is_transfer": false,
// "replaced_order_id": "4ccc89ba-3c3d-4047-8900-0aa5fb4ef706",
// "trigger_type": null,
// "trigger_price_type": null,
// "trigger_price": null,
// "trigger_reject_message": null
// },
// "id": "cef61e2a-cb13-4779-8e6b-535361981fad"
// }
//
// {
// "result": {
// "cancelled_orders": 1
// },
// "id": "674e075e-1e8a-4a47-99ff-75efbdd2370f"
// }
//
let mut extendParams: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m
});
let mut order: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&isByClientOrder) {
add_element_to_object(&mut extendParams, &Value::Str("client_order_id".to_string()), clientOrderIdExchangeSpecific.clone());
}
let __ws_arg_12 = self.parse_order(order.clone(), &[market.clone()]);
return self.extend(__ws_arg_12, &[extendParams.clone()]);
Value::Null
}
/*
* @method
* @name derive#cancelAllOrders
* @see https://docs.derive.xyz/reference/post_private-cancel-by-instrument
* @see https://docs.derive.xyz/reference/post_private-cancel-all
* @description cancel all open orders in a market
* @param {string} [symbol] unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount_id] *required* the subaccount id
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("cancelAllOrders".to_string()), params.clone()); subaccountId = 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("subaccount_id".to_string(), subaccountId.clone());
m
});
let mut response: Value = Value::Null;
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cancel_by_instrument(&[__ws_arg_13]).await;
} else {
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cancel_all(&[__ws_arg_14]).await;
}
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[])]);
Value::Null
}
/*
* @method
* @name derive#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://docs.derive.xyz/reference/post_private-get-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.paginate] set to true if you want to fetch orders with pagination
* @param {boolean} [params.trigger] whether the order is a trigger/algo order
* @param {string} [params.subaccount_id] *required* the subaccount id
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrders".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_incremental(Value::Str("fetchOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("page".to_string()), Value::Int(500)]).await;
}
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("fetchOrders".to_string()), params.clone()); subaccountId = 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("subaccount_id".to_string(), subaccountId.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), Value::Int(500));
}
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("status".to_string()), Value::Str("untriggered".to_string()));
}
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_orders(&[__ws_arg_15]).await;
//
// {
// "result": {
// "subaccount_id": 130837,
// "orders": [
// {
// "subaccount_id": 130837,
// "order_id": "63a80cb8-387b-472b-a838-71cd9513c365",
// "instrument_name": "BTC-PERP",
// "direction": "buy",
// "label": "test1234",
// "quote_id": null,
// "creation_timestamp": 1737551053207,
// "last_update_timestamp": 1737551053207,
// "limit_price": "10000",
// "amount": "0.01",
// "filled_amount": "0",
// "average_price": "0",
// "order_fee": "0",
// "order_type": "limit",
// "time_in_force": "post_only",
// "order_status": "open",
// "max_fee": "211",
// "signature_expiry_sec": 1737551652765,
// "nonce": 1737551052765,
// "signer": "0x30CB7B06AdD6749BbE146A6827502B8f2a79269A",
// "signature": "0x35535ccb1bcad509ecc435c79e966174db6403fc9aeee1e237d08a941014c57b59279dfe4be39e081f9921a53eaad59cb2a151d9f52f2d05fc47e6280254952e1c",
// "cancel_reason": "",
// "mmp": false,
// "is_transfer": false,
// "replaced_order_id": null,
// "trigger_type": null,
// "trigger_price_type": null,
// "trigger_price": null,
// "trigger_reject_message": null
// }
// ],
// "pagination": {
// "num_pages": 1,
// "count": 1
// }
// },
// "id": "e5a88d4f-7ac7-40cd-aec9-e0e8152b8b92"
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "result", &[]);
let mut page: Value = self.safe_integer_k(params.clone(), "page", &[]);
if !is_equal(&page, &Value::Null) {
let mut pagination: Value = self.safe_dict_k(data.clone(), "pagination", &[]);
let mut currentPage: Value = self.safe_integer_k(pagination.clone(), "num_pages", &[Value::Int(0)]);
if is_greater_than(&page, ¤tPage) {
return Value::List(vec![]);
}
}
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 derive#fetchOpenOrders
* @description fetches information on multiple orders made by the user
* @see https://docs.derive.xyz/reference/post_private-get-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.paginate] set to true if you want to fetch orders with pagination
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut extendedParams: Value = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("open".to_string()));
m
})]);
return self.fetch_orders(&[symbol.clone(), since.clone(), limit.clone(), extendedParams.clone()]).await;
Value::Null
}
/*
* @method
* @name derive#fetchClosedOrders
* @description fetches information on multiple orders made by the user
* @see https://docs.derive.xyz/reference/post_private-get-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.paginate] set to true if you want to fetch orders with pagination
* @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.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut extendedParams: Value = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("filled".to_string()));
m
})]);
return self.fetch_orders(&[symbol.clone(), since.clone(), limit.clone(), extendedParams.clone()]).await;
Value::Null
}
/*
* @method
* @name derive#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://docs.derive.xyz/reference/post_private-get-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.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut extendedParams: Value = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("cancelled".to_string()));
m
})]);
return self.fetch_orders(&[symbol.clone(), since.clone(), limit.clone(), extendedParams.clone()]).await;
Value::Null
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ioc".to_string(), Value::Str("IOC".to_string()));
m.insert("fok".to_string(), Value::Str("FOK".to_string()));
m.insert("gtc".to_string(), Value::Str("GTC".to_string()));
m.insert("post_only".to_string(), Value::Str("PO".to_string()));
m
});
return self.safe_string(timeInForces.clone(), timeInForce.clone(), &[]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
if !is_equal(&status, &Value::Null) {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("open".to_string(), Value::Str("open".to_string()));
m.insert("untriggered".to_string(), Value::Str("open".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("cancelled".to_string(), Value::Str("canceled".to_string()));
m.insert("expired".to_string(), Value::Str("rejected".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
}
return status;
Value::Null
}
pub fn parse_order(&self, mut rawOrder: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "subaccount_id": 130837,
// "nonce": 1736923517552,
// "module": "0x87F2863866D85E3192a35A73b388BD625D83f2be",
// "expiry": 86400,
// "owner": "0x108b9aF9279a525b8A8AeAbE7AC2bA925Bc50075",
// "signer": "0x108b9aF9279a525b8A8AeAbE7AC2bA925Bc50075",
// "signature": "0xaa4f42b2f3da33c668fa703ea872d4c3a6b55aca66025b5119e3bebb6679fe2e2794638db51dcace21fc39a498047835994f07eb59f311bb956ce057e66793d1c",
// "data": {
// "asset": "0xAFB6Bb95cd70D5367e2C39e9dbEb422B9815339D",
// "sub_id": 0,
// "limit_price": "10000",
// "desired_amount": "0.001",
// "worst_fee": "0",
// "recipient_id": 130837,
// "is_bid": true,
// "trade_id": ""
// }
// }
// {
// "subaccount_id": 130837,
// "order_id": "96349ebb-7d46-43ae-81c7-7ab390444293",
// "instrument_name": "BTC-PERP",
// "direction": "buy",
// "label": "",
// "quote_id": null,
// "creation_timestamp": 1737467576257,
// "last_update_timestamp": 1737467576257,
// "limit_price": "10000",
// "amount": "0.01",
// "filled_amount": "0",
// "average_price": "0",
// "order_fee": "0",
// "order_type": "limit",
// "time_in_force": "gtc",
// "order_status": "open",
// "max_fee": "210",
// "signature_expiry_sec": 1737468175989,
// "nonce": 1737467575989,
// "signer": "0x30CB7B06AdD6749BbE146A6827502B8f2a79269A",
// "signature": "0xd1ca49df1fa06bd805bb59b132ff6c0de29bf973a3e01705abe0a01cc956e4945ed9eb99ab68f3df4c037908113cac5a5bfc3a954a0b7103cdab285962fa6a51c",
// "cancel_reason": "",
// "mmp": false,
// "is_transfer": false,
// "replaced_order_id": null,
// "trigger_type": null,
// "trigger_price_type": null,
// "trigger_price": null,
// "trigger_reject_message": null
// }
let mut order: Value = self.safe_dict_k(rawOrder.clone(), "data", &[]);
if is_equal(&order, &Value::Null) {
order = rawOrder.clone();
}
let mut timestamp: Value = self.safe_integer2(rawOrder.clone(), Value::Str("creation_timestamp".to_string()), Value::Str("nonce".to_string()), &[]);
let mut orderId: Value = self.safe_string_k(order.clone(), "order_id", &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "instrument_name", &[]);
if !is_equal(&marketId, &Value::Null) {
market = self.safe_market(&[marketId.clone(), market.clone()]);
}
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut price: Value = self.safe_string_k(order.clone(), "limit_price", &[]);
let mut average: Value = self.safe_string_k(order.clone(), "average_price", &[]);
let mut amount: Value = self.safe_string_k(order.clone(), "desired_amount", &[]);
let mut filled: Value = self.safe_string_k(order.clone(), "filled_amount", &[]);
let mut fee: Value = self.safe_string_k(order.clone(), "order_fee", &[]);
let mut orderType: Value = self.safe_string_lower(order.clone(), Value::Str("order_type".to_string()), &[]);
let mut isBid: Value = self.safe_bool_k(order.clone(), "is_bid", &[]);
let mut side: Value = self.safe_string_k(order.clone(), "direction", &[]);
if is_equal(&side, &Value::Null) {
if is_equal(&isBid, &Value::Bool(true)) {
side = Value::Str("buy".to_string());
} else {
side = Value::Str("sell".to_string());
}
}
let mut triggerType: Value = self.safe_string_k(order.clone(), "trigger_type", &[]);
let mut stopLossPrice: Value = Value::Null;
let mut takeProfitPrice: Value = Value::Null;
let mut triggerPrice: Value = Value::Null;
if !is_equal(&triggerType, &Value::Null) {
triggerPrice = self.safe_string_k(order.clone(), "trigger_price", &[]);
if is_equal(&triggerType, &Value::Str("stoploss".to_string())) {
stopLossPrice = triggerPrice.clone();
} else {
takeProfitPrice = triggerPrice.clone();
}
}
let mut lastUpdateTimestamp: Value = self.safe_integer_k(rawOrder.clone(), "last_update_timestamp", &[]);
let mut status: Value = self.safe_string_k(order.clone(), "order_status", &[]);
let mut timeInForce: Value = self.safe_string_k(order.clone(), "time_in_force", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "label", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.clone());
m.insert("status".to_string(), self.parse_order_status(status.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), orderType.clone());
m.insert("timeInForce".to_string(), self.parse_time_in_force(timeInForce.clone()));
m.insert("postOnly".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), self.safe_bool_k(order.clone(), "reduce_only", &[]));
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("takeProfitPrice".to_string(), takeProfitPrice.clone());
m.insert("stopLossPrice".to_string(), stopLossPrice.clone());
m.insert("average".to_string(), average.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), fee.clone());
m.insert("currency".to_string(), Value::Str("USDC".to_string()));
m
}));
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name derive#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://docs.derive.xyz/reference/post_private-get-trade-history
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount_id] *required* the subaccount id
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("fetchOrderTrades".to_string()), params.clone()); subaccountId = 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("order_id".to_string(), id.clone());
m.insert("subaccount_id".to_string(), subaccountId.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from_timestamp".to_string()), since.clone());
}
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_trade_history(&[__ws_arg_16]).await;
//
// {
// "result": {
// "subaccount_id": 130837,
// "trades": [
// {
// "subaccount_id": 130837,
// "order_id": "30c48194-8d48-43ac-ad00-0d5ba29eddc9",
// "instrument_name": "BTC-PERP",
// "direction": "sell",
// "label": "test1234",
// "quote_id": null,
// "trade_id": "f8a30740-488c-4c2d-905d-e17057bafde1",
// "timestamp": 1738065303708,
// "mark_price": "102740.137375457314192317",
// "index_price": "102741.553409299981533184",
// "trade_price": "102700.6",
// "trade_amount": "0.01",
// "liquidity_role": "taker",
// "realized_pnl": "0",
// "realized_pnl_excl_fees": "0",
// "is_transfer": false,
// "tx_status": "settled",
// "trade_fee": "1.127415534092999815",
// "tx_hash": "0xc55df1f07330faf86579bd8a6385391fbe9e73089301149d8550e9d29c9ead74",
// "transaction_id": "e18b9426-3fa5-41bb-99d3-8b54fb4d51bb"
// }
// ],
// "pagination": {
// "num_pages": 1,
// "count": 1
// }
// },
// "id": "a16f798c-a121-44e2-b77e-c38a063f8a99"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(result.clone(), "trades", &[Value::List(vec![])]);
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name derive#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.derive.xyz/reference/post_private-get-trade-history
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] set to true if you want to fetch trades with pagination
* @param {string} [params.subaccount_id] *required* the subaccount id
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_incremental(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("page".to_string()), Value::Int(500)]).await;
}
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("fetchMyTrades".to_string()), params.clone()); subaccountId = 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("subaccount_id".to_string(), subaccountId.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from_timestamp".to_string()), since.clone());
}
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_trade_history(&[__ws_arg_17]).await;
//
// {
// "result": {
// "subaccount_id": 130837,
// "trades": [
// {
// "subaccount_id": 130837,
// "order_id": "30c48194-8d48-43ac-ad00-0d5ba29eddc9",
// "instrument_name": "BTC-PERP",
// "direction": "sell",
// "label": "test1234",
// "quote_id": null,
// "trade_id": "f8a30740-488c-4c2d-905d-e17057bafde1",
// "timestamp": 1738065303708,
// "mark_price": "102740.137375457314192317",
// "index_price": "102741.553409299981533184",
// "trade_price": "102700.6",
// "trade_amount": "0.01",
// "liquidity_role": "taker",
// "realized_pnl": "0",
// "realized_pnl_excl_fees": "0",
// "is_transfer": false,
// "tx_status": "settled",
// "trade_fee": "1.127415534092999815",
// "tx_hash": "0xc55df1f07330faf86579bd8a6385391fbe9e73089301149d8550e9d29c9ead74",
// "transaction_id": "e18b9426-3fa5-41bb-99d3-8b54fb4d51bb"
// }
// ],
// "pagination": {
// "num_pages": 1,
// "count": 1
// }
// },
// "id": "a16f798c-a121-44e2-b77e-c38a063f8a99"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut page: Value = self.safe_integer_k(params.clone(), "page", &[]);
if !is_equal(&page, &Value::Null) {
let mut pagination: Value = self.safe_dict_k(result.clone(), "pagination", &[]);
let mut currentPage: Value = self.safe_integer_k(pagination.clone(), "num_pages", &[Value::Int(0)]);
if is_greater_than(&page, ¤tPage) {
return Value::List(vec![]);
}
}
let mut trades: Value = self.safe_list_k(result.clone(), "trades", &[Value::List(vec![])]);
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name derive#fetchPositions
* @description fetch all open positions
* @see https://docs.derive.xyz/reference/post_private-get-positions
* @param {string[]} [symbols] not used by fetchPositions ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subaccount_id] *required* the subaccount id
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("fetchPositions".to_string()), params.clone()); subaccountId = 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("subaccount_id".to_string(), subaccountId.clone());
m
});
params = self.omit(params.clone(), Value::List(vec![Value::Str("subaccount_id".to_string())]), &[]);
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_positions(&[__ws_arg_18]).await;
//
// {
// "result": {
// "subaccount_id": 130837,
// "positions": [
// {
// "instrument_type": "perp",
// "instrument_name": "BTC-PERP",
// "amount": "-0.02",
// "average_price": "102632.9105389869500088",
// "realized_pnl": "0",
// "unrealized_pnl": "-2.6455959784245548835819950103759765625",
// "total_fees": "2.255789220260999824",
// "average_price_excl_fees": "102745.7",
// "realized_pnl_excl_fees": "0",
// "unrealized_pnl_excl_fees": "-0.3898067581635550595819950103759765625",
// "net_settlements": "-4.032902047219498639",
// "cumulative_funding": "-0.004677736347850093",
// "pending_funding": "0",
// "mark_price": "102765.190337908177752979099750518798828125",
// "index_price": "102767.657193800017641472",
// "delta": "1",
// "gamma": "0",
// "vega": "0",
// "theta": "0",
// "mark_value": "1.38730606879471451975405216217041015625",
// "maintenance_margin": "-101.37788426911356509663164615631103515625",
// "initial_margin": "-132.2074413704858670826070010662078857421875",
// "open_orders_margin": "264.116085900726830004714429378509521484375",
// "leverage": "8.6954476205089299495699106539379941746377322586618",
// "liquidation_price": "109125.705451984322280623018741607666015625",
// "creation_timestamp": 1738065303840
// }
// ]
// },
// "id": "167350f1-d9fc-41d4-9797-1c78f83fda8e"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positions: Value = self.safe_list_k(result.clone(), "positions", &[Value::List(vec![])]);
return self.parse_positions(positions.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "instrument_type": "perp",
// "instrument_name": "BTC-PERP",
// "amount": "-0.02",
// "average_price": "102632.9105389869500088",
// "realized_pnl": "0",
// "unrealized_pnl": "-2.6455959784245548835819950103759765625",
// "total_fees": "2.255789220260999824",
// "average_price_excl_fees": "102745.7",
// "realized_pnl_excl_fees": "0",
// "unrealized_pnl_excl_fees": "-0.3898067581635550595819950103759765625",
// "net_settlements": "-4.032902047219498639",
// "cumulative_funding": "-0.004677736347850093",
// "pending_funding": "0",
// "mark_price": "102765.190337908177752979099750518798828125",
// "index_price": "102767.657193800017641472",
// "delta": "1",
// "gamma": "0",
// "vega": "0",
// "theta": "0",
// "mark_value": "1.38730606879471451975405216217041015625",
// "maintenance_margin": "-101.37788426911356509663164615631103515625",
// "initial_margin": "-132.2074413704858670826070010662078857421875",
// "open_orders_margin": "264.116085900726830004714429378509521484375",
// "leverage": "8.6954476205089299495699106539379941746377322586618",
// "liquidation_price": "109125.705451984322280623018741607666015625",
// "creation_timestamp": 1738065303840
// }
//
let mut contract: Value = self.safe_string_k(position.clone(), "instrument_name", &[]);
market = self.safe_market(&[contract.clone(), market.clone()]);
let mut size: Value = self.safe_string_k(position.clone(), "amount", &[]);
let mut side: Value = Value::Null;
if is_true(&crate::precise::Precise::stringGt(&size, &Value::Str("0".to_string()))) {
side = Value::Str("long".to_string());
} else {
side = Value::Str("short".to_string());
}
let mut contractSize: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
let mut markPrice: Value = self.safe_string_k(position.clone(), "mark_price", &[]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "creation_timestamp", &[]);
let mut unrealisedPnl: Value = self.safe_string_k(position.clone(), "unrealized_pnl", &[]);
size = crate::precise::Precise::stringAbs(&size);
let mut notional: Value = crate::precise::Precise::stringMul(&size, &markPrice);
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(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "initial_margin", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), self.safe_number_k(position.clone(), "maintenance_margin", &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("entryPrice".to_string(), Value::Null);
m.insert("notional".to_string(), self.parse_number(notional.clone(), &[]));
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("unrealizedPnl".to_string(), self.parse_number(unrealisedPnl.clone(), &[]));
m.insert("contracts".to_string(), self.parse_number(size.clone(), &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSize.clone(), &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liquidation_price", &[]));
m.insert("markPrice".to_string(), self.parse_number(markPrice.clone(), &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("percentage".to_string(), Value::Null);
m.insert("hedged".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name derive#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://docs.derive.xyz/reference/post_private-get-funding-history
* @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 {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a [funding history structure]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
pub async fn fetch_funding_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_incremental(Value::Str("fetchFundingHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("page".to_string()), Value::Int(500)]).await;
}
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("fetchFundingHistory".to_string()), params.clone()); subaccountId = 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("subaccount_id".to_string(), subaccountId.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instrument_name".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_timestamp".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
}
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_funding_history(&[__ws_arg_19]).await;
//
// {
// "result": {
// "events": [
// {
// "instrument_name": "BTC-PERP",
// "timestamp": 1738066618272,
// "funding": "-0.004677736347850093",
// "pnl": "-0.944081615774632967"
// },
// {
// "instrument_name": "BTC-PERP",
// "timestamp": 1738066617964,
// "funding": "0",
// "pnl": "-0.437556413479249408"
// },
// {
// "instrument_name": "BTC-PERP",
// "timestamp": 1738065307565,
// "funding": "0",
// "pnl": "-0.39547479770461644"
// }
// ],
// "pagination": {
// "num_pages": 1,
// "count": 3
// }
// },
// "id": "524b817f-2108-467f-8795-511066f4acec"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut page: Value = self.safe_integer_k(params.clone(), "page", &[]);
if !is_equal(&page, &Value::Null) {
let mut pagination: Value = self.safe_dict_k(result.clone(), "pagination", &[]);
let mut currentPage: Value = self.safe_integer_k(pagination.clone(), "num_pages", &[Value::Int(0)]);
if is_greater_than(&page, ¤tPage) {
return Value::List(vec![]);
}
}
let mut events: Value = self.safe_list_k(result.clone(), "events", &[Value::List(vec![])]);
return self.parse_incomes(events.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_income(&self, mut income: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "instrument_name": "BTC-PERP",
// "timestamp": 1738065307565,
// "funding": "0",
// "pnl": "-0.39547479770461644"
// }
//
let mut marketId: Value = self.safe_string_k(income.clone(), "instrument_name", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut rate: Value = self.safe_string_k(income.clone(), "funding", &[]);
let mut code: Value = self.safe_currency_code(Value::Str("USDC".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_k(income.clone(), "timestamp", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), income.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("code".to_string(), code.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), Value::Null);
m.insert("amount".to_string(), Value::Null);
m.insert("rate".to_string(), rate.clone());
m
});
Value::Null
}
/*
* @method
* @name derive#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.derive.xyz/reference/post_private-get-all-portfolios
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut deriveWalletAddress: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_wallet_address(Value::Str("fetchBalance".to_string()), params.clone()); deriveWalletAddress = 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("wallet".to_string(), deriveWalletAddress.clone());
m
});
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_all_portfolios(&[__ws_arg_20]).await;
//
// {
// "result": [{
// "subaccount_id": 130837,
// "label": "",
// "currency": "all",
// "margin_type": "SM",
// "is_under_liquidation": false,
// "positions_value": "0",
// "collaterals_value": "318.0760325000001103035174310207366943359375",
// "subaccount_value": "318.0760325000001103035174310207366943359375",
// "positions_maintenance_margin": "0",
// "positions_initial_margin": "0",
// "collaterals_maintenance_margin": "238.557024375000082727638073265552520751953125",
// "collaterals_initial_margin": "190.845619500000083235136116854846477508544921875",
// "maintenance_margin": "238.557024375000082727638073265552520751953125",
// "initial_margin": "190.845619500000083235136116854846477508544921875",
// "open_orders_margin": "0",
// "projected_margin_change": "0",
// "open_orders": [],
// "positions": [],
// "collaterals": [
// {
// "asset_type": "erc20",
// "asset_name": "ETH",
// "currency": "ETH",
// "amount": "0.1",
// "mark_price": "3180.760325000000438272",
// "mark_value": "318.0760325000001103035174310207366943359375",
// "cumulative_interest": "0",
// "pending_interest": "0",
// "initial_margin": "190.845619500000083235136116854846477508544921875",
// "maintenance_margin": "238.557024375000082727638073265552520751953125",
// "realized_pnl": "0",
// "average_price": "3184.891931",
// "unrealized_pnl": "-0.413161",
// "total_fees": "0",
// "average_price_excl_fees": "3184.891931",
// "realized_pnl_excl_fees": "0",
// "unrealized_pnl_excl_fees": "-0.413161",
// "open_orders_margin": "0",
// "creation_timestamp": 1736860533493
// }
// ]
// }],
// "id": "27b9a64e-3379-4ce6-a126-9fb941c4a970"
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "result", &[]);
return self.parse_balance(result.clone());
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_635: bool = true;
while { if !__for_first_635 { i = add(&i, &Value::Int(1)); } __for_first_635 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut subaccount: Value = get_value(&response, &i);
let mut subaccount: Value = get_value(&response, &i);
let mut collaterals: Value = self.safe_list_k(subaccount.clone(), "collaterals", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_634: bool = true;
while { if !__for_first_634 { j = add(&j, &Value::Int(1)); } __for_first_634 = false; is_less_than(&j, &get_array_length(&collaterals)) } {
let mut balance: Value = get_value(&collaterals, &j);
let mut balance: Value = get_value(&collaterals, &j);
let mut code: Value = self.safe_currency_code(self.safe_string_k(balance.clone(), "currency", &[]), &[]);
let mut account: Value = self.safe_dict(result.clone(), code.clone(), &[]);
if is_equal(&account, &Value::Null) {
account = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "amount", &[]));
} else {
let mut amount: Value = self.safe_string_k(balance.clone(), "amount", &[]);
{ let __be_tmp = crate::precise::Precise::stringAdd(&get_value(&account, &Value::Str("total".to_string())), &amount); add_element_to_object(&mut account, &Value::Str("total".to_string()), __be_tmp); };
}
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name derive#fetchDeposits
* @description fetch all deposits made to an account
* @see https://docs.derive.xyz/reference/post_private-get-deposit-history
* @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_id] *required* the subaccount id
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("fetchDeposits".to_string()), params.clone()); subaccountId = 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("subaccount_id".to_string(), subaccountId.clone());
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_timestamp".to_string()), since.clone());
}
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_deposit_history(&[__ws_arg_21]).await;
//
// {
// "result": {
// "events": [
// {
// "timestamp": 1736860533599,
// "transaction_id": "f2069395-ec00-49f5-925a-87202a5d240f",
// "asset": "ETH",
// "amount": "0.1",
// "tx_status": "settled",
// "tx_hash": "0xeda21a315c59302a19c42049b4cef05a10b685302b6cc3edbaf49102d91166d4",
// "error_log": {}
// }
// ]
// },
// "id": "ceebc730-22ab-40cd-9941-33ceb2a74389"
// }
//
let mut currency: Value = self.safe_currency(code.clone(), &[]);
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut events: Value = self.safe_list_k(result.clone(), "events", &[Value::List(vec![])]);
return self.parse_transactions(events.clone(), &[currency.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name derive#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://docs.derive.xyz/reference/post_private-get-withdrawal-history
* @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_id] *required* the subaccount id
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut subaccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_derive_subaccount_id(Value::Str("fetchWithdrawals".to_string()), params.clone()); subaccountId = 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("subaccount_id".to_string(), subaccountId.clone());
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_timestamp".to_string()), since.clone());
}
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_get_withdrawal_history(&[__ws_arg_22]).await;
//
// {
// "result": {
// "events": [
// {
// "timestamp": 1736860533599,
// "transaction_id": "f2069395-ec00-49f5-925a-87202a5d240f",
// "asset": "ETH",
// "amount": "0.1",
// "tx_status": "settled",
// "tx_hash": "0xeda21a315c59302a19c42049b4cef05a10b685302b6cc3edbaf49102d91166d4",
// "error_log": {}
// }
// ]
// },
// "id": "ceebc730-22ab-40cd-9941-33ceb2a74389"
// }
//
let mut currency: Value = self.safe_currency(code.clone(), &[]);
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut events: Value = self.safe_list_k(result.clone(), "events", &[Value::List(vec![])]);
return self.parse_transactions(events.clone(), &[currency.clone(), since.clone(), limit.clone(), params.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);
//
// {
// "timestamp": 1736860533599,
// "transaction_id": "f2069395-ec00-49f5-925a-87202a5d240f",
// "asset": "ETH",
// "amount": "0.1",
// "tx_status": "settled",
// "tx_hash": "0xeda21a315c59302a19c42049b4cef05a10b685302b6cc3edbaf49102d91166d4",
// "error_log": {}
// }
//
let mut code: Value = self.safe_string_k(transaction.clone(), "asset", &[]);
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "timestamp", &[]);
let mut txId: Value = self.safe_string_k(transaction.clone(), "tx_hash", &[]);
if is_equal(&txId, &Value::Str("0x0".to_string())) {
txId = Value::Null;
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), Value::Null);
m.insert("txid".to_string(), txId.clone());
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(), Value::Null);
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "tx_status", &[])));
m.insert("updated".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("network".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settled".to_string(), Value::Str("ok".to_string()));
m.insert("reverted".to_string(), Value::Str("failed".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn handle_derive_subaccount_id(&self, mut methodName: Value, mut params: Value) -> Value {
let mut derivesubAccountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("subaccount_id".to_string()), &[]); derivesubAccountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(!is_equal(&derivesubAccountId, &Value::Null))) && is_true(&(!is_equal(&derivesubAccountId, &Value::Str("".to_string())))) {
add_element_to_object(&mut self.options.clone(), &Value::Str("subaccount_id".to_string()), derivesubAccountId.clone()); // saving in options
return Value::List(vec![derivesubAccountId.clone(), params.clone()]);
}
let mut optionsWallet: Value = self.safe_string_k(self.options.clone(), "subaccount_id", &[]);
if !is_equal(&optionsWallet, &Value::Null) {
return Value::List(vec![optionsWallet.clone(), params.clone()]);
}
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a subaccount_id parameter inside 'params' or exchange.options['subaccount_id']=ID.".to_string()))));
Value::Null
}
pub fn handle_derive_wallet_address(&self, mut methodName: Value, mut params: Value) -> Value {
let mut deriveWalletAddress: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("deriveWalletAddress".to_string()), &[]); deriveWalletAddress = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(!is_equal(&deriveWalletAddress, &Value::Null))) && is_true(&(!is_equal(&deriveWalletAddress, &Value::Str("".to_string())))) {
add_element_to_object(&mut self.options.clone(), &Value::Str("deriveWalletAddress".to_string()), deriveWalletAddress.clone()); // saving in options
return Value::List(vec![deriveWalletAddress.clone(), params.clone()]);
}
let mut optionsWallet: Value = self.safe_string_k(self.options.clone(), "deriveWalletAddress", &[]);
if !is_equal(&optionsWallet, &Value::Null) {
return Value::List(vec![optionsWallet.clone(), params.clone()]);
}
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a deriveWalletAddress parameter inside 'params' or exchange.options['deriveWalletAddress'] = ADDRESS, the address can find in HOME => Developers tab.".to_string()))));
Value::Null
}
pub fn handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
let mut error: Value = self.safe_dict_k(response.clone(), "error", &[]);
if !is_equal(&error, &Value::Null) {
let mut errorCode: Value = self.safe_string_k(error.clone(), "code", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &self.json(response.clone()));
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), body.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &path);
if is_equal(&method, &Value::Str("POST".to_string())) {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
if is_equal(&api, &Value::Str("private".to_string())) {
let mut now: Value = to_string_val(&self.milliseconds());
let mut signature: Value = self.sign_message(now.clone(), self.privateKey.clone());
add_element_to_object(&mut headers, &Value::Str("X-LyraWallet".to_string()), self.safe_string_k(self.options.clone(), "deriveWalletAddress", &[]));
add_element_to_object(&mut headers, &Value::Str("X-LyraTimestamp".to_string()), now.clone());
add_element_to_object(&mut headers, &Value::Str("X-LyraSignature".to_string()), signature.clone());
}
body = self.json(params.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
}
}