// 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;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct GateCore {
pub exchange: crate::exchange::Exchange,
}
impl GateCore {
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 = GateCore::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 GateCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_order(self, order, &[market])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_position(self, position, &[market])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_funding_rate(self, rate, &[market])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_deposit_address(self, depositAddress, &[currency])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_transfer(self, transfer, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_open_interest(self, interest, &[market])
}
fn parse_liquidation(&self, liquidation: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_liquidation(self, liquidation, &[market])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_margin_modification(self, data, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_transaction(self, transaction, &[currency])
}
fn parse_borrow_interest(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_borrow_interest(self, info, &[market])
}
fn parse_greeks(&self, greeks: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_greeks(self, greeks, &[market])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_leverage(self, leverage, &[market])
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_market_leverage_tiers(self, info, &[market])
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::parse_deposit_withdraw_fee(self, fee, &[currency])
}
fn create_expired_option_market(&self, symbol: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::create_expired_option_market(self, symbol)
}
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 GateCore.
GateCore::sign(self, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on GateCore.
GateCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for GateCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"borrow_cross_margin" => self.borrow_cross_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"borrow_isolated_margin" => self.borrow_isolated_margin(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[3.min(args.len())..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders_for_symbols" => self.cancel_orders_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_expired_option_market" => self.create_expired_option_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"create_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_orders_request" => self.create_orders_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"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[4.min(args.len())..]).await,
"edit_order_request" => self.edit_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]),
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_borrow_interest" => self.fetch_borrow_interest(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args[..]).await,
"fetch_future_markets" => self.fetch_future_markets(&args[..]).await,
"fetch_greeks" => self.fetch_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args[..]).await,
"fetch_leverages" => self.fetch_leverages(&args[..]).await,
"fetch_liquidations" => self.fetch_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_market_leverage_tiers" => self.fetch_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_liquidations" => self.fetch_my_liquidations(&args[..]).await,
"fetch_my_settlement_history" => self.fetch_my_settlement_history(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_network_deposit_address" => self.fetch_network_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_option" => self.fetch_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_option_chain" => self.fetch_option_chain(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_option_markets" => self.fetch_option_markets(&args[..]).await,
"fetch_option_ohlcv" => self.fetch_option_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_option_underlyings" => self.fetch_option_underlyings().await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_request" => self.fetch_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args[..]).await,
"fetch_settlement_history" => self.fetch_settlement_history(&args[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(&args[..]).await,
"fetch_swap_markets" => self.fetch_swap_markets(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_transaction_fees" => self.fetch_transaction_fees(&args[..]).await,
"fetch_underlying_assets" => self.fetch_underlying_assets(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"get_margin_mode" => self.get_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"get_settlement_currencies" => self.get_settlement_currencies(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)),
"load_unified_status" => self.load_unified_status(&args[..]).await,
"modify_margin_helper" => self.modify_margin_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"multi_order_spot_prepare_request" => self.multi_order_spot_prepare_request(&args[..]),
"nonce" => self.nonce(),
"parse_balance_helper" => self.parse_balance_helper(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_borrow_interest" => self.parse_borrow_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_contract_market" => self.parse_contract_market(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_emulated_leverage_tiers" => self.parse_emulated_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_histories" => self.parse_funding_histories(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)),
"parse_funding_history" => self.parse_funding_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_greeks" => self.parse_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_liquidation" => self.parse_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_loan" => self.parse_margin_loan(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_option" => self.parse_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_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[1.min(args.len())..]),
"parse_settlement" => self.parse_settlement(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_settlements" => self.parse_settlements(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trading_fees" => self.parse_trading_fees(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"prepare_orders_by_status_request" => self.prepare_orders_by_status_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"prepare_request" => self.prepare_request(&args[..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"repay_cross_margin" => self.repay_cross_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"repay_isolated_margin" => self.repay_isolated_margin(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[3.min(args.len())..]).await,
"safe_market" => self.safe_market(&args[..]),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"set_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"spot_order_prepare_request" => self.spot_order_prepare_request(&args[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"upgrade_unified_trade_account" => self.upgrade_unified_trade_account(&args[..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for GateCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for GateCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl GateCore {
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("gate".into()));
m.insert("name".to_string(), Value::Str("Gate".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("KR".into())]));
m.insert("rateLimit".to_string(), Value::Int(50));
m.insert("version".to_string(), Value::Str("v4".into()));
m.insert("certified".to_string(), Value::Bool(true));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/b4fd9d41-eaed-46fe-8a7b-b2677edface0".into()));
m.insert("doc".to_string(), Value::Str("https://www.gate.com/docs/developers/apiv4/en".into()));
m.insert("www".to_string(), Value::Str("https://gate.com".into()));
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("wallet".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("futures".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("margin".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("delivery".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("spot".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("options".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("sub_accounts".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("earn".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdrawals".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("wallet".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("futures".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("margin".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("delivery".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("spot".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("options".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("subAccounts".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("unified".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("rebate".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("earn".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("account".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("loan".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m.insert("otc".to_string(), Value::Str("https://api.gateio.ws/api/v4".into()));
m
}));
m
}));
m.insert("test".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("futures".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("delivery".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("options".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("spot".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("wallet".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("margin".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("sub_accounts".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("account".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("futures".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("delivery".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("options".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("spot".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("wallet".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("margin".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("sub_accounts".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m.insert("account".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".into()));
m
}));
m
}));
m.insert("referral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Str("https://www.gate.com/share/CCXTGATE".into()));
m.insert("discount".to_string(), Value::Float(0.2));
m
}));
m
}));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(true));
m.insert("addMargin".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(true));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(true));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("cancelOrdersForSymbols".to_string(), Value::Bool(true));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
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(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(true));
m.insert("createStopMarketOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
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(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Str("emulated".into()));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(true));
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(true));
m.insert("fetchGreeks".to_string(), Value::Bool(true));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(true));
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(true));
m.insert("fetchLeverages".to_string(), Value::Bool(true));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchLiquidations".to_string(), Value::Bool(true));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(true));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchNetworkDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(true));
m.insert("fetchOptionChain".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Str("emulated".into()));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactionFees".to_string(), Value::Bool(true));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(true));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(true));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(true));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("wallet".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("currency_chains".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("unified".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("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("history_loan_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("spot".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("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currency_pairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currency_pairs/{currency_pair}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("candlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("insurance_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("margin".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("uni/currency_pairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("uni/currency_pairs/{currency_pair}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loan_margin_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currency_pairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currency_pairs/{currency_pair}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("funding_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cross/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cross/currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("flash_swap".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("currency_pairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("futures".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("{settle}/contracts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/contracts/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/order_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/candlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/premium_index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/funding_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/insurance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/contract_stats".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/index_constituents/{index}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/liq_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/risk_limit_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/adl_risk_states".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("{settle}/funding_rates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("delivery".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("{settle}/contracts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/contracts/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/order_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/candlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/insurance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/risk_limit_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("options".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("underlyings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("expirations".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contracts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contracts/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("settlements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("settlements/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("underlying/tickers/{underlying}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("candlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("underlying/candlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("earn".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("uni/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("uni/currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("dual/investment_plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("structured/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("dual/project-recommend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fixed-term/product".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fixed-term/product/{asset}/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("loan".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("collateral/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("multi_collateral/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("multi_collateral/ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("multi_collateral/fixed_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("multi_collateral/current_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdrawals".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("withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("push".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdrawals/{withdrawal_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("wallet".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("deposit_address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub_account_transfers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order_status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdraw_status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub_account_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_account_margin_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_account_futures_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_account_cross_margin_balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("saved_address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("total_balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("small_balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("small_balance_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("push".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("getLowCapExchangeList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfers".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("transfers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_account_transfers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_account_to_sub_account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("small_balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("subAccounts".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("sub_accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_accounts/{user_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_accounts/{user_id}/keys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_accounts/{user_id}/keys/{key}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_accounts/{user_id}/keys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_accounts/{user_id}/lock".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("sub_accounts/{user_id}/unlock".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_accounts/{user_id}/keys/{key}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub_accounts/{user_id}/keys/{key}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m
}));
m
}));
m.insert("unified".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("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("transferable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("transferables".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("batch_borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loan_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("risk_units".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("unified_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("estimate_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("currency_discount_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loan_margin_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("leverage/user_currency_config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("leverage/user_currency_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("delta_neutral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("estimated_quick_repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("account_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(200)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("portfolio_calculator".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("leverage/user_currency_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral_currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("delta_neutral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("leverage/user_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("quick_repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("account_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unified_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("spot".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("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("batch_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("open_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("my_trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("pov_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("pov_orders/{order_id}".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("batch_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("cross_liquidate_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("cancel_batch_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("countdown_cancel_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("amend_batch_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("pov_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("pov_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("pov_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("patch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m
}));
m
}));
m.insert("margin".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("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("funding_accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("auto_repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("transferable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/estimate_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/loan_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("user/loan_margin_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("user/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loans/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loans/{loan_id}/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loan_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loan_records/{loan_record_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/loans/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/repayments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/transferable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/estimate_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("auto_repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("leverage/user_market_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("merged_loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loans/{loan_id}/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("cross/repayments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("patch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("loans/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("loan_records/{loan_record_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("loans/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("flash_swap".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("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders/{order_id}".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("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders/preview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("futures".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("{settle}/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/positions/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/get_leverage/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/dual_comp/positions/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/orders_timerange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/my_trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/my_trades_timerange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/position_close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/liquidates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/auto_deleverages".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/risk_limit_table".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/autoorder/v1/trail/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/autoorder/v1/trail/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/autoorder/v1/trail/change_log".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/autoorder/v1/chase/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/autoorder/v1/chase/detail".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("{settle}/positions/{contract}/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/positions/{contract}/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/positions/{contract}/set_leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/positions/{contract}/risk_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/positions/cross_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/dual_comp/positions/cross_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/dual_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/set_position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/dual_comp/positions/{contract}/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/dual_comp/positions/{contract}/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/dual_comp/positions/{contract}/risk_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/batch_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/countdown_cancel_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/batch_cancel_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/batch_amend_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/bbo_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/autoorder/v1/trail/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/autoorder/v1/trail/stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/autoorder/v1/trail/stop_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/autoorder/v1/trail/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/autoorder/v1/chase/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/autoorder/v1/chase/stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("{settle}/autoorder/v1/chase/stop_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(75)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("delivery".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("{settle}/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/positions/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/my_trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/position_close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/liquidates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/settlements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("{settle}/positions/{contract}/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/positions/{contract}/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/positions/{contract}/risk_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("options".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("my_settlements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("positions/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("position_close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("my_trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("countdown_cancel_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("mmp/reset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("earn".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("uni/lends".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/lend_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/interests/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/interest_status/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/chart".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("staking/eth2/rate_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("dual/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("dual/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("structured/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("staking/coins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("staking/order_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("staking/award_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("staking/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("dual/order-refund-preview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("fixed-term/user/lend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("fixed-term/user/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/coins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/plans/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/plans/list_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/plans/records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("uni/currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uni/lends".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("staking/eth2/swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("dual/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("structured/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("staking/swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("dual/order-refund".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("dual/modify-order-reinvest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("fixed-term/user/lend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("fixed-term/user/pre-redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/min_invest_amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/plans/add_position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/plans/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/plans/stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("autoinvest/plans/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uni/interest_reinvest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("patch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uni/lends".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("loan".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("collateral/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/repay_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/collaterals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/total_amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/mortgage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/currency_quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/fixed_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/current_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("collateral/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("collateral/collaterals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("multi_collateral/mortgage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("account".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("detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("main_keys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("rate_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("stp_groups".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("stp_groups/{stp_id}/users".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("stp_groups/debit_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("debit_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stp_groups".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("stp_groups/{stp_id}/users".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("debit_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stp_groups/{stp_id}/users".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("rebate".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("agency/transaction_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("agency/commission_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("partner/transaction_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("partner/commission_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("partner/sub_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("broker/commission_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("broker/transaction_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("user/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("user/sub_relation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m.insert("partner/data/aggregated".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), (match ((Value::Int(20)).as_f64(), (Value::Int(15)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
m
}));
m
}));
m
}));
m.insert("otc".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_user_def_bank".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("stable_coin/order/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("bank/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("bank/bank_supplement_checklist".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("quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("stable_coin/order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/paid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("bank/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("bank/delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("bank/set_default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("bank/personal/bank_supplement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("bank/enterprise/bank_supplement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("upload/pre_upload".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("10s".to_string(), Value::Str("10s".into()));
m.insert("1m".to_string(), Value::Str("1m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15m".to_string(), Value::Str("15m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("2h".to_string(), Value::Str("2h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("8h".to_string(), Value::Str("8h".into()));
m.insert("1d".to_string(), Value::Str("1d".into()));
m.insert("7d".to_string(), Value::Str("7d".into()));
m.insert("1w".to_string(), Value::Str("7d".into()));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ORT".to_string(), Value::Str("XREATORS".into()));
m.insert("ASS".to_string(), Value::Str("ASSF".into()));
m.insert("88MPH".to_string(), Value::Str("MPH".into()));
m.insert("AXIS".to_string(), Value::Str("AXISDEFI".into()));
m.insert("BIFI".to_string(), Value::Str("BITCOINFILE".into()));
m.insert("BOX".to_string(), Value::Str("DEFIBOX".into()));
m.insert("BYN".to_string(), Value::Str("BEYONDFI".into()));
m.insert("EGG".to_string(), Value::Str("GOOSEFINANCE".into()));
m.insert("GTC".to_string(), Value::Str("GAMECOM".into()));
m.insert("GTC_HT".to_string(), Value::Str("GAMECOM_HT".into()));
m.insert("GTC_BSC".to_string(), Value::Str("GAMECOM_BSC".into()));
m.insert("HIT".to_string(), Value::Str("HITCHAIN".into()));
m.insert("MM".to_string(), Value::Str("MILLION".into()));
m.insert("MPH".to_string(), Value::Str("MORPHER".into()));
m.insert("POINT".to_string(), Value::Str("GATEPOINT".into()));
m.insert("RAI".to_string(), Value::Str("RAIREFLEXINDEX".into()));
m.insert("SBTC".to_string(), Value::Str("SUPERBITCOIN".into()));
m.insert("TNC".to_string(), Value::Str("TRINITYNETWORKCREDIT".into()));
m.insert("VAI".to_string(), Value::Str("VAIOT".into()));
m.insert("TRAC".to_string(), Value::Str("TRACO".into()));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m
}));
m.insert("headers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-Gate-Channel-Id".to_string(), Value::Str("ccxt".into()));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("sandboxMode".to_string(), Value::Bool(false));
m.insert("unifiedAccount".to_string(), Value::Null);
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("expiration".to_string(), Value::Int(86400));
m
}));
m.insert("fetchOrderBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maxSpotLimit".to_string(), Value::Int(1000));
m
}));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".into()));
m.insert("BRC20".to_string(), Value::Str("BTCBRC".into()));
m.insert("ETH".to_string(), Value::Str("ETH".into()));
m.insert("ERC20".to_string(), Value::Str("ETH".into()));
m.insert("TRX".to_string(), Value::Str("TRX".into()));
m.insert("TRC20".to_string(), Value::Str("TRX".into()));
m.insert("HECO".to_string(), Value::Str("HT".into()));
m.insert("HRC20".to_string(), Value::Str("HT".into()));
m.insert("BSC".to_string(), Value::Str("BSC".into()));
m.insert("BEP20".to_string(), Value::Str("BSC".into()));
m.insert("SOL".to_string(), Value::Str("SOL".into()));
m.insert("MATIC".to_string(), Value::Str("MATIC".into()));
m.insert("OPTIMISM".to_string(), Value::Str("OPETH".into()));
m.insert("ADA".to_string(), Value::Str("ADA".into()));
m.insert("AVAXC".to_string(), Value::Str("AVAX_C".into()));
m.insert("NEAR".to_string(), Value::Str("NEAR".into()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBEVM".into()));
m.insert("ARBITRUM_NOVA".to_string(), Value::Str("ARBNOVA".into()));
m.insert("BASE".to_string(), Value::Str("BASEEVM".into()));
m.insert("SUI".to_string(), Value::Str("SUI".into()));
m.insert("CRONOS".to_string(), Value::Str("CRO".into()));
m.insert("CRO".to_string(), Value::Str("CRO".into()));
m.insert("APT".to_string(), Value::Str("APT".into()));
m.insert("SCROLL".to_string(), Value::Str("SCROLLETH".into()));
m.insert("TAIKO".to_string(), Value::Str("TAIKOETH".into()));
m.insert("HYPE".to_string(), Value::Str("HYPE".into()));
m.insert("ALGO".to_string(), Value::Str("ALGO".into()));
m.insert("LINEA".to_string(), Value::Str("LINEAETH".into()));
m.insert("BLAST".to_string(), Value::Str("BLASTETH".into()));
m.insert("XLM".to_string(), Value::Str("XLM".into()));
m.insert("RSK".to_string(), Value::Str("RBTC".into()));
m.insert("TON".to_string(), Value::Str("TON".into()));
m.insert("MNT".to_string(), Value::Str("MNT".into()));
m.insert("CELO".to_string(), Value::Str("CELO".into()));
m.insert("HBAR".to_string(), Value::Str("HBAR".into()));
m.insert("ZKSYNC".to_string(), Value::Str("ZKSERA".into()));
m.insert("KLAY".to_string(), Value::Str("KLAY".into()));
m.insert("EOS".to_string(), Value::Str("EOS".into()));
m.insert("ACA".to_string(), Value::Str("ACA".into()));
m.insert("XTZ".to_string(), Value::Str("XTZ".into()));
m.insert("EGLD".to_string(), Value::Str("EGLD".into()));
m.insert("GLMR".to_string(), Value::Str("GLMR".into()));
m.insert("AURORA".to_string(), Value::Str("AURORAEVM".into()));
m.insert("KON".to_string(), Value::Str("KONET".into()));
m.insert("GATECHAIN".to_string(), Value::Str("GTEVM".into()));
m.insert("KUSAMA".to_string(), Value::Str("KSMSM".into()));
m.insert("OKC".to_string(), Value::Str("OKT".into()));
m.insert("POLKADOT".to_string(), Value::Str("DOTSM".into()));
m.insert("LUNA".to_string(), Value::Str("LUNC".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("OPETH".to_string(), Value::Str("OP".into()));
m.insert("ETH".to_string(), Value::Str("ERC20".into()));
m.insert("ERC20".to_string(), Value::Str("ERC20".into()));
m.insert("TRX".to_string(), Value::Str("TRC20".into()));
m.insert("TRC20".to_string(), Value::Str("TRC20".into()));
m.insert("HT".to_string(), Value::Str("HRC20".into()));
m.insert("HECO".to_string(), Value::Str("HRC20".into()));
m.insert("BSC".to_string(), Value::Str("BEP20".into()));
m.insert("BEP20".to_string(), Value::Str("BEP20".into()));
m.insert("POLYGON".to_string(), Value::Str("MATIC".into()));
m.insert("POL".to_string(), Value::Str("MATIC".into()));
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("gtc".into()));
m.insert("IOC".to_string(), Value::Str("ioc".into()));
m.insert("PO".to_string(), Value::Str("poc".into()));
m.insert("POC".to_string(), Value::Str("poc".into()));
m.insert("FOK".to_string(), Value::Str("fok".into()));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("funding".to_string(), Value::Str("spot".into()));
m.insert("spot".to_string(), Value::Str("spot".into()));
m.insert("margin".to_string(), Value::Str("margin".into()));
m.insert("cross_margin".to_string(), Value::Str("cross_margin".into()));
m.insert("cross".to_string(), Value::Str("cross_margin".into()));
m.insert("isolated".to_string(), Value::Str("margin".into()));
m.insert("swap".to_string(), Value::Str("futures".into()));
m.insert("future".to_string(), Value::Str("delivery".into()));
m.insert("futures".to_string(), Value::Str("futures".into()));
m.insert("delivery".to_string(), Value::Str("delivery".into()));
m.insert("option".to_string(), Value::Str("options".into()));
m.insert("options".to_string(), Value::Str("options".into()));
m
}));
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("types".to_string(), Value::from(vec![Value::Str("spot".into()), Value::Str("swap".into()), Value::Str("future".into()), Value::Str("option".into())]));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settlementCurrencies".to_string(), Value::from(vec![Value::Str("usdt".into()), Value::Str("btc".into())]));
m
}));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settlementCurrencies".to_string(), Value::from(vec![Value::Str("usdt".into())]));
m
}));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerDirection".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(true));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(40));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(30));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("untilDays".to_string(), Value::Int(30));
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("spot".into()));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(10));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("untilDays".to_string(), Value::Null);
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("untilDays".to_string(), Value::Null);
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1999));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".into()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".into()));
m
}));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".into()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".into()));
m
}));
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("feeSide".to_string(), Value::Str("get".into()));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.002".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.002".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1.5".into()), &[]), self.parse_number(Value::Str("0.00185".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3".into()), &[]), self.parse_number(Value::Str("0.00175".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6".into()), &[]), self.parse_number(Value::Str("0.00165".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("12.5".into()), &[]), self.parse_number(Value::Str("0.00155".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25".into()), &[]), self.parse_number(Value::Str("0.00145".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75".into()), &[]), self.parse_number(Value::Str("0.00135".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200".into()), &[]), self.parse_number(Value::Str("0.00125".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500".into()), &[]), self.parse_number(Value::Str("0.00115".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1250".into()), &[]), self.parse_number(Value::Str("0.00105".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500".into()), &[]), self.parse_number(Value::Str("0.00095".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3000".into()), &[]), self.parse_number(Value::Str("0.00085".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6000".into()), &[]), self.parse_number(Value::Str("0.00075".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("11000".into()), &[]), self.parse_number(Value::Str("0.00065".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000".into()), &[]), self.parse_number(Value::Str("0.00055".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("40000".into()), &[]), self.parse_number(Value::Str("0.00055".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75000".into()), &[]), self.parse_number(Value::Str("0.00055".into()), &[])])]));
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1.5".into()), &[]), self.parse_number(Value::Str("0.00195".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3".into()), &[]), self.parse_number(Value::Str("0.00185".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6".into()), &[]), self.parse_number(Value::Str("0.00175".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("12.5".into()), &[]), self.parse_number(Value::Str("0.00165".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25".into()), &[]), self.parse_number(Value::Str("0.00155".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75".into()), &[]), self.parse_number(Value::Str("0.00145".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200".into()), &[]), self.parse_number(Value::Str("0.00135".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500".into()), &[]), self.parse_number(Value::Str("0.00125".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1250".into()), &[]), self.parse_number(Value::Str("0.00115".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500".into()), &[]), self.parse_number(Value::Str("0.00105".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3000".into()), &[]), self.parse_number(Value::Str("0.00095".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6000".into()), &[]), self.parse_number(Value::Str("0.00085".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("11000".into()), &[]), self.parse_number(Value::Str("0.00075".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000".into()), &[]), self.parse_number(Value::Str("0.00065".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("40000".into()), &[]), self.parse_number(Value::Str("0.00065".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75000".into()), &[]), self.parse_number(Value::Str("0.00065".into()), &[])])]));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("feeSide".to_string(), Value::Str("base".into()));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0005".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.0000".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1.5".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("12.5".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1250".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500".into()), &[]), self.parse_number(Value::Str("-0.00005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3000".into()), &[]), self.parse_number(Value::Str("-0.00008".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6000".into()), &[]), self.parse_number(Value::Str("-0.01000".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("11000".into()), &[]), self.parse_number(Value::Str("-0.01002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000".into()), &[]), self.parse_number(Value::Str("-0.01005".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("40000".into()), &[]), self.parse_number(Value::Str("-0.02000".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75000".into()), &[]), self.parse_number(Value::Str("-0.02005".into()), &[])])]));
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.00050".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1.5".into()), &[]), self.parse_number(Value::Str("0.00048".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3".into()), &[]), self.parse_number(Value::Str("0.00046".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6".into()), &[]), self.parse_number(Value::Str("0.00044".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("12.5".into()), &[]), self.parse_number(Value::Str("0.00042".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25".into()), &[]), self.parse_number(Value::Str("0.00040".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75".into()), &[]), self.parse_number(Value::Str("0.00038".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200".into()), &[]), self.parse_number(Value::Str("0.00036".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500".into()), &[]), self.parse_number(Value::Str("0.00034".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1250".into()), &[]), self.parse_number(Value::Str("0.00032".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("3000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("6000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("11000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("40000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("75000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])])]));
m
}));
m
}));
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("INVALID_PARAM_VALUE".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("INVALID_PROTOCOL".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("INVALID_ARGUMENT".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("INVALID_REQUEST_BODY".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("MISSING_REQUIRED_PARAM".to_string(), Value::Str("ArgumentsRequired".into()).clone());
m.insert("BAD_REQUEST".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("INVALID_CONTENT_TYPE".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("NOT_ACCEPTABLE".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("METHOD_NOT_ALLOWED".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("NOT_FOUND".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("AUTHENTICATION_FAILED".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("INVALID_CREDENTIALS".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("INVALID_KEY".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("IP_FORBIDDEN".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("READ_ONLY".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("INVALID_SIGNATURE".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("MISSING_REQUIRED_HEADER".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("REQUEST_EXPIRED".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("ACCOUNT_LOCKED".to_string(), Value::Str("AccountSuspended".into()).clone());
m.insert("FORBIDDEN".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("SUB_ACCOUNT_NOT_FOUND".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("SUB_ACCOUNT_LOCKED".to_string(), Value::Str("AccountSuspended".into()).clone());
m.insert("MARGIN_BALANCE_EXCEPTION".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("MARGIN_TRANSFER_FAILED".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("TOO_MUCH_FUTURES_AVAILABLE".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("FUTURES_BALANCE_NOT_ENOUGH".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("ACCOUNT_EXCEPTION".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("SUB_ACCOUNT_TRANSFER_FAILED".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("ADDRESS_NOT_USED".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("TOO_FAST".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("WITHDRAWAL_OVER_LIMIT".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("API_WITHDRAW_DISABLED".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("INVALID_WITHDRAW_ID".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("INVALID_WITHDRAW_CANCEL_STATUS".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("INVALID_PRECISION".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("INVALID_CURRENCY".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("INVALID_CURRENCY_PAIR".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("POC_FILL_IMMEDIATELY".to_string(), Value::Str("OrderImmediatelyFillable".into()).clone());
m.insert("ORDER_NOT_FOUND".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("CLIENT_ID_NOT_FOUND".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("ORDER_CLOSED".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_CANCELLED".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("QUANTITY_NOT_ENOUGH".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("BALANCE_NOT_ENOUGH".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("MARGIN_NOT_SUPPORTED".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("MARGIN_BALANCE_NOT_ENOUGH".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("AMOUNT_TOO_LITTLE".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("AMOUNT_TOO_MUCH".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("REPEATED_CREATION".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("LOAN_NOT_FOUND".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("LOAN_RECORD_NOT_FOUND".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("NO_MATCHED_LOAN".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("NOT_MERGEABLE".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("REPAY_TOO_MUCH".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("TOO_MANY_CURRENCY_PAIRS".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("TOO_MANY_ORDERS".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("TOO_MANY_REQUESTS".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("MIXED_ACCOUNT_TYPE".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("AUTO_BORROW_TOO_MUCH".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("TRADE_RESTRICTED".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("USER_NOT_FOUND".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("CONTRACT_NO_COUNTER".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("CONTRACT_NOT_FOUND".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("RISK_LIMIT_EXCEEDED".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("INSUFFICIENT_AVAILABLE".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("LIQUIDATE_IMMEDIATELY".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("LEVERAGE_TOO_HIGH".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("LEVERAGE_TOO_LOW".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_NOT_OWNED".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("ORDER_FINISHED".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("POSITION_CROSS_MARGIN".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("POSITION_IN_LIQUIDATION".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("POSITION_IN_CLOSE".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("POSITION_EMPTY".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("REMOVE_TOO_MUCH".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("RISK_LIMIT_NOT_MULTIPLE".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("RISK_LIMIT_TOO_HIGH".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("RISK_LIMIT_TOO_lOW".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("PRICE_TOO_DEVIATED".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("SIZE_TOO_LARGE".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("SIZE_TOO_SMALL".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("PRICE_OVER_LIQUIDATION".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("PRICE_OVER_BANKRUPT".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("ORDER_POC_IMMEDIATE".to_string(), Value::Str("OrderImmediatelyFillable".into()).clone());
m.insert("INCREASE_POSITION".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("CONTRACT_IN_DELISTING".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("INTERNAL".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("SERVER_ERROR".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("TOO_BUSY".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("CROSS_ACCOUNT_NOT_FOUND".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("RISK_LIMIT_TOO_LOW".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("AUTO_TRIGGER_PRICE_LESS_LAST".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("AUTO_TRIGGER_PRICE_GREATE_LAST".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("POSITION_HOLDING".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("USER_LOAN_EXCEEDED".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("NO_CHANGE".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("PRICE_THRESHOLD_EXCEEDED".to_string(), Value::Str("InvalidOrder".into()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Your order size".to_string(), Value::Str("InvalidOrder".into()).clone());
m
}));
m
}));
m.insert("rollingWindowSize".to_string(), Value::Int(5000));
m
})]);
Value::Null
}
pub fn set_sandbox_mode(&mut self, mut enable: Value) {
self.super_set_sandbox_mode(enable.clone());
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("sandboxMode".into(), enable); }
}
/*
* @method
* @name gate#loadUnifiedStatus
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @description returns unifiedAccount so the user can check if the unified account is enabled
* @see https://www.gate.com/docs/developers/apiv4/#retrieve-user-account-information
* @returns {boolean} true or false if the enabled unified account is enabled or not and sets the unifiedAccount option if it is undefined
*/
pub async fn load_unified_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut unifiedAccount: Value = self.safe_bool_k(self.options.clone(), "unifiedAccount", &[]);
if (unifiedAccount == Value::Null) {
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
//
// {
// "user_id": 10406147,
// "ip_whitelist": [],
// "currency_pairs": [],
// "key": {
// "mode": 1
// },
// "tier": 0,
// "tier_expire_time": "0001-01-01T00:00:00Z",
// "copy_trading_role": 0
// }
//
let mut response: Value = self.private_account_get_detail(&[params]).await;
let mut result: Value = self.safe_dict_k(response, "key", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = Value::Bool(self.safe_integer_k(result, "mode", &[]).as_f64() == Some(2.0)); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("unifiedAccount".into(), __be_tmp); } }
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
// if the request fails, the unifiedAccount is disabled
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("unifiedAccount".into(), Value::Bool(false)); }
}
}
return self.options.as_map().and_then(|__m| __m.get("unifiedAccount")).cloned().unwrap_or(Value::Null);
Value::Null
}
pub async fn upgrade_unified_trade_account(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.private_unified_put_unified_mode(&[params]).await;
Value::Null
}
/*
* @method
* @name gate#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://www.gate.com/docs/developers/apiv4/#get-server-current-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_spot_get_time(&[params]).await;
return self.safe_integer_k(response, "server_time", &[]);
Value::Null
}
pub fn create_expired_option_market(&self, mut symbol: Value) -> Value {
// support expired option contracts
let mut quote: Value = Value::Str("USDT".into());
let mut settle: Value = quote.clone();
let mut optionParts: Value = split(&symbol, &Value::Str("-".into()));
let mut symbolBase: Value = split(&symbol, &Value::Str("/".into()));
let mut marketIdBase: Value = split(&symbol, &Value::Str("_".into()));
let mut base: Value = Value::Null;
let mut expiry: Value = self.safe_string(optionParts.clone(), Value::Int(1), &[]);
if Value::Int(symbol.as_str().and_then(|__s| __s.find("/")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) > ((-1i64) as f64) {
base = self.safe_string(symbolBase, Value::Int(0), &[]);
} else {
base = self.safe_string(marketIdBase, Value::Int(0), &[]);
expiry = expiry.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(2); let __j = __l.min(8); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null); // convert 20230728 to 230728
}
let mut strike: Value = self.safe_string(optionParts.clone(), Value::Int(2), &[]);
let mut optionType: Value = self.safe_string(optionParts, Value::Int(3), &[]);
let mut datetime: Value = self.convert_expire_date(expiry.clone());
let mut timestamp: Value = self.parse8601(datetime.clone());
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("_".into())).into()), quote).into()), Value::Str("-".into())).into()), Value::Str("20".into())).into()), expiry).into()), Value::Str("-".into())).into()), strike).into()), Value::Str("-".into())).into()), optionType).into()));
m.insert("symbol".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), settle).into()), Value::Str("-".into())).into()), expiry).into()), Value::Str("-".into())).into()), strike).into()), Value::Str("-".into())).into()), optionType).into()));
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(), base);
m.insert("quoteId".to_string(), quote);
m.insert("settleId".to_string(), settle);
m.insert("active".to_string(), Value::Bool(false));
m.insert("type".to_string(), Value::Str("option".into()));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("expiry".to_string(), timestamp);
m.insert("expiryDatetime".to_string(), datetime);
m.insert("optionType".to_string(), (if (optionType.as_str() == Some("C")) { Value::Str("call".into()) } else { Value::Str("put".into()) }));
m.insert("strike".to_string(), self.parse_number(strike, &[]));
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("price".to_string(), Value::Null);
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("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("info".to_string(), Value::Null);
m
});
Value::Null
}
pub fn safe_market(&self, optional_args: &[Value]) -> Value {
let mut marketId = get_arg(optional_args, 0, Value::Null);
let mut market = get_arg(optional_args, 1, Value::Null);
let mut delimiter = get_arg(optional_args, 2, Value::Null);
let mut marketType = get_arg(optional_args, 3, Value::Null);
let mut isOption: bool = (marketId != Value::Null) && ((Value::Int(marketId.as_str().and_then(|__s| __s.find("-C")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) > ((-1i64) as f64)) || (Value::Int(marketId.as_str().and_then(|__s| __s.find("-P")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) > ((-1i64) as f64)));
if isOption && ((self.markets_by_id.clone() == Value::Null) || !(in_op(&self.markets_by_id, &marketId))) {
return self.create_expired_option_market(marketId.clone());
}
return self.super_safe_market(marketId, market, delimiter, marketType);
Value::Null
}
/*
* @method
* @name gate#fetchMarkets
* @description retrieves data on all markets for gate
* @see https://www.gate.com/docs/developers/apiv4/#query-all-supported-currency-pairs // spot
* @see https://www.gate.com/docs/developers/apiv4/en/#list-all-supported-currency-pairs-supported-in-margin-trading // margin
* @see https://www.gate.com/docs/developers/apiv4/en/#query-all-futures-contracts // swap
* @see https://www.gate.com/docs/developers/apiv4/en/#query-all-futures-contracts-2 // future
* @see https://www.gate.com/docs/developers/apiv4/en/#list-all-contracts-for-specified-underlying-and-expiration-date // option
* @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
}));
if matches!(self.safe_bool_k(self.options.clone(), "adjustForTimeDifference", &[Value::Bool(false)]), Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
if self.check_required_credentials(&[Value::Bool(false)]).as_bool() == Some(true) {
self.load_unified_status(&[]).await;
}
let mut rawPromises: Value = Value::from(vec![]);
let mut fetchMarketsOptions: Value = self.safe_dict_k(self.options.clone(), "fetchMarkets", &[]);
let mut types: Value = self.safe_list_k(fetchMarketsOptions, "types", &[Value::from(vec![Value::Str("spot".into()), Value::Str("swap".into()), Value::Str("future".into()), Value::Str("option".into())])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_679: bool = true;
while { if !__for_first_679 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_679 = false; i.as_f64().unwrap_or(f64::NAN) < ((types.len() as i64) as f64) } {
let mut marketType: Option<String> = self.safe_string(types.clone(), i.clone(), &[]).as_str().map(str::to_owned);
if (marketType.as_deref() == Some("spot")) {
// if (!sandboxMode) {
// gate doesn't have a sandbox for spot markets
append_to_array(&mut rawPromises, self.fetch_spot_markets(&[params.clone()]).await);
} else if (marketType.as_deref() == Some("swap")) {
append_to_array(&mut rawPromises, self.fetch_swap_markets(&[params.clone()]).await);
} else if (marketType.as_deref() == Some("future")) {
append_to_array(&mut rawPromises, self.fetch_future_markets(&[params.clone()]).await);
} else if (marketType.as_deref() == Some("option")) {
append_to_array(&mut rawPromises, self.fetch_option_markets(&[params.clone()]).await);
}
}
}
let mut results: Value = promise_all(&rawPromises).await;
return self.arrays_concat(results);
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 marginPromise: Value = self.public_margin_get_currency_pairs(&[params.clone()]).await;
let mut spotMarketsPromise: Value = self.public_spot_get_currency_pairs(&[params]).await;
let mut marginResponsespotMarketsResponseVariable = promise_all(&Value::from(vec![marginPromise, spotMarketsPromise])).await;
let mut marginResponse: Value = marginResponsespotMarketsResponseVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut spotMarketsResponse: Value = marginResponsespotMarketsResponseVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginMarkets: Value = self.index_by(marginResponse, Value::Str("id".into()));
//
// Spot
//
// [
// {
// "id": "QTUM_ETH",
// "base": "QTUM",
// "base_name": "Quantum",
// "quote": "ETH",
// "quote_name": "Ethereum",
// "fee": "0.2",
// "min_base_amount": "0.01",
// "min_quote_amount": "0.001",
// "max_quote_amount": "50000",
// "amount_precision": 3,
// "precision": 6,
// "trade_status": "tradable",
// "sell_start": 1607313600,
// "buy_start": 1700492400,
// "type": "normal",
// "trade_url": "https://www.gate.com/trade/QTUM_ETH",
// }
//
// Margin
//
// [
// {
// "id":"HOODON_USDT",
// "base":"HOODON",
// "quote":"USDT",
// "leverage":10,
// "min_base_amount":"0.01",
// "min_quote_amount":"1",
// "max_quote_amount":"5000",
// "status":1
// }
// ]
//
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_680: bool = true;
while { if !__for_first_680 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_680 = false; i.as_f64().unwrap_or(f64::NAN) < ((spotMarketsResponse.len() as i64) as f64) } {
let mut spotMarket: Value = self.safe_dict(spotMarketsResponse.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut id: Value = self.safe_string_k(spotMarket.clone(), "id", &[]);
let mut marginMarket: Value = self.safe_dict(marginMarkets.clone(), id.clone(), &[]);
let mut market: Value = self.deep_extend(marginMarket, &[spotMarket.clone()]);
let mut baseIdquoteIdVariable = split(&id, &Value::Str("_".into()));
let mut baseId: Value = baseIdquoteIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut quoteId: Value = baseIdquoteIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
continue;
}
let mut takerPercent: Value = self.safe_string_k(market.clone(), "fee", &[]);
let mut makerPercent: Value = self.safe_string_k(market.clone(), "maker_fee_rate", &[takerPercent.clone()]);
let mut amountPrecision: Value = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "amount_precision", &[])]), &[]);
let mut tradeStatus: Option<String> = self.safe_string_k(market.clone(), "trade_status", &[]).as_str().map(str::to_owned);
let mut marginStatus: Option<i64> = self.safe_integer_k(market.clone(), "status", &[Value::Int(1)]).as_i64(); // 0 disabled, 1 enabled
let mut leverage: Option<f64> = self.safe_number_k(market.clone(), "leverage", &[]).as_f64();
let mut margin: Value = Value::Bool(leverage.is_some());
let mut buyStart: Value = self.safe_integer_product_k(spotMarket.clone(), "buy_start", Value::Int(1000), &[]); // buy_start is the trading start time, while sell_start is offline orders start time
let mut createdTs: Value = (if (buyStart.as_f64() != Some(0.0)) { buyStart } else { Value::Null });
let mut active: Value = Value::Bool((tradeStatus.as_deref() == Some("tradable")) || (matches!(&margin, Value::Bool(true)) && (marginStatus == Some(1))));
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("symbol".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()));
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".into()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), margin.clone());
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active);
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&takerPercent, &Value::Str("100".into())), &[]));
m.insert("maker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&makerPercent, &Value::Str("100".into())), &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amountPrecision.clone());
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "precision", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "leverage", &[Value::Int(1)]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(spotMarket, "min_base_amount", &[amountPrecision]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "min_quote_amount", &[]));
m.insert("max".to_string(), (if matches!(&margin, Value::Bool(true)) { self.safe_number_k(market.clone(), "max_quote_amount", &[]) } else { Value::Null }));
m
}));
m
}));
m.insert("created".to_string(), createdTs);
m.insert("info".to_string(), market);
m
}));
}
}
return result;
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 result: Value = Value::from(vec![]);
let mut swapSettlementCurrencies: Value = self.get_settlement_currencies(Value::Str("swap".into()), Value::Str("fetchMarkets".into()));
if matches!(self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]), Value::Bool(true)) {
swapSettlementCurrencies = Value::from(vec![Value::Str("usdt".into())]); // gate sandbox only has usdt-margined swaps
}
{
let mut c: Value = Value::Int(0);
let mut __for_first_682: bool = true;
while { if !__for_first_682 { c = (match (&(c), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_682 = false; c.as_f64().unwrap_or(f64::NAN) < ((swapSettlementCurrencies.len() as i64) as f64) } {
let mut settleId: Value = swapSettlementCurrencies.as_array().and_then(|__arr| match &c { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settle".to_string(), settleId.clone());
m
});
let __ws_arg_0 = self.extend(request, &[params.clone()]);
let mut response: Value = self.public_futures_get_settle_contracts(&[__ws_arg_0]).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_681: bool = true;
while { if !__for_first_681 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_681 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut contract: Value = self.safe_dict(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut parsedMarket: Value = self.parse_contract_market(contract, settleId.clone());
if (parsedMarket != Value::Null) {
append_to_array(&mut result, parsedMarket);
}
}
}
}
}
return result;
Value::Null
}
pub async fn fetch_future_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if matches!(self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]), Value::Bool(true)) {
return Value::from(vec![]);
}
let mut result: Value = Value::from(vec![]);
let mut futureSettlementCurrencies: Value = self.get_settlement_currencies(Value::Str("future".into()), Value::Str("fetchMarkets".into()));
{
let mut c: Value = Value::Int(0);
let mut __for_first_684: bool = true;
while { if !__for_first_684 { c = (match (&(c), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_684 = false; c.as_f64().unwrap_or(f64::NAN) < ((futureSettlementCurrencies.len() as i64) as f64) } {
let mut settleId: Value = futureSettlementCurrencies.as_array().and_then(|__arr| match &c { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settle".to_string(), settleId.clone());
m
});
let __ws_arg_1 = self.extend(request, &[params.clone()]);
let mut response: Value = self.public_delivery_get_settle_contracts(&[__ws_arg_1]).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_683: bool = true;
while { if !__for_first_683 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_683 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut contract: Value = self.safe_dict(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut parsedMarket: Value = self.parse_contract_market(contract, settleId.clone());
if (parsedMarket != Value::Null) {
append_to_array(&mut result, parsedMarket);
}
}
}
}
}
return result;
Value::Null
}
pub fn parse_contract_market(&self, mut market: Value, mut settleId: Value) -> Value {
//
// Perpetual swap
//
// {
// "funding_rate_indicative":"-0.003216",
// "mark_price_round":"0.0001",
// "funding_offset":0,
// "in_delisting":false,
// "risk_limit_base":"5000",
// "interest_rate":"0.0003",
// "index_price":"0.2077",
// "order_price_round":"0.0001",
// "order_size_min":1,
// "enable_decimal":false,
// "ref_rebate_rate":"0.2",
// "name":"0G_USDT",
// "ref_discount_rate":"0",
// "order_price_deviate":"0.15",
// "maintenance_rate":"0.01",
// "mark_type":"index",
// "funding_interval":28800,
// "type":"direct",
// "risk_limit_step":"2495000",
// "enable_bonus":true,
// "enable_credit":true,
// "leverage_min":"1",
// "funding_rate":"-0.003216",
// "last_price":"0.2048",
// "mark_price":"0.2048",
// "order_size_max":450000,
// "funding_next_apply":1784131200,
// "short_users":157,
// "config_change_time":1782119113,
// "create_time":1758124392,
// "trade_size":767606392,
// "position_size":783779,
// "long_users":191,
// "quanto_multiplier":"1",
// "funding_impact_value":"7000",
// "leverage_max":"50",
// "cross_leverage_default":"10",
// "risk_limit_max":"2500000",
// "maker_fee_rate":"-0.0001", // not actual value for regular users
// "taker_fee_rate":"0.00075", // not actual value for regular users
// "orders_limit":100,
// "trade_id":10376084,
// "orderbook_id":1203922859,
// "funding_cap_ratio":"1",
// "voucher_leverage":"0",
// "is_pre_market":false,
// "status":"trading", // or "suspend"
// "launch_time":1758124392,
// "enable_circuit_breaker":false,
// "funding_rate_limit":"0.02",
// "market_order_slip_ratio":"0.04",
// "market_order_size_max":"300000",
// "contract_type":""
// }
//
// Delivery Futures
//
// {
// "name": "BTC_USDT_20200814",
// "underlying": "BTC_USDT",
// "cycle": "WEEKLY",
// "type": "direct",
// "quanto_multiplier": "0.0001",
// "mark_type": "index",
// "last_price": "9017",
// "mark_price": "9019",
// "index_price": "9005.3",
// "basis_rate": "0.185095",
// "basis_value": "13.7",
// "basis_impact_value": "100000",
// "settle_price": "0",
// "settle_price_interval": 60,
// "settle_price_duration": 1800,
// "settle_fee_rate": "0.0015",
// "expire_time": 1593763200,
// "order_price_round": "0.1",
// "mark_price_round": "0.1",
// "leverage_min": "1",
// "leverage_max": "100",
// "maintenance_rate": "1000000",
// "risk_limit_base": "140.726652109199",
// "risk_limit_step": "1000000",
// "risk_limit_max": "8000000",
// "maker_fee_rate": "-0.00025", // not actual value for regular users
// "taker_fee_rate": "0.00075", // not actual value for regular users
// "ref_discount_rate": "0",
// "ref_rebate_rate": "0.2",
// "order_price_deviate": "0.5",
// "order_size_min": 1,
// "order_size_max": 1000000,
// "orders_limit": 50,
// "orderbook_id": 63,
// "trade_id": 26,
// "trade_size": 435,
// "position_size": 130,
// "config_change_time": 1593158867,
// "in_delisting": false
// }
//
let mut id: Value = self.safe_string_k(market.clone(), "name", &[]);
let mut parts: Value = split(&id, &Value::Str("_".into()));
let mut baseId: Value = self.safe_string(parts.clone(), Value::Int(0), &[]);
let mut quoteId: Value = self.safe_string(parts.clone(), Value::Int(1), &[]);
let mut date: Option<String> = self.safe_string(parts, Value::Int(2), &[]).as_str().map(str::to_owned);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut expiry: Value = self.safe_timestamp_k(market.clone(), "expire_time", &[]);
let mut symbol: Value = Value::Str("".into());
let mut marketType: Value = Value::Str("swap".into());
if (date.is_some()) {
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), settle).into()), Value::Str("-".into())).into()), self.yymmdd(expiry.clone(), &[Value::Str("".into())])).into());
marketType = Value::Str("future".into());
} else {
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), Value::Str(":".into())).into()), settle).into());
}
let mut priceDeviate: Value = self.safe_string_k(market.clone(), "order_price_deviate", &[]);
let mut markPrice: Value = self.safe_string_k(market.clone(), "mark_price", &[]);
let mut minMultiplier: Value = crate::precise::Precise::stringSub(&Value::Str("1".into()), &priceDeviate);
let mut maxMultiplier: Value = crate::precise::Precise::stringAdd(&Value::Str("1".into()), &priceDeviate);
let mut minPrice: Value = crate::precise::Precise::stringMul(&minMultiplier, &markPrice);
let mut maxPrice: Value = crate::precise::Precise::stringMul(&maxMultiplier, &markPrice);
let mut isLinear: Value = Value::Bool(quote.as_str() == settle.as_str());
let mut contractSize: Value = self.safe_string_k(market.clone(), "quanto_multiplier", &[]);
// exception only for one market: https://api.gateio.ws/api/v4/futures/btc/contracts
if (contractSize.as_str() == Some("0")) {
contractSize = Value::Str("1".into()); // 1 USD in WEB: https://i.imgur.com/MBBUI04.png
}
let mut status: Option<String> = self.safe_string_k(market.clone(), "status", &[Value::Str("trading".into())]).as_str().map(str::to_owned); // or "suspend"
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), settle);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), marketType.clone());
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(marketType.as_str() == Some("swap")));
m.insert("future".to_string(), Value::Bool(marketType.as_str() == Some("future")));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool(status.as_deref() == Some("trading")));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), isLinear.clone());
m.insert("inverse".to_string(), Value::Bool(!(matches!(&isLinear, Value::Bool(true)))));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0005".into()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".into()), &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSize, &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "order_price_round", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "leverage_min", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "leverage_max", &[]));
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(), "order_size_min", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "order_size_max", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minPrice, &[]));
m.insert("max".to_string(), self.parse_number(maxPrice, &[]));
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(), self.safe_integer_product_k(market.clone(), "create_time", Value::Int(1000), &[]));
m.insert("info".to_string(), market);
m
});
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 result: Value = Value::from(vec![]);
let mut underlyings: Value = self.fetch_option_underlyings().await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_686: bool = true;
while { if !__for_first_686 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_686 = false; i.as_f64().unwrap_or(f64::NAN) < ((underlyings.len() as i64) as f64) } {
let mut underlying: Value = underlyings.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut query: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[params.clone()]);
add_element_to_object(&mut query, &Value::Str("underlying".into()), underlying.clone());
let mut response: Value = self.public_options_get_contracts(&[query]).await;
{
let mut j: Value = Value::Int(0);
let mut __for_first_685: bool = true;
while { if !__for_first_685 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_685 = false; j.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut market: Value = self.safe_dict(response.clone(), j.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut id: Value = self.safe_string_k(market.clone(), "name", &[]);
let mut parts: Value = split(&underlying, &Value::Str("_".into()));
let mut baseId: Value = self.safe_string(parts.clone(), Value::Int(0), &[]);
let mut quoteId: Value = self.safe_string(parts, Value::Int(1), &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
continue;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut expiry: Value = self.safe_timestamp_k(market.clone(), "expiration_time", &[]);
let mut strike: Value = self.safe_string_k(market.clone(), "strike_price", &[]);
let mut isCall: Value = self.safe_bool_k(market.clone(), "is_call", &[]);
let mut optionLetter: Value = Value::Str("P".into());
if (isCall.as_bool() == Some(true)) {
optionLetter = Value::Str("C".into());
}
let mut optionType: Value = Value::Str("put".into());
if (isCall.as_bool() == Some(true)) {
optionType = Value::Str("call".into());
}
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), quote).into()), Value::Str("-".into())).into()), self.yymmdd(expiry.clone(), &[])).into()), Value::Str("-".into())).into()), strike).into()), Value::Str("-".into())).into()), optionLetter).into());
let mut priceDeviate: Value = self.safe_string_k(market.clone(), "order_price_deviate", &[]);
let mut markPrice: Value = self.safe_string_k(market.clone(), "mark_price", &[]);
let mut minMultiplier: Value = crate::precise::Precise::stringSub(&Value::Str("1".into()), &priceDeviate);
let mut maxMultiplier: Value = crate::precise::Precise::stringAdd(&Value::Str("1".into()), &priceDeviate);
let mut minPrice: Value = crate::precise::Precise::stringMul(&minMultiplier, &markPrice);
let mut maxPrice: Value = crate::precise::Precise::stringMul(&maxMultiplier, &markPrice);
let mut createdTs: Value = self.safe_timestamp_k(market.clone(), "create_time", &[]);
if (createdTs.as_f64() == Some(0.0)) {
createdTs = Value::Null;
}
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), quote);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), quoteId);
m.insert("type".to_string(), Value::Str("option".into()));
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(true));
m.insert("active".to_string(), Value::Bool(true));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), Value::Bool(true));
m.insert("inverse".to_string(), Value::Bool(false));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0003".into()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0003".into()), &[]));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry));
m.insert("strike".to_string(), self.parse_number(strike, &[]));
m.insert("optionType".to_string(), optionType);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(Value::Str("1".into()), &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "order_price_round", &[]));
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(), "order_size_min", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "order_size_max", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minPrice, &[]));
m.insert("max".to_string(), self.parse_number(maxPrice, &[]));
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(), createdTs);
m.insert("info".to_string(), market);
m
}));
}
}
}
}
return result;
Value::Null
}
pub async fn fetch_option_underlyings(&mut self) -> Value {
let mut underlyingsResponse: Value = self.public_options_get_underlyings(&[]).await;
//
// [
// {
// "index_time": "1646915796",
// "name": "BTC_USDT",
// "index_price": "39142.73"
// }
// ]
//
let mut underlyings: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_687: bool = true;
while { if !__for_first_687 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_687 = false; i.as_f64().unwrap_or(f64::NAN) < ((underlyingsResponse.len() as i64) as f64) } {
let mut underlying: Value = self.safe_dict(underlyingsResponse.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut name: Value = self.safe_string_k(underlying, "name", &[]);
if (name != Value::Null) {
append_to_array(&mut underlyings, name);
}
}
}
return underlyings;
Value::Null
}
pub fn prepare_request(&self, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut type_var = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @ignore
* @method
* @name gate#prepareRequest
* @description Fills request params contract, settle, currency_pair, market and account where applicable
* @param {object} market CCXT market, required when type is undefined
* @param {string} type 'spot', 'swap', or 'future', required when market is undefined
* @param {object} [params] request parameters
* @returns the api request object, and the new params object with non-needed parameters removed
*/
// * Do not call for multi spot order methods like cancelAllOrders and fetchOpenOrders. Use multiOrderSpotPrepareRequest instead
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (market != Value::Null) {
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("contract".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("settle".into(), market.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null)); }
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
} else {
let mut swap: bool = type_var.as_str() == Some("swap");
let mut future: bool = type_var.as_str() == Some("future");
if swap || future {
let mut defaultSettle: Value = Value::Str("btc".into());
if swap {
defaultSettle = Value::Str("usdt".into());
}
let mut settle: Value = self.safe_string_lower_k(params.clone(), "settle", &[defaultSettle]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("settle".into(), settle); }
return Value::from(vec![request.clone(), self.omit(params.clone(), Value::Str("settle".into()), &[])]);
}
}
return Value::from(vec![request, params]);
Value::Null
}
pub fn spot_order_prepare_request(&self, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut trigger = get_arg(optional_args, 1, Value::Bool(false));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @ignore
* @method
* @name gate#multiOrderSpotPrepareRequest
* @description Fills request params currency_pair, market and account where applicable for spot order methods like fetchOpenOrders, cancelAllOrders
* @param {object} market CCXT market
* @param {bool} trigger true if for a trigger order
* @param {object} [params] request parameters
* @returns the api request object, and the new params object with non-needed parameters removed
*/
let mut marginModequeryVariable = self.get_margin_mode(trigger.clone(), params.clone());
let mut marginMode: Value = marginModequeryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = marginModequeryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_true(&trigger) {
if (market == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" spotOrderPrepareRequest() requires a market argument for non-trigger orders".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("account".into(), marginMode); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }; // Should always be set for non-trigger
}
return Value::from(vec![request, query]);
Value::Null
}
pub fn multi_order_spot_prepare_request(&self, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut trigger = get_arg(optional_args, 1, Value::Bool(false));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
/*
* @ignore
* @method
* @name gate#multiOrderSpotPrepareRequest
* @description Fills request params currency_pair, market and account where applicable for spot order methods like fetchOpenOrders, cancelAllOrders
* @param {object} market CCXT market
* @param {bool} trigger true if for a trigger order
* @param {object} [params] request parameters
* @returns the api request object, and the new params object with non-needed parameters removed
*/
let mut marginModequeryVariable = self.get_margin_mode(trigger.clone(), params.clone());
let mut marginMode: Value = marginModequeryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = marginModequeryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account".to_string(), marginMode);
m
});
if (market != Value::Null) {
if is_true(&trigger) {
// gate spot and margin trigger orders use the term market instead of currency_pair, and normal instead of spot. Neither parameter is used when fetching/cancelling a single order. They are used for creating a single trigger order, but createOrder does not call this method
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("market".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
}
return Value::from(vec![request, query]);
Value::Null
}
pub fn get_margin_mode(&self, mut trigger: Value, mut params: Value) -> Value {
/*
* @ignore
* @method
* @name gate#getMarginMode
* @description Gets the margin type for this api call
* @param {bool} trigger True if for a trigger order
* @param {object} [params] Request params
* @returns The marginMode and the updated request params with marginMode removed, marginMode value is the value that can be read by the "account" property specified in gates api docs
*/
let mut defaultMarginMode: Value = self.safe_string_lower2(self.options.clone(), Value::Str("defaultMarginMode".into()), Value::Str("marginMode".into()), &[Value::Str("spot".into())]); // 'margin' is isolated margin on gate's api
let mut marginMode: Value = self.safe_string_lower2(params.clone(), Value::Str("marginMode".into()), Value::Str("account".into()), &[defaultMarginMode]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("marginMode".into()), Value::Str("account".into())]), &[]);
if (marginMode.as_str() == Some("cross")) {
marginMode = Value::Str("cross_margin".into());
} else if (marginMode.as_str() == Some("isolated")) {
marginMode = Value::Str("margin".into());
} else if (marginMode.as_str() == Some("")) {
marginMode = Value::Str("spot".into());
}
if (trigger.as_bool() == Some(true)) {
if (marginMode.as_str() == Some("spot")) {
// gate spot trigger orders use the term normal instead of spot
marginMode = Value::Str("normal".into());
}
if (marginMode.as_str() == Some("cross_margin")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" getMarginMode() does not support trigger orders for cross margin".into()))));
}
}
let mut isUnifiedAccountparamsUnifiedAccountVariable = self.handle_option_bool_and_params(paramsOmitted, Value::Str("getMarginMode".into()), Value::Str("unifiedAccount".into()), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&isUnifiedAccount) {
marginMode = Value::Str("unified".into());
}
return Value::from(vec![marginMode, paramsUnifiedAccount]);
Value::Null
}
pub fn get_settlement_currencies(&self, mut type_var: Value, mut method: Value) -> Value {
let mut options: Value = self.safe_dict(self.options.clone(), type_var.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]); // [ 'BTC', 'USDT' ] unified codes
let mut fetchMarketsContractOptions: Value = self.safe_dict(options, method, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultSettle: Value = (if (type_var.as_str() == Some("swap")) { Value::from(vec![Value::Str("usdt".into())]) } else { Value::from(vec![Value::Str("btc".into())]) });
return self.safe_list_k(fetchMarketsContractOptions, "settlementCurrencies", &[defaultSettle]);
Value::Null
}
/*
* @method
* @name gate#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://www.gate.com/docs/developers/apiv4/en/#query-all-currency-information
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// sandbox/testnet only supports future markets
let mut apiBackup: Value = self.safe_dict_k(self.urls.clone(), "apiBackup", &[]);
if (apiBackup != Value::Null) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut response: Value = self.public_spot_get_currencies(&[params]).await;
return self.parse_currencies(response);
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(), &[]);
// check leveraged tokens (e.g. BTC3S, ETH5L)
let mut type_var: Value = Value::Str("crypto".into());
if self.is_leveraged_currency(currencyId.clone(), &[]).as_bool() == Some(true) {
type_var = Value::Str("leveraged".into());
}
let mut chains: Value = self.safe_list_k(rawCurrency.clone(), "chains", &[Value::from(vec![])]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_688: bool = true;
while { if !__for_first_688 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_688 = false; j.as_f64().unwrap_or(f64::NAN) < ((chains.len() as i64) as f64) } {
let mut chain: Value = chains.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.safe_string_k(chain.clone(), "name", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut networks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), networkId);
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool(!is_true(&self.safe_bool_k(chain.clone(), "deposit_disabled", &[Value::Bool(false)]))));
m.insert("withdraw".to_string(), Value::Bool(!is_true(&self.safe_bool_k(chain, "withdraw_disabled", &[Value::Bool(false)]))));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".into()), &[]));
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
})); }
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId);
m.insert("code".to_string(), code);
m.insert("name".to_string(), self.safe_string_k(rawCurrency.clone(), "name", &[]));
m.insert("type".to_string(), type_var);
m.insert("active".to_string(), Value::Bool(!is_true(&self.safe_bool_k(rawCurrency.clone(), "delisted", &[Value::Bool(false)]))));
m.insert("deposit".to_string(), Value::Bool(!is_true(&self.safe_bool_k(rawCurrency.clone(), "deposit_disabled", &[Value::Bool(false)]))));
m.insert("withdraw".to_string(), Value::Bool(!is_true(&self.safe_bool_k(rawCurrency.clone(), "withdraw_disabled", &[Value::Bool(false)]))));
m.insert("fee".to_string(), Value::Null);
m.insert("networks".to_string(), networks);
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".into()), &[]));
m.insert("info".to_string(), rawCurrency);
m
}));
Value::Null
}
/*
* @method
* @name gate#fetchFundingRate
* @description fetch the current funding rate
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-contract-information
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRate() supports swap contracts only".into()))));
}
let mut requestqueryVariable = self.prepare_request(&[market, Value::Null, params]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_2 = self.extend(request, &[query]);
let mut response: Value = self.public_futures_get_settle_contracts_contract(&[__ws_arg_2]).await;
return self.parse_funding_rate(response, &[]);
Value::Null
}
/*
* @method
* @name gate#fetchFundingRates
* @description fetch the funding rate for multiple markets
* @see https://www.gate.com/docs/developers/apiv4/en/#query-all-futures-contracts
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rates-structure}, indexed by market symbols
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut market: Value = Value::Null;
if (symbolsNormalized != Value::Null) {
let mut firstSymbol: Value = self.safe_string(symbolsNormalized.clone(), Value::Int(0), &[]);
market = self.market(firstSymbol);
}
let mut requestqueryVariable = self.prepare_request(&[market, Value::Str("swap".into()), params]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_3 = self.extend(request, &[query]);
let mut response: Value = self.public_futures_get_settle_contracts(&[__ws_arg_3]).await;
return self.parse_funding_rates(response, &[symbolsNormalized]);
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);
//
// {
// "name": "BTC_USDT",
// "type": "direct",
// "quanto_multiplier": "0.0001",
// "ref_discount_rate": "0",
// "order_price_deviate": "0.5",
// "maintenance_rate": "0.005",
// "mark_type": "index",
// "last_price": "38026",
// "mark_price": "37985.6",
// "index_price": "37954.92",
// "funding_rate_indicative": "0.000219",
// "mark_price_round": "0.01",
// "funding_offset": 0,
// "in_delisting": false,
// "risk_limit_base": "1000000",
// "interest_rate": "0.0003",
// "order_price_round": "0.1",
// "order_size_min": 1,
// "ref_rebate_rate": "0.2",
// "funding_interval": 28800,
// "risk_limit_step": "1000000",
// "leverage_min": "1",
// "leverage_max": "100",
// "risk_limit_max": "8000000",
// "maker_fee_rate": "-0.00025",
// "taker_fee_rate": "0.00075",
// "funding_rate": "0.002053",
// "order_size_max": 1000000,
// "funding_next_apply": 1610035200,
// "short_users": 977,
// "config_change_time": 1609899548,
// "trade_size": 28530850594,
// "position_size": 5223816,
// "long_users": 455,
// "funding_impact_value": "60000",
// "orders_limit": 50,
// "trade_id": 10851092,
// "orderbook_id": 2129638396
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "name", &[]);
let mut symbol: Value = self.safe_symbol(marketId, &[market, Value::Str("_".into()), Value::Str("swap".into())]);
let mut markPrice: Value = self.safe_number_k(contract.clone(), "mark_price", &[]);
let mut indexPrice: Value = self.safe_number_k(contract.clone(), "index_price", &[]);
let mut interestRate: Value = self.safe_number_k(contract.clone(), "interest_rate", &[]);
let mut fundingRate: Value = self.safe_number_k(contract.clone(), "funding_rate", &[]);
let mut fundingTime: Value = self.safe_timestamp_k(contract.clone(), "funding_next_apply", &[]);
let mut fundingRateIndicative: Value = self.safe_number_k(contract.clone(), "funding_rate_indicative", &[]);
let mut fundingInterval: Value = crate::precise::Precise::stringMul(&Value::Str("1000".into()), &self.safe_string_k(contract.clone(), "funding_interval", &[]));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract);
m.insert("symbol".to_string(), symbol);
m.insert("markPrice".to_string(), markPrice);
m.insert("indexPrice".to_string(), indexPrice);
m.insert("interestRate".to_string(), interestRate);
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(), fundingRate);
m.insert("fundingTimestamp".to_string(), fundingTime.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTime));
m.insert("nextFundingRate".to_string(), fundingRateIndicative);
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(), self.parse_funding_interval(fundingInterval).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m
});
Value::Null
}
pub fn parse_funding_interval(&self, mut interval: Value) -> Option<String> {
let mut intervals: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("3600000".to_string(), Value::Str("1h".into()));
m.insert("14400000".to_string(), Value::Str("4h".into()));
m.insert("28800000".to_string(), Value::Str("8h".into()));
m.insert("57600000".to_string(), Value::Str("16h".into()));
m.insert("86400000".to_string(), Value::Str("24h".into()));
m
});
return self.safe_string(intervals, interval.clone(), &[interval.clone()]).as_str().map(str::to_owned);
}
pub async fn fetch_network_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_4 = self.extend(request, &[params]);
let mut response: Value = self.private_wallet_get_deposit_address(&[__ws_arg_4]).await;
let mut addresses: Value = self.safe_value_k(response.clone(), "multichain_addresses", &[]);
let mut currencyId: Value = self.safe_string_k(response, "currency", &[]);
let mut codeValue: Value = self.safe_currency_code(currencyId, &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_689: bool = true;
while { if !__for_first_689 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_689 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&addresses).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = get_value(&addresses, &i);
let mut entry: Value = get_value(&addresses, &i);
//
// {
// "chain": "ETH",
// "address": "0x359a697945E79C7e17b634675BD73B33324E9408",
// "payment_id": "",
// "payment_name": "",
// "obtain_failed": "0"
// }
//
let mut obtainFailed: Option<i64> = self.safe_integer_k(entry.clone(), "obtain_failed", &[]).as_i64();
if (obtainFailed.is_some()) && (obtainFailed != Some(0)) {
continue;
}
let mut network: Value = self.safe_string_k(entry.clone(), "chain", &[]);
let mut address: Value = self.safe_string_k(entry.clone(), "address", &[]);
let mut tag: Value = self.safe_string_k(entry.clone(), "payment_id", &[]);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&network), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry);
m.insert("code".to_string(), codeValue.clone());
m.insert("currency".to_string(), codeValue.clone());
m.insert("address".to_string(), address);
m.insert("tag".to_string(), tag);
m
})); }
}
}
return result;
Value::Null
}
/*
* @method
* @name gate#fetchDepositAddressesByNetwork
* @description fetch a dictionary of addresses for a currency, indexed by network
* @see https://www.gate.com/docs/developers/apiv4/en/#generate-currency-deposit-address
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the api endpoint
* @returns {object} a dictionary of [address structures]{@link https://docs.ccxt.com/?id=address-structure} indexed by the network
*/
pub async fn fetch_deposit_addresses_by_network(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_5 = self.extend(request, &[params]);
let mut response: Value = self.private_wallet_get_deposit_address(&[__ws_arg_5]).await;
let mut chains: Value = self.safe_list_k(response.clone(), "multichain_addresses", &[Value::from(vec![])]);
let mut currencyId: Value = self.safe_string_k(response, "currency", &[]);
currency = self.safe_currency(currencyId, &[currency.clone()]);
let mut parsed: Value = self.parse_deposit_addresses(chains, &[Value::Null, Value::Bool(false)]);
return self.index_by(parsed, Value::Str("network".into()));
Value::Null
}
/*
* @method
* @name gate#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://www.gate.com/docs/developers/apiv4/en/#generate-currency-deposit-address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] unified network code (not used directly by gate.com but used by ccxt to filter the response)
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(params);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut chainsIndexedByIdRaw: Value = self.fetch_deposit_addresses_by_network(code.clone(), &[paramsNetworkCode]).await;
let mut chainsIndexedById: Value = chainsIndexedByIdRaw;
let mut selectedNetworkIdOrCode: Value = self.select_network_code_from_unified_networks(code, networkCode, chainsIndexedById.clone());
return chainsIndexedById.as_map().and_then(|__m| selectedNetworkIdOrCode.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null);
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
//
// {
// chain: "BTC",
// address: "1Nxu.......Ys",
// payment_id: "",
// payment_name: "",
// obtain_failed: "0",
// }
//
let mut address: Value = self.safe_string_k(depositAddress.clone(), "address", &[]);
self.check_address(&[address.clone()]);
let mut code: Value = (match currency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), code.clone());
m.insert("address".to_string(), address);
m.insert("tag".to_string(), self.safe_string_k(depositAddress.clone(), "payment_id", &[]));
m.insert("network".to_string(), self.network_id_to_code(&[self.safe_string_k(depositAddress, "chain", &[]), code]));
m
});
Value::Null
}
/*
* @method
* @name gate#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-fees
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_trading_fee(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency_pair".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_6 = self.extend(request, &[params]);
let mut response: Value = self.private_wallet_get_fee(&[__ws_arg_6]).await;
return self.parse_trading_fee(response, &[market]);
Value::Null
}
/*
* @method
* @name gate#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-fees
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_wallet_get_fee(&[params]).await;
return self.parse_trading_fees(response);
Value::Null
}
pub fn parse_trading_fees(&self, mut response: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut symbols: Value = self.symbols.clone();
{
let mut i: Value = Value::Int(0);
let mut __for_first_690: bool = true;
while { if !__for_first_690 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_690 = false; i.as_f64().unwrap_or(f64::NAN) < ((symbols.len() as i64) as f64) } {
let mut symbol: Value = symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(symbol.clone());
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), self.parse_trading_fee(response.clone(), &[market])); }
}
}
return result;
Value::Null
}
pub fn parse_trading_fee(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "user_id": 1486602,
// "taker_fee": "0.002",
// "maker_fee": "0.002",
// "gt_discount": true,
// "gt_taker_fee": "0.0015",
// "gt_maker_fee": "0.0015",
// "loan_fee": "0.18",
// "point_type": "0",
// "futures_taker_fee": "0.0005",
// "futures_maker_fee": "0"
// }
//
let mut gtDiscount: Value = self.safe_bool_k(info.clone(), "gt_discount", &[]);
let mut taker: Value = Value::Str("taker_fee".into());
if (gtDiscount.as_bool() == Some(true)) {
taker = Value::Str("gt_taker_fee".into());
}
let mut maker: Value = Value::Str("maker_fee".into());
if (gtDiscount.as_bool() == Some(true)) {
maker = Value::Str("gt_maker_fee".into());
}
let mut contract: Value = self.safe_bool_k(market.clone(), "contract", &[]);
let mut takerKey: Value = taker;
if (contract.as_bool() == Some(true)) {
takerKey = Value::Str("futures_taker_fee".into());
}
let mut makerKey: Value = maker;
if (contract.as_bool() == Some(true)) {
makerKey = Value::Str("futures_maker_fee".into());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_string_k(market, "symbol", &[]));
m.insert("maker".to_string(), self.safe_number(info.clone(), makerKey, &[]));
m.insert("taker".to_string(), self.safe_number(info, takerKey, &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name gate#fetchTransactionFees
* @deprecated
* @description please use fetchDepositWithdrawFees instead
* @see https://www.gate.com/docs/developers/apiv4/en/#query-withdrawal-status
* @param {string[]|undefined} codes list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_transaction_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_wallet_get_withdraw_status(&[params]).await;
//
// {
// "currency": "MTN",
// "name": "Medicalchain",
// "name_cn": "Medicalchain",
// "deposit": "0",
// "withdraw_percent": "0%",
// "withdraw_fix": "900",
// "withdraw_day_limit": "500000",
// "withdraw_day_limit_remain": "500000",
// "withdraw_amount_mini": "900.1",
// "withdraw_eachtime_limit": "90000000000",
// "withdraw_fix_on_chains": {
// "ETH": "900"
// }
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut withdrawFees: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_692: bool = true;
while { if !__for_first_692 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_692 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
withdrawFees = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut entry: Value = self.safe_dict(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
if (codes != Value::Null) && !(self.in_array(code.clone(), codes.clone()).as_bool() == Some(true)) {
continue;
}
let mut withdrawFixOnChains: Value = self.safe_dict_k(entry.clone(), "withdraw_fix_on_chains", &[]);
if (withdrawFixOnChains == Value::Null) {
withdrawFees = self.safe_number_k(entry.clone(), "withdraw_fix", &[]);
} else {
let mut networkIds: Value = object_keys(&withdrawFixOnChains);
{
let mut j: Value = Value::Int(0);
let mut __for_first_691: bool = true;
while { if !__for_first_691 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_691 = false; j.as_f64().unwrap_or(f64::NAN) < ((networkIds.len() as i64) as f64) } {
let mut networkId: Value = networkIds.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if (networkCode != Value::Null) {
add_element_to_object(&mut withdrawFees, &networkCode, self.parse_number(withdrawFixOnChains.as_map().and_then(|__m| networkId.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), &[]));
}
}
}
}
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), withdrawFees.clone());
m.insert("deposit".to_string(), Value::Null);
m.insert("info".to_string(), entry);
m
})); }
}
}
return result;
Value::Null
}
/*
* @method
* @name gate#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees
* @see https://www.gate.com/docs/developers/apiv4/en/#query-withdrawal-status
* @param {string[]|undefined} codes list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_wallet_get_withdraw_status(&[params]).await;
return self.parse_deposit_withdraw_fees(response, &[codes, Value::Str("currency".into())]);
Value::Null
}
pub fn parse_deposit_withdraw_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "currency": "MTN",
// "name": "Medicalchain",
// "name_cn": "Medicalchain",
// "deposit": "0",
// "withdraw_percent": "0%",
// "withdraw_fix": "900",
// "withdraw_day_limit": "500000",
// "withdraw_day_limit_remain": "500000",
// "withdraw_amount_mini": "900.1",
// "withdraw_eachtime_limit": "90000000000",
// "withdraw_fix_on_chains": {
// "ETH": "900"
// }
// }
//
let mut withdrawFixOnChains: Value = self.safe_dict_k(fee.clone(), "withdraw_fix_on_chains", &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), self.safe_number_k(fee.clone(), "withdraw_fix", &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), self.safe_number_k(fee.clone(), "deposit", &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
if (withdrawFixOnChains != Value::Null) {
let mut chainKeys: Value = object_keys(&withdrawFixOnChains);
{
let mut i: Value = Value::Int(0);
let mut __for_first_693: bool = true;
while { if !__for_first_693 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_693 = false; i.as_f64().unwrap_or(f64::NAN) < ((chainKeys.len() as i64) as f64) } {
let mut chainKey: Value = chainKeys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut currencyId: Value = self.safe_string_k(fee.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency.clone()]);
let mut networkCode: Value = self.network_id_to_code(&[chainKey.clone(), code]);
if (networkCode != Value::Null) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("networks".into())), &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), self.parse_number(withdrawFixOnChains.as_map().and_then(|__m| chainKey.as_str().and_then(|__k| __m.get(__k))).cloned().unwrap_or(Value::Null), &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
}));
}
}
}
}
return result;
Value::Null
}
/*
* @method
* @name gate#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-account-change-history
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-account-change-history-2
* @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
* @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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
// let defaultType = 'future';
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut symbolResolved: Value = (if (market != Value::Null) { market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) } else { Value::Null });
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchFundingHistory".into()), &[market.clone(), params]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestrequestParamsVariable = self.prepare_request(&[market, type_var.clone(), query]);
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut request, &Value::Str("type".into()), Value::Str("fund".into())); // 'dnw' 'pnl' 'fee' 'refr' 'fund' 'point_dnw' 'point_fee' 'point_refr'
if (since != Value::Null) {
// from should be integer
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), limit.clone());
}
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
let __ws_arg_7 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_get_settle_account_book(&[__ws_arg_7]).await;
} else if (type_var.as_str() == Some("future")) {
let __ws_arg_8 = self.extend(request, &[requestParams]);
response = self.private_delivery_get_settle_account_book(&[__ws_arg_8]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingHistory() only support swap & future market type".into()))));
}
return self.parse_funding_histories(response, symbolResolved, since, limit);
Value::Null
}
pub fn parse_funding_histories(&self, mut response: Value, mut symbol: Value, mut since: Value, mut limit: Value) -> Value {
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_694: bool = true;
while { if !__for_first_694 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_694 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut entry: Value = self.safe_dict(response.clone(), i.clone(), &[]);
let mut funding: Value = self.parse_funding_history(entry, &[]);
append_to_array(&mut result, funding);
}
}
let mut sorted: Value = self.sort_by(result, Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
pub fn parse_funding_history(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "time": 1646899200,
// "change": "-0.027722",
// "balance": "11.653120591841",
// "text": "XRP_USDT",
// "type": "fund"
// }
//
let mut timestamp: Value = self.safe_timestamp_k(info.clone(), "time", &[]);
let mut marketId: Value = self.safe_string_k(info.clone(), "text", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Str("_".into()), Value::Str("swap".into())]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_string_k(marketResolved.clone(), "symbol", &[]));
m.insert("code".to_string(), self.safe_string_k(marketResolved, "settle", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("id".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_number_k(info, "change", &[]));
m
});
Value::Null
}
/*
* @method
* @name gate#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://www.gate.com/docs/developers/apiv4/en/#get-market-depth-information
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-market-depth-information
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-market-depth-information-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-options-contract-order-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
//
// const request: Dict = {
// 'currency_pair': market['id'],
// 'interval': '0', // depth, 0 means no aggregation is applied, default to 0
// 'limit': limit, // maximum number of order depth data in asks or bids
// 'with_id': true, // return order book ID
// }
//
let mut requestqueryVariable = self.prepare_request(&[market.clone(), self.safe_string_k(market.clone(), "type", &[]), params]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (limit != Value::Null) {
// gateeu returns an empty book for a spot limit above 100
let mut maxLimit: Value = (if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { self.handle_option(Value::Str("fetchOrderBook".into()), Value::Str("maxSpotLimit".into()), &[Value::Int(1000)]) } else { Value::Int(300) });
add_element_to_object(&mut request, &Value::Str("limit".into()), crate::runtime::Math::min(&limit, &maxLimit));
}
add_element_to_object(&mut request, &Value::Str("with_id".into()), Value::Bool(true));
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) || (market.as_map().and_then(|__m| __m.get("margin")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_9 = self.extend(request.clone(), &[query.clone()]);
response = self.public_spot_get_order_book(&[__ws_arg_9]).await;
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_10 = self.extend(request.clone(), &[query.clone()]);
response = self.public_futures_get_settle_order_book(&[__ws_arg_10]).await;
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_11 = self.extend(request.clone(), &[query.clone()]);
response = self.public_delivery_get_settle_order_book(&[__ws_arg_11]).await;
} else if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_12 = self.extend(request, &[query]);
response = self.public_options_get_order_book(&[__ws_arg_12]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderBook() not support this market type".into()))));
}
//
// spot
//
// {
// "id": 6358770031
// "current": 1634345973275,
// "update": 1634345973271,
// "asks": [
// ["2.2241","12449.827"],
// ["2.2242","200"],
// ["2.2244","826.931"],
// ["2.2248","3876.107"],
// ["2.225","2377.252"],
// ["2.22509","439.484"],
// ["2.2251","1489.313"],
// ["2.2253","714.582"],
// ["2.2254","1349.784"],
// ["2.2256","234.701"]],
// "bids": [
// ["2.2236","32.465"],
// ["2.2232","243.983"],
// ["2.2231","32.207"],
// ["2.223","449.827"],
// ["2.2228","7.918"],
// ["2.2227","12703.482"],
// ["2.2226","143.033"],
// ["2.2225","143.027"],
// ["2.2224","1369.352"],
// ["2.2223","756.063"]
// ]
// }
//
// swap, future and option
//
// {
// "id": 6358770031
// "current": 1634350208.745,
// "asks": [
// {"s": 24909, "p": "61264.8"},
// {"s": 81, "p": "61266.6"},
// {"s": 2000, "p": "61267.6"},
// {"s": 490, "p": "61270.2"},
// {"s": 12, "p": "61270.4"},
// {"s": 11782, "p": "61273.2"},
// {"s": 14666, "p": "61273.3"},
// {"s": 22541, "p": "61273.4"},
// {"s": 33, "p": "61273.6"},
// {"s": 11980, "p": "61274.5"}
// ],
// "bids": [
// {"s": 41844, "p": "61264.7"},
// {"s": 13783, "p": "61263.3"},
// {"s": 1143, "p": "61259.8"},
// {"s": 81, "p": "61258.7"},
// {"s": 2471, "p": "61257.8"},
// {"s": 2471, "p": "61257.7"},
// {"s": 2471, "p": "61256.5"},
// {"s": 3, "p": "61254.2"},
// {"s": 114, "p": "61252.4"},
// {"s": 14372, "p": "61248.6"}
// ],
// "update": 1634350208.724
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "current", &[]);
if (timestamp == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" method() missing timestamp".into()))));
}
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
timestamp = (match (&(timestamp), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
}
let mut priceKey: Value = (if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { Value::Int(0) } else { Value::Str("p".into()) });
let mut amountKey: Value = (if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { Value::Int(1) } else { Value::Str("s".into()) });
let mut nonce: Value = self.safe_integer_k(response.clone(), "id", &[]);
let mut result: Value = self.parse_order_book(response, symbol, &[timestamp, Value::Str("bids".into()), Value::Str("asks".into()), priceKey, amountKey]);
add_element_to_object(&mut result, &Value::Str("nonce".into()), nonce);
return result;
Value::Null
}
/*
* @method
* @name gate#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.gate.com/docs/developers/apiv4/en/#get-currency-pair-ticker-information
* @see https://www.gate.com/docs/developers/apiv4/en/#get-all-futures-trading-statistics
* @see https://www.gate.com/docs/developers/apiv4/en/#get-all-futures-trading-statistics-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-options-market-ticker-information
* @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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, params]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) || (market.as_map().and_then(|__m| __m.get("margin")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_13 = self.extend(request.clone(), &[query.clone()]);
response = self.public_spot_get_tickers(&[__ws_arg_13]).await;
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_14 = self.extend(request.clone(), &[query.clone()]);
response = self.public_futures_get_settle_tickers(&[__ws_arg_14]).await;
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_15 = self.extend(request.clone(), &[query.clone()]);
response = self.public_delivery_get_settle_tickers(&[__ws_arg_15]).await;
} else if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let mut marketId: Value = market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
let mut optionParts: Value = split(&marketId, &Value::Str("-".into()));
add_element_to_object(&mut request, &Value::Str("underlying".into()), self.safe_string(optionParts, Value::Int(0), &[]));
let __ws_arg_16 = self.extend(request, &[query]);
response = self.public_options_get_tickers(&[__ws_arg_16]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTicker() not support this market type".into()))));
}
let mut ticker: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_695: bool = true;
while { if !__for_first_695 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_695 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
if (self.safe_string_k(entry.clone(), "name", &[]).as_str() == market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null).as_str()) {
ticker = entry;
break;
}
}
}
} else {
ticker = self.safe_dict(response, Value::Int(0), &[]);
}
if (ticker == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" fetchTicker() returned empty response".into()))));
}
return self.parse_ticker(ticker, &[market]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// SPOT
//
// {
// "currency_pair": "KFC_USDT",
// "last": "7.255",
// "lowest_ask": "7.298",
// "highest_bid": "7.218",
// "change_percentage": "-1.18",
// "base_volume": "1219.053687865",
// "quote_volume": "8807.40299875455",
// "high_24h": "7.262",
// "low_24h": "7.095"
// }
//
// LINEAR/DELIVERY
//
// {
// "contract": "BTC_USDT",
// "last": "6432",
// "low_24h": "6278",
// "high_24h": "6790",
// "change_percentage": "4.43",
// "total_size": "32323904",
// "volume_24h": "184040233284",
// "volume_24h_btc": "28613220",
// "volume_24h_usd": "184040233284",
// "volume_24h_base": "28613220",
// "volume_24h_quote": "184040233284",
// "volume_24h_settle": "28613220",
// "mark_price": "6534",
// "funding_rate": "0.0001",
// "funding_rate_indicative": "0.0001",
// "index_price": "6531"
// }
//
// bookTicker
// {
// "t": 1671363004228,
// "u": 9793320464,
// "s": "BTC_USDT",
// "b": "16716.8", // best bid price
// "B": "0.0134", // best bid size
// "a": "16716.9", // best ask price
// "A": "0.0353" // best ask size
// }
//
// option
//
// {
// "vega": "0.00002",
// "leverage": "12.277188268663",
// "ask_iv": "0",
// "delta": "-0.99999",
// "last_price": "0",
// "theta": "-0.00661",
// "bid1_price": "1096",
// "mark_iv": "0.7799",
// "name": "BTC_USDT-20230608-28500-P",
// "bid_iv": "0",
// "ask1_price": "2935",
// "mark_price": "2147.3",
// "position_size": 0,
// "bid1_size": 12,
// "ask1_size": -14,
// "gamma": "0"
// }
//
let mut marketId: Value = self.safe_string_n(ticker.clone(), Value::from(vec![Value::Str("currency_pair".into()), Value::Str("contract".into()), Value::Str("name".into())]), &[]);
let mut marketType: Value = Value::Str("spot".into());
if (matches!(&ticker, Value::Dict(__d) if __d.contains_key("mark_price"))) {
marketType = Value::Str("contract".into());
}
let mut symbol: Value = self.safe_symbol(marketId, &[market.clone(), Value::Str("_".into()), marketType]);
let mut last: Value = self.safe_string2(ticker.clone(), Value::Str("last".into()), Value::Str("last_price".into()), &[]);
let mut ask: Value = self.safe_string_n(ticker.clone(), Value::from(vec![Value::Str("lowest_ask".into()), Value::Str("a".into()), Value::Str("ask1_price".into())]), &[]);
let mut bid: Value = self.safe_string_n(ticker.clone(), Value::from(vec![Value::Str("highest_bid".into()), Value::Str("b".into()), Value::Str("bid1_price".into())]), &[]);
let mut high: Value = self.safe_string_k(ticker.clone(), "high_24h", &[]);
let mut low: Value = self.safe_string_k(ticker.clone(), "low_24h", &[]);
let mut bidVolume: Value = self.safe_string2(ticker.clone(), Value::Str("B".into()), Value::Str("bid1_size".into()), &[]);
let mut askVolume: Value = self.safe_string2(ticker.clone(), Value::Str("A".into()), Value::Str("ask1_size".into()), &[]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
let mut baseVolume: Value = self.safe_string2(ticker.clone(), Value::Str("base_volume".into()), Value::Str("volume_24h_base".into()), &[]);
if (baseVolume.as_str() == Some("nan")) {
baseVolume = Value::Str("0".into());
}
let mut quoteVolume: Value = self.safe_string2(ticker.clone(), Value::Str("quote_volume".into()), Value::Str("volume_24h_quote".into()), &[]);
if (quoteVolume.as_str() == Some("nan")) {
quoteVolume = Value::Str("0".into());
}
let mut percentage: Value = self.safe_string_k(ticker.clone(), "change_percentage", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), high);
m.insert("low".to_string(), low);
m.insert("bid".to_string(), bid);
m.insert("bidVolume".to_string(), bidVolume);
m.insert("ask".to_string(), ask);
m.insert("askVolume".to_string(), askVolume);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), percentage);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume);
m.insert("quoteVolume".to_string(), quoteVolume);
m.insert("markPrice".to_string(), self.safe_string_k(ticker.clone(), "mark_price", &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "index_price", &[]));
m.insert("info".to_string(), ticker);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name gate#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://www.gate.com/docs/developers/apiv4/en/#get-currency-pair-ticker-information
* @see https://www.gate.com/docs/developers/apiv4/en/#get-all-futures-trading-statistics
* @see https://www.gate.com/docs/developers/apiv4/en/#get-all-futures-trading-statistics-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-options-market-ticker-information
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut first: Value = self.safe_string(symbolsNormalized.clone(), Value::Int(0), &[]);
let mut market: Value = Value::Null;
if (first != Value::Null) {
market = self.market(first);
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchTickers".into()), &[market.clone(), params]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestrequestParamsVariable = self.prepare_request(&[Value::Null, type_var.clone(), query]);
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
add_element_to_object(&mut request, &Value::Str("timezone".into()), Value::Str("utc0".into())); // default to utc
if (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin")) {
let __ws_arg_17 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_spot_get_tickers(&[__ws_arg_17]).await;
} else if (type_var.as_str() == Some("swap")) {
let __ws_arg_18 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_futures_get_settle_tickers(&[__ws_arg_18]).await;
} else if (type_var.as_str() == Some("future")) {
let __ws_arg_19 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_delivery_get_settle_tickers(&[__ws_arg_19]).await;
} else if (type_var.as_str() == Some("option")) {
self.check_required_argument(Value::Str("fetchTickers".into()), symbolsNormalized.clone(), Value::Str("symbols".into()), &[]);
let mut marketId: Value = self.safe_string_k(market, "id", &[]);
let mut optionParts: Value = split(&marketId, &Value::Str("-".into()));
add_element_to_object(&mut request, &Value::Str("underlying".into()), self.safe_string(optionParts, Value::Int(0), &[]));
let __ws_arg_20 = self.extend(request, &[requestParams]);
response = self.public_options_get_tickers(&[__ws_arg_20]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTickers() not support this market type, provide symbols or set params[\"defaultType\"] to one from spot/margin/swap/future/option".into()))));
}
return self.parse_tickers(response, &[symbolsNormalized]);
Value::Null
}
pub fn parse_balance_helper(&self, mut entry: Value) -> Value {
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string2(entry.clone(), Value::Str("freeze".into()), Value::Str("locked".into()), &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(entry.clone(), "available", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string_k(entry.clone(), "total", &[])); }
if (matches!(&entry, Value::Dict(__d) if __d.contains_key("borrowed"))) {
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("debt".into(), self.safe_string_k(entry.clone(), "borrowed", &[])); }
}
return account;
Value::Null
}
/*
* @method
* @name gate#fetchBalance
* @see https://www.gate.com/docs/developers/apiv4/en/#get-unified-account-information
* @see https://www.gate.com/docs/developers/apiv4/en/#list-spot-trading-accounts
* @see https://www.gate.com/docs/developers/apiv4/en/#margin-account-list
* @see https://www.gate.com/docs/developers/apiv4/en/#funding-account-list
* @see https://www.gate.com/docs/developers/apiv4/en/#get-futures-account
* @see https://www.gate.com/docs/developers/apiv4/en/#get-futures-account-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-account-information
* @param {object} [params] exchange specific parameters
* @param {string} [params.type] spot, margin, swap or future, if not provided this.options['defaultType'] is used
* @param {string} [params.settle] 'btc' or 'usdt' - settle currency for perpetual swap and future - default="usdt" for swap and "btc" for future
* @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
* @param {string} [params.symbol] margin only - unified ccxt symbol
* @param {boolean} [params.unifiedAccount] default false, set to true for fetching the unified account balance
* @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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut symbol: Value = self.safe_string_k(params.clone(), "symbol", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("symbol".into()), &[]);
let mut isUnifiedAccountparamsUnifiedAccountVariable = self.handle_option_bool_and_params(paramsOmitted, Value::Str("fetchBalance".into()), Value::Str("unifiedAccount".into()), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchBalance".into()), &[Value::Null, paramsUnifiedAccount.clone()]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestrequestParamsVariable = self.prepare_request(&[Value::Null, type_var.clone(), query]);
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marginModerequestQueryVariable = self.get_margin_mode(Value::Bool(false), requestParams);
let mut marginMode: Value = marginModerequestQueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestQuery: Value = marginModerequestQueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (symbol != Value::Null) {
let mut market: Value = self.market(symbol);
add_element_to_object(&mut request, &Value::Str("currency_pair".into()), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
let mut response: Value = Value::Null;
if is_true(&isUnifiedAccount) {
let __ws_arg_21 = self.extend(request.clone(), &[paramsUnifiedAccount]);
response = self.private_unified_get_accounts(&[__ws_arg_21]).await;
} else if (type_var.as_str() == Some("spot")) {
if (marginMode.as_str() == Some("spot")) {
let __ws_arg_22 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_spot_get_accounts(&[__ws_arg_22]).await;
} else if (marginMode.as_str() == Some("margin")) {
let __ws_arg_23 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_margin_get_accounts(&[__ws_arg_23]).await;
} else if (marginMode.as_str() == Some("cross_margin")) {
let __ws_arg_24 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_margin_get_cross_accounts(&[__ws_arg_24]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchBalance() not support this marginMode".into()))));
}
} else if (type_var.as_str() == Some("funding")) {
let __ws_arg_25 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_margin_get_funding_accounts(&[__ws_arg_25]).await;
} else if (type_var.as_str() == Some("swap")) {
let __ws_arg_26 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_futures_get_settle_accounts(&[__ws_arg_26]).await;
} else if (type_var.as_str() == Some("future")) {
let __ws_arg_27 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_delivery_get_settle_accounts(&[__ws_arg_27]).await;
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_28 = self.extend(request, &[requestQuery]);
response = self.private_options_get_accounts(&[__ws_arg_28]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchBalance() not support this market type".into()))));
}
let mut contract: bool = (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) || (type_var.as_str() == Some("option"));
if contract {
response = Value::from(vec![response.clone()]);
}
//
// Spot / margin funding
//
// [
// {
// "currency": "DBC",
// "available": "0",
// "locked": "0"
// "lent": "0", // margin funding only
// "total_lent": "0" // margin funding only
// },
// ...
// ]
//
// Margin
//
// [
// {
// "currency_pair": "DOGE_USDT",
// "locked": false,
// "risk": "9999.99",
// "base": {
// "currency": "DOGE",
// "available": "0",
// "locked": "0",
// "borrowed": "0",
// "interest": "0"
// },
// "quote": {
// "currency": "USDT",
// "available": "0.73402",
// "locked": "0",
// "borrowed": "0",
// "interest": "0"
// }
// },
// ...
// ]
//
// Cross margin
//
// {
// "user_id": 10406147,
// "locked": false,
// "balances": {
// "USDT": {
// "available": "1",
// "freeze": "0",
// "borrowed": "0",
// "interest": "0"
// }
// },
// "total": "1",
// "borrowed": "0",
// "interest": "0",
// "risk": "9999.99"
// }
//
// Perpetual Swap
//
// {
// "order_margin": "0",
// "point": "0",
// "bonus": "0",
// "history": {
// "dnw": "2.1321",
// "pnl": "11.5351",
// "refr": "0",
// "point_fee": "0",
// "fund": "-0.32340576684",
// "bonus_dnw": "0",
// "point_refr": "0",
// "bonus_offset": "0",
// "fee": "-0.20132775",
// "point_dnw": "0",
// },
// "unrealised_pnl": "13.315100000006",
// "total": "12.51345151332",
// "available": "0",
// "in_dual_mode": false,
// "currency": "USDT",
// "position_margin": "12.51345151332",
// "user": "6333333",
// }
//
// Delivery Future
//
// {
// "order_margin": "0",
// "point": "0",
// "history": {
// "dnw": "1",
// "pnl": "0",
// "refr": "0",
// "point_fee": "0",
// "point_dnw": "0",
// "settle": "0",
// "settle_fee": "0",
// "point_refr": "0",
// "fee": "0",
// },
// "unrealised_pnl": "0",
// "total": "1",
// "available": "1",
// "currency": "USDT",
// "position_margin": "0",
// "user": "6333333",
// }
//
// option
//
// {
// "order_margin": "0",
// "bid_order_margin": "0",
// "init_margin": "0",
// "history": {
// "dnw": "32",
// "set": "0",
// "point_fee": "0",
// "point_dnw": "0",
// "prem": "0",
// "point_refr": "0",
// "insur": "0",
// "fee": "0",
// "refr": "0"
// },
// "total": "32",
// "available": "32",
// "liq_triggered": false,
// "maint_margin": "0",
// "ask_order_margin": "0",
// "point": "0",
// "position_notional_limit": "2000000",
// "unrealised_pnl": "0",
// "equity": "32",
// "user": 5691076,
// "currency": "USDT",
// "short_enabled": false,
// "orders_limit": 10
// }
//
// unified
//
// {
// "user_id": 10001,
// "locked": false,
// "balances": {
// "ETH": {
// "available": "0",
// "freeze": "0",
// "borrowed": "0.075393666654",
// "negative_liab": "0",
// "futures_pos_liab": "0",
// "equity": "1016.1",
// "total_freeze": "0",
// "total_liab": "0"
// },
// "POINT": {
// "available": "9999999999.017023138734",
// "freeze": "0",
// "borrowed": "0",
// "negative_liab": "0",
// "futures_pos_liab": "0",
// "equity": "12016.1",
// "total_freeze": "0",
// "total_liab": "0"
// },
// "USDT": {
// "available": "0.00000062023",
// "freeze": "0",
// "borrowed": "0",
// "negative_liab": "0",
// "futures_pos_liab": "0",
// "equity": "16.1",
// "total_freeze": "0",
// "total_liab": "0"
// }
// },
// "total": "230.94621713",
// "borrowed": "161.66395521",
// "total_initial_margin": "1025.0524665088",
// "total_margin_balance": "3382495.944473949183",
// "total_maintenance_margin": "205.01049330176",
// "total_initial_margin_rate": "3299.827135672679",
// "total_maintenance_margin_rate": "16499.135678363399",
// "total_available_margin": "3381470.892007440383",
// "unified_account_total": "3381470.892007440383",
// "unified_account_total_liab": "0",
// "unified_account_total_equity": "100016.1",
// "leverage": "2"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut isolated: bool = (marginMode.as_str() == Some("margin")) && (type_var.as_str() == Some("spot"));
let mut data: Value = response;
if (matches!(&data, Value::Dict(__d) if __d.contains_key("balances"))) {
let mut flatBalances: Value = Value::from(vec![]);
let mut balances: Value = self.safe_dict_k(data.clone(), "balances", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
// inject currency and create an artificial balance object
// so it can follow the existent flow
let mut keys: Value = object_keys(&balances);
{
let mut i: Value = Value::Int(0);
let mut __for_first_696: bool = true;
while { if !__for_first_696 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_696 = false; i.as_f64().unwrap_or(f64::NAN) < ((keys.len() as i64) as f64) } {
let mut currencyId: Value = keys.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut content: Value = get_value(&balances, ¤cyId);
add_element_to_object(&mut content, &Value::Str("currency".into()), currencyId.clone());
crate::set_value(&mut balances, ¤cyId, content.clone());
append_to_array(&mut flatBalances, content);
}
}
data = flatBalances;
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_697: bool = true;
while { if !__for_first_697 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_697 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
if isolated {
let mut base: Value = self.safe_dict_k(entry.clone(), "base", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut quote: Value = self.safe_dict_k(entry.clone(), "quote", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut baseCode: Value = self.safe_currency_code(self.safe_string_k(base.clone(), "currency", &[]), &[]);
let mut quoteCode: Value = self.safe_currency_code(self.safe_string_k(quote.clone(), "currency", &[]), &[]);
result = self.merge_balance_account(result.clone(), baseCode, self.parse_balance_helper(base));
result = self.merge_balance_account(result.clone(), quoteCode, self.parse_balance_helper(quote));
} else {
let mut code: Value = self.safe_currency_code(self.safe_string_k(entry.clone(), "currency", &[]), &[]);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), self.parse_balance_helper(entry)); }
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name gate#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://www.gate.com/docs/developers/apiv4/en/#market-k-line-chart // spot
* @see https://www.gate.com/docs/developers/apiv4/en/#futures-market-k-line-chart // swap
* @see https://www.gate.com/docs/developers/apiv4/en/#futures-market-k-line-chart-2 // future
* @see https://www.gate.com/docs/developers/apiv4/en/#options-contract-market-candlestick-chart // option
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch, limit is conflicted with since and params["until"], If either since and params["until"] is specified, request will be rejected
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.price] "mark" or "index" for mark price and index price candles
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @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 {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume (units in quote currency)
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), Value::Int(1000)]).await;
}
if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
return self.fetch_option_ohlcv(symbol, &[timeframe.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut price: Value = self.safe_string_k(paramsPaginate.clone(), "price", &[]);
let mut requestparamsRequestVariable = self.prepare_request(&[market.clone(), Value::Null, paramsPaginate]);
let mut request: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsRequest: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut request, &Value::Str("interval".into()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
let mut maxLimit: Value = (if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) { Value::Int(1999) } else { Value::Int(1000) });
let mut limitValue: Value = (if (limit == Value::Null) { maxLimit.clone() } else { crate::runtime::Math::min(&limit, &maxLimit) });
let mut until: Value = self.safe_integer_k(paramsRequest.clone(), "until", &[]);
if (until != Value::Null) {
until = self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
}
let mut paramsOmitted: Value = self.omit(paramsRequest, Value::Str("until".into()), &[]);
if (since != Value::Null) {
let mut duration: Value = self.parse_timeframe(timeframe.clone());
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
let mut distance: Value = (match (&(((match (&(limitValue), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null }))), &(duration)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
let mut toTimestamp: Value = self.sum(&[request.as_map().and_then(|__m| __m.get("from")).cloned().unwrap_or(Value::Null), distance]);
let mut currentTimestamp: Value = self.seconds();
let mut to: Value = crate::runtime::Math::min(&toTimestamp, ¤tTimestamp);
if (until != Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".into()), crate::runtime::Math::min(&to, &until));
} else {
add_element_to_object(&mut request, &Value::Str("to".into()), to);
}
} else {
if (until != Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".into()), until);
}
add_element_to_object(&mut request, &Value::Str("limit".into()), limitValue.clone());
}
let mut response: Value = Value::from(vec![]);
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let mut isMark: bool = price.as_str() == Some("mark");
let mut isIndex: bool = price.as_str() == Some("index");
if isMark || isIndex {
add_element_to_object(&mut request, &Value::Str("contract".into()), Value::Str(format!("{}{}", Value::Str(format!("{}{}", price, Value::Str("_".into())).into()), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)).into()));
}
let mut paramsContract: Value = paramsOmitted.clone();
if isMark || isIndex {
paramsContract = self.omit(paramsOmitted.clone(), Value::Str("price".into()), &[]);
}
if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_29 = self.extend(request.clone(), &[paramsContract.clone()]);
response = self.public_delivery_get_settle_candlesticks(&[__ws_arg_29]).await;
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_30 = self.extend(request.clone(), &[paramsContract]);
response = self.public_futures_get_settle_candlesticks(&[__ws_arg_30]).await;
}
} else {
let __ws_arg_31 = self.extend(request, &[paramsOmitted]);
response = self.public_spot_get_candlesticks(&[__ws_arg_31]).await;
}
return self.parse_ohlc_vs(self.to_array(response), &[market, timeframe, since, limitValue]);
Value::Null
}
pub async fn fetch_option_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// separated option logic because the from, to and limit parameters weren't functioning
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut requestparamsValueVariable = self.prepare_request(&[market.clone(), Value::Null, params]);
let mut request: Value = requestparamsValueVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsValue: Value = requestparamsValueVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut request, &Value::Str("interval".into()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
let __ws_arg_32 = self.extend(request, &[paramsValue]);
let mut response: Value = self.public_options_get_candlesticks(&[__ws_arg_32]).await;
return self.parse_ohlc_vs(self.to_array(response), &[market, timeframe, since, limit]);
Value::Null
}
/*
* @method
* @name gate#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://www.gate.com/docs/developers/apiv4/en/#get-all-futures-trading-statistics
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest funding rate to fetch
* @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 [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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() supports swap contracts only".into()))));
}
let mut requestparamsRequestVariable = self.prepare_request(&[market.clone(), Value::Null, paramsPaginate]);
let mut request: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsRequest: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), limit.clone());
}
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
let mut until: Value = self.safe_integer_k(paramsRequest.clone(), "until", &[]);
if (until != Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".into()), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
let __ws_arg_33 = self.extend(request, &[self.omit(paramsRequest, Value::Str("until".into()), &[])]);
let mut response: Value = self.public_futures_get_settle_funding_rate(&[__ws_arg_33]).await;
//
// {
// "r": "0.00063521",
// "t": "1621267200000",
// }
//
let mut rates: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_698: bool = true;
while { if !__for_first_698 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_698 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut entry: Value = self.safe_dict(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_timestamp_k(entry.clone(), "t", &[]);
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(), symbol.clone());
m.insert("fundingRate".to_string(), self.safe_number_k(entry, "r", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates, Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[self.safe_string_k(market, "symbol", &[]), since, limit]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// Spot market candles
//
// [
// "1660957920", // timestamp
// "6227.070147198573", // quote volume
// "0.0000133485", // close
// "0.0000133615", // high
// "0.0000133347", // low
// "0.0000133468", // open
// "466641934.99" // base volume
// ]
//
//
// Swap, Future, Option, Mark and Index price candles
//
// {
// "t":1632873600, // Unix timestamp in seconds
// "o": "41025", // Open price
// "h": "41882.17", // Highest price
// "c": "41776.92", // Close price
// "l": "40783.94" // Lowest price
// }
//
if (matches!(&ohlcv, Value::Arr(_))) {
return Value::from(vec![self.safe_timestamp(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(6), &[])]);
} else {
return Value::from(vec![self.safe_timestamp_k(ohlcv.clone(), "t", &[]), self.safe_number_k(ohlcv.clone(), "o", &[]), self.safe_number_k(ohlcv.clone(), "h", &[]), self.safe_number_k(ohlcv.clone(), "l", &[]), self.safe_number_k(ohlcv.clone(), "c", &[]), self.safe_number_k(ohlcv, "v", &[])]);
}
Value::Null
}
/*
* @method
* @name gate#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://www.gate.com/docs/developers/apiv4/en/#query-market-transaction-records
* @see https://www.gate.com/docs/developers/apiv4/en/#futures-market-transaction-records
* @see https://www.gate.com/docs/developers/apiv4/en/#futures-market-transaction-records-2
* @see https://www.gate.com/docs/developers/apiv4/en/#market-trade-records
* @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] timestamp in ms of the latest trade to fetch
* @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 {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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut market: Value = self.market(symbol);
//
// spot
//
// const request: Dict = {
// 'currency_pair': market['id'],
// 'limit': limit, // maximum number of records to be returned in a single list
// 'last_id': 'id', // specify list staring point using the id of last record in previous list-query results
// 'reverse': false, // true to retrieve records where id is smaller than the specified last_id, false to retrieve records where id is larger than the specified last_id
// }
//
// swap, future
//
// const request: Dict = {
// 'settle': market['settleId'],
// 'contract': market['id'],
// 'limit': limit, // maximum number of records to be returned in a single list
// 'last_id': 'id', // specify list staring point using the id of last record in previous list-query results
// 'from': since / 1000), // starting time in seconds, if not specified, to and limit will be used to limit response items
// 'to': this.seconds (), // end time in seconds, default to current time
// }
//
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, paramsPaginate.clone()]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut until: Value = self.safe_integer2(paramsPaginate, Value::Str("to".into()), Value::Str("until".into()), &[]);
if (until != Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".into()), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), crate::runtime::Math::min(&limit, &Value::Int(1000))); // default 100, max 1000
}
if (since != Value::Null) && (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null).as_str() == Some("spot")) || (market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null).as_str() == Some("margin")) {
let __ws_arg_34 = self.extend(request.clone(), &[query.clone()]);
response = self.public_spot_get_trades(&[__ws_arg_34]).await;
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_35 = self.extend(request.clone(), &[query.clone()]);
response = self.public_futures_get_settle_trades(&[__ws_arg_35]).await;
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_36 = self.extend(request.clone(), &[query.clone()]);
response = self.public_delivery_get_settle_trades(&[__ws_arg_36]).await;
} else if (market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null).as_str() == Some("option")) {
let __ws_arg_37 = self.extend(request, &[query]);
response = self.public_options_get_trades(&[__ws_arg_37]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchTrades() not support this market type.".into()))));
}
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name gate#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records-by-time-range
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records-3
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records-4
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderTrades() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
//
// [
// {
// "id":"3711449544",
// "create_time":"1655486040",
// "create_time_ms":"1655486040177.599900",
// "currency_pair":"SHIB_USDT",
// "side":"buy",
// "role":"taker",
// "amount":"1360039",
// "price":"0.0000081084",
// "order_id":"169717399644",
// "fee":"2720.078",
// "fee_currency":"SHIB",
// "point_fee":"0",
// "gt_fee":"0"
// }
// ]
//
let mut response: Value = self.fetch_my_trades(&[symbol, since, limit, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id);
m
})]).await;
return response;
Value::Null
}
/*
* @method
* @name gate#fetchMyTrades
* @description Fetch personal trading history
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records-by-time-range
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records-3
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-trading-records-4
* @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 {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
* @param {string} [params.type] 'spot', 'swap', or 'future', if not provided this.options['defaultMarginMode'] is used
* @param {int} [params.until] The latest timestamp, in ms, that fetched trades were made
* @param {int} [params.page] *spot only* Page number
* @param {string} [params.order_id] *spot only* Filter trades with specified order ID. symbol is also required if this field is present
* @param {string} [params.order] *contract only* Futures order ID, return related data only if specified
* @param {int} [params.offset] *contract only* list offset, starting from 0
* @param {string} [params.last_id] *contract only* specify list staring point using the id of last record in previous list-query results
* @param {int} [params.count_total] *contract only* whether to return total number matched, default to 0(no return)
* @param {bool} [params.unifiedAccount] set to true for fetching trades in a unified account
* @param {bool} [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 {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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchMyTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut marginMode: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut query: Value = Value::Null;
let mut market: Value = (if (symbol != Value::Null) { self.market(symbol) } else { Value::Null });
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(paramsPaginate, Value::from(vec![Value::Str("until".into())]), &[]);
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchMyTrades".into()), &[market.clone(), paramsOmitted]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut contract: bool = (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) || (type_var.as_str() == Some("option"));
if contract {
let mut contractQuery: Value = Value::Null;
{ let __destr_tmp = self.prepare_request(&[market.clone(), type_var.clone(), paramsMarketType.clone()]); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); contractQuery = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
query = (if (type_var.as_str() == Some("option")) { self.omit(contractQuery.clone(), Value::Str("order_id".into()), &[]) } else { contractQuery });
} else {
if (market != Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency_pair".into()), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); // Should always be set for non-trigger
}
{ let __destr_tmp = self.get_margin_mode(Value::Bool(false), paramsMarketType); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); query = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
add_element_to_object(&mut request, &Value::Str("account".into()), marginMode);
}
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), limit.clone()); // default 100, max 1000
}
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
if (until != Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".into()), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin")) {
let __ws_arg_38 = self.extend(request.clone(), &[query.clone()]);
response = self.private_spot_get_my_trades(&[__ws_arg_38]).await;
} else if (type_var.as_str() == Some("swap")) {
let __ws_arg_39 = self.extend(request.clone(), &[query.clone()]);
response = self.private_futures_get_settle_my_trades_timerange(&[__ws_arg_39]).await;
} else if (type_var.as_str() == Some("future")) {
let __ws_arg_40 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delivery_get_settle_my_trades(&[__ws_arg_40]).await;
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_41 = self.extend(request, &[query]);
response = self.private_options_get_my_trades(&[__ws_arg_41]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() not support this market type.".into()))));
}
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// public
//
// spot:
// {
// "id": "1334253759",
// "create_time": "1626342738",
// "create_time_ms": "1626342738331.497000",
// "currency_pair": "BTC_USDT",
// "side": "sell",
// "amount": "0.0022",
// "price": "32452.16"
// }
//
// swap:
//
// {
// "id": "442288327",
// "contract": "BTC_USDT",
// "create_time": "1739814676.707",
// "create_time_ms": "1739814676.707",
// "size": "-105",
// "price": "95594.8"
// }
//
//
// public ws
//
// {
// "id": 221994511,
// "time": 1580311438.618647,
// "price": "9309",
// "amount": "0.0019",
// "type": "sell"
// }
//
// spot rest
//
// {
// "id": "2876130500",
// "create_time": "1645464610",
// "create_time_ms": "1645464610777.399200",
// "currency_pair": "DOGE_USDT",
// "side": "sell",
// "role": "taker",
// "amount": "10.97",
// "price": "0.137384",
// "order_id": "125924049993",
// "fee": "0.00301420496",
// "fee_currency": "USDT",
// "point_fee": "1.1",
// "gt_fee":"2.2"
// }
//
// perpetual swap rest
//
// {
// "size": -5,
// "order_id": "130264979823",
// "id": 26884791,
// "role": "taker",
// "create_time": 1645465199.5472,
// "contract": "DOGE_USDT",
// "price": "0.136888"
// }
//
// future rest
//
// {
// "id": 121234231,
// "create_time": 1514764800.123,
// "contract": "BTC_USDT",
// "order_id": "21893289839",
// "size": 100,
// "price": "100.123",
// "role": "taker"
// }
//
// fetchTrades: option
//
// {
// "size": -5,
// "id": 25,
// "create_time": 1682378573,
// "contract": "ETH_USDT-20230526-2000-P",
// "price": "209.1"
// }
//
// fetchMyTrades: option
//
// {
// "underlying_price": "26817.84",
// "size": -1,
// "contract": "BTC_USDT-20230602-26500-C",
// "id": 16,
// "role": "taker",
// "create_time": 1685594770,
// "order_id": 2611026125,
// "price": "333"
// }
//
let mut id: Value = self.safe_string2(trade.clone(), Value::Str("id".into()), Value::Str("trade_id".into()), &[]);
let mut timestamp: Value = Value::Null;
let mut msString: Value = self.safe_string_k(trade.clone(), "create_time_ms", &[]);
if (msString != Value::Null) {
msString = crate::precise::Precise::stringMul(&msString, &Value::Str("1000".into()));
msString = msString.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(0); let __j = __l.min(13); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
timestamp = self.parse_to_int(msString);
} else {
timestamp = self.safe_timestamp2(trade.clone(), Value::Str("time".into()), Value::Str("create_time".into()), &[]);
}
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("currency_pair".into()), Value::Str("contract".into()), &[]);
let mut marketType: Value = Value::Str("spot".into());
if (matches!(&trade, Value::Dict(__d) if __d.contains_key("contract"))) {
marketType = Value::Str("contract".into());
}
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Str("_".into()), marketType]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("amount".into()), Value::Str("size".into()), &[]);
let mut priceString: Value = self.safe_string_k(trade.clone(), "price", &[]);
let mut contractSide: Value = Value::Str("buy".into());
if is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".into()))) {
contractSide = Value::Str("sell".into());
}
amountString = crate::precise::Precise::stringAbs(&amountString);
let mut side: Value = self.safe_string2(trade.clone(), Value::Str("side".into()), Value::Str("type".into()), &[contractSide]);
let mut orderId: Value = self.safe_string_k(trade.clone(), "order_id", &[]);
let mut feeAmount: Value = self.safe_string_k(trade.clone(), "fee", &[]);
let mut gtFee: Value = self.omit_zero(self.safe_string_k(trade.clone(), "gt_fee", &[]));
let mut pointFee: Value = self.omit_zero(self.safe_string_k(trade.clone(), "point_fee", &[]));
let mut fees: Value = Value::from(vec![]);
if (feeAmount != Value::Null) {
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "fee_currency", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId, &[]);
if (feeCurrencyCode == Value::Null) {
feeCurrencyCode = self.safe_string_k(marketResolved.clone(), "settle", &[]);
}
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeAmount);
m.insert("currency".to_string(), feeCurrencyCode);
m
}));
}
if (gtFee != Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), gtFee);
m.insert("currency".to_string(), Value::Str("GT".into()));
m
}));
}
if (pointFee != Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), pointFee);
m.insert("currency".to_string(), Value::Str("GATEPOINT".into()));
m
}));
}
let mut takerOrMaker: Value = self.safe_string_k(trade.clone(), "role", &[]);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade);
m.insert("id".to_string(), id);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("order".to_string(), orderId);
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("price".to_string(), priceString);
m.insert("amount".to_string(), amountString);
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("fees".to_string(), fees);
m
}), &[marketResolved]);
Value::Null
}
/*
* @method
* @name gate#fetchDeposits
* @description fetch all deposits made to an account
* @see https://www.gate.com/docs/developers/apiv4/en/#get-deposit-records
* @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 {int} [params.until] end time in ms
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchDeposits".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchDeposits".into()), &[code.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }; // todo: currencies have network-junctions
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit); }
}
if (since != Value::Null) {
let mut start: Value = self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), start.clone()); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("to".into(), self.sum(&[start, (match (&((match (&((match (&(Value::Int(30)), &(Value::Int(24))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })])); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("to".into()), request, paramsPaginate, &[Value::Float(0.001)]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_42 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.private_wallet_get_deposits(&[__ws_arg_42]).await;
return self.parse_transactions(response, &[currency]);
Value::Null
}
/*
* @method
* @name gate#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://www.gate.com/docs/developers/apiv4/en/#get-withdrawal-records
* @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 {int} [params.until] end time in ms
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchWithdrawals".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchWithdrawals".into()), &[code.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }; // todo: currencies have network-junctions
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit); }
}
if (since != Value::Null) {
let mut start: Value = self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), start.clone()); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("to".into(), self.sum(&[start, (match (&((match (&((match (&(Value::Int(30)), &(Value::Int(24))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })])); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("to".into()), request, paramsPaginate, &[Value::Float(0.001)]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_43 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.private_wallet_get_withdrawals(&[__ws_arg_43]).await;
return self.parse_transactions(response, &[currency]);
Value::Null
}
/*
* @method
* @name gate#withdraw
* @description make a withdrawal
* @see https://www.gate.com/docs/developers/apiv4/en/#withdraw
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut tagWithdrawTagparamsWithdrawTagVariable = self.handle_withdraw_tag_and_params(tag, params);
let mut tagWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("address".to_string(), address);
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount, &[]));
m
});
if (tagWithdrawTag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("memo".into(), tagWithdrawTag); }
}
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(paramsWithdrawTag);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("chain".into(), self.network_code_to_id(networkCode, &[code])); }
}
let __ws_arg_44 = self.extend(request, &[paramsNetworkCode]);
let mut response: Value = self.private_withdrawals_post_withdrawals(&[__ws_arg_44]).await;
return self.parse_transaction(response, &[currency]);
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("PEND".to_string(), Value::Str("pending".into()));
m.insert("REQUEST".to_string(), Value::Str("pending".into()));
m.insert("DMOVE".to_string(), Value::Str("pending".into()));
m.insert("MANUAL".to_string(), Value::Str("pending".into()));
m.insert("VERIFY".to_string(), Value::Str("pending".into()));
m.insert("PROCES".to_string(), Value::Str("pending".into()));
m.insert("EXTPEND".to_string(), Value::Str("pending".into()));
m.insert("SPLITPEND".to_string(), Value::Str("pending".into()));
m.insert("CANCEL".to_string(), Value::Str("canceled".into()));
m.insert("FAIL".to_string(), Value::Str("failed".into()));
m.insert("INVALID".to_string(), Value::Str("failed".into()));
m.insert("DONE".to_string(), Value::Str("ok".into()));
m.insert("BCODE".to_string(), Value::Str("ok".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transaction_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("d".to_string(), Value::Str("deposit".into()));
m.insert("w".to_string(), Value::Str("withdrawal".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchDeposits
//
// {
// "id": "d33361395",
// "currency": "USDT_TRX",
// "address": "TErdnxenuLtXfnMafLbfappYdHtnXQ5U4z",
// "amount": "100",
// "txid": "ae9374de34e558562fe18cbb1bf9ab4d9eb8aa7669d65541c9fa2a532c1474a0",
// "timestamp": "1626345819",
// "status": "DONE",
// "memo": ""
// }
//
// withdraw
//
// {
// "id":"w64413318",
// "currency":"usdt",
// "amount":"10150",
// "address":"0x0ab891497116f7f5532a4c2f4f7b1784488628e1",
// "memo":null,
// "status":"REQUEST",
// "chain":"eth",
// "withdraw_order_id":"",
// "fee_amount":"4.15000000"
// }
//
// fetchWithdrawals
//
// {
// "id": "210496",
// "timestamp": "1542000000",
// "withdraw_order_id": "order_123456",
// "currency": "USDT",
// "address": "1HkxtBAMrA3tP5ENnYY2CZortjZvFDH5Cs",
// "txid": "128988928203223323290",
// "block_number": "41575382",
// "amount": "222.61",
// "fee": "0.01",
// "memo": "",
// "status": "DONE",
// "chain": "TRX"
// }
//
// {
// "id": "w13389675",
// "currency": "USDT",
// "amount": "50",
// "address": "TUu2rLFrmzUodiWfYki7QCNtv1akL682p1",
// "memo": null
// }
//
// {
// "currency":"usdt",
// "address":"0x01c0A9b7b4CdE774AF0f3E47CB4f1c2CCdBa0806",
// "amount":"1880",
// "chain":"eth"
// }
//
let mut id: Value = self.safe_string_k(transaction.clone(), "id", &[]);
let mut type_var: Value = Value::Null;
let mut amountString: Value = self.safe_string_k(transaction.clone(), "amount", &[]);
if (id != Value::Null) {
if (get_value(&id, &Value::Int(0)).as_str() == Some("b")) {
// GateCode handling
type_var = (if is_true(&crate::precise::Precise::stringGt(&amountString, &Value::Str("0".into()))) { Value::Str("deposit".into()) } else { Value::Str("withdrawal".into()) });
amountString = crate::precise::Precise::stringAbs(&amountString);
} else {
type_var = self.parse_transaction_type(get_value(&id, &Value::Int(0))).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
}
}
let mut feeCostString: Value = self.safe_string2(transaction.clone(), Value::Str("fee".into()), Value::Str("fee_amount".into()), &[]);
if (type_var.as_str() == Some("withdrawal")) {
amountString = crate::precise::Precise::stringSub(&amountString, &feeCostString);
}
let mut networkId: Value = self.safe_string_upper_k(transaction.clone(), "chain", &[]);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut txid: Value = self.safe_string_k(transaction.clone(), "txid", &[]);
let mut rawStatus: Value = self.safe_string_k(transaction.clone(), "status", &[]);
let mut status: Value = self.parse_transaction_status(rawStatus);
let mut address: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut tag: Value = self.safe_string_k(transaction.clone(), "memo", &[]);
let mut timestamp: Value = self.safe_timestamp_k(transaction.clone(), "timestamp", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction);
m.insert("id".to_string(), id);
m.insert("txid".to_string(), txid);
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(amountString, &[]));
m.insert("network".to_string(), self.network_id_to_code(&[networkId, code.clone()]));
m.insert("address".to_string(), address);
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), tag);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("status".to_string(), status);
m.insert("type".to_string(), type_var);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("updated".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("cost".to_string(), self.parse_number(feeCostString, &[]));
m
}));
m
});
Value::Null
}
/*
* @method
* @name gate#createOrder
* @description Create an order on the exchange
* @see https://www.gate.com/docs/developers/apiv4/en/#create-an-order
* @see https://www.gate.com/docs/developers/apiv4/en/#create-price-triggered-order
* @see https://www.gate.com/docs/developers/apiv4/en/#place-futures-order
* @see https://www.gate.com/docs/developers/apiv4/en/#create-price-triggered-order-2
* @see https://www.gate.com/docs/developers/apiv4/en/#place-futures-order-2
* @see https://www.gate.com/docs/developers/apiv4/en/#create-price-triggered-order-3
* @see https://www.gate.com/docs/developers/apiv4/en/#create-an-options-order
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market' *"market" is contract only*
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @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 {float} [params.triggerPrice] The price at which a trigger order is triggered at
* @param {string} [params.timeInForce] "GTC", "IOC", or "PO"
* @param {float} [params.stopLossPrice] The price at which a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] The price at which a take profit order is triggered at
* @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
* @param {int} [params.iceberg] Amount to display for the iceberg order, Null or 0 for normal orders, Set to -1 to hide the order completely
* @param {string} [params.text] User defined information
* @param {string} [params.account] *spot and margin only* "spot", "margin" or "cross_margin"
* @param {bool} [params.auto_borrow] *margin only* Used in margin or cross margin trading to allow automatic loan of insufficient amount if balance is not enough
* @param {string} [params.settle] *contract only* Unified Currency Code for settle currency
* @param {bool} [params.reduceOnly] *contract only* Indicates if this order is to reduce the size of a position
* @param {bool} [params.close] *contract only* Set as true to close the position, with size set to 0
* @param {bool} [params.auto_size] *contract only* Set side to close dual-mode position, close_long closes the long side, while close_short the short one, size also needs to be set to 0
* @param {int} [params.price_type] *contract only* 0 latest deal price, 1 mark price, 2 index price
* @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
* @param {bool} [params.unifiedAccount] set to true for creating an order in the unified account
* @param {string} [params.clientOrderId] the clientOrderId of the order
* @returns {object|undefined} [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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut trigger: Value = self.safe_value_k(params.clone(), "trigger", &[]);
let mut triggerPrice: Value = self.safe_value2(params.clone(), Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), &[]);
let mut stopLossPrice: Value = self.safe_value_k(params.clone(), "stopLossPrice", &[triggerPrice]);
let mut takeProfitPrice: Option<String> = self.safe_string_k(params.clone(), "takeProfitPrice", &[]).as_str().map(str::to_owned);
let mut isStopLossOrder: bool = stopLossPrice != Value::Null;
let mut isTakeProfitOrder: bool = takeProfitPrice.is_some();
let mut isTpsl: bool = isStopLossOrder || isTakeProfitOrder;
let mut nonTriggerOrder: bool = !isTpsl && (trigger == Value::Null);
let mut orderRequest: Value = self.create_order_request(symbol, type_var, side, amount, &[price, params]);
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) || (market.as_map().and_then(|__m| __m.get("margin")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if nonTriggerOrder {
response = self.private_spot_post_orders(&[orderRequest.clone()]).await;
} else {
response = self.private_spot_post_price_orders(&[orderRequest.clone()]).await;
}
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if nonTriggerOrder {
response = self.private_futures_post_settle_orders(&[orderRequest.clone()]).await;
} else {
response = self.private_futures_post_settle_price_orders(&[orderRequest.clone()]).await;
}
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if nonTriggerOrder {
response = self.private_delivery_post_settle_orders(&[orderRequest.clone()]).await;
} else {
response = self.private_delivery_post_settle_price_orders(&[orderRequest.clone()]).await;
}
} else {
response = self.private_options_post_orders(&[orderRequest]).await;
}
return self.parse_order(response, &[market]);
Value::Null
}
pub fn create_orders_request(&self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut ordersRequests: Value = Value::from(vec![]);
let mut orderSymbols: Value = Value::from(vec![]);
let mut ordersLength: f64 = ((orders.len() as i64) as f64);
if (ordersLength == 0.0) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" createOrders() requires at least one order".into()))));
}
if ordersLength > ((10i64) as f64) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" createOrders() accepts a maximum of 10 orders at a time".into()))));
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_699: bool = true;
while { if !__for_first_699 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_699 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut rawOrder: Value = self.safe_dict(orders.clone(), i.clone(), &[]);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
append_to_array(&mut orderSymbols, marketId.clone());
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder, "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut extendedParams: Value = self.extend(orderParams.clone(), &[params.clone()]); // the request does not accept extra params since it's a list, so we're extending each order with the common params
let mut triggerValue: Value = self.safe_value_n(orderParams, Value::from(vec![Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), Value::Str("takeProfitPrice".into()), Value::Str("stopLossPrice".into())]), &[]);
if (triggerValue != Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrders() does not support advanced order properties (stopPrice, takeProfitPrice, stopLossPrice)".into()))));
}
add_element_to_object(&mut extendedParams, &Value::Str("textIsRequired".into()), Value::Bool(true)); // the exchange requires a text parameter for each order here
let mut orderRequest: Value = self.create_order_request(marketId, type_var, side, amount, &[price, extendedParams]);
append_to_array(&mut ordersRequests, orderRequest);
}
}
let mut symbols: Value = self.market_symbols(&[orderSymbols, Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.market(symbols.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) || (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrders() does not support futures or options markets".into()))));
}
return ordersRequests;
Value::Null
}
/*
* @method
* @name gate#createOrders
* @description create a list of trade orders
* @see https://www.gate.com/docs/developers/apiv4/en/#batch-place-orders
* @see https://www.gate.com/docs/developers/apiv4/en/#place-batch-futures-orders
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut ordersRequests: Value = self.create_orders_request(orders.clone(), &[params]);
let mut firstOrder: Value = orders.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(firstOrder.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
response = self.private_spot_post_batch_orders(&[ordersRequests.clone()]).await;
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
response = self.private_futures_post_settle_batch_orders(&[ordersRequests]).await;
}
return self.parse_orders(response, &[]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
let mut market: Value = self.market(symbol.clone());
let mut contract: Value = market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null);
let mut trigger: Value = self.safe_value_k(params.clone(), "trigger", &[]);
let mut triggerPrice: Value = self.safe_value2(params.clone(), Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), &[]);
let mut stopLossPrice: Value = self.safe_value_k(params.clone(), "stopLossPrice", &[triggerPrice]);
let mut takeProfitPrice: Value = self.safe_value_k(params.clone(), "takeProfitPrice", &[]);
let mut isStopLossOrder: bool = stopLossPrice != Value::Null;
let mut isTakeProfitOrder: bool = takeProfitPrice != Value::Null;
let mut isTpsl: bool = isStopLossOrder || isTakeProfitOrder;
if isStopLossOrder && isTakeProfitOrder {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" createOrder() stopLossPrice and takeProfitPrice cannot both be defined".into()))));
}
let mut reduceOnly: Value = self.safe_value_k(params.clone(), "reduceOnly", &[]);
let mut exchangeSpecificTimeInForce: Option<String> = self.safe_string_lower_n(params.clone(), Value::from(vec![Value::Str("timeInForce".into()), Value::Str("tif".into()), Value::Str("time_in_force".into())]), &[]).as_str().map(str::to_owned);
let mut postOnlyparamsPostOnlyVariable = self.handle_post_only(Value::Bool(type_var.as_str() == Some("market")), Value::Bool(exchangeSpecificTimeInForce.as_deref() == Some("poc")), &[params]);
let mut postOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut timeInForce: Value = self.handle_time_in_force(&[paramsPostOnly.clone()]);
if (postOnly.as_bool() == Some(true)) {
timeInForce = Value::Str("poc".into());
}
// we only omit the unified params here
// this is because the other params will get extended into the request
let mut clientOrderId: Value = self.safe_string2(paramsPostOnly.clone(), Value::Str("text".into()), Value::Str("clientOrderId".into()), &[]);
let mut query: Value = self.omit(paramsPostOnly, Value::from(vec![Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), Value::Str("stopLossPrice".into()), Value::Str("takeProfitPrice".into()), Value::Str("reduceOnly".into()), Value::Str("timeInForce".into()), Value::Str("postOnly".into()), Value::Str("clientOrderId".into())]), &[]);
let mut isLimitOrder: bool = type_var.as_str() == Some("limit");
let mut isMarketOrder: bool = type_var.as_str() == Some("market");
if isLimitOrder && (price == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrder () requires a price argument for ".into())).into()), type_var).into()), Value::Str(" orders".into()))));
}
if isMarketOrder {
if (timeInForce.as_str() == Some("poc")) || (timeInForce.as_str() == Some("gtc")) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" createOrder () timeInForce for market order can only be \"FOK\" or \"IOC\"".into()))));
} else {
if (timeInForce == Value::Null) {
let mut defaultTif: Value = self.safe_string_k(self.options.clone(), "defaultTimeInForce", &[Value::Str("IOC".into())]);
let mut exchangeSpecificTif: Value = self.safe_string(self.options.as_map().and_then(|__m| __m.get("timeInForce")).cloned().unwrap_or(Value::Null), defaultTif, &[Value::Str("ioc".into())]);
timeInForce = exchangeSpecificTif;
}
}
}
let mut priceResolved: Value = price;
if isMarketOrder && (contract.as_bool() == Some(true)) {
priceResolved = Value::Int(0);
}
let mut contractAmount: Value = Value::Int(0);
if (contract.as_bool() == Some(true)) {
let mut isClose: Value = self.safe_bool_k(query.clone(), "close", &[]);
if (isClose.as_bool() != Some(true)) {
let mut amountToPrecision: Value = self.amount_to_precision(symbol.clone(), amount.clone());
let mut signedAmount: Value = amountToPrecision.clone();
if (side.as_str() == Some("sell")) {
signedAmount = crate::precise::Precise::stringNeg(&amountToPrecision);
}
contractAmount = (match &signedAmount { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null });
}
}
let mut amountResolved: Value = (if (contract.as_bool() == Some(true)) { contractAmount } else { amount });
let mut request: Value = Value::Null;
let mut nonTriggerOrder: bool = !isTpsl && (trigger == Value::Null);
if nonTriggerOrder {
if (contract.as_bool() == Some(true)) {
// contract order
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("size".to_string(), amountResolved.clone());
m
});
if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
add_element_to_object(&mut request, &Value::Str("settle".into()), market.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null)); // filled in prepareRequest above
}
if isMarketOrder {
add_element_to_object(&mut request, &Value::Str("price".into()), Value::Str("0".into())); // set to 0 for market orders
} else {
add_element_to_object(&mut request, &Value::Str("price".into()), (if (priceResolved.as_f64() == Some(0.0)) { Value::Str("0".into()) } else { self.price_to_precision(symbol.clone(), priceResolved.clone()) }));
}
if (reduceOnly != Value::Null) {
add_element_to_object(&mut request, &Value::Str("reduce_only".into()), reduceOnly.clone());
}
if (timeInForce != Value::Null) {
add_element_to_object(&mut request, &Value::Str("tif".into()), timeInForce.clone());
}
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.get_margin_mode(Value::Bool(false), query.clone()); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); query = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
// spot order
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency_pair".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), type_var.clone());
m.insert("account".to_string(), marginMode.clone());
m.insert("side".to_string(), side.clone());
m
});
if isMarketOrder && (side.as_str() == Some("buy")) {
let mut quoteAmount: Value = Value::Null;
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_bool_and_params(query.clone(), Value::Str("createOrder".into()), Value::Str("createMarketBuyOrderRequiresPrice".into()), &[Value::Bool(true)]); createMarketBuyOrderRequiresPrice = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); query = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut cost: Value = self.safe_number_k(query.clone(), "cost", &[]);
query = self.omit(query.clone(), Value::Str("cost".into()), &[]);
if (cost != Value::Null) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost);
} else if is_true(&createMarketBuyOrderRequiresPrice) {
if (priceResolved == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument".into()))));
} else {
let mut amountString: Value = self.number_to_string(amountResolved.clone());
let mut priceString: Value = self.number_to_string(priceResolved.clone());
let mut costRequest: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
quoteAmount = self.cost_to_precision(symbol.clone(), costRequest);
}
} else {
quoteAmount = self.cost_to_precision(symbol.clone(), amountResolved.clone());
}
add_element_to_object(&mut request, &Value::Str("amount".into()), quoteAmount);
} else {
add_element_to_object(&mut request, &Value::Str("amount".into()), self.amount_to_precision(symbol.clone(), amountResolved.clone()));
}
if isLimitOrder {
add_element_to_object(&mut request, &Value::Str("price".into()), self.price_to_precision(symbol.clone(), priceResolved.clone()));
}
if (timeInForce != Value::Null) {
add_element_to_object(&mut request, &Value::Str("time_in_force".into()), timeInForce.clone());
}
}
let mut textIsRequired: Value = self.safe_bool_k(query.clone(), "textIsRequired", &[Value::Bool(false)]);
if (clientOrderId != Value::Null) {
// user-defined, must follow the rules if not empty
// prefixed with t-
// no longer than 28 bytes without t- prefix
// can only include 0-9, A-Z, a-z, underscores (_), hyphens (-) or dots (.)
if ((clientOrderId.len() as i64) as f64) > ((28i64) as f64) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" createOrder () clientOrderId or text param must be up to 28 characters".into()))));
}
query = self.omit(query.clone(), Value::Str("textIsRequired".into()), &[]);
if (get_value(&clientOrderId, &Value::Int(0)).as_str() != Some("t")) {
clientOrderId = Value::Str(format!("{}{}", Value::Str("t-".into()), clientOrderId).into());
}
add_element_to_object(&mut request, &Value::Str("text".into()), clientOrderId.clone());
} else {
if (textIsRequired.as_bool() == Some(true)) {
// batchOrders requires text in the request
add_element_to_object(&mut request, &Value::Str("text".into()), Value::Str(format!("{}{}", Value::Str("t-".into()), self.uuid16(&[])).into()));
}
}
} else {
if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() conditional option orders are not supported".into()))));
}
if (contract.as_bool() == Some(true)) {
// contract conditional order
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("initial".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("size".to_string(), amountResolved.clone());
m
}));
m.insert("settle".to_string(), market.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null));
m
});
if (type_var.as_str() == Some("market")) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".into())), &Value::Str("price".into()), Value::Str("0".into()));
} else {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".into())), &Value::Str("price".into()), (if (priceResolved.as_f64() == Some(0.0)) { Value::Str("0".into()) } else { self.price_to_precision(symbol.clone(), priceResolved.clone()) }));
}
if (trigger == Value::Null) {
let mut rule: Value = Value::Null;
let mut triggerOrderPrice: Value = Value::Null;
if isStopLossOrder {
// we let trigger orders be aliases for stopLoss orders because
// gateio doesn't accept conventional trigger orders for spot markets
rule = (if (side.as_str() == Some("buy")) { Value::Int(1) } else { Value::Int(2) });
triggerOrderPrice = self.price_to_precision(symbol.clone(), stopLossPrice.clone());
} else if isTakeProfitOrder {
rule = (if (side.as_str() == Some("buy")) { Value::Int(2) } else { Value::Int(1) });
triggerOrderPrice = self.price_to_precision(symbol.clone(), takeProfitPrice.clone());
}
let mut priceType: Value = self.safe_integer_k(query.clone(), "price_type", &[Value::Int(0)]);
if priceType.as_f64().unwrap_or(f64::NAN) < ((0i64) as f64) || priceType.as_f64().unwrap_or(f64::NAN) > ((2i64) as f64) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" createOrder () price_type should be 0 latest deal price, 1 mark price, 2 index price".into()))));
}
query = self.omit(query.clone(), Value::from(vec![Value::Str("price_type".into())]), &[]);
add_element_to_object(&mut request, &Value::Str("trigger".into()), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price_type".to_string(), priceType);
m.insert("price".to_string(), self.price_to_precision(symbol.clone(), triggerOrderPrice.clone()));
m.insert("rule".to_string(), rule.clone());
m
}));
}
if (reduceOnly != Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".into())), &Value::Str("reduce_only".into()), reduceOnly);
}
if (timeInForce != Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".into())), &Value::Str("tif".into()), timeInForce.clone());
}
if (clientOrderId != Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".into())), &Value::Str("text".into()), clientOrderId.clone());
}
} else {
// spot conditional order
let mut options: Value = self.safe_dict_k(self.options.clone(), "createOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.get_margin_mode(Value::Bool(true), query.clone()); marginMode = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); query = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (timeInForce == Value::Null) {
timeInForce = Value::Str("gtc".into());
}
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var);
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.price_to_precision(symbol.clone(), priceResolved));
m.insert("amount".to_string(), self.amount_to_precision(symbol.clone(), amountResolved));
m.insert("account".to_string(), marginMode);
m.insert("time_in_force".to_string(), timeInForce);
m
}));
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (trigger == Value::Null) {
let mut defaultExpiration: Value = self.safe_integer_k(options, "expiration", &[]);
let mut expiration: Value = self.safe_integer_k(query.clone(), "expiration", &[defaultExpiration]);
let mut rule: Value = Value::Null;
let mut triggerOrderPrice: Value = Value::Null;
if isStopLossOrder {
// we let trigger orders be aliases for stopLoss orders because
// gateio doesn't accept conventional trigger orders for spot markets
rule = (if (side.as_str() == Some("buy")) { Value::Str(">=".into()) } else { Value::Str("<=".into()) });
triggerOrderPrice = self.price_to_precision(symbol.clone(), stopLossPrice);
} else if isTakeProfitOrder {
rule = (if (side.as_str() == Some("buy")) { Value::Str("<=".into()) } else { Value::Str(">=".into()) });
triggerOrderPrice = self.price_to_precision(symbol.clone(), takeProfitPrice);
}
add_element_to_object(&mut request, &Value::Str("trigger".into()), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), self.price_to_precision(symbol, triggerOrderPrice));
m.insert("rule".to_string(), rule);
m.insert("expiration".to_string(), expiration);
m
}));
if (clientOrderId != Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("trigger".into())), &Value::Str("text".into()), clientOrderId);
}
}
}
}
return self.extend(request, &[query]);
Value::Null
}
/*
* @method
* @name gate#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @see https://www.gate.com/docs/developers/apiv4/en/#create-an-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.unifiedAccount] set to true for creating a unified account order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_market_buy_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketBuyOrderWithCost() supports spot orders only".into()))));
}
let mut paramsExtended: Value = self.extend(params, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(false));
m
})]);
return self.create_order(symbol, Value::Str("market".into()), Value::Str("buy".into()), cost, &[Value::Null, paramsExtended]).await;
Value::Null
}
pub fn edit_order_request(&self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut market: Value = self.market(symbol.clone());
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("editOrder".into()), &[market.clone(), params]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut account: Value = self.convert_type_to_account(marketType.clone());
let mut isUnifiedAccountparamsUnifiedAccountVariable = self.handle_option_bool_and_params(paramsMarketType, Value::Str("editOrder".into()), Value::Str("unifiedAccount".into()), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&isUnifiedAccount) {
account = Value::Str("unified".into());
}
let mut isLimitOrder: bool = type_var.as_str() == Some("limit");
if (account.as_str() == Some("spot")) {
if !isLimitOrder {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" editOrder() does not support ".into())).into()), type_var).into()), Value::Str(" orders for ".into())).into()), marketType).into()), Value::Str(" markets".into()))));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), to_string_val(&id));
m.insert("currency_pair".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("account".to_string(), account);
m
});
if (amount != Value::Null) {
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("amount".into(), self.amount_to_precision(symbol.clone(), amount.clone())); }
} else {
if (side.as_str() == Some("sell")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("size".into(), self.parse_to_numeric(crate::precise::Precise::stringNeg(&self.amount_to_precision(symbol.clone(), amount.clone())))); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("size".into(), self.parse_to_numeric(self.amount_to_precision(symbol.clone(), amount))); }
}
}
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol, price)); }
}
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("settle".into(), market.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null)); }
}
return self.extend(request, &[paramsUnifiedAccount]);
Value::Null
}
/*
* @method
* @name gate#editOrder
* @description edit a trade order, gate currently only supports the modification of the price or amount fields
* @see https://www.gate.com/docs/developers/apiv4/en/#amend-single-order
* @see https://www.gate.com/docs/developers/apiv4/en/#amend-single-order-2
* @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 the currency you want to trade in units of the 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 {bool} [params.unifiedAccount] set to true for editing an order in a unified account
* @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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut extendedRequest: Value = self.edit_order_request(id, symbol, type_var, side, &[amount, price, params]);
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
response = self.private_spot_patch_orders_order_id(&[extendedRequest.clone()]).await;
} else {
response = self.private_futures_put_settle_orders_order_id(&[extendedRequest]).await;
}
return self.parse_order(response, &[market]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("open".to_string(), Value::Str("open".into()));
m.insert("_new".to_string(), Value::Str("open".into()));
m.insert("filled".to_string(), Value::Str("closed".into()));
m.insert("cancelled".to_string(), Value::Str("canceled".into()));
m.insert("liquidated".to_string(), Value::Str("closed".into()));
m.insert("ioc".to_string(), Value::Str("canceled".into()));
m.insert("failed".to_string(), Value::Str("canceled".into()));
m.insert("expired".to_string(), Value::Str("canceled".into()));
m.insert("finished".to_string(), Value::Str("closed".into()));
m.insert("finish".to_string(), Value::Str("closed".into()));
m.insert("succeeded".to_string(), Value::Str("closed".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// SPOT
// createOrder/cancelOrder/fetchOrder/editOrder
//
// {
// "id": "62364648575",
// "text": "apiv4",
// "create_time": "1626354834",
// "update_time": "1626354834",
// "create_time_ms": "1626354833544",
// "update_time_ms": "1626354833544",
// "status": "open",
// "currency_pair": "BTC_USDT",
// "type": "limit",
// "account": "spot",
// "side": "buy",
// "amount": "0.0001",
// "price": "30000",
// "time_in_force": "gtc",
// "iceberg": "0",
// "left": "0.0001",
// "fill_price": "0",
// "filled_total": "0",
// "fee": "0",
// "fee_currency": "BTC",
// "point_fee": "0",
// "gt_fee": "0",
// "gt_discount": true,
// "rebated_fee": "0",
// "rebated_fee_currency": "USDT"
// }
//
// SPOT TRIGGER ORDERS
// createOrder
//
// {
// "id": 12604556
// }
//
// fetchOrder/cancelOrder
//
// {
// "market": "ADA_USDT",
// "user": 6392049,
// "trigger": {
// "price": "1.08", // stopPrice
// "rule": "\u003e=",
// "expiration": 86400
// },
// "put": {
// "type": "limit",
// "side": "buy",
// "price": "1.08", // order price
// "amount": "1.00000000000000000000",
// "account": "normal",
// "time_in_force": "gtc"
// },
// "id": 71639298,
// "ctime": 1643945985,
// "status": "open"
// }
//
// FUTURE, SWAP AND OPTION
// createOrder/cancelOrder/fetchOrder
//
// {
// "id": 123028481731,
// "contract": "ADA_USDT",
// "mkfr": "-0.00005",
// "tkfr": "0.00048",
// "tif": "ioc",
// "is_reduce_only": false,
// "create_time": 1643950262.68,
// "finish_time": 1643950262.68,
// "price": "0",
// "size": 1,
// "refr": "0",
// "left":0,
// "text": "api",
// "fill_price": "1.05273",
// "user":6329238,
// "finish_as": "filled",
// "status": "finished",
// "is_liq": false,
// "refu":0,
// "is_close": false,
// "iceberg": 0
// }
//
// TRIGGER ORDERS (FUTURE AND SWAP)
// createOrder
//
// {
// "id": 12604556
// }
//
// fetchOrder/cancelOrder
//
// {
// "user": 6320300,
// "trigger": {
// "strategy_type": 0,
// "price_type": 0,
// "price": "1.03", // stopPrice
// "rule": 2,
// "expiration": 0
// },
// "initial": {
// "contract": "ADA_USDT",
// "size": -1,
// "price": "1.02",
// "tif": "gtc",
// "text": "",
// "iceberg": 0,
// "is_close": false,
// "is_reduce_only": false,
// "auto_size": ""
// },
// "id": 126393906,
// "trade_id": 0,
// "status": "open",
// "reason": "",
// "create_time": 1643953482,
// "finish_time": 1643953482,
// "is_stop_order": false,
// "stop_trigger": {
// "rule": 0,
// "trigger_price": "",
// "order_price": ""
// },
// "me_order_id": 0,
// "order_type": ""
// }
//
// {
// "text": "t-d18baf9ac44d82e2",
// "succeeded": false,
// "label": "BALANCE_NOT_ENOUGH",
// "message": "Not enough balance"
// }
//
// {"user_id":10406147,"id":"id","succeeded":false,"message":"INVALID_PROTOCOL","label":"INVALID_PROTOCOL"}
//
// cancel trigger order returns timestamps in ms
// id: '2007047737421336576',
// id_string: '2007047737421336576',
// trigger_time: '0',
// trade_id: '0',
// trade_id_string: '',
// status: 'finished',
// finish_as: 'cancelled',
// reason: '',
// create_time: '1767352444402496'
// finish_time: '1767352509535790',
// is_stop_order: false,
// stop_trigger: { rule: '0', trigger_price: '', order_price: '' },
// me_order_id: '0',
// me_order_id_string: '',
// order_type: '',
// in_dual_mode: false,
// parent_id: '0',
//
// unified spot: watchOrders
//
// {
// "id": "1036717689726",
// "text": "apiv4",
// "create_time": "1774613210",
// "update_time": "1774613210",
// "currency_pair": "BTC_USDT",
// "type": "limit",
// "account": "unified",
// "side": "buy",
// "amount": "0.1",
// "price": "200",
// "time_in_force": "gtc",
// "left": "0.1",
// "filled_amount": "0",
// "filled_total": "0",
// "avg_deal_price": "0",
// "fee": "0",
// "fee_currency": "BTC",
// "point_fee": "0",
// "gt_fee": "0",
// "rebated_fee": "0",
// "rebated_fee_currency": "BTC",
// "create_time_ms": "1774613210391",
// "update_time_ms": "1774613210391",
// "user": 10406147,
// "event": "put",
// "stp_id": 0,
// "stp_act": "-",
// "finish_as": "open",
// "biz_info": "ch:ccxt",
// "amend_text": "-"
// }
//
let mut succeeded: Value = self.safe_bool_k(order.clone(), "succeeded", &[Value::Bool(true)]);
if (succeeded.as_bool() != Some(true)) {
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "text", &[]));
m.insert("info".to_string(), order.clone());
m.insert("status".to_string(), Value::Str("rejected".into()));
m.insert("id".to_string(), self.safe_string_k(order.clone(), "id", &[]));
m
}), &[]);
}
let mut put: Value = self.safe_dict2(order.clone(), Value::Str("put".into()), Value::Str("initial".into()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trigger: Value = self.safe_dict_k(order.clone(), "trigger", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contract: Value = self.safe_string_k(put.clone(), "contract", &[]);
let mut type_var: Value = self.safe_string_k(put.clone(), "type", &[]);
let mut timeInForce: Value = self.safe_string_upper2(put.clone(), Value::Str("time_in_force".into()), Value::Str("tif".into()), &[]);
let mut amount: Value = self.safe_string2(put.clone(), Value::Str("amount".into()), Value::Str("size".into()), &[]);
let mut side: Value = self.safe_string_k(put.clone(), "side", &[]);
let mut price: Value = self.safe_string_k(put, "price", &[]);
contract = self.safe_string_k(order.clone(), "contract", &[contract.clone()]);
type_var = self.safe_string_k(order.clone(), "type", &[type_var.clone()]);
timeInForce = self.safe_string_upper2(order.clone(), Value::Str("time_in_force".into()), Value::Str("tif".into()), &[timeInForce.clone()]);
if (timeInForce.as_str() == Some("POC")) {
timeInForce = Value::Str("PO".into());
}
let mut postOnly: Value = (Value::Bool(timeInForce.as_str() == Some("PO")));
amount = self.safe_string2(order.clone(), Value::Str("amount".into()), Value::Str("size".into()), &[amount.clone()]);
side = self.safe_string_k(order.clone(), "side", &[side.clone()]);
price = self.safe_string_k(order.clone(), "price", &[price.clone()]);
let mut remainingString: Value = self.safe_string_k(order.clone(), "left", &[]);
let mut cost: Value = self.safe_string_k(order.clone(), "filled_total", &[]);
let mut triggerPrice: Value = self.safe_number_k(trigger, "price", &[]);
let mut average: Value = self.safe_number2(order.clone(), Value::Str("avg_deal_price".into()), Value::Str("fill_price".into()), &[]);
if (triggerPrice != Value::Null) && (triggerPrice.as_f64() != Some(0.0)) {
remainingString = amount.clone();
cost = Value::Str("0".into());
}
if (contract != Value::Null) && (contract.as_str() != Some("")) {
let mut isMarketOrder: bool = is_true(&crate::precise::Precise::stringEquals(&price, &Value::Str("0".into()))) && (timeInForce.as_str() == Some("IOC"));
type_var = (if isMarketOrder { Value::Str("market".into()) } else { Value::Str("limit".into()) });
side = (if is_true(&crate::precise::Precise::stringGt(&amount, &Value::Str("0".into()))) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
}
let mut rawStatus: Value = self.safe_string_n(order.clone(), Value::from(vec![Value::Str("finish_as".into()), Value::Str("status".into()), Value::Str("open".into())]), &[]);
let mut timestampStr: Value = self.safe_string_k(order.clone(), "create_time_ms", &[]);
if (timestampStr == Value::Null) {
timestampStr = self.safe_string2(order.clone(), Value::Str("create_time".into()), Value::Str("ctime".into()), &[]);
if (timestampStr != Value::Null) {
if (Value::Int(timestampStr.len() as i64).as_f64() == Some(10.0)) || Value::Int(timestampStr.as_str().and_then(|__s| __s.find(".")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
// ts in seconds, multiply to ms
timestampStr = crate::precise::Precise::stringMul(×tampStr, &Value::Str("1000".into()));
} else if (Value::Int(timestampStr.len() as i64).as_f64() == Some(16.0)) {
// ts in microseconds, divide to ms
timestampStr = crate::precise::Precise::stringDiv(×tampStr, &Value::Str("1000".into()));
}
}
}
let mut lastTradeTimestampStr: Value = self.safe_string_k(order.clone(), "update_time_ms", &[]);
if (lastTradeTimestampStr == Value::Null) {
lastTradeTimestampStr = self.safe_string2(order.clone(), Value::Str("update_time".into()), Value::Str("finish_time".into()), &[]);
if (lastTradeTimestampStr != Value::Null) {
if (Value::Int(lastTradeTimestampStr.len() as i64).as_f64() == Some(10.0)) || Value::Int(lastTradeTimestampStr.as_str().and_then(|__s| __s.find(".")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
// ts in seconds, multiply to ms
lastTradeTimestampStr = crate::precise::Precise::stringMul(&lastTradeTimestampStr, &Value::Str("1000".into()));
} else if (Value::Int(lastTradeTimestampStr.len() as i64).as_f64() == Some(16.0)) {
// ts in microseconds, divide to ms
lastTradeTimestampStr = crate::precise::Precise::stringDiv(&lastTradeTimestampStr, &Value::Str("1000".into()));
}
}
}
let mut marketType: Value = Value::Str("contract".into());
if (matches!(&order, Value::Dict(__d) if __d.contains_key("currency_pair"))) || (matches!(&order, Value::Dict(__d) if __d.contains_key("market"))) {
marketType = Value::Str("spot".into());
}
let mut exchangeSymbol: Value = self.safe_string2(order.clone(), Value::Str("currency_pair".into()), Value::Str("market".into()), &[contract]);
let mut symbol: Value = self.safe_symbol(exchangeSymbol, &[market.clone(), Value::Str("_".into()), marketType]);
let mut fees: Value = Value::from(vec![]);
let mut gtFee: Value = self.safe_string_k(order.clone(), "gt_fee", &[]);
if (gtFee != Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), Value::Str("GT".into()));
m.insert("cost".to_string(), gtFee);
m
}));
}
let mut fee: Value = self.safe_string_k(order.clone(), "fee", &[]);
if (fee != Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(order.clone(), "fee_currency", &[]), &[]));
m.insert("cost".to_string(), fee);
m
}));
}
let mut rebate: Value = self.safe_string_k(order.clone(), "rebated_fee", &[]);
if (rebate != Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(order.clone(), "rebated_fee_currency", &[]), &[]));
m.insert("cost".to_string(), crate::precise::Precise::stringNeg(&rebate));
m
}));
}
let mut numFeeCurrencies: f64 = ((fees.len() as i64) as f64);
let mut multipleFeeCurrencies: bool = numFeeCurrencies > ((1i64) as f64);
let mut status: Value = self.parse_order_status(rawStatus);
let mut remaining: Value = crate::precise::Precise::stringAbs(&remainingString);
// handle spot market buy
let mut account: Option<String> = self.safe_string_k(order.clone(), "account", &[]).as_str().map(str::to_owned); // using this instead of market type because of the conflicting ids
if (account.as_deref() == Some("spot")) || (account.as_deref() == Some("unified")) {
let mut averageString: Value = self.safe_string_k(order.clone(), "avg_deal_price", &[]);
average = self.parse_number(averageString.clone(), &[]);
if (type_var.as_str() == Some("market")) && (side.as_str() == Some("buy")) {
remaining = crate::precise::Precise::stringDiv(&remainingString, &averageString);
price = Value::Null; // arrives as 0
cost = amount.clone();
amount = crate::precise::Precise::stringDiv(&amount, &averageString);
}
}
let mut timestamp: Value = Value::Null;
let mut lastTradeTimestamp: Value = Value::Null;
if (timestampStr != Value::Null) {
timestamp = self.parse_to_int(timestampStr);
}
if (lastTradeTimestampStr != Value::Null) {
lastTradeTimestamp = self.parse_to_int(lastTradeTimestampStr);
}
let mut initial: Value = self.safe_dict_k(order.clone(), "initial", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut reduceOnlyInitial: Value = self.safe_bool_k(initial, "is_reduce_only", &[]);
let mut reduceOnly: Value = self.safe_bool_k(order.clone(), "is_reduce_only", &[reduceOnlyInitial]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "text", &[]);
if (clientOrderId == Value::Null) {
if (matches!(&order, Value::Dict(__d) if __d.contains_key("initial"))) {
clientOrderId = self.safe_string(order.as_map().and_then(|__m| __m.get("initial")).cloned().unwrap_or(Value::Null), Value::Str("text".into()), &[]);
} else if (matches!(&order, Value::Dict(__d) if __d.contains_key("trigger"))) {
clientOrderId = self.safe_string(order.as_map().and_then(|__m| __m.get("trigger")).cloned().unwrap_or(Value::Null), Value::Str("text".into()), &[]);
}
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(order.clone(), "id", &[]));
m.insert("clientOrderId".to_string(), clientOrderId);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), lastTradeTimestamp);
m.insert("status".to_string(), status);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), type_var);
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), postOnly);
m.insert("reduceOnly".to_string(), reduceOnly);
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("triggerPrice".to_string(), triggerPrice);
m.insert("average".to_string(), average);
m.insert("amount".to_string(), crate::precise::Precise::stringAbs(&amount));
m.insert("cost".to_string(), crate::precise::Precise::stringAbs(&cost));
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), remaining);
m.insert("fee".to_string(), (if multipleFeeCurrencies { Value::Null } else { self.safe_dict(fees.clone(), Value::Int(0), &[]) }));
m.insert("fees".to_string(), (if multipleFeeCurrencies { fees } else { Value::from(vec![]) }));
m.insert("trades".to_string(), Value::Null);
m.insert("info".to_string(), order);
m
}), &[market]);
Value::Null
}
pub fn fetch_order_request(&self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut market: Value = (if (symbol == Value::Null) { Value::Null } else { self.market(symbol) });
let mut trigger: Value = self.safe_bool_n(params.clone(), Value::from(vec![Value::Str("trigger".into()), Value::Str("is_stop_order".into()), Value::Str("stop".into())]), &[Value::Bool(false)]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("is_stop_order".into()), Value::Str("stop".into()), Value::Str("trigger".into())]), &[]);
let mut clientOrderId: Value = self.safe_string2(paramsOmitted.clone(), Value::Str("text".into()), Value::Str("clientOrderId".into()), &[]);
let mut orderId: Value = id;
if (clientOrderId != Value::Null) {
if (get_value(&clientOrderId, &Value::Int(0)).as_str() != Some("t")) {
clientOrderId = Value::Str(format!("{}{}", Value::Str("t-".into()), clientOrderId).into());
}
orderId = clientOrderId.clone();
}
let mut paramsOrder: Value = (if (clientOrderId != Value::Null) { self.omit(paramsOmitted.clone(), Value::from(vec![Value::Str("text".into()), Value::Str("clientOrderId".into())]), &[]) } else { paramsOmitted });
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchOrder".into()), &[market.clone(), paramsOrder]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut contract: bool = (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) || (type_var.as_str() == Some("option"));
let mut requestrequestParamsVariable = (if contract { self.prepare_request(&[market.clone(), type_var, query.clone()]) } else { self.spot_order_prepare_request(&[market, trigger, query]) });
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut request, &Value::Str("order_id".into()), to_string_val(&orderId));
return Value::from(vec![request, requestParams]);
Value::Null
}
/*
* @method
* @name gate#fetchOrder
* @description Retrieves information on an order
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-order-details
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-auto-order-details
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-order-details-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-auto-order-details-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-order-details-3
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-auto-order-details-3
* @see https://www.gate.com/docs/developers/apiv4/en/#query-single-order-details-4
* @param {string} id Order id
* @param {string} symbol Unified market symbol, *required for spot and margin*
* @param {object} [params] Parameters specified by the exchange api
* @param {bool} [params.trigger] True if the order being fetched is a trigger order
* @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
* @param {string} [params.type] 'spot', 'swap', or 'future', if not provided this.options['defaultMarginMode'] is used
* @param {string} [params.settle] 'btc' or 'usdt' - settle currency for perpetual swap and future - market settle currency is used if symbol !== undefined, default="usdt" for swap and "btc" for future
* @param {bool} [params.unifiedAccount] set to true for fetching a unified account order
* @returns An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = (if (symbol == Value::Null) { Value::Null } else { self.market(symbol.clone()) });
let mut type_var: Value = self.handle_market_type_and_params(Value::Str("fetchOrder".into()), &[market.clone(), params.clone()]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut trigger: Value = self.safe_bool_n(params.clone(), Value::from(vec![Value::Str("trigger".into()), Value::Str("is_stop_order".into()), Value::Str("stop".into())]), &[Value::Bool(false)]);
let mut requestrequestParamsVariable = self.fetch_order_request(id.clone(), &[symbol, params]);
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_45 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_get_price_orders_order_id(&[__ws_arg_45]).await;
} else {
let __ws_arg_46 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_get_orders_order_id(&[__ws_arg_46]).await;
}
} else if (type_var.as_str() == Some("swap")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_47 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_get_settle_price_orders_order_id(&[__ws_arg_47]).await;
} else {
let __ws_arg_48 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_get_settle_orders_order_id(&[__ws_arg_48]).await;
}
} else if (type_var.as_str() == Some("future")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_49 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_get_settle_price_orders_order_id(&[__ws_arg_49]).await;
} else {
let __ws_arg_50 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_get_settle_orders_order_id(&[__ws_arg_50]).await;
}
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_51 = self.extend(request, &[requestParams]);
response = self.private_options_get_orders_order_id(&[__ws_arg_51]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrder() not support this market type".into()))));
}
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name gate#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://www.gate.com/docs/developers/apiv4/en/#list-all-open-orders
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] true for fetching trigger orders
* @param {string} [params.type] spot, margin, swap or future, if not provided this.options['defaultType'] is used
* @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for type='margin', if not provided this.options['defaultMarginMode'] is used
* @param {bool} [params.unifiedAccount] set to true for fetching unified account orders
* @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
}));
return self.fetch_orders_by_status(Value::Str("open".into()), &[symbol, since, limit, params]).await;
Value::Null
}
/*
* @method
* @name gate#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://www.gate.com/en-eu/docs/developers/apiv4/#list-orders
* @see https://www.gate.com/en-eu/docs/developers/apiv4/#retrieve-running-auto-order-list
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-order-list
* @see https://www.gate.com/docs/developers/apiv4/en/#query-auto-order-list
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-order-list-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-auto-order-list-2
* @see https://www.gate.com/docs/developers/apiv4/en/#list-options-orders
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-order-list-by-time-range
* @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 {bool} [params.trigger] true for fetching trigger orders
* @param {string} [params.type] spot, swap or future, if not provided this.options['defaultType'] is used
* @param {string} [params.marginMode] 'cross' or 'isolated' - marginMode for margin trading if not provided this.options['defaultMarginMode'] is used
* @param {boolean} [params.historical] *swap only* true for using historical endpoint
* @param {bool} [params.unifiedAccount] set to true for fetching unified account orders
* @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 {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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchClosedOrders".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchClosedOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut until: Value = self.safe_integer_k(paramsPaginate.clone(), "until", &[]);
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut symbolResolved: Value = (if (market != Value::Null) { self.safe_string_k(market.clone(), "symbol", &[]) } else { symbol });
let mut type_var: Value = self.handle_market_type_and_params(Value::Str("fetchClosedOrders".into()), &[market.clone(), paramsPaginate.clone()]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut useHistoricalparamsHistoricalVariable = self.handle_option_bool_and_params(paramsPaginate, Value::Str("fetchClosedOrders".into()), Value::Str("historical".into()), &[Value::Bool(false)]);
let mut useHistorical: Value = useHistoricalparamsHistoricalVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsHistorical: Value = useHistoricalparamsHistoricalVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if !is_true(&useHistorical) && (((since == Value::Null) && (until == Value::Null)) || (type_var.as_str() != Some("swap"))) {
return self.fetch_orders_by_status(Value::Str("finished".into()), &[symbolResolved, since.clone(), limit.clone(), paramsHistorical.clone()]).await;
}
let mut requestparamsRequestVariable = self.prepare_request(&[market.clone(), type_var, self.omit(paramsHistorical, Value::Str("type".into()), &[])]);
let mut request: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsRequest: Value = requestparamsRequestVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
if (until != Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".into()), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), limit.clone());
}
let __ws_arg_52 = self.extend(request, &[self.omit(paramsRequest, Value::Str("until".into()), &[])]);
let mut response: Value = self.private_futures_get_settle_orders_timerange(&[__ws_arg_52]).await;
return self.parse_orders(response, &[market, since, limit]);
Value::Null
}
pub fn prepare_orders_by_status_request(&self, mut status: 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
}));
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut triggerparamsTriggerVariable = self.handle_param_bool2(params, Value::Str("trigger".into()), Value::Str("stop".into()), &[]);
let mut trigger: Value = triggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTrigger: Value = triggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".into()), &[market.clone(), paramsTrigger]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut spot: bool = (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin"));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut query: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = (if spot { self.multi_order_spot_prepare_request(&[market.clone(), trigger.clone(), paramsMarketType.clone()]) } else { self.prepare_request(&[market, type_var, paramsMarketType]) }); request = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); query = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if spot && (trigger.as_bool() == Some(true)) {
request = self.omit(request.clone(), Value::Str("account".into()), &[]);
}
add_element_to_object(&mut request, &Value::Str("status".into()), (if (status.as_str() == Some("closed")) { Value::Str("finished".into()) } else { status }));
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), limit);
}
if spot {
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
let mut until: Value = self.safe_integer_k(query.clone(), "until", &[]);
if (until != Value::Null) {
query = self.omit(query.clone(), Value::Str("until".into()), &[]);
add_element_to_object(&mut request, &Value::Str("to".into()), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
}
let mut lastIdfinalParamsVariable = self.handle_param_string2(query, Value::Str("lastId".into()), Value::Str("last_id".into()), &[]);
let mut lastId: Value = lastIdfinalParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut finalParams: Value = lastIdfinalParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (lastId != Value::Null) {
add_element_to_object(&mut request, &Value::Str("last_id".into()), lastId);
}
return Value::from(vec![request, finalParams]);
Value::Null
}
pub async fn fetch_orders_by_status(&mut self, mut status: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut symbolResolved: Value = (if (market != Value::Null) { self.safe_string_k(market.clone(), "symbol", &[]) } else { symbol });
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".into()), Value::Str("stop".into()), &[]);
let mut type_var: Value = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".into()), &[market.clone(), params.clone()]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
// don't omit here, omits done in prepareOrdersByStatusRequest
let mut requestrequestParamsVariable = self.prepare_orders_by_status_request(status.clone(), &[symbolResolved.clone(), since.clone(), limit.clone(), params]);
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut spot: bool = (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin"));
let mut openStatus: bool = status.as_str() == Some("open");
let mut openSpotOrders: bool = spot && openStatus && (trigger.as_bool() != Some(true));
let mut response: Value = Value::Null;
if spot {
if (trigger.as_bool() != Some(true)) {
if openStatus {
let __ws_arg_53 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_get_open_orders(&[__ws_arg_53]).await;
} else {
let __ws_arg_54 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_get_orders(&[__ws_arg_54]).await;
}
} else {
let __ws_arg_55 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_get_price_orders(&[__ws_arg_55]).await;
}
} else if (type_var.as_str() == Some("swap")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_56 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_get_settle_price_orders(&[__ws_arg_56]).await;
} else {
let __ws_arg_57 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_get_settle_orders(&[__ws_arg_57]).await;
}
} else if (type_var.as_str() == Some("future")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_58 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_get_settle_price_orders(&[__ws_arg_58]).await;
} else {
let __ws_arg_59 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_get_settle_orders(&[__ws_arg_59]).await;
}
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_60 = self.extend(request, &[requestParams]);
response = self.private_options_get_orders(&[__ws_arg_60]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() not support this market type".into()))));
}
//
// spot open orders
//
// [
// {
// "currency_pair": "ADA_USDT",
// "total": 2,
// "orders": [
// {
// "id": "155498539874",
// "text": "apiv4",
// "create_time": "1652406843",
// "update_time": "1652406843",
// "create_time_ms": 1652406843295,
// "update_time_ms": 1652406843295,
// "status": "open",
// "currency_pair": "ADA_USDT",
// "type": "limit",
// "account": "spot",
// "side": "buy",
// "amount": "3",
// "price": "0.35",
// "time_in_force": "gtc",
// "iceberg": "0",
// "left": "3",
// "fill_price": "0",
// "filled_total": "0",
// "fee": "0",
// "fee_currency": "ADA",
// "point_fee": "0",
// "gt_fee": "0",
// "gt_discount": false,
// "rebated_fee": "0",
// "rebated_fee_currency": "USDT"
// },
// ...
// ]
// },
// ...
// ]
//
// spot
//
// [
// {
// "id": "8834234273",
// "text": "3",
// "create_time": "1635406193",
// "update_time": "1635406193",
// "create_time_ms": 1635406193361,
// "update_time_ms": 1635406193361,
// "status": "closed",
// "currency_pair": "BTC_USDT",
// "type": "limit",
// "account": "spot", // margin for margin orders
// "side": "sell",
// "amount": "0.0002",
// "price": "58904.01",
// "time_in_force": "gtc",
// "iceberg": "0",
// "left": "0.0000",
// "fill_price": "11.790516",
// "filled_total": "11.790516",
// "fee": "0.023581032",
// "fee_currency": "USDT",
// "point_fee": "0",
// "gt_fee": "0",
// "gt_discount": false,
// "rebated_fee_currency": "BTC"
// }
// ]
//
// spot trigger
//
// [
// {
// "market": "ADA_USDT",
// "user": 10406147,
// "trigger": {
// "price": "0.65",
// "rule": "\u003c=",
// "expiration": 86400
// },
// "put": {
// "type": "limit",
// "side": "sell",
// "price": "0.65",
// "amount": "2.00000000000000000000",
// "account": "normal", // margin for margin orders
// "time_in_force": "gtc"
// },
// "id": 8449909,
// "ctime": 1652188982,
// "status": "open"
// }
// ]
//
// swap
//
// [
// {
// "status": "finished",
// "size": -1,
// "left": 0,
// "id": 82750739203,
// "is_liq": false,
// "is_close": false,
// "contract": "BTC_USDT",
// "text": "web",
// "fill_price": "60721.3",
// "finish_as": "filled",
// "iceberg": 0,
// "tif": "ioc",
// "is_reduce_only": true,
// "create_time": 1635403475.412,
// "finish_time": 1635403475.4127,
// "price": "0"
// }
// ]
//
// option
//
// [
// {
// "id": 2593450699,
// "contract": "BTC_USDT-20230601-27500-C",
// "mkfr": "0.0003",
// "tkfr": "0.0003",
// "tif": "gtc",
// "is_reduce_only": false,
// "create_time": 1685503873,
// "price": "200",
// "size": 1,
// "refr": "0",
// "left": 1,
// "text": "api",
// "fill_price": "0",
// "user": 5691076,
// "status": "open",
// "is_liq": false,
// "refu": 0,
// "is_close": false,
// "iceberg": 0
// }
// ]
//
let mut result: Value = response.clone();
if openSpotOrders {
let mut spotResult: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_700: bool = true;
while { if !__for_first_700 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_700 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut responseEntry: Value = self.safe_dict(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ordersInner: Value = self.safe_value_k(responseEntry, "orders", &[]);
spotResult = self.array_concat(spotResult.clone(), ordersInner);
}
}
result = spotResult;
}
let mut orders: Value = self.parse_orders(result, &[market, since.clone(), limit.clone()]);
return self.filter_by_symbol_since_limit(orders, &[symbolResolved, since, limit]);
Value::Null
}
/*
* @method
* @name gate#cancelOrder
* @description Cancels an open order
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-single-order
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-single-auto-order
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-single-order-2
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-single-auto-order-2
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-single-order-3
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-single-auto-order-3
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-single-order-4
* @param {string} id Order id
* @param {string} symbol Unified market symbol
* @param {object} [params] Parameters specified by the exchange api
* @param {bool} [params.trigger] True if the order to be cancelled is a trigger order
* @param {bool} [params.unifiedAccount] set to true for canceling unified account orders
* @returns 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = (if (symbol == Value::Null) { Value::Null } else { self.market(symbol) });
let mut trigger: Value = self.safe_bool_n(params.clone(), Value::from(vec![Value::Str("is_stop_order".into()), Value::Str("stop".into()), Value::Str("trigger".into())]), &[Value::Bool(false)]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("is_stop_order".into()), Value::Str("stop".into()), Value::Str("trigger".into())]), &[]);
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("cancelOrder".into()), &[market.clone(), paramsOmitted]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestrequestParamsVariable = (if ((type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin"))) { self.spot_order_prepare_request(&[market.clone(), trigger.clone(), query.clone()]) } else { self.prepare_request(&[market.clone(), type_var.clone(), query]) });
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut request, &Value::Str("order_id".into()), id.clone());
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_61 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_delete_price_orders_order_id(&[__ws_arg_61]).await;
} else {
let __ws_arg_62 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_delete_orders_order_id(&[__ws_arg_62]).await;
}
} else if (type_var.as_str() == Some("swap")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_63 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_delete_settle_price_orders_order_id(&[__ws_arg_63]).await;
} else {
let __ws_arg_64 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_delete_settle_orders_order_id(&[__ws_arg_64]).await;
}
} else if (type_var.as_str() == Some("future")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_65 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_delete_settle_price_orders_order_id(&[__ws_arg_65]).await;
} else {
let __ws_arg_66 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_delete_settle_orders_order_id(&[__ws_arg_66]).await;
}
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_67 = self.extend(request, &[requestParams]);
response = self.private_options_delete_orders_order_id(&[__ws_arg_67]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() not support this market type".into()))));
}
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name gate#cancelOrders
* @description cancel multiple orders
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-batch-orders-by-specified-id-list
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-batch-orders-by-specified-id-list-2
* @param {string[]} ids order ids
* @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 {bool} [params.unifiedAccount] set to true for canceling unified account orders
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut defaultSettle: Value = Value::Null;
if (market == Value::Null) {
defaultSettle = Value::Str("usdt".into());
} else {
defaultSettle = market.as_map().and_then(|__m| __m.get("settle")).cloned().unwrap_or(Value::Null);
}
let mut settle: Value = self.safe_string_lower_k(params.clone(), "settle", &[defaultSettle]);
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("cancelOrders".into()), &[market, params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut isSpot: bool = type_var.as_str() == Some("spot");
if isSpot && (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrders requires a symbol argument for spot markets".into()))));
}
if isSpot {
let mut ordersRequests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_701: bool = true;
while { if !__for_first_701 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_701 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
let mut id: Value = ids.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut orderItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("symbol".to_string(), symbol.clone());
m
});
append_to_array(&mut ordersRequests, orderItem);
}
}
return self.cancel_orders_for_symbols(ordersRequests, &[paramsMarketType]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settle".to_string(), settle);
m
});
let mut finalList: Value = Value::from(vec![request]); // hacky but needs to be done here
{
let mut i: Value = Value::Int(0);
let mut __for_first_702: bool = true;
while { if !__for_first_702 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_702 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
append_to_array(&mut finalList, ids.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
}
}
let mut response: Value = self.private_futures_post_settle_batch_cancel_orders(&[finalList]).await;
return self.parse_orders(response, &[]);
Value::Null
}
/*
* @method
* @name gate#cancelOrdersForSymbols
* @description cancel multiple orders for multiple symbols
* @see https://www.gate.com/en-eu/docs/developers/apiv4/#cancel-a-batch-of-orders-with-an-id-list
* @param {CancellationRequest[]} orders list of order ids with symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string[]} [params.clientOrderIds] client order ids
* @param {bool} [params.unifiedAccount] set to true for canceling unified account orders
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders_for_symbols(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut ordersRequests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_703: bool = true;
while { if !__for_first_703 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_703 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut order: Value = self.safe_dict(orders.clone(), i.clone(), &[]);
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelOrdersForSymbols() supports only spot markets".into()))));
}
let mut id: Value = self.safe_string_k(order, "id", &[]);
let mut orderItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("currency_pair".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
append_to_array(&mut ordersRequests, orderItem);
}
}
let mut response: Value = self.private_spot_post_cancel_batch_orders(&[ordersRequests]).await;
return self.parse_orders(response, &[]);
Value::Null
}
/*
* @method
* @name gate#cancelAllOrders
* @description cancel all open orders
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-all-open-orders-in-specified-currency-pair
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-all-auto-orders
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-all-orders-with-open-status
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-all-auto-orders-2
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-all-orders-with-open-status-2
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-all-auto-orders-3
* @see https://www.gate.com/docs/developers/apiv4/en/#cancel-all-orders-with-open-status-3
* @param {string} [symbol] unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.unifiedAccount] set to true for canceling unified account orders
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = (if (symbol == Value::Null) { Value::Null } else { self.market(symbol) });
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".into()), Value::Str("trigger".into()), &[]);
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("stop".into()), Value::Str("trigger".into())]), &[]);
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("cancelAllOrders".into()), &[market.clone(), paramsOmitted]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestrequestParamsVariable = (if (type_var.as_str() == Some("spot")) { self.multi_order_spot_prepare_request(&[market.clone(), trigger.clone(), query.clone()]) } else { self.prepare_request(&[market.clone(), type_var.clone(), query]) });
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_68 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_delete_price_orders(&[__ws_arg_68]).await;
} else {
let __ws_arg_69 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_spot_delete_orders(&[__ws_arg_69]).await;
}
} else if (type_var.as_str() == Some("swap")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_70 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_delete_settle_price_orders(&[__ws_arg_70]).await;
} else {
let __ws_arg_71 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_delete_settle_orders(&[__ws_arg_71]).await;
}
} else if (type_var.as_str() == Some("future")) {
if (trigger.as_bool() == Some(true)) {
let __ws_arg_72 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_delete_settle_price_orders(&[__ws_arg_72]).await;
} else {
let __ws_arg_73 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_delete_settle_orders(&[__ws_arg_73]).await;
}
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_74 = self.extend(request, &[requestParams]);
response = self.private_options_delete_orders(&[__ws_arg_74]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" cancelAllOrders() not support this market type".into()))));
}
return self.parse_orders(response, &[market]);
Value::Null
}
/*
* @method
* @name gate#transfer
* @description transfer currency internally between wallets on the same account
* @see https://www.gate.com/docs/developers/apiv4/en/#transfer-between-trading-accounts
* @param {string} code unified currency code for currency being transferred
* @param {float} amount the amount of currency to transfer
* @param {string} fromAccount the account to transfer currency from
* @param {string} toAccount the account to transfer currency to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.symbol] Unified market symbol *required for type == margin*
* @returns A [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut fromId: Value = self.convert_type_to_account(fromAccount);
let mut toId: Value = self.convert_type_to_account(toAccount);
let mut truncated: Value = self.currency_to_precision(code, amount, &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), truncated);
m
});
if !(in_op(&self.options.as_map().and_then(|__m| __m.get("accountsByType")).cloned().unwrap_or(Value::Null), &fromId)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), Value::Str("margin".into())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), fromId.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), fromId.clone()); }
}
if !(in_op(&self.options.as_map().and_then(|__m| __m.get("accountsByType")).cloned().unwrap_or(Value::Null), &toId)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("to".into(), Value::Str("margin".into())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), toId.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("to".into(), toId.clone()); }
}
if (fromId.as_str() == Some("margin")) || (toId.as_str() == Some("margin")) {
let mut symbol: Value = self.safe_string2(params.clone(), Value::Str("symbol".into()), Value::Str("currency_pair".into()), &[]);
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" transfer requires params[\"symbol\"] for isolated margin transfers".into()))));
}
let mut market: Value = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (toId.as_str() == Some("futures")) || (toId.as_str() == Some("delivery")) || (fromId.as_str() == Some("futures")) || (fromId.as_str() == Some("delivery")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("settle".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }; // todo: currencies have network-junctions
}
let mut isMarginTransfer: bool = (fromId.as_str() == Some("margin")) || (toId.as_str() == Some("margin"));
let mut query: Value = params.clone();
if isMarginTransfer {
query = self.omit(params, Value::Str("symbol".into()), &[]);
}
let __ws_arg_75 = self.extend(request, &[query]);
let mut response: Value = self.private_wallet_post_transfers(&[__ws_arg_75]).await;
return self.parse_transfer(response, &[currency]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "tx_id", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("currency".to_string(), self.safe_currency_code(Value::Null, &[currency]));
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m.insert("info".to_string(), transfer);
m
});
Value::Null
}
/*
* @method
* @name gate#setLeverage
* @description set the level of leverage for a market
* @see https://www.gate.com/docs/developers/apiv4/en/#update-position-leverage
* @see https://www.gate.com/docs/developers/apiv4/en/#update-position-leverage-2
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
// WARNING: THIS WILL INCREASE LIQUIDATION PRICE FOR OPEN ISOLATED LONG POSITIONS
// AND DECREASE LIQUIDATION PRICE FOR OPEN ISOLATED SHORT POSITIONS
if (leverage.as_f64().unwrap_or(f64::NAN) < ((0i64) as f64)) || (leverage.as_f64().unwrap_or(f64::NAN) > ((100i64) as f64)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() leverage should be between 1 and 100".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, params]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut defaultMarginMode: Value = self.safe_string2(self.options.clone(), Value::Str("marginMode".into()), Value::Str("defaultMarginMode".into()), &[]);
let mut crossLeverageLimit: Value = self.safe_string_k(query.clone(), "cross_leverage_limit", &[]);
let mut marginMode: Value = self.safe_string_k(query.clone(), "marginMode", &[defaultMarginMode]);
let mut stringifiedMargin: Value = self.number_to_string(leverage);
if (crossLeverageLimit != Value::Null) {
marginMode = Value::Str("cross".into());
stringifiedMargin = crossLeverageLimit;
}
if (marginMode.as_str() == Some("cross")) || (marginMode.as_str() == Some("cross_margin")) {
add_element_to_object(&mut request, &Value::Str("cross_leverage_limit".into()), stringifiedMargin.clone());
add_element_to_object(&mut request, &Value::Str("leverage".into()), Value::Str("0".into()));
} else {
add_element_to_object(&mut request, &Value::Str("leverage".into()), stringifiedMargin);
}
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_76 = self.extend(request.clone(), &[query.clone()]);
response = self.private_futures_post_settle_positions_contract_leverage(&[__ws_arg_76]).await;
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_77 = self.extend(request, &[query]);
response = self.private_delivery_post_settle_positions_contract_leverage(&[__ws_arg_77]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() not support this market type".into()))));
}
return response;
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// swap and future
//
// {
// "value": "4.60516",
// "leverage": "0",
// "mode": "single",
// "realised_point": "0",
// "contract": "BTC_USDT",
// "entry_price": "46030.3",
// "mark_price": "46051.6",
// "history_point": "0",
// "realised_pnl": "-0.002301515",
// "close_order": null,
// "size": 1,
// "cross_leverage_limit": "0",
// "pending_orders": 0,
// "adl_ranking": 5,
// "maintenance_rate": "0.004",
// "unrealised_pnl": "0.00213",
// "user": 5691076,
// "leverage_max": "125",
// "history_pnl": "0",
// "risk_limit": "1000000",
// "margin": "8.997698485",
// "last_close_pnl": "0",
// "liq_price": "0",
// "update_time": 1705034246,
// "update_id": 1,
// "initial_margin": "0",
// "maintenance_margin": "0",
// "open_time": 1705034246,
// "trade_max_size": "0"
// }
//
// option
//
// {
// "close_order": null,
// "size": 1,
// "vega": "5.29756",
// "theta": "-98.98917",
// "gamma": "0.00056",
// "delta": "0.68691",
// "contract": "BTC_USDT-20230602-26500-C",
// "entry_price": "529",
// "unrealised_pnl": "-1.0131",
// "user": 5691076,
// "mark_price": "427.69",
// "underlying_price": "26810.2",
// "underlying": "BTC_USDT",
// "realised_pnl": "-0.08042877",
// "mark_iv": "0.4224",
// "pending_orders": 0
// }
//
// fetchPositionsHistory (swap and future)
//
// {
// "contract": "SLERF_USDT", // Futures contract
// "text": "web", // Text of close order
// "long_price": "0.766306", // When 'side' is 'long,' it indicates the opening average price; when 'side' is 'short,' it indicates the closing average price.
// "pnl": "-23.41702352", // PNL
// "pnl_pnl": "-22.7187", // Position P/L
// "pnl_fee": "-0.06527125", // Transaction Fees
// "pnl_fund": "-0.63305227", // Funding Fees
// "accum_size": "100",
// "time": 1711279263, // Position close time
// "short_price": "0.539119", // When 'side' is 'long,' it indicates the opening average price; when 'side' is 'short,' it indicates the closing average price
// "side": "long", // Position side, long or short
// "max_size": "100", // Max Trade Size
// "first_open_time": 1711037985 // First Open Time
// }
//
let mut contract: Value = self.safe_string_k(position.clone(), "contract", &[]);
let mut marketResolved: Value = self.safe_market(&[contract, market, Value::Str("_".into()), Value::Str("contract".into())]);
let mut size: Value = self.safe_string2(position.clone(), Value::Str("size".into()), Value::Str("accum_size".into()), &[]);
let mut side: Value = self.safe_string_k(position.clone(), "side", &[]);
if (side == Value::Null) {
if is_true(&crate::precise::Precise::stringGt(&size, &Value::Str("0".into()))) {
side = Value::Str("long".into());
} else if is_true(&crate::precise::Precise::stringLt(&size, &Value::Str("0".into()))) {
side = Value::Str("short".into());
}
}
let mut notional: Value = self.safe_string_k(position.clone(), "value", &[]);
let mut leverage: Option<String> = self.safe_string_k(position.clone(), "leverage", &[]).as_str().map(str::to_owned);
let mut marginMode: Value = Value::Null;
if (leverage.is_some()) {
if (leverage.as_deref() == Some("0")) {
marginMode = Value::Str("cross".into());
} else {
marginMode = Value::Str("isolated".into());
}
}
// gate returns the initial margin requirement in the initial_margin field (= value / leverage + taker fee), see https://github.com/ccxt/ccxt/issues/27152
let mut marginBalance: Value = self.safe_string_k(position.clone(), "margin", &[]);
let mut initialMarginString: Value = self.omit_zero(self.safe_string_k(position.clone(), "initial_margin", &[]));
// gate returns the actual maintenance margin requirement in the maintenance_margin field (= value * (average_maintenance_rate + taker fee))
// it is the exact liquidation threshold: the position is liquidated when margin + unrealised_pnl drops to maintenance_margin
let mut maintenanceMarginString: Value = self.omit_zero(self.safe_string_k(position.clone(), "maintenance_margin", &[]));
// the margin field is the position margin balance, which excludes the unrealized pnl,
// the position is liquidated when margin + unrealised_pnl drops to the maintenance margin,
// so the unified collateral (the amount that can be lost, affected by pnl) includes it
let mut unrealisedPnl: Value = self.safe_string_k(position.clone(), "unrealised_pnl", &[]);
let mut collateral: Value = marginBalance.clone();
if (marginBalance != Value::Null) && (unrealisedPnl != Value::Null) {
collateral = crate::precise::Precise::stringAdd(&marginBalance, &unrealisedPnl);
}
let mut timestamp: Value = self.safe_timestamp2(position.clone(), Value::Str("open_time".into()), Value::Str("first_open_time".into()), &[]);
if (timestamp.as_f64() == Some(0.0)) {
timestamp = Value::Null;
}
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(marketResolved.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastUpdateTimestamp".to_string(), self.safe_timestamp2(position.clone(), Value::Str("update_time".into()), Value::Str("time".into()), &[]));
m.insert("initialMargin".to_string(), self.parse_number(initialMarginString.clone(), &[]));
m.insert("initialMarginPercentage".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&initialMarginString, ¬ional), &[]));
m.insert("maintenanceMargin".to_string(), self.parse_number(maintenanceMarginString.clone(), &[]));
m.insert("maintenanceMarginPercentage".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&maintenanceMarginString, ¬ional), &[]));
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "entry_price", &[]));
m.insert("notional".to_string(), self.parse_number(notional, &[]));
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("unrealizedPnl".to_string(), self.parse_number(unrealisedPnl, &[]));
m.insert("realizedPnl".to_string(), self.safe_number2(position.clone(), Value::Str("realised_pnl".into()), Value::Str("pnl".into()), &[]));
m.insert("contracts".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&size), &[]));
m.insert("contractSize".to_string(), self.safe_number_k(marketResolved, "contractSize", &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liq_price", &[]));
m.insert("markPrice".to_string(), self.safe_number_k(position, "mark_price", &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("collateral".to_string(), self.parse_number(collateral, &[]));
m.insert("marginMode".to_string(), marginMode);
m.insert("side".to_string(), side);
m.insert("percentage".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name gate#fetchPosition
* @description fetch data on an open contract position
* @see https://www.gate.com/docs/developers/apiv4/en/#get-single-position-information
* @see https://www.gate.com/docs/developers/apiv4/en/#get-single-position-information-2
* @see https://www.gate.com/docs/developers/apiv4/en/#get-specified-contract-position
* @param {string} symbol unified market symbol of the market the position is held in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchPosition() supports contract markets only".into()))));
}
let mut requestparamsValueVariable = self.prepare_request(&[market.clone(), self.safe_string_k(market.clone(), "type", &[]), params]);
let mut request: Value = requestparamsValueVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsValue: Value = requestparamsValueVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut extendedRequest: Value = self.extend(request, &[paramsValue]);
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
response = self.private_futures_get_settle_positions_contract(&[extendedRequest.clone()]).await;
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
response = self.private_delivery_get_settle_positions_contract(&[extendedRequest.clone()]).await;
} else if (market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null).as_str() == Some("option")) {
response = self.private_options_get_positions_contract(&[extendedRequest]).await;
}
//
// swap and future
//
// {
// "value": "4.60516",
// "leverage": "0",
// "mode": "single",
// "realised_point": "0",
// "contract": "BTC_USDT",
// "entry_price": "46030.3",
// "mark_price": "46051.6",
// "history_point": "0",
// "realised_pnl": "-0.002301515",
// "close_order": null,
// "size": 1,
// "cross_leverage_limit": "0",
// "pending_orders": 0,
// "adl_ranking": 5,
// "maintenance_rate": "0.004",
// "unrealised_pnl": "0.00213",
// "user": 5691076,
// "leverage_max": "125",
// "history_pnl": "0",
// "risk_limit": "1000000",
// "margin": "8.997698485",
// "last_close_pnl": "0",
// "liq_price": "0",
// "update_time": 1705034246,
// "update_id": 1,
// "initial_margin": "0",
// "maintenance_margin": "0",
// "open_time": 1705034246,
// "trade_max_size": "0"
// }
//
// option
//
// {
// "close_order": null,
// "size": 1,
// "vega": "5.29756",
// "theta": "-98.98917",
// "gamma": "0.00056",
// "delta": "0.68691",
// "contract": "BTC_USDT-20230602-26500-C",
// "entry_price": "529",
// "unrealised_pnl": "-1.0131",
// "user": 5691076,
// "mark_price": "427.69",
// "underlying_price": "26810.2",
// "underlying": "BTC_USDT",
// "realised_pnl": "-0.08042877",
// "mark_iv": "0.4224",
// "pending_orders": 0
// }
//
if (response == Value::Null) {
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", self.id.clone(), Value::Str(" fetchPosition() returned empty response".into()))));
}
return self.parse_position(response, &[market]);
Value::Null
}
/*
* @method
* @name gate#fetchPositions
* @description fetch all open positions
* @see https://www.gate.com/docs/developers/apiv4/en/#get-user-position-list
* @see https://www.gate.com/docs/developers/apiv4/en/#get-user-position-list-2
* @see https://www.gate.com/docs/developers/apiv4/en/#list-user-s-positions-of-specified-underlying
* @param {string[]|undefined} symbols Not used by gate, but parsed internally by CCXT
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.settle] 'btc' or 'usdt' - settle currency for perpetual swap and future - default="usdt" for swap and "btc" for future
* @param {string} [params.type] swap, future or option, if not provided this.options['defaultType'] is used
* @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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut symbolsNormalized: Value = self.market_symbols(&[symbols, Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
if (symbolsNormalized != Value::Null) {
let mut symbolsLength: f64 = ((symbolsNormalized.len() as i64) as f64);
if symbolsLength > ((0i64) as f64) {
market = self.market(symbolsNormalized.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
}
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchPositions".into()), &[market.clone(), params]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut type_var: Value = marketType.clone();
if (marketType == Value::Null) || (marketType.as_str() == Some("spot")) {
type_var = Value::Str("swap".into()); // default to swap
}
// prepareRequest leaves request empty and params untouched for options
let mut requestqueryVariable = self.prepare_request(&[Value::Null, type_var.clone(), paramsMarketType]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (type_var.as_str() == Some("option")) {
if (symbolsNormalized != Value::Null) {
let mut marketId: Value = self.safe_string_k(market, "id", &[]);
let mut optionParts: Value = split(&marketId, &Value::Str("-".into()));
add_element_to_object(&mut request, &Value::Str("underlying".into()), self.safe_string(optionParts, Value::Int(0), &[]));
}
}
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
let __ws_arg_78 = self.extend(request.clone(), &[query.clone()]);
response = self.private_futures_get_settle_positions(&[__ws_arg_78]).await;
} else if (type_var.as_str() == Some("future")) {
let __ws_arg_79 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delivery_get_settle_positions(&[__ws_arg_79]).await;
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_80 = self.extend(request, &[query]);
response = self.private_options_get_positions(&[__ws_arg_80]).await;
}
//
// swap and future
//
// [
// {
// "value": "4.602828",
// "leverage": "0",
// "mode": "single",
// "realised_point": "0",
// "contract": "BTC_USDT",
// "entry_price": "46030.3",
// "mark_price": "46028.28",
// "history_point": "0",
// "realised_pnl": "-0.002301515",
// "close_order": null,
// "size": 1,
// "cross_leverage_limit": "0",
// "pending_orders": 0,
// "adl_ranking": 5,
// "maintenance_rate": "0.004",
// "unrealised_pnl": "-0.000202",
// "user": 5691076,
// "leverage_max": "125",
// "history_pnl": "0",
// "risk_limit": "1000000",
// "margin": "8.997698485",
// "last_close_pnl": "0",
// "liq_price": "0",
// "update_time": 1705034246,
// "update_id": 1,
// "initial_margin": "0",
// "maintenance_margin": "0",
// "open_time": 1705034246,
// "trade_max_size": "0"
// }
// ]
//
// option
//
// [
// {
// "close_order": null,
// "size": 0,
// "vega": "0.01907",
// "theta": "-3.04888",
// "gamma": "0.00001",
// "delta": "0.0011",
// "contract": "BTC_USDT-20230601-27500-C",
// "entry_price": "0",
// "unrealised_pnl": "0",
// "user": 5691076,
// "mark_price": "0.07",
// "underlying_price": "26817.27",
// "underlying": "BTC_USDT",
// "realised_pnl": "0",
// "mark_iv": "0.4339",
// "pending_orders": 0
// }
// ]
//
let mut responseList: Value = Value::from(vec![]);
if (response != Value::Null) {
responseList = self.to_array(response);
}
return self.parse_positions(responseList, &[symbolsNormalized]);
Value::Null
}
/*
* @method
* @name gate#fetchLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
* @see https://www.gate.com/docs/developers/apiv4/en/#query-all-futures-contracts
* @see https://www.gate.com/docs/developers/apiv4/en/#query-all-futures-contracts-2
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}, indexed by market symbols
*/
pub async fn fetch_leverage_tiers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchLeverageTiers".into()), &[Value::Null, params]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestrequestParamsVariable = self.prepare_request(&[Value::Null, type_var.clone(), query]);
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (type_var.as_str() != Some("future")) && (type_var.as_str() != Some("swap")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchLeverageTiers only supports swap and future".into()))));
}
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
let __ws_arg_81 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_futures_get_settle_contracts(&[__ws_arg_81]).await;
} else if (type_var.as_str() == Some("future")) {
let __ws_arg_82 = self.extend(request, &[requestParams]);
response = self.public_delivery_get_settle_contracts(&[__ws_arg_82]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLeverageTiers() not support this market type".into()))));
}
return self.parse_leverage_tiers(response, &[symbols, Value::Str("name".into())]);
Value::Null
}
/*
* @method
* @name gate#fetchMarketLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
* @see https://www.gate.com/docs/developers/apiv4/en/#query-risk-limit-tiers
* @see https://www.gate.com/docs/developers/apiv4/en/#query-risk-limit-tiers-2
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
*/
pub async fn fetch_market_leverage_tiers(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchMarketLeverageTiers".into()), &[market.clone(), params]);
let mut type_var: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = type_varqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut requestrequestParamsVariable = self.prepare_request(&[market.clone(), type_var.clone(), query]);
let mut request: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut requestParams: Value = requestrequestParamsVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (type_var.as_str() != Some("future")) && (type_var.as_str() != Some("swap")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchMarketLeverageTiers only supports swap and future".into()))));
}
let mut response: Value = Value::Null;
if (type_var.as_str() == Some("swap")) {
//
// [
// {
// "maintenance_rate": "0.004",
// "tier": 1,
// "initial_rate": "0.008",
// "leverage_max": "125",
// "risk_limit": "1000000"
// }
// ]
//
let __ws_arg_83 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_futures_get_settle_risk_limit_tiers(&[__ws_arg_83]).await;
} else {
let __ws_arg_84 = self.extend(request, &[requestParams]);
response = self.public_delivery_get_settle_risk_limit_tiers(&[__ws_arg_84]).await;
}
return self.parse_market_leverage_tiers(response, &[market]);
Value::Null
}
pub fn parse_emulated_leverage_tiers(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(info.clone(), "name", &[]);
let mut maintenanceMarginUnit: Value = self.safe_string_k(info.clone(), "maintenance_rate", &[]); // '0.005',
let mut leverageMax: Value = self.safe_string_k(info.clone(), "leverage_max", &[]); // '100',
let mut riskLimitStep: Value = self.safe_string_k(info.clone(), "risk_limit_step", &[]); // '1000000',
let mut riskLimitMax: Value = self.safe_string_k(info.clone(), "risk_limit_max", &[]); // '16000000',
let mut initialMarginUnit: Value = crate::precise::Precise::stringDiv(&Value::Str("1".into()), &leverageMax);
let mut maintenanceMarginRate: Value = maintenanceMarginUnit.clone();
let mut initialMarginRatio: Value = initialMarginUnit.clone();
let mut floor: Value = Value::Str("0".into());
let mut tiers: Value = Value::from(vec![]);
while is_true(&crate::precise::Precise::stringLt(&floor, &riskLimitMax)) {
let mut cap: Value = crate::precise::Precise::stringAdd(&floor, &riskLimitStep);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&cap, &riskLimitStep), &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".into())]));
m.insert("currency".to_string(), self.safe_string_k(market.clone(), "settle", &[]));
m.insert("minNotional".to_string(), self.parse_number(floor.clone(), &[]));
m.insert("maxNotional".to_string(), self.parse_number(cap.clone(), &[]));
m.insert("maintenanceMarginRate".to_string(), self.parse_number(maintenanceMarginRate.clone(), &[]));
m.insert("maxLeverage".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&Value::Str("1".into()), &initialMarginRatio), &[]));
m.insert("info".to_string(), info.clone());
m
}));
maintenanceMarginRate = crate::precise::Precise::stringAdd(&maintenanceMarginRate, &maintenanceMarginUnit);
initialMarginRatio = crate::precise::Precise::stringAdd(&initialMarginRatio, &initialMarginUnit);
floor = cap;
}
return tiers;
Value::Null
}
pub fn parse_market_leverage_tiers(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// {
// "maintenance_rate": "0.004",
// "tier": 1,
// "initial_rate": "0.008",
// "leverage_max": "125",
// "risk_limit": "1000000"
// }
// ]
//
if !(matches!(&info, Value::Arr(_))) {
return self.parse_emulated_leverage_tiers(info.clone(), &[market.clone()]);
}
let mut minNotional: Value = Value::Int(0);
let mut tiers: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_704: bool = true;
while { if !__for_first_704 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_704 = false; i.as_f64().unwrap_or(f64::NAN) < ((info.len() as i64) as f64) } {
let mut item: Value = self.safe_dict(info.clone(), i.clone(), &[]);
let mut maxNotional: Value = self.safe_number_k(item.clone(), "risk_limit", &[]);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.sum(&[i.clone(), Value::Int(1)]));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("currency".to_string(), self.safe_string_k(market.clone(), "base", &[]));
m.insert("minNotional".to_string(), minNotional.clone());
m.insert("maxNotional".to_string(), maxNotional.clone());
m.insert("maintenanceMarginRate".to_string(), self.safe_number_k(item.clone(), "maintenance_rate", &[]));
m.insert("maxLeverage".to_string(), self.safe_number_k(item.clone(), "leverage_max", &[]));
m.insert("info".to_string(), item);
m
}));
minNotional = maxNotional;
}
}
return tiers;
Value::Null
}
/*
* @method
* @name gate#repayIsolatedMargin
* @description repay borrowed margin and interest
* @see https://www.gate.com/docs/developers/apiv4/en/#borrow-or-repay-2
* @param {string} symbol unified market symbol
* @param {string} code unified currency code of the currency to repay
* @param {float} amount the amount to repay
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
* @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn repay_isolated_margin(&mut self, mut symbol: Value, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), to_upper(&get_value(¤cy, &Value::Str("id".into()))));
m.insert("amount".to_string(), self.currency_to_precision(code, amount, &[]));
m
});
let mut market: Value = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("repay".into())); }
let __ws_arg_85 = self.extend(request, &[params]);
let mut response: Value = self.private_margin_post_uni_loans(&[__ws_arg_85]).await;
return self.parse_margin_loan(response, &[currency]);
Value::Null
}
/*
* @method
* @name gate#repayCrossMargin
* @description repay cross margin borrowed margin and interest
* @see https://www.gate.com/docs/developers/apiv4/en/#borrow-or-repay
* @param {string} code unified currency code of the currency to repay
* @param {float} amount the amount to repay
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.mode] 'all' or 'partial' payment mode, extra parameter required for isolated margin
* @param {string} [params.id] '34267567' loan id, extra parameter required for isolated margin
* @param {boolean} [params.unifiedAccount] set to true for repaying in the unified account
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn repay_cross_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), to_upper(&get_value(¤cy, &Value::Str("id".into()))));
m.insert("amount".to_string(), self.currency_to_precision(code, amount, &[]));
m
});
let mut isUnifiedAccountparamsUnifiedAccountVariable = self.handle_option_bool_and_params(params, Value::Str("repayCrossMargin".into()), Value::Str("unifiedAccount".into()), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if is_true(&isUnifiedAccount) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("repay".into())); }
let __ws_arg_86 = self.extend(request.clone(), &[paramsUnifiedAccount.clone()]);
response = self.private_unified_post_loans(&[__ws_arg_86]).await;
} else {
// deprecated and not present in the exchange's docs but still works
let __ws_arg_87 = self.extend(request, &[paramsUnifiedAccount]);
response = self.private_margin_post_cross_repayments(&[__ws_arg_87]).await;
response = self.safe_dict(response.clone(), Value::Int(0), &[]);
}
return self.parse_margin_loan(response, &[currency]);
Value::Null
}
/*
* @method
* @name gate#borrowIsolatedMargin
* @description create a loan to borrow margin
* @see https://www.gate.com/docs/developers/apiv4/en/#borrow-or-repay-2
* @param {string} symbol unified market symbol, required for isolated margin
* @param {string} code unified currency code of the currency to borrow
* @param {float} amount the amount to borrow
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn borrow_isolated_margin(&mut self, mut symbol: Value, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), to_upper(&get_value(¤cy, &Value::Str("id".into()))));
m.insert("amount".to_string(), self.currency_to_precision(code, amount, &[]));
m
});
let mut market: Value = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("borrow".into())); }
let __ws_arg_88 = self.extend(request, &[params]);
let mut response: Value = self.private_margin_post_uni_loans(&[__ws_arg_88]).await;
return self.parse_margin_loan(response, &[currency]);
Value::Null
}
/*
* @method
* @name gate#borrowCrossMargin
* @description create a loan to borrow margin
* @see https://www.gate.com/docs/developers/apiv4/en/#borrow-or-repay
* @param {string} code unified currency code of the currency to borrow
* @param {float} amount the amount to borrow
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.rate] '0.0002' or '0.002' extra parameter required for isolated margin
* @param {boolean} [params.unifiedAccount] default true (set to false to use deprecated privateMarginPostCrossLoans method)
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn borrow_cross_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), to_upper(&get_value(¤cy, &Value::Str("id".into()))));
m.insert("amount".to_string(), self.currency_to_precision(code, amount, &[]));
m
});
let mut isUnifiedAccountparamsUnifiedAccountVariable = self.handle_option_bool_and_params(params, Value::Str("borrowCrossMargin".into()), Value::Str("unifiedAccount".into()), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if is_true(&isUnifiedAccount) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("borrow".into())); }
let __ws_arg_89 = self.extend(request.clone(), &[paramsUnifiedAccount.clone()]);
response = self.private_unified_post_loans(&[__ws_arg_89]).await;
} else {
// deprecated and not present in the exchange's docs
// returns {"label":"REQUEST_FORBIDDEN","message":"Request is forbidden"}
let __ws_arg_90 = self.extend(request, &[paramsUnifiedAccount]);
response = self.private_margin_post_cross_loans(&[__ws_arg_90]).await;
}
return self.parse_margin_loan(response, &[currency]);
Value::Null
}
pub fn parse_margin_loan(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// Cross
//
// {
// "id": "17",
// "create_time": 1620381696159,
// "update_time": 1620381696159,
// "currency": "EOS",
// "amount": "110.553635",
// "text": "web",
// "status": 2,
// "repaid": "110.506649705159",
// "repaid_interest": "0.046985294841",
// "unpaid_interest": "0.0000074393366667"
// }
//
// Isolated
//
// {
// "id": "34267567",
// "create_time": "1656394778",
// "expire_time": "1657258778",
// "status": "loaned",
// "side": "borrow",
// "currency": "USDT",
// "rate": "0.0002",
// "amount": "100",
// "days": 10,
// "auto_renew": false,
// "currency_pair": "LTC_USDT",
// "left": "0",
// "repaid": "0",
// "paid_interest": "0",
// "unpaid_interest": "0.003333333333"
// }
//
let mut marginMode: Option<String> = self.safe_string2(self.options.clone(), Value::Str("defaultMarginMode".into()), Value::Str("marginMode".into()), &[Value::Str("cross".into())]).as_str().map(str::to_owned);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "create_time", &[]);
if (marginMode.as_deref() == Some("isolated")) {
timestamp = self.safe_timestamp_k(info.clone(), "create_time", &[]);
}
let mut currencyId: Value = self.safe_string_k(info.clone(), "currency", &[]);
let mut marketId: Value = self.safe_string_k(info.clone(), "currency_pair", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(info.clone(), "id", &[]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "amount", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[Value::Null, Value::Str("_".into()), Value::Str("margin".into())]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("info".to_string(), info);
m
});
Value::Null
}
/*
* @method
* @name gate#fetchBorrowInterest
* @description fetch the interest owed by the user for borrowing currency for margin trading
* @see https://www.gate.com/docs/developers/apiv4/en/#query-interest-deduction-records
* @see https://www.gate.com/docs/developers/apiv4/en/#query-interest-deduction-records-2
* @param {string} [code] unified currency code
* @param {string} [symbol] unified market symbol when fetching interest in isolated markets
* @param {int} [since] the earliest time in ms to fetch borrow interest for
* @param {int} [limit] the maximum number of structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.unifiedAccount] set to true for fetching borrow interest in the unified account
* @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/?id=borrow-interest-structure}
*/
pub async fn fetch_borrow_interest(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut symbol = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut isUnifiedAccountparamsUnifiedAccountVariable = self.handle_option_bool_and_params(params, Value::Str("fetchBorrowInterest".into()), Value::Str("unifiedAccount".into()), &[Value::Bool(false)]);
let mut isUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUnifiedAccount: Value = isUnifiedAccountparamsUnifiedAccountVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("to".into()), request, paramsUnifiedAccount, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut requestUntil, &Value::Str("currency".into()), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
if (since != Value::Null) {
add_element_to_object(&mut requestUntil, &Value::Str("from".into()), since.clone());
}
if (limit != Value::Null) {
add_element_to_object(&mut requestUntil, &Value::Str("limit".into()), limit.clone());
}
let mut response: Value = Value::Null;
let mut marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("fetchBorrowInterest".into()), &[paramsUntil, Value::Str("cross".into())]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&isUnifiedAccount) {
let __ws_arg_91 = self.extend(requestUntil.clone(), &[paramsMarginMode.clone()]);
response = self.private_unified_get_interest_records(&[__ws_arg_91]).await;
} else if (marginMode.as_str() == Some("isolated")) {
if (market != Value::Null) {
add_element_to_object(&mut requestUntil, &Value::Str("currency_pair".into()), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
let __ws_arg_92 = self.extend(requestUntil.clone(), &[paramsMarginMode.clone()]);
response = self.private_margin_get_uni_interest_records(&[__ws_arg_92]).await;
} else if (marginMode.as_str() == Some("cross")) {
// deprecated and not present in the exchange's docs but still works
let __ws_arg_93 = self.extend(requestUntil, &[paramsMarginMode]);
response = self.private_margin_get_cross_interest_records(&[__ws_arg_93]).await;
}
let mut interest: Value = self.parse_borrow_interests(response, &[market]);
return self.filter_by_currency_since_limit(interest, &[code, since, limit]);
Value::Null
}
pub fn parse_borrow_interest(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(info.clone(), "currency_pair", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone(), market]);
let mut marginMode: Value = Value::Str("cross".into());
if (marketId != Value::Null) {
marginMode = Value::Str("isolated".into());
}
let mut timestamp: Value = self.safe_integer_k(info.clone(), "create_time", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_string_k(marketResolved, "symbol", &[]));
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(info.clone(), "currency", &[]), &[]));
m.insert("interest".to_string(), self.safe_number_k(info.clone(), "interest", &[]));
m.insert("interestRate".to_string(), self.safe_number_k(info, "actual_rate", &[]));
m.insert("amountBorrowed".to_string(), Value::Null);
m.insert("marginMode".to_string(), marginMode);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
Value::Null
}
pub fn nonce(&self) -> Value {
let mut timeDifference: Value = self.safe_integer_k(self.options.clone(), "timeDifference", &[]);
if (timeDifference == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" nonce() requires a numeric options[\"timeDifference\"]".into()))));
}
return (match (&(self.milliseconds()), &(timeDifference)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut authentication: Value = get_value(&api, &Value::Int(0)); // public, private
let mut type_var: Value = get_value(&api, &Value::Int(1)); // spot, margin, future, delivery
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut pathImploded: Value = Value::Null;
let mut bodyJson: Value = Value::Null;
let mut signedHeaders: Value = Value::Null;
let mut containsSettle: bool = Value::Int(path.as_str().and_then(|__s| __s.find("settle")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) > ((-1i64) as f64);
if containsSettle && (Value::Bool(ends_with(&path, &Value::Str("batch_cancel_orders".into()))).as_bool() == Some(true)) {
// special case where we need to extract the settle from the path
// but the body is an array of strings
let mut settle: Value = self.safe_dict(params.clone(), Value::Int(0), &[]);
pathImploded = self.implode_params(path.clone(), settle);
// remove the first element from params
let mut newParams: Value = Value::from(vec![]);
let mut anyParams: Value = self.to_array(params.clone());
{
let mut i: Value = Value::Int(1);
let mut __for_first_705: bool = true;
while { if !__for_first_705 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_705 = false; i.as_f64().unwrap_or(f64::NAN) < ((anyParams.len() as i64) as f64) } {
append_to_array(&mut newParams, get_value(¶ms, &i));
}
}
query = newParams;
} else if (matches!(¶ms, Value::Arr(_))) {
// endpoints like createOrders use an array instead of an object
// so we infer the settle from one of the elements
// they have to be all the same so relying on the first one is fine
let mut first: Value = self.safe_dict(params.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
pathImploded = self.implode_params(path.clone(), first);
} else {
pathImploded = self.implode_params(path, params);
}
let mut endPart: Value = Value::Null;
if (pathImploded.as_str() == Some("")) {
endPart = Value::Str("".into());
} else {
endPart = (Value::Str(format!("{}{}", Value::Str("/".into()), pathImploded).into()));
}
let mut entirePath: Value = Value::Str(format!("{}{}", add(&Value::Str("/".into()), &type_var), endPart).into());
if (type_var.as_str() == Some("subAccounts")) || (type_var.as_str() == Some("withdrawals")) {
entirePath = endPart;
}
let mut url: Value = get_value(&get_value(&self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), &authentication), &type_var);
if (url == Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", add(&Value::Str(format!("{}{}", self.id.clone(), Value::Str(" does not have a testnet for the ".into())).into()), &type_var), Value::Str(" market type.".into()))));
}
url = add(&url, &entirePath);
if (authentication.as_str() == Some("public")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
url = add(&url, &Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into()));
}
} else {
self.check_required_credentials(&[]);
let mut queryString: Value = Value::Str("".into());
let mut rawQueryString: Value = Value::Str("".into());
let mut requiresURLEncoding: bool = false;
if ((type_var.as_str() == Some("futures")) || (type_var.as_str() == Some("delivery"))) && (method.as_str() == Some("POST")) {
let mut pathParts: Value = split(&pathImploded, &Value::Str("/".into()));
let mut secondPart: Value = self.safe_string(pathParts, Value::Int(1), &[Value::Str("".into())]);
requiresURLEncoding = (Value::Int(secondPart.as_str().and_then(|__s| __s.find("dual")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64)) || (Value::Int(secondPart.as_str().and_then(|__s| __s.find("positions")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64));
}
if (method.as_str() == Some("GET")) || (method.as_str() == Some("DELETE")) || requiresURLEncoding || (method.as_str() == Some("PATCH")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
// https://github.com/ccxt/ccxt/issues/27663
// sort explicitly (true) so the signed order matches the url order in Go,
// where map iteration is not ordered (keysort's order is otherwise lost)
rawQueryString = self.rawencode(query.clone(), &[Value::Bool(true)]);
queryString = self.urlencode(query.clone(), &[Value::Bool(true)]);
// https://github.com/ccxt/ccxt/issues/25570
if Value::Int(queryString.as_str().and_then(|__s| __s.find("currencies=")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) && Value::Int(queryString.as_str().and_then(|__s| __s.find("%2C")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
queryString = replace_all_str(&queryString, &Value::Str("%2C".into()), &Value::Str(",".into()));
}
url = add(&url, &Value::Str(format!("{}{}", Value::Str("?".into()), queryString).into()));
}
if (method.as_str() == Some("PATCH")) {
bodyJson = json_stringify(&query);
}
} else {
let mut urlQueryParams: Value = self.safe_dict_k(query.clone(), "query", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if ((object_keys(&urlQueryParams).len() as i64) as f64) > ((0i64) as f64) {
queryString = self.urlencode(urlQueryParams.clone(), &[]);
url = add(&url, &Value::Str(format!("{}{}", Value::Str("?".into()), queryString).into()));
}
query = self.omit(query.clone(), Value::Str("query".into()), &[]);
bodyJson = json_stringify(&query);
}
let mut bodySigned: Value = (if (bodyJson == Value::Null) { body.clone() } else { bodyJson.clone() });
let mut bodyPayload: Value = (if (bodySigned == Value::Null) { Value::Str("".into()) } else { bodySigned });
let mut bodySignature: Value = self.hash(self.encode(bodyPayload), Value::Str("sha512".into()), &[]);
let mut nonce: Value = self.nonce();
let mut timestamp: Value = self.parse_to_int((match ((nonce).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }));
let mut timestampString: Value = to_string_val(×tamp);
let mut signaturePath: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("/api/".into()), self.version.clone()).into()), entirePath).into());
let mut payloadArray: Value = Value::from(vec![to_upper(&method), signaturePath, rawQueryString, bodySignature, timestampString.clone()]);
// eslint-disable-next-line quotes
let mut payload: Value = join(&payloadArray, &Value::Str("\n".into()));
let mut signature: Value = self.hmac(self.encode(payload), self.encode(self.secret.clone()), Value::Str("sha512".into()), &[]);
signedHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("KEY".to_string(), self.apiKey.clone());
m.insert("Timestamp".to_string(), timestampString);
m.insert("SIGN".to_string(), signature);
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
}
let mut bodyResolved: Value = (if (bodyJson == Value::Null) { body } else { bodyJson });
let mut headersResolved: Value = (if (signedHeaders == Value::Null) { headers } else { signedHeaders });
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), bodyResolved);
m.insert("headers".to_string(), headersResolved);
m
});
Value::Null
}
pub async fn modify_margin_helper(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, params]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut request, &Value::Str("change".into()), self.number_to_string(amount));
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_94 = self.extend(request.clone(), &[query.clone()]);
response = self.private_futures_post_settle_positions_contract_margin(&[__ws_arg_94]).await;
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_95 = self.extend(request, &[query]);
response = self.private_delivery_post_settle_positions_contract_margin(&[__ws_arg_95]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" modifyMarginHelper() not support this market type".into()))));
}
return self.parse_margin_modification(response, &[market]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "value": "11.9257",
// "leverage": "5",
// "mode": "single",
// "realised_point": "0",
// "contract": "ETH_USDT",
// "entry_price": "1203.45",
// "mark_price": "1192.57",
// "history_point": "0",
// "realised_pnl": "-0.00577656",
// "close_order": null,
// "size": "1",
// "cross_leverage_limit": "0",
// "pending_orders": "0",
// "adl_ranking": "5",
// "maintenance_rate": "0.005",
// "unrealised_pnl": "-0.1088",
// "user": "1486602",
// "leverage_max": "100",
// "history_pnl": "0",
// "risk_limit": "1000000",
// "margin": "5.415925875",
// "last_close_pnl": "0",
// "liq_price": "665.69"
// }
//
let mut contract: Value = self.safe_string_k(data.clone(), "contract", &[]);
let mut marketResolved: Value = self.safe_market(&[contract, market, Value::Str("_".into()), Value::Str("contract".into())]);
let mut total: Value = self.safe_number_k(data.clone(), "margin", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data);
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), total);
m.insert("code".to_string(), self.safe_string_k(marketResolved, "quote", &[]));
m.insert("status".to_string(), Value::Str("ok".into()));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name gate#reduceMargin
* @description remove margin from a position
* @see https://www.gate.com/docs/developers/apiv4/en/#update-position-margin
* @see https://www.gate.com/docs/developers/apiv4/en/#update-position-margin-2
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol, negate(&amount), &[params]).await;
Value::Null
}
/*
* @method
* @name gate#addMargin
* @description add margin
* @see https://www.gate.com/docs/developers/apiv4/en/#update-position-margin
* @see https://www.gate.com/docs/developers/apiv4/en/#update-position-margin-2
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol, amount, &[params]).await;
Value::Null
}
/*
* @method
* @name gate#fetchOpenInterest
* @description Retrieves the open interest of a currency
* @see https://www.gate.com/docs/developers/apiv4/en/#futures-statistics
* @param {string} symbol Unified CCXT market symbol
* @param {string} timeframe "5m", "15m", "30m", "1h", "4h", "1d"
* @param {int} [since] the time(ms) of the earliest record to retrieve as a unix timestamp
* @param {int} [limit] default 30
* @param {object} [params] exchange specific parameters
* @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} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("5m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOpenInterestHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOpenInterestHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), Value::Int(100)]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchOpenInterest() supports swap markets only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("settle".to_string(), market.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null }))); }
}
let __ws_arg_96 = self.extend(request, &[paramsPaginate]);
let mut response: Value = self.public_futures_get_settle_contract_stats(&[__ws_arg_96]).await;
return self.parse_open_interests_history(response, &[market, since, limit]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "long_liq_size": "0",
// "short_liq_size": "0",
// "short_liq_usd": "0",
// "lsr_account": "3.2808988764045",
// "mark_price": "0.34619",
// "top_lsr_size": "0",
// "time": "1674057000",
// "short_liq_amount": "0",
// "long_liq_amount": "0",
// "open_interest_usd": "9872386.7775",
// "top_lsr_account": "0",
// "open_interest": "2851725",
// "long_liq_usd": "0",
// "lsr_taker": "9.3765153315902"
// }
//
let mut timestamp: Value = self.safe_timestamp_k(interest.clone(), "time", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market, "symbol", &[]));
m.insert("openInterestAmount".to_string(), self.safe_number_k(interest.clone(), "open_interest", &[]));
m.insert("openInterestValue".to_string(), self.safe_number_k(interest.clone(), "open_interest_usd", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("info".to_string(), interest);
m
});
Value::Null
}
/*
* @method
* @name gate#fetchSettlementHistory
* @description fetches historical settlement records
* @see https://www.gate.com/docs/developers/apiv4/en/#list-settlement-history
* @param {string} symbol unified market symbol of the settlement history, required on gate
* @param {int} [since] timestamp in ms
* @param {int} [limit] number of records
* @param {object} [params] exchange specific params
* @returns {object[]} a list of [settlement history objects]{@link https://docs.ccxt.com/?id=settlement-history-structure}
*/
pub async fn fetch_settlement_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchSettlementHistory() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchSettlementHistory".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (type_var.as_str() != Some("option")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchSettlementHistory() supports option markets only".into()))));
}
let mut marketId: Value = market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
let mut optionParts: Value = split(&marketId, &Value::Str("-".into()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("underlying".to_string(), self.safe_string(optionParts, Value::Int(0), &[]));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_97 = self.extend(request, &[paramsMarketType]);
let mut response: Value = self.public_options_get_settlements(&[__ws_arg_97]).await;
//
// [
// {
// "time": 1685952000,
// "profit": "18.266806892718",
// "settle_price": "26826.68068927182",
// "fee": "0.040240021034",
// "contract": "BTC_USDT-20230605-25000-C",
// "strike_price": "25000"
// }
// ]
//
let mut settlements: Value = self.parse_settlements(response, &[market]);
let mut sorted: Value = self.sort_by(settlements, Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbol, since, limit]);
Value::Null
}
/*
* @method
* @name gate#fetchMySettlementHistory
* @description fetches historical settlement records of the user
* @see https://www.gate.com/docs/developers/apiv4/en/#query-personal-settlement-records
* @see https://www.gate.com/docs/developers/apiv4/en/#query-settlement-records
* @param {string} symbol unified market symbol of the settlement history
* @param {int} [since] timestamp in ms
* @param {int} [limit] number of records
* @param {object} [params] exchange specific params
* @returns {object[]} a list of [settlement history objects]
*/
pub async fn fetch_my_settlement_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut symbolResolved: Value = (if (market != Value::Null) { self.safe_string_k(market.clone(), "symbol", &[]) } else { symbol });
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchMySettlementHistory".into()), &[market.clone(), params]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut isOption: bool = type_var.as_str() == Some("option");
let mut isFuture: bool = type_var.as_str() == Some("future");
if !isOption && !isFuture {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchMySettlementHistory() supports option and future markets only".into()))));
}
let mut requestqueryVariable = self.prepare_request(&[market.clone(), type_var, paramsMarketType.clone()]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), limit.clone());
}
let mut response: Value = Value::Null;
if isFuture {
//
// [
// {
// "time": 1548654951,
// "contract": "BTC_USDT",
// "size": 600,
// "leverage": "25",
// "margin": "0.006705256878",
// "entry_price": "3536.123",
// "settle_price": "3421.54",
// "profit": "-6.87498",
// "fee": "0.03079386"
// }
// ]
//
let __ws_arg_98 = self.extend(request.clone(), &[query]);
response = self.private_delivery_get_settle_settlements(&[__ws_arg_98]).await;
} else {
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".into()), since.clone());
}
if (market == Value::Null) {
let mut underlying: Option<String> = self.safe_string_k(paramsMarketType.clone(), "underlying", &[]).as_str().map(str::to_owned);
if (underlying.is_none()) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMySettlementHistory() requires a symbol argument or an underlying parameter in params".into()))));
}
} else {
let mut marketId: Value = market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
let mut optionParts: Value = split(&marketId, &Value::Str("-".into()));
add_element_to_object(&mut request, &Value::Str("underlying".into()), self.safe_string(optionParts, Value::Int(0), &[]));
}
//
// [
// {
// "size": -1,
// "settle_profit": "0",
// "contract": "BTC_USDT-20220624-26000-C",
// "strike_price": "26000",
// "time": 1656057600,
// "settle_price": "20917.461281337048",
// "underlying": "BTC_USDT",
// "realised_pnl": "-0.00116042",
// "fee": "0"
// }
// ]
//
let __ws_arg_99 = self.extend(request, &[paramsMarketType]);
response = self.private_options_get_my_settlements(&[__ws_arg_99]).await;
}
let mut result: Value = self.safe_dict_k(response, "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result, "list", &[Value::from(vec![])]);
let mut settlements: Value = self.parse_settlements(data, &[market]);
let mut sorted: Value = self.sort_by(settlements, Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[symbolResolved, since, limit]);
Value::Null
}
pub fn parse_settlement(&self, mut settlement: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchSettlementHistory
//
// {
// "time": 1685952000,
// "profit": "18.266806892718",
// "settle_price": "26826.68068927182",
// "fee": "0.040240021034",
// "contract": "BTC_USDT-20230605-25000-C",
// "strike_price": "25000"
// }
//
// fetchMySettlementHistory option
//
// {
// "size": -1,
// "settle_profit": "0",
// "contract": "BTC_USDT-20220624-26000-C",
// "strike_price": "26000",
// "time": 1656057600,
// "settle_price": "20917.461281337048",
// "underlying": "BTC_USDT",
// "realised_pnl": "-0.00116042",
// "fee": "0"
// }
//
// fetchMySettlementHistory future
// {
// "time": 1548654951,
// "contract": "BTC_USDT",
// "size": 600,
// "leverage": "25",
// "margin": "0.006705256878",
// "entry_price": "3536.123",
// "settle_price": "3421.54",
// "profit": "-6.87498",
// "fee": "0.03079386"
// }
//
let mut timestamp: Value = self.safe_timestamp_k(settlement.clone(), "time", &[]);
let mut marketId: Value = self.safe_string_k(settlement.clone(), "contract", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), settlement.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("price".to_string(), self.safe_number_k(settlement, "settle_price", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
Value::Null
}
pub fn parse_settlements(&self, mut settlements: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchSettlementHistory
//
// [
// {
// "time": 1685952000,
// "profit": "18.266806892718",
// "settle_price": "26826.68068927182",
// "fee": "0.040240021034",
// "contract": "BTC_USDT-20230605-25000-C",
// "strike_price": "25000"
// }
// ]
//
// fetchMySettlementHistory
//
// [
// {
// "size": -1,
// "settle_profit": "0",
// "contract": "BTC_USDT-20220624-26000-C",
// "strike_price": "26000",
// "time": 1656057600,
// "settle_price": "20917.461281337048",
// "underlying": "BTC_USDT",
// "realised_pnl": "-0.00116042",
// "fee": "0"
// }
// ]
//
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_706: bool = true;
while { if !__for_first_706 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_706 = false; i.as_f64().unwrap_or(f64::NAN) < ((settlements.len() as i64) as f64) } {
append_to_array(&mut result, self.parse_settlement(settlements.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), &[market.clone()]));
}
}
return result;
Value::Null
}
/*
* @method
* @name gate#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://www.gate.com/docs/developers/apiv4/en/#query-spot-account-transaction-history
* @see https://www.gate.com/docs/developers/apiv4/en/#query-margin-account-balance-change-history
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-account-change-history
* @see https://www.gate.com/docs/developers/apiv4/en/#query-futures-account-change-history-2
* @see https://www.gate.com/docs/developers/apiv4/en/#query-account-change-history
* @param {string} [code] unified currency code
* @param {int} [since] timestamp in ms of the earliest ledger entry
* @param {int} [limit] max number of ledger entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] end time in ms
* @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 [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchLedger".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchLedger".into()), &[code.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut currency: Value = Value::Null;
let mut response: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut type_varparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchLedger".into()), &[Value::Null, paramsPaginate]);
let mut type_var: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = type_varparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (type_var.as_str() == Some("spot")) || (type_var.as_str() == Some("margin")) {
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }; // todo: currencies have network-junctions
}
}
if (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future")) {
let mut defaultSettle: Value = Value::Str("btc".into());
if (type_var.as_str() == Some("swap")) {
defaultSettle = Value::Str("usdt".into());
}
let mut settle: Value = self.safe_string_lower_k(paramsMarketType.clone(), "settle", &[defaultSettle]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("settle".into(), settle); }
}
let mut isContract: bool = (type_var.as_str() == Some("swap")) || (type_var.as_str() == Some("future"));
let mut paramsSettle: Value = paramsMarketType.clone();
if isContract {
paramsSettle = self.omit(paramsMarketType, Value::Str("settle".into()), &[]);
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("to".into()), request, paramsSettle, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (type_var.as_str() == Some("spot")) {
let __ws_arg_100 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_spot_get_account_book(&[__ws_arg_100]).await;
} else if (type_var.as_str() == Some("margin")) {
let __ws_arg_101 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_margin_get_account_book(&[__ws_arg_101]).await;
} else if (type_var.as_str() == Some("swap")) {
let __ws_arg_102 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_futures_get_settle_account_book(&[__ws_arg_102]).await;
} else if (type_var.as_str() == Some("future")) {
let __ws_arg_103 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_delivery_get_settle_account_book(&[__ws_arg_103]).await;
} else if (type_var.as_str() == Some("option")) {
let __ws_arg_104 = self.extend(requestUntil, &[paramsUntil]);
response = self.private_options_get_account_book(&[__ws_arg_104]).await;
}
return self.parse_ledger(response, &[currency, since, limit]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// spot
//
// {
// "id": "123456",
// "time": 1547633726123,
// "currency": "BTC",
// "change": "1.03",
// "balance": "4.59316525194",
// "type": "margin_in"
// }
//
// margin
//
// {
// "id": "123456",
// "time": "1547633726",
// "time_ms": 1547633726123,
// "currency": "BTC",
// "currency_pair": "BTC_USDT",
// "change": "1.03",
// "balance": "4.59316525194"
// }
//
// swap and future
//
// {
// "time": 1682294400.123456,
// "change": "0.000010152188",
// "balance": "4.59316525194",
// "text": "ETH_USD:6086261",
// "type": "fee"
// }
//
// option
//
// {
// "time": 1685594770,
// "change": "3.33",
// "balance": "29.87911771",
// "text": "BTC_USDT-20230602-26500-C:2611026125",
// "type": "prem"
// }
//
let mut direction: Value = Value::Null;
let mut amount: Value = self.safe_string_k(item.clone(), "change", &[]);
if is_true(&crate::precise::Precise::stringLt(&amount, &Value::Str("0".into()))) {
direction = Value::Str("out".into());
amount = crate::precise::Precise::stringAbs(&amount);
} else {
direction = Value::Str("in".into());
}
let mut currencyId: Value = self.safe_string_k(item.clone(), "currency", &[]);
let mut currencyResolved: Value = self.safe_currency(currencyId.clone(), &[currency]);
let mut type_var: Value = self.safe_string_k(item.clone(), "type", &[]);
let mut rawTimestamp: Value = self.safe_string_k(item.clone(), "time", &[]);
let mut timestamp: Value = Value::Null;
if ((rawTimestamp.len() as i64) as f64) > ((10i64) as f64) {
timestamp = (match &rawTimestamp { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null });
} else {
timestamp = (match (&((match &rawTimestamp { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
}
let mut balanceString: Value = self.safe_string_k(item.clone(), "balance", &[]);
let mut changeString: Value = self.safe_string_k(item.clone(), "change", &[]);
let mut before: Value = self.parse_number(crate::precise::Precise::stringSub(&balanceString, &changeString), &[]);
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string_k(item.clone(), "id", &[]));
m.insert("direction".to_string(), direction);
m.insert("account".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("referenceId".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_ledger_entry_type(type_var).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currencyResolved.clone()]));
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("before".to_string(), before);
m.insert("after".to_string(), self.safe_number_k(item, "balance", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currencyResolved]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Option<String> {
let mut ledgerType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Str("deposit".into()));
m.insert("withdraw".to_string(), Value::Str("withdrawal".into()));
m.insert("sub_account_transfer".to_string(), Value::Str("transfer".into()));
m.insert("margin_in".to_string(), Value::Str("transfer".into()));
m.insert("margin_out".to_string(), Value::Str("transfer".into()));
m.insert("margin_funding_in".to_string(), Value::Str("transfer".into()));
m.insert("margin_funding_out".to_string(), Value::Str("transfer".into()));
m.insert("cross_margin_in".to_string(), Value::Str("transfer".into()));
m.insert("cross_margin_out".to_string(), Value::Str("transfer".into()));
m.insert("copy_trading_in".to_string(), Value::Str("transfer".into()));
m.insert("copy_trading_out".to_string(), Value::Str("transfer".into()));
m.insert("quant_in".to_string(), Value::Str("transfer".into()));
m.insert("quant_out".to_string(), Value::Str("transfer".into()));
m.insert("futures_in".to_string(), Value::Str("transfer".into()));
m.insert("futures_out".to_string(), Value::Str("transfer".into()));
m.insert("delivery_in".to_string(), Value::Str("transfer".into()));
m.insert("delivery_out".to_string(), Value::Str("transfer".into()));
m.insert("new_order".to_string(), Value::Str("trade".into()));
m.insert("order_fill".to_string(), Value::Str("trade".into()));
m.insert("referral_fee".to_string(), Value::Str("rebate".into()));
m.insert("order_fee".to_string(), Value::Str("fee".into()));
m.insert("interest".to_string(), Value::Str("interest".into()));
m.insert("lend".to_string(), Value::Str("loan".into()));
m.insert("redeem".to_string(), Value::Str("loan".into()));
m.insert("profit".to_string(), Value::Str("interest".into()));
m.insert("flash_swap_buy".to_string(), Value::Str("trade".into()));
m.insert("flash_swap_sell".to_string(), Value::Str("trade".into()));
m.insert("unknown".to_string(), Value::Str("unknown".into()));
m.insert("set".to_string(), Value::Str("settlement".into()));
m.insert("prem".to_string(), Value::Str("trade".into()));
m.insert("point_refr".to_string(), Value::Str("rebate".into()));
m.insert("point_fee".to_string(), Value::Str("fee".into()));
m.insert("point_dnw".to_string(), Value::Str("deposit/withdraw".into()));
m.insert("fund".to_string(), Value::Str("fee".into()));
m.insert("refr".to_string(), Value::Str("rebate".into()));
m.insert("fee".to_string(), Value::Str("fee".into()));
m.insert("pnl".to_string(), Value::Str("trade".into()));
m.insert("dnw".to_string(), Value::Str("deposit/withdraw".into()));
m
});
return self.safe_string(ledgerType, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name gate#setPositionMode
* @description set dual/hedged mode to true or false for a swap market, make sure all positions are closed and no orders are open before setting dual mode
* @see https://www.gate.com/docs/developers/apiv4/en/#set-position-mode
* @param {bool} hedged set to true to enable dual mode
* @param {string|undefined} symbol if passed, dual mode is set for all markets with the same settle currency
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} params.settle settle currency
* @returns {object} response from the exchange
*/
pub async fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut market: Value = (if (symbol != Value::Null) { self.market(symbol) } else { Value::Null });
let mut requestqueryVariable = self.prepare_request(&[market, Value::Str("swap".into()), params]);
let mut request: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut query: Value = requestqueryVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
add_element_to_object(&mut request, &Value::Str("dual_mode".into()), hedged);
let __ws_arg_105 = self.extend(request, &[query]);
return self.private_futures_post_settle_dual_mode(&[__ws_arg_105]).await;
Value::Null
}
/*
* @method
* @name gate#fetchUnderlyingAssets
* @description fetches the market ids of underlying assets for a specific contract market type
* @see https://www.gate.com/docs/developers/apiv4/en/#list-all-underlying-assets
* @param {object} [params] exchange specific params
* @param {string} [params.type] the contract market type, 'option', 'swap' or 'future', the default is 'option'
* @returns {object[]} a list of [underlying assets]{@link https://docs.ccxt.com/?id=underlying-assets-structure}
*/
pub async fn fetch_underlying_assets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut marketTypeRawparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchUnderlyingAssets".into()), &[Value::Null, params]);
let mut marketTypeRaw: Value = marketTypeRawparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeRawparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut marketType: Value = marketTypeRaw.clone();
if (marketTypeRaw == Value::Null) || (marketTypeRaw.as_str() == Some("spot")) {
marketType = Value::Str("option".into());
}
if (marketType.as_str() != Some("option")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchUnderlyingAssets() supports option markets only".into()))));
}
let mut response: Value = self.public_options_get_underlyings(&[paramsMarketType]).await;
//
// [
// {
// "index_time": "1646915796",
// "name": "BTC_USDT",
// "index_price": "39142.73"
// }
// ]
//
let mut underlyings: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_707: bool = true;
while { if !__for_first_707 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_707 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut underlying: Value = self.safe_dict(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut name: Value = self.safe_string_k(underlying, "name", &[]);
if (name != Value::Null) {
append_to_array(&mut underlyings, name);
}
}
}
return underlyings;
Value::Null
}
/*
* @method
* @name gate#fetchLiquidations
* @description retrieves the public liquidations of a trading pair
* @see https://www.gate.com/docs/developers/apiv4/en/#query-liquidation-order-history
* @param {string} symbol unified CCXT market symbol
* @param {int} [since] the earliest time in ms to fetch liquidations for
* @param {int} [limit] the maximum number of liquidation structures to retrieve
* @param {object} [params] exchange specific parameters for the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest liquidation
* @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/?id=liquidation-structure}
*/
pub async fn fetch_liquidations(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" fetchLiquidations() supports swap markets only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settle".to_string(), market.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null));
m.insert("contract".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("from".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("to".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_106 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_futures_get_settle_liq_orders(&[__ws_arg_106]).await;
return self.parse_liquidations(self.to_array(response), &[market, since, limit]);
Value::Null
}
/*
* @method
* @name gate#fetchMyLiquidations
* @description retrieves the users liquidated positions
* @see https://www.gate.com/docs/developers/apiv4/en/#query-liquidation-history
* @see https://www.gate.com/docs/developers/apiv4/en/#query-liquidation-history-2
* @see https://www.gate.com/docs/developers/apiv4/en/#list-user-s-liquidation-history-of-specified-underlying
* @param {string} symbol unified CCXT market symbol
* @param {int} [since] the earliest time in ms to fetch liquidations for
* @param {int} [limit] the maximum number of liquidation structures to retrieve
* @param {object} [params] exchange specific parameters for the exchange API endpoint
* @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/?id=liquidation-structure}
*/
pub async fn fetch_my_liquidations(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMyLiquidations() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) || (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("settle".into(), market.as_map().and_then(|__m| __m.get("settleId")).cloned().unwrap_or(Value::Null)); }
} else if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let mut marketId: Value = market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
let mut optionParts: Value = split(&marketId, &Value::Str("-".into()));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("underlying".into(), self.safe_string(optionParts, Value::Int(0), &[])); }
}
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_107 = self.extend(request.clone(), &[params.clone()]);
response = self.private_futures_get_settle_liquidates(&[__ws_arg_107]).await;
} else if (market.as_map().and_then(|__m| __m.get("future")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_108 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delivery_get_settle_liquidates(&[__ws_arg_108]).await;
} else if (market.as_map().and_then(|__m| __m.get("option")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_109 = self.extend(request, &[params]);
response = self.private_options_get_position_close(&[__ws_arg_109]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchMyLiquidations() does not support ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" orders".into()))));
}
return self.parse_liquidations(self.to_array(response), &[market, since, limit]);
Value::Null
}
pub fn parse_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchLiquidations
//
// {
// "contract": "BTC_USDT",
// "left": 0,
// "size": -165,
// "fill_price": "28070",
// "order_price": "28225",
// "time": 1696736132
// }
//
// swap and future: fetchMyLiquidations
//
// {
// "time": 1548654951,
// "contract": "BTC_USDT",
// "size": 600,
// "leverage": "25",
// "margin": "0.006705256878",
// "entry_price": "3536.123",
// "liq_price": "3421.54",
// "mark_price": "3420.27",
// "order_id": 317393847,
// "order_price": "3405",
// "fill_price": "3424",
// "left": 0
// }
//
// option: fetchMyLiquidations
//
// {
// "time": 1631764800,
// "pnl": "-42914.291",
// "settle_size": "-10001",
// "side": "short",
// "contract": "BTC_USDT-20210916-5000-C",
// "text": "settled"
// }
//
let mut marketId: Value = self.safe_string_k(liquidation.clone(), "contract", &[]);
let mut timestamp: Value = self.safe_timestamp_k(liquidation.clone(), "time", &[]);
let mut size: Value = self.safe_string2(liquidation.clone(), Value::Str("size".into()), Value::Str("settle_size".into()), &[]);
let mut left: Value = self.safe_string_k(liquidation.clone(), "left", &[Value::Str("0".into())]);
let mut contractsString: Value = crate::precise::Precise::stringAbs(&crate::precise::Precise::stringSub(&size, &left));
let mut contractSizeString: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
let mut priceString: Value = self.safe_string2(liquidation.clone(), Value::Str("liq_price".into()), Value::Str("fill_price".into()), &[]);
let mut baseValueString: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
let mut quoteValueString: Value = self.safe_string_k(liquidation.clone(), "pnl", &[]);
if (quoteValueString == Value::Null) {
quoteValueString = crate::precise::Precise::stringMul(&baseValueString, &priceString);
}
// --- derive side ---
// 1) options payload has explicit 'side': 'long' | 'short'
let mut optPos: Option<String> = self.safe_string_lower_k(liquidation.clone(), "side", &[]).as_str().map(str::to_owned);
let mut side: Value = Value::Null;
if (optPos.as_deref() == Some("long")) {
side = Value::Str("buy".into());
} else if (optPos.as_deref() == Some("short")) {
side = Value::Str("sell".into());
} else {
if (size != Value::Null) {
if is_true(&crate::precise::Precise::stringGt(&size, &Value::Str("0".into()))) {
side = Value::Str("buy".into());
} else if is_true(&crate::precise::Precise::stringLt(&size, &Value::Str("0".into()))) {
side = Value::Str("sell".into());
}
}
}
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), liquidation);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("contracts".to_string(), self.parse_number(contractsString, &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSizeString, &[]));
m.insert("price".to_string(), self.parse_number(priceString, &[]));
m.insert("side".to_string(), side);
m.insert("baseValue".to_string(), self.parse_number(baseValueString, &[]));
m.insert("quoteValue".to_string(), self.parse_number(crate::precise::Precise::stringAbs("eValueString), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
}), &[]);
Value::Null
}
/*
* @method
* @name gate#fetchGreeks
* @description fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
* @see https://www.gate.com/docs/developers/apiv4/en/#query-options-market-ticker-information
* @param {string} symbol unified symbol of the market to fetch greeks for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [greeks structure]{@link https://docs.ccxt.com/?id=greeks-structure}
*/
pub async fn fetch_greeks(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("underlying".to_string(), crate::value::get_value_k(&market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), "underlying"));
m
});
let __ws_arg_110 = self.extend(request, &[params]);
let mut response: Value = self.public_options_get_tickers(&[__ws_arg_110]).await;
//
// [
// {
// "vega": "1.78992",
// "leverage": "6.2096777055417",
// "ask_iv": "0.6245",
// "delta": "-0.69397",
// "last_price": "0",
// "theta": "-2.5723",
// "bid1_price": "222.9",
// "mark_iv": "0.5909",
// "name": "ETH_USDT-20231201-2300-P",
// "bid_iv": "0.5065",
// "ask1_price": "243.6",
// "mark_price": "236.57",
// "position_size": 0,
// "bid1_size": 368,
// "ask1_size": -335,
// "gamma": "0.00116"
// },
// ]
//
let mut marketId: Value = market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
{
let mut i: Value = Value::Int(0);
let mut __for_first_708: bool = true;
while { if !__for_first_708 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_708 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut entry: Value = self.safe_dict(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut entryMarketId: Value = self.safe_string_k(entry.clone(), "name", &[]);
if (entryMarketId.as_str() == marketId.as_str()) {
return self.parse_greeks(entry, &[market.clone()]);
}
}
}
panic!("{}", crate::exchange_errors::null_response(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchGreeks() could not find greeks for ".into())).into()), symbol)));
Value::Null
}
pub fn parse_greeks(&self, mut greeks: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "vega": "1.78992",
// "leverage": "6.2096777055417",
// "ask_iv": "0.6245",
// "delta": "-0.69397",
// "last_price": "0",
// "theta": "-2.5723",
// "bid1_price": "222.9",
// "mark_iv": "0.5909",
// "name": "ETH_USDT-20231201-2300-P",
// "bid_iv": "0.5065",
// "ask1_price": "243.6",
// "mark_price": "236.57",
// "position_size": 0,
// "bid1_size": 368,
// "ask1_size": -335,
// "gamma": "0.00116"
// }
//
let mut marketId: Value = self.safe_string_k(greeks.clone(), "name", &[]);
let mut symbol: Value = self.safe_symbol(marketId, &[market.clone()]);
if (market == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" parseGreeks() could not resolve market".into()))));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("delta".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "delta", &[]), &[]));
m.insert("gamma".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "gamma", &[]), &[]));
m.insert("theta".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "theta", &[]), &[]));
m.insert("vega".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "vega", &[]), &[]));
m.insert("rho".to_string(), Value::Null);
m.insert("bidSize".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "bid1_size", &[]), &[]));
m.insert("askSize".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "ask1_size", &[]), &[]));
m.insert("bidImpliedVolatility".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "bid_iv", &[]), &[]));
m.insert("askImpliedVolatility".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "ask_iv", &[]), &[]));
m.insert("markImpliedVolatility".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "mark_iv", &[]), &[]));
m.insert("bidPrice".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "bid1_price", &[]), &[]));
m.insert("askPrice".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "ask1_price", &[]), &[]));
m.insert("markPrice".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "mark_price", &[]), &[]));
m.insert("lastPrice".to_string(), self.parse_number(self.safe_number_k(greeks.clone(), "last_price", &[]), &[]));
m.insert("underlyingPrice".to_string(), self.parse_number(crate::value::get_value_k(&market.as_map().and_then(|__m| __m.get("info")).cloned().unwrap_or(Value::Null), "underlying_price"), &[]));
m.insert("info".to_string(), greeks);
m
});
Value::Null
}
/*
* @method
* @name gate#closePosition
* @description closes open positions for a market
* @see https://www.gate.com/docs/developers/apiv4/en/#place-futures-order
* @see https://www.gate.com/docs/developers/apiv4/en/#place-futures-order-2
* @see https://www.gate.com/docs/developers/apiv4/en/#create-an-options-order
* @param {string} symbol Unified CCXT market symbol
* @param {string} side 'buy' or 'sell'
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("close".to_string(), Value::Bool(true));
m
});
let mut paramsExtended: Value = self.extend(request, &[params]);
// side is not used but needs to be present, otherwise crashes in php
let mut sideResolved: Value = (if (side == Value::Null) { Value::Str("".into()) } else { side });
return self.create_order(symbol, Value::Str("market".into()), sideResolved, Value::Int(0), &[Value::Null, paramsExtended]).await;
Value::Null
}
/*
* @method
* @name gate#fetchLeverage
* @description fetch the set leverage for a market
* @see https://www.gate.com/docs/developers/apiv4/en/#get-unified-account-information
* @see https://www.gate.com/docs/developers/apiv4/en/#get-lending-market-details
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.unified] default false, set to true for fetching the unified accounts leverage
* @returns {object} a [leverage structure]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverage(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
// unified account does not require a symbol
market = self.market(symbol);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut isUnified: Value = self.safe_bool_k(params.clone(), "unified", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("unified".into()), &[]);
if matches!(self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]), Value::Bool(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency_pair".into(), self.safe_string_k(market.clone(), "id", &[])); }
if (isUnified.as_bool() == Some(true)) {
let __ws_arg_111 = self.extend(request.clone(), &[paramsOmitted.clone()]);
response = self.public_margin_get_uni_currency_pairs_currency_pair(&[__ws_arg_111]).await;
} else {
let __ws_arg_112 = self.extend(request.clone(), &[paramsOmitted.clone()]);
response = self.public_margin_get_currency_pairs_currency_pair(&[__ws_arg_112]).await; // deprecated
}
} else if (isUnified.as_bool() == Some(true)) {
let __ws_arg_113 = self.extend(request, &[paramsOmitted]);
response = self.private_unified_get_accounts(&[__ws_arg_113]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchLeverage() does not support ".into())).into()), self.safe_string_k(market.clone(), "type", &[])).into()), Value::Str(" markets".into()))));
}
return self.parse_leverage(response, &[market]);
Value::Null
}
/*
* @method
* @name gate#fetchLeverages
* @description fetch the set leverage for all leverage markets, only spot margin is supported on gate
* @see https://www.gate.com/docs/developers/apiv4/en/#list-lending-markets
* @param {string[]} symbols a list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.unified] default false, set to true for fetching unified account leverages
* @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverages(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = Value::Null;
let mut isUnified: Value = self.safe_bool_k(params.clone(), "unified", &[]);
let mut paramsOmitted: Value = self.omit(params, Value::Str("unified".into()), &[]);
let mut marketIdRequest: Value = Value::Str("id".into());
if (isUnified.as_bool() == Some(true)) {
marketIdRequest = Value::Str("currency_pair".into());
response = self.public_margin_get_uni_currency_pairs(&[paramsOmitted.clone()]).await;
} else {
response = self.public_margin_get_currency_pairs(&[paramsOmitted]).await; // deprecated
}
return self.parse_leverages(self.to_array(response), &[symbolsNormalized, marketIdRequest, Value::Str("spot".into())]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string2(leverage.clone(), Value::Str("currency_pair".into()), Value::Str("id".into()), &[]);
let mut leverageValue: Value = self.safe_integer_k(leverage.clone(), "leverage", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market, Value::Str("_".into()), Value::Str("spot".into())]));
m.insert("marginMode".to_string(), Value::Null);
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue);
m
});
Value::Null
}
/*
* @method
* @name gate#fetchOption
* @description fetches option data that is commonly found in an option chain
* @see https://www.gate.com/docs/developers/apiv4/en/#query-specified-contract-details
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [option chain structure]{@link https://docs.ccxt.com/?id=option-chain-structure}
*/
pub async fn fetch_option(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_114 = self.extend(request, &[params]);
let mut response: Value = self.public_options_get_contracts_contract(&[__ws_arg_114]).await;
return self.parse_option(response, &[Value::Null, market]);
Value::Null
}
/*
* @method
* @name gate#fetchOptionChain
* @description fetches data for an underlying asset that is commonly found in an option chain
* @see https://www.gate.com/docs/developers/apiv4/en/#list-all-contracts-for-specified-underlying-and-expiration-date
* @param {string} code base currency to fetch an option chain for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.underlying] the underlying asset, can be obtained from fetchUnderlyingAssets ()
* @param {int} [params.expiration] unix timestamp of the expiration time
* @returns {object} a list of [option chain structures]{@link https://docs.ccxt.com/?id=option-chain-structure}
*/
pub async fn fetch_option_chain(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("underlying".to_string(), Value::Str(format!("{}{}", currency.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null), Value::Str("_USDT".into())).into()));
m
});
let __ws_arg_115 = self.extend(request, &[params]);
let mut response: Value = self.public_options_get_contracts(&[__ws_arg_115]).await;
return self.parse_option_chain(self.to_array(response), &[Value::Null, Value::Str("name".into())]);
Value::Null
}
pub fn parse_option(&self, mut chain: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut market = get_arg(optional_args, 1, Value::Null);
//
// {
// "is_active": true,
// "mark_price_round": "0.1",
// "settle_fee_rate": "0.00015",
// "bid1_size": 434,
// "taker_fee_rate": "0.0003",
// "price_limit_fee_rate": "0.1",
// "order_price_round": "1",
// "tag": "day",
// "ref_rebate_rate": "0",
// "name": "BTC_USDT-20240324-63500-P",
// "strike_price": "63500",
// "ask1_price": "387",
// "ref_discount_rate": "0",
// "order_price_deviate": "0.15",
// "ask1_size": -454,
// "mark_price_down": "124.3",
// "orderbook_id": 29600,
// "is_call": false,
// "last_price": "0",
// "mark_price": "366.6",
// "underlying": "BTC_USDT",
// "create_time": 1711118829,
// "settle_limit_fee_rate": "0.1",
// "orders_limit": 10,
// "mark_price_up": "630",
// "position_size": 0,
// "order_size_max": 10000,
// "position_limit": 10000,
// "multiplier": "0.01",
// "order_size_min": 1,
// "trade_size": 0,
// "underlying_price": "64084.65",
// "maker_fee_rate": "0.0003",
// "expiration_time": 1711267200,
// "trade_id": 0,
// "bid1_price": "307"
// }
//
let mut marketId: Value = self.safe_string_k(chain.clone(), "name", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut timestamp: Value = self.safe_timestamp_k(chain.clone(), "create_time", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("currency".to_string(), Value::Null);
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("impliedVolatility".to_string(), Value::Null);
m.insert("openInterest".to_string(), Value::Null);
m.insert("bidPrice".to_string(), self.parse_number(self.safe_number_k(chain.clone(), "bid1_price", &[]), &[]));
m.insert("askPrice".to_string(), self.parse_number(self.safe_number_k(chain.clone(), "ask1_price", &[]), &[]));
m.insert("midPrice".to_string(), Value::Null);
m.insert("markPrice".to_string(), self.parse_number(self.safe_number_k(chain.clone(), "mark_price", &[]), &[]));
m.insert("lastPrice".to_string(), self.parse_number(self.safe_number_k(chain.clone(), "last_price", &[]), &[]));
m.insert("underlyingPrice".to_string(), self.parse_number(self.safe_number_k(chain, "underlying_price", &[]), &[]));
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("baseVolume".to_string(), Value::Null);
m.insert("quoteVolume".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name gate#fetchPositionsHistory
* @description fetches historical positions
* @see https://www.gate.com/docs/developers/apiv4/#query-position-close-history
* @see https://www.gate.com/docs/developers/apiv4/#query-position-close-history-2
* @param {string[]} symbols unified conract symbols, must all have the same settle currency and the same market type
* @param {int} [since] the earliest time in ms to fetch positions for
* @param {int} [limit] the maximum amount of records to fetch, default=1000
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch positions for
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {int} [params.offset] list offset, starting from 0
* @param {string} [params.side] long or short
* @param {string} [params.pnl] query profit or loss
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbols != Value::Null) {
let mut symbolsLength: f64 = ((symbols.len() as i64) as f64);
if (symbolsLength == 1.0) {
market = self.market(symbols.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null));
}
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(Value::Str("fetchPositionsHistory".into()), &[market.clone(), params, Value::Str("swap".into())]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut until: Value = self.safe_integer_k(paramsMarketType.clone(), "until", &[]);
let mut paramsOmitted: Value = self.omit(paramsMarketType, Value::Str("until".into()), &[]);
let mut requestparamsValueVariable = self.prepare_request(&[market, marketType.clone(), paramsOmitted]);
let mut request: Value = requestparamsValueVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsValue: Value = requestparamsValueVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (limit != Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".into()), limit);
}
if (since != Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".into()), self.parse_to_int((match ((since).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
if (until != Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".into()), self.parse_to_int((match ((until).as_f64(), (Value::Int(1000)).as_f64()) { (Some(x), Some(y)) if y != 0.0 => Value::Float(x / y), _ => Value::Null })));
}
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("swap")) {
let __ws_arg_116 = self.extend(request.clone(), &[paramsValue.clone()]);
response = self.private_futures_get_settle_position_close(&[__ws_arg_116]).await;
} else if (marketType.as_str() == Some("future")) {
let __ws_arg_117 = self.extend(request, &[paramsValue.clone()]);
response = self.private_delivery_get_settle_position_close(&[__ws_arg_117]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchPositionsHistory() does not support markets of type ".into())).into()), marketType)));
}
//
// [
// {
// "contract": "SLERF_USDT",
// "text": "web",
// "long_price": "0.766306",
// "pnl": "-23.41702352",
// "pnl_pnl": "-22.7187",
// "pnl_fee": "-0.06527125",
// "pnl_fund": "-0.63305227",
// "accum_size": "100",
// "time": 1711279263,
// "short_price": "0.539119",
// "side": "long",
// "max_size": "100",
// "first_open_time": 1711037985
// },
// ...
// ]
//
let mut responseList: Value = Value::from(vec![]);
if (response != Value::Null) {
responseList = self.to_array(response);
}
return self.parse_positions(responseList, &[symbols, paramsValue]);
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
//
// {"label": "ORDER_NOT_FOUND", "message": "Order not found"}
// {"label": "INVALID_PARAM_VALUE", "message": "invalid argument: status"}
// {"label": "INVALID_PARAM_VALUE", "message": "invalid argument: Trigger.rule"}
// {"label": "INVALID_PARAM_VALUE", "message": "invalid argument: trigger.expiration invalid range"}
// {"label": "INVALID_ARGUMENT", "detail": "invalid size"}
// {"user_id":10406147,"id":"id","succeeded":false,"message":"INVALID_PROTOCOL","label":"INVALID_PROTOCOL"}
//
let mut label: Value = self.safe_string_k(response, "label", &[]);
if (label != Value::Null) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), label, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}