// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
pub struct 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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on 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.get(2..).unwrap_or(&[]).to_vec()[..]).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.get(2..).unwrap_or(&[]).to_vec()[..]).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.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders_for_symbols" => self.cancel_orders_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).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.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_orders_request" => self.create_orders_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"edit_order_request" => self.edit_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_interest" => self.fetch_borrow_interest(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_future_markets" => self.fetch_future_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_greeks" => self.fetch_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverages" => self.fetch_leverages(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_liquidations" => self.fetch_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_market_leverage_tiers" => self.fetch_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_liquidations" => self.fetch_my_liquidations(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_settlement_history" => self.fetch_my_settlement_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_network_deposit_address" => self.fetch_network_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option" => self.fetch_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option_chain" => self.fetch_option_chain(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option_markets" => self.fetch_option_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option_ohlcv" => self.fetch_option_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option_underlyings" => self.fetch_option_underlyings().await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_request" => self.fetch_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_settlement_history" => self.fetch_settlement_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_swap_markets" => self.fetch_swap_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transaction_fees" => self.fetch_transaction_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_underlying_assets" => self.fetch_underlying_assets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"modify_margin_helper" => self.modify_margin_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"multi_order_spot_prepare_request" => self.multi_order_spot_prepare_request(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_emulated_leverage_tiers" => self.parse_emulated_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_interval" => self.parse_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_greeks" => self.parse_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_liquidation" => self.parse_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_loan" => self.parse_margin_loan(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_option" => self.parse_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_settlement" => self.parse_settlement(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_settlements" => self.parse_settlements(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transaction_type" => self.parse_transaction_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"prepare_orders_by_status_request" => self.prepare_orders_by_status_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"prepare_request" => self.prepare_request(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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.get(2..).unwrap_or(&[]).to_vec()[..]).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.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"safe_market" => self.safe_market(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"spot_order_prepare_request" => self.spot_order_prepare_request(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"upgrade_unified_trade_account" => self.upgrade_unified_trade_account(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for 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".to_string()));
m.insert("name".to_string(), Value::Str("Gate".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("KR".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(50));
m.insert("version".to_string(), Value::Str("v4".to_string()));
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".to_string()));
m.insert("doc".to_string(), Value::Str("https://www.gate.com/docs/developers/apiv4/en".to_string()));
m.insert("www".to_string(), Value::Str("https://gate.com".to_string()));
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".to_string()));
m.insert("futures".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("margin".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("delivery".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("spot".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("options".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("sub_accounts".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("earn".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
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".to_string()));
m.insert("wallet".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("futures".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("margin".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("delivery".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("spot".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("options".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("subAccounts".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("unified".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("rebate".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("earn".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("account".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("loan".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
m.insert("otc".to_string(), Value::Str("https://api.gateio.ws/api/v4".to_string()));
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".to_string()));
m.insert("delivery".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("options".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("spot".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("wallet".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("margin".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("sub_accounts".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("account".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
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".to_string()));
m.insert("delivery".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("options".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("spot".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("wallet".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("margin".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("sub_accounts".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
m.insert("account".to_string(), Value::Str("https://api-testnet.gateapi.io/api/v4".to_string()));
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".to_string()));
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".to_string()));
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".to_string()));
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
}));
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
}));
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
}));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("transferable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("transferables".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("batch_borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loan_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("risk_units".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("unified_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("estimate_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("currency_discount_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loan_margin_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("leverage/user_currency_config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("leverage/user_currency_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("account_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(200), &Value::Int(15)));
m
}));
m.insert("portfolio_calculator".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("leverage/user_currency_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral_currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("account_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
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
}));
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(), divide(&Value::Int(20), &Value::Int(75)));
m
}));
m.insert("countdown_cancel_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(75)));
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
}));
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(), divide(&Value::Int(20), &Value::Int(75)));
m
}));
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(75)));
m
}));
m.insert("price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(75)));
m
}));
m.insert("price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(75)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("funding_accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("auto_repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("transferable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/estimate_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/loan_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("user/loan_margin_tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("user/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loans/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loans/{loan_id}/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loan_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loan_records/{loan_record_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/loans/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/repayments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/transferable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/estimate_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("leverage/user_market_setting".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("merged_loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loans/{loan_id}/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("cross/repayments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("loan_records/{loan_record_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
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
}));
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
}));
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(), divide(&Value::Int(20), &Value::Int(75)));
m
}));
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(75)));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(75)));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(75)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/positions/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/my_trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/position_close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/liquidates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/settlements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/positions/{contract}/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/positions/{contract}/risk_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/price_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("{settle}/price_orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("account_book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("positions/{contract}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("position_close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("my_trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("countdown_cancel_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("mmp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("mmp/reset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/lend_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/interests/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/interest_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/interest_status/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/chart".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("staking/eth2/rate_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("dual/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("dual/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("structured/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("staking/coins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("staking/order_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("staking/award_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("staking/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("uni/currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("staking/eth2/swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("dual/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("structured/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("staking/swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/repay_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/collaterals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/total_amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/orders/{order_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/mortgage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/currency_quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/fixed_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/current_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("collateral/collaterals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("multi_collateral/mortgage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("main_keys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("rate_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("stp_groups".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("stp_groups/{stp_id}/users".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("stp_groups/debit_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("debit_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("stp_groups/{stp_id}/users".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("debit_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
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(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("agency/commission_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("partner/transaction_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("partner/commission_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("partner/sub_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("broker/commission_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("broker/transaction_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("user/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
m
}));
m.insert("user/sub_relation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(20), &Value::Int(15)));
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
}));
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
}));
m
}));
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("10s".to_string(), Value::Str("10s".to_string()));
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("8h".to_string(), Value::Str("8h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("7d".to_string(), Value::Str("7d".to_string()));
m.insert("1w".to_string(), Value::Str("7d".to_string()));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ORT".to_string(), Value::Str("XREATORS".to_string()));
m.insert("ASS".to_string(), Value::Str("ASSF".to_string()));
m.insert("88MPH".to_string(), Value::Str("MPH".to_string()));
m.insert("AXIS".to_string(), Value::Str("AXISDEFI".to_string()));
m.insert("BIFI".to_string(), Value::Str("BITCOINFILE".to_string()));
m.insert("BOX".to_string(), Value::Str("DEFIBOX".to_string()));
m.insert("BYN".to_string(), Value::Str("BEYONDFI".to_string()));
m.insert("EGG".to_string(), Value::Str("GOOSEFINANCE".to_string()));
m.insert("GTC".to_string(), Value::Str("GAMECOM".to_string()));
m.insert("GTC_HT".to_string(), Value::Str("GAMECOM_HT".to_string()));
m.insert("GTC_BSC".to_string(), Value::Str("GAMECOM_BSC".to_string()));
m.insert("HIT".to_string(), Value::Str("HITCHAIN".to_string()));
m.insert("MM".to_string(), Value::Str("MILLION".to_string()));
m.insert("MPH".to_string(), Value::Str("MORPHER".to_string()));
m.insert("POINT".to_string(), Value::Str("GATEPOINT".to_string()));
m.insert("RAI".to_string(), Value::Str("RAIREFLEXINDEX".to_string()));
m.insert("SBTC".to_string(), Value::Str("SUPERBITCOIN".to_string()));
m.insert("TNC".to_string(), Value::Str("TRINITYNETWORKCREDIT".to_string()));
m.insert("VAI".to_string(), Value::Str("VAIOT".to_string()));
m.insert("TRAC".to_string(), Value::Str("TRACO".to_string()));
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".to_string()));
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("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".to_string()));
m.insert("BRC20".to_string(), Value::Str("BTCBRC".to_string()));
m.insert("ETH".to_string(), Value::Str("ETH".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("TRX".to_string(), Value::Str("TRX".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRX".to_string()));
m.insert("HECO".to_string(), Value::Str("HT".to_string()));
m.insert("HRC20".to_string(), Value::Str("HT".to_string()));
m.insert("BSC".to_string(), Value::Str("BSC".to_string()));
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("SOL".to_string(), Value::Str("SOL".to_string()));
m.insert("MATIC".to_string(), Value::Str("MATIC".to_string()));
m.insert("OPTIMISM".to_string(), Value::Str("OPETH".to_string()));
m.insert("ADA".to_string(), Value::Str("ADA".to_string()));
m.insert("AVAXC".to_string(), Value::Str("AVAX_C".to_string()));
m.insert("NEAR".to_string(), Value::Str("NEAR".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBEVM".to_string()));
m.insert("ARBITRUM_NOVA".to_string(), Value::Str("ARBNOVA".to_string()));
m.insert("BASE".to_string(), Value::Str("BASEEVM".to_string()));
m.insert("SUI".to_string(), Value::Str("SUI".to_string()));
m.insert("CRONOS".to_string(), Value::Str("CRO".to_string()));
m.insert("CRO".to_string(), Value::Str("CRO".to_string()));
m.insert("APT".to_string(), Value::Str("APT".to_string()));
m.insert("SCROLL".to_string(), Value::Str("SCROLLETH".to_string()));
m.insert("TAIKO".to_string(), Value::Str("TAIKOETH".to_string()));
m.insert("HYPE".to_string(), Value::Str("HYPE".to_string()));
m.insert("ALGO".to_string(), Value::Str("ALGO".to_string()));
m.insert("LINEA".to_string(), Value::Str("LINEAETH".to_string()));
m.insert("BLAST".to_string(), Value::Str("BLASTETH".to_string()));
m.insert("XLM".to_string(), Value::Str("XLM".to_string()));
m.insert("RSK".to_string(), Value::Str("RBTC".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("MNT".to_string(), Value::Str("MNT".to_string()));
m.insert("CELO".to_string(), Value::Str("CELO".to_string()));
m.insert("HBAR".to_string(), Value::Str("HBAR".to_string()));
m.insert("ZKSYNC".to_string(), Value::Str("ZKSERA".to_string()));
m.insert("KLAY".to_string(), Value::Str("KLAY".to_string()));
m.insert("EOS".to_string(), Value::Str("EOS".to_string()));
m.insert("ACA".to_string(), Value::Str("ACA".to_string()));
m.insert("XTZ".to_string(), Value::Str("XTZ".to_string()));
m.insert("EGLD".to_string(), Value::Str("EGLD".to_string()));
m.insert("GLMR".to_string(), Value::Str("GLMR".to_string()));
m.insert("AURORA".to_string(), Value::Str("AURORAEVM".to_string()));
m.insert("KON".to_string(), Value::Str("KONET".to_string()));
m.insert("GATECHAIN".to_string(), Value::Str("GTEVM".to_string()));
m.insert("KUSAMA".to_string(), Value::Str("KSMSM".to_string()));
m.insert("OKC".to_string(), Value::Str("OKT".to_string()));
m.insert("POLKADOT".to_string(), Value::Str("DOTSM".to_string()));
m.insert("LUNA".to_string(), Value::Str("LUNC".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("OPETH".to_string(), Value::Str("OP".to_string()));
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
m.insert("TRX".to_string(), Value::Str("TRC20".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRC20".to_string()));
m.insert("HT".to_string(), Value::Str("HRC20".to_string()));
m.insert("HECO".to_string(), Value::Str("HRC20".to_string()));
m.insert("BSC".to_string(), Value::Str("BEP20".to_string()));
m.insert("BEP20".to_string(), Value::Str("BEP20".to_string()));
m.insert("POLYGON".to_string(), Value::Str("MATIC".to_string()));
m.insert("POL".to_string(), Value::Str("MATIC".to_string()));
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("gtc".to_string()));
m.insert("IOC".to_string(), Value::Str("ioc".to_string()));
m.insert("PO".to_string(), Value::Str("poc".to_string()));
m.insert("POC".to_string(), Value::Str("poc".to_string()));
m.insert("FOK".to_string(), Value::Str("fok".to_string()));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("funding".to_string(), Value::Str("spot".to_string()));
m.insert("spot".to_string(), Value::Str("spot".to_string()));
m.insert("margin".to_string(), Value::Str("margin".to_string()));
m.insert("cross_margin".to_string(), Value::Str("cross_margin".to_string()));
m.insert("cross".to_string(), Value::Str("cross_margin".to_string()));
m.insert("isolated".to_string(), Value::Str("margin".to_string()));
m.insert("swap".to_string(), Value::Str("futures".to_string()));
m.insert("future".to_string(), Value::Str("delivery".to_string()));
m.insert("futures".to_string(), Value::Str("futures".to_string()));
m.insert("delivery".to_string(), Value::Str("delivery".to_string()));
m.insert("option".to_string(), Value::Str("options".to_string()));
m.insert("options".to_string(), Value::Str("options".to_string()));
m
}));
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("types".to_string(), Value::List(vec![Value::Str("spot".to_string()), Value::Str("swap".to_string()), Value::Str("future".to_string()), Value::Str("option".to_string())]));
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::List(vec![Value::Str("usdt".to_string()), Value::Str("btc".to_string())]));
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::List(vec![Value::Str("usdt".to_string())]));
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".to_string()));
m
}));
m.insert("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("spot".to_string()));
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".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".to_string()));
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".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivatives".to_string()));
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".to_string()));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.002".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.002".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1.5".to_string()), &[]), self.parse_number(Value::Str("0.00185".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3".to_string()), &[]), self.parse_number(Value::Str("0.00175".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6".to_string()), &[]), self.parse_number(Value::Str("0.00165".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("12.5".to_string()), &[]), self.parse_number(Value::Str("0.00155".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25".to_string()), &[]), self.parse_number(Value::Str("0.00145".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75".to_string()), &[]), self.parse_number(Value::Str("0.00135".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.00125".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.00115".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1250".to_string()), &[]), self.parse_number(Value::Str("0.00105".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500".to_string()), &[]), self.parse_number(Value::Str("0.00095".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3000".to_string()), &[]), self.parse_number(Value::Str("0.00085".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6000".to_string()), &[]), self.parse_number(Value::Str("0.00075".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("11000".to_string()), &[]), self.parse_number(Value::Str("0.00065".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000".to_string()), &[]), self.parse_number(Value::Str("0.00055".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("0.00055".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75000".to_string()), &[]), self.parse_number(Value::Str("0.00055".to_string()), &[])])]));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1.5".to_string()), &[]), self.parse_number(Value::Str("0.00195".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3".to_string()), &[]), self.parse_number(Value::Str("0.00185".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6".to_string()), &[]), self.parse_number(Value::Str("0.00175".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("12.5".to_string()), &[]), self.parse_number(Value::Str("0.00165".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25".to_string()), &[]), self.parse_number(Value::Str("0.00155".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75".to_string()), &[]), self.parse_number(Value::Str("0.00145".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.00135".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.00125".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1250".to_string()), &[]), self.parse_number(Value::Str("0.00115".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500".to_string()), &[]), self.parse_number(Value::Str("0.00105".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3000".to_string()), &[]), self.parse_number(Value::Str("0.00095".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6000".to_string()), &[]), self.parse_number(Value::Str("0.00085".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("11000".to_string()), &[]), self.parse_number(Value::Str("0.00075".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000".to_string()), &[]), self.parse_number(Value::Str("0.00065".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("0.00065".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75000".to_string()), &[]), self.parse_number(Value::Str("0.00065".to_string()), &[])])]));
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".to_string()));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0005".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.0000".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1.5".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("12.5".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1250".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3000".to_string()), &[]), self.parse_number(Value::Str("-0.00008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6000".to_string()), &[]), self.parse_number(Value::Str("-0.01000".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("11000".to_string()), &[]), self.parse_number(Value::Str("-0.01002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000".to_string()), &[]), self.parse_number(Value::Str("-0.01005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("-0.02000".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75000".to_string()), &[]), self.parse_number(Value::Str("-0.02005".to_string()), &[])])]));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.00050".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1.5".to_string()), &[]), self.parse_number(Value::Str("0.00048".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3".to_string()), &[]), self.parse_number(Value::Str("0.00046".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6".to_string()), &[]), self.parse_number(Value::Str("0.00044".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("12.5".to_string()), &[]), self.parse_number(Value::Str("0.00042".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25".to_string()), &[]), self.parse_number(Value::Str("0.00040".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75".to_string()), &[]), self.parse_number(Value::Str("0.00038".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.00036".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.00034".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1250".to_string()), &[]), self.parse_number(Value::Str("0.00032".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("3000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("6000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("11000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])])]));
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".to_string()).clone());
m.insert("INVALID_PROTOCOL".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("INVALID_ARGUMENT".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("INVALID_REQUEST_BODY".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("MISSING_REQUIRED_PARAM".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("BAD_REQUEST".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("INVALID_CONTENT_TYPE".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("NOT_ACCEPTABLE".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("METHOD_NOT_ALLOWED".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("NOT_FOUND".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("AUTHENTICATION_FAILED".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("INVALID_CREDENTIALS".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("INVALID_KEY".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("IP_FORBIDDEN".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("READ_ONLY".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("INVALID_SIGNATURE".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("MISSING_REQUIRED_HEADER".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("REQUEST_EXPIRED".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("ACCOUNT_LOCKED".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("FORBIDDEN".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("SUB_ACCOUNT_NOT_FOUND".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("SUB_ACCOUNT_LOCKED".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("MARGIN_BALANCE_EXCEPTION".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("MARGIN_TRANSFER_FAILED".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("TOO_MUCH_FUTURES_AVAILABLE".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("FUTURES_BALANCE_NOT_ENOUGH".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("ACCOUNT_EXCEPTION".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("SUB_ACCOUNT_TRANSFER_FAILED".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("ADDRESS_NOT_USED".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("TOO_FAST".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("WITHDRAWAL_OVER_LIMIT".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("API_WITHDRAW_DISABLED".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("INVALID_WITHDRAW_ID".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("INVALID_WITHDRAW_CANCEL_STATUS".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("INVALID_PRECISION".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("INVALID_CURRENCY".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("INVALID_CURRENCY_PAIR".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("POC_FILL_IMMEDIATELY".to_string(), Value::Str("OrderImmediatelyFillable".to_string()).clone());
m.insert("ORDER_NOT_FOUND".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("CLIENT_ID_NOT_FOUND".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("ORDER_CLOSED".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_CANCELLED".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("QUANTITY_NOT_ENOUGH".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("BALANCE_NOT_ENOUGH".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("MARGIN_NOT_SUPPORTED".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("MARGIN_BALANCE_NOT_ENOUGH".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("AMOUNT_TOO_LITTLE".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("AMOUNT_TOO_MUCH".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("REPEATED_CREATION".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("LOAN_NOT_FOUND".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("LOAN_RECORD_NOT_FOUND".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("NO_MATCHED_LOAN".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("NOT_MERGEABLE".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("REPAY_TOO_MUCH".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("TOO_MANY_CURRENCY_PAIRS".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("TOO_MANY_ORDERS".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("TOO_MANY_REQUESTS".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("MIXED_ACCOUNT_TYPE".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("AUTO_BORROW_TOO_MUCH".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("TRADE_RESTRICTED".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("USER_NOT_FOUND".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("CONTRACT_NO_COUNTER".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("CONTRACT_NOT_FOUND".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("RISK_LIMIT_EXCEEDED".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("INSUFFICIENT_AVAILABLE".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("LIQUIDATE_IMMEDIATELY".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("LEVERAGE_TOO_HIGH".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("LEVERAGE_TOO_LOW".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_NOT_OWNED".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("ORDER_FINISHED".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("POSITION_CROSS_MARGIN".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("POSITION_IN_LIQUIDATION".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("POSITION_IN_CLOSE".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("POSITION_EMPTY".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("REMOVE_TOO_MUCH".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("RISK_LIMIT_NOT_MULTIPLE".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("RISK_LIMIT_TOO_HIGH".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("RISK_LIMIT_TOO_lOW".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("PRICE_TOO_DEVIATED".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("SIZE_TOO_LARGE".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("SIZE_TOO_SMALL".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("PRICE_OVER_LIQUIDATION".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("PRICE_OVER_BANKRUPT".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("ORDER_POC_IMMEDIATE".to_string(), Value::Str("OrderImmediatelyFillable".to_string()).clone());
m.insert("INCREASE_POSITION".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("CONTRACT_IN_DELISTING".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("INTERNAL".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("SERVER_ERROR".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("TOO_BUSY".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("CROSS_ACCOUNT_NOT_FOUND".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("RISK_LIMIT_TOO_LOW".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("AUTO_TRIGGER_PRICE_LESS_LAST".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("AUTO_TRIGGER_PRICE_GREATE_LAST".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("POSITION_HOLDING".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("USER_LOAN_EXCEEDED".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("NO_CHANGE".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("PRICE_THRESHOLD_EXCEEDED".to_string(), Value::Str("InvalidOrder".to_string()).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".to_string()).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());
add_element_to_object(&mut self.options, &Value::Str("sandboxMode".to_string()), enable.clone());
}
/*
* @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 is_equal(&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.clone()]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "key", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = Value::Bool(is_equal(&self.safe_integer_k(result.clone(), "mode", &[]), &Value::Int(2))); add_element_to_object(&mut self.options, &Value::Str("unifiedAccount".to_string()), __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
add_element_to_object(&mut self.options, &Value::Str("unifiedAccount".to_string()), Value::Bool(false));
}
}
return get_value(&self.options, &Value::Str("unifiedAccount".to_string()));
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.clone()]).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.clone()]).await;
return self.safe_integer_k(response.clone(), "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".to_string());
let mut settle: Value = quote.clone();
let mut optionParts: Value = split(&symbol, &Value::Str("-".to_string()));
let mut symbolBase: Value = split(&symbol, &Value::Str("/".to_string()));
let mut marketIdBase: Value = split(&symbol, &Value::Str("_".to_string()));
let mut base: Value = Value::Null;
let mut expiry: Value = self.safe_string(optionParts.clone(), Value::Int(1), &[]);
if is_greater_than(&get_index_of(&symbol, &Value::Str("/".to_string())), &negate(&Value::Int(1))) {
base = self.safe_string(symbolBase.clone(), Value::Int(0), &[]);
} else {
base = self.safe_string(marketIdBase.clone(), Value::Int(0), &[]);
expiry = slice(&expiry, &Value::Int(2), &Value::Int(8)); // convert 20230728 to 230728
}
let mut strike: Value = self.safe_string(optionParts.clone(), Value::Int(2), &[]);
let mut optionType: Value = self.safe_string(optionParts.clone(), 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(), add(&add(&add(&add(&add(&add(&add(&add(&add(&base, &Value::Str("_".to_string())), "e), &Value::Str("-".to_string())), &Value::Str("20".to_string())), &expiry), &Value::Str("-".to_string())), &strike), &Value::Str("-".to_string())), &optionType));
m.insert("symbol".to_string(), add(&add(&add(&add(&add(&add(&add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle), &Value::Str("-".to_string())), &expiry), &Value::Str("-".to_string())), &strike), &Value::Str("-".to_string())), &optionType));
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.clone());
m.insert("quoteId".to_string(), quote.clone());
m.insert("settleId".to_string(), settle.clone());
m.insert("active".to_string(), Value::Bool(false));
m.insert("type".to_string(), Value::Str("option".to_string()));
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".to_string()), &[]));
m.insert("expiry".to_string(), timestamp.clone());
m.insert("expiryDatetime".to_string(), datetime.clone());
m.insert("optionType".to_string(), ternary(is_true(&(is_equal(&optionType, &Value::Str("C".to_string())))), Value::Str("call".to_string()), Value::Str("put".to_string())));
m.insert("strike".to_string(), self.parse_number(strike.clone(), &[]));
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
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 = is_true(&(!is_equal(&marketId, &Value::Null))) && is_true(&(is_true(&(is_greater_than(&get_index_of(&marketId, &Value::Str("-C".to_string())), &negate(&Value::Int(1))))) || is_true(&(is_greater_than(&get_index_of(&marketId, &Value::Str("-P".to_string())), &negate(&Value::Int(1)))))));
if is_true(&isOption) && is_true(&(is_true(&(is_equal(&self.markets_by_id, &Value::Null))) || !is_true(&(Value::Bool(in_op(&self.markets_by_id, &marketId)))))) {
return self.create_expired_option_market(marketId.clone());
}
return self.super_safe_market(marketId.clone(), market.clone(), delimiter.clone(), marketType.clone());
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 is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
if is_true(&self.check_required_credentials(&[Value::Bool(false)])) {
self.load_unified_status(&[]).await;
}
let mut rawPromises: Value = Value::List(vec![]);
let mut fetchMarketsOptions: Value = self.safe_dict_k(self.options.clone(), "fetchMarkets", &[]);
let mut types: Value = self.safe_list_k(fetchMarketsOptions.clone(), "types", &[Value::List(vec![Value::Str("spot".to_string()), Value::Str("swap".to_string()), Value::Str("future".to_string()), Value::Str("option".to_string())])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_675: bool = true;
while { if !__for_first_675 { i = add(&i, &Value::Int(1)); } __for_first_675 = false; is_less_than(&i, &get_array_length(&types)) } {
let mut marketType: Value = get_value(&types, &i);
let mut marketType: Value = get_value(&types, &i);
if is_equal(&marketType, &Value::Str("spot".to_string())) {
// 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 is_equal(&marketType, &Value::Str("swap".to_string())) {
append_to_array(&mut rawPromises, self.fetch_swap_markets(&[params.clone()]).await);
} else if is_equal(&marketType, &Value::Str("future".to_string())) {
append_to_array(&mut rawPromises, self.fetch_future_markets(&[params.clone()]).await);
} else if is_equal(&marketType, &Value::Str("option".to_string())) {
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.clone());
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.clone()]).await;
let mut marginResponsespotMarketsResponseVariable = promise_all(&Value::List(vec![marginPromise.clone(), spotMarketsPromise.clone()])).await;
let mut marginResponse: Value = get_value(&marginResponsespotMarketsResponseVariable, &Value::Int(0));
let mut spotMarketsResponse: Value = get_value(&marginResponsespotMarketsResponseVariable, &Value::Int(1));
let mut marginMarkets: Value = self.index_by(marginResponse.clone(), Value::Str("id".to_string()));
//
// 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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_676: bool = true;
while { if !__for_first_676 { i = add(&i, &Value::Int(1)); } __for_first_676 = false; is_less_than(&i, &get_array_length(&spotMarketsResponse)) } {
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_value(marginMarkets.clone(), id.clone(), &[]);
let mut market: Value = self.deep_extend(marginMarket.clone(), &[spotMarket.clone()]);
let mut baseIdquoteIdVariable = split(&id, &Value::Str("_".to_string()));
let mut baseId: Value = get_value(&baseIdquoteIdVariable, &Value::Int(0));
let mut quoteId: Value = get_value(&baseIdquoteIdVariable, &Value::Int(1));
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
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: Value = self.safe_string_k(market.clone(), "trade_status", &[]);
let mut marginStatus: Value = self.safe_integer_k(market.clone(), "status", &[Value::Int(1)]); // 0 disabled, 1 enabled
let mut leverage: Value = self.safe_number_k(market.clone(), "leverage", &[]);
let mut margin: Value = Value::Bool(!is_equal(&leverage, &Value::Null));
let mut buyStart: Value = self.safe_integer_product(spotMarket.clone(), Value::Str("buy_start".to_string()), Value::Int(1000), &[]); // buy_start is the trading start time, while sell_start is offline orders start time
let mut createdTs: Value = ternary(is_true(&(!is_equal(&buyStart, &Value::Int(0)))), buyStart.clone(), Value::Null);
let mut active: Value = Value::Bool(is_true(&(is_equal(&tradeStatus, &Value::Str("tradable".to_string())))) || is_true(&(is_true(&margin) && is_true(&(is_equal(&marginStatus, &Value::Int(1)))))));
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), add(&add(&base, &Value::Str("/".to_string())), "e));
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".to_string()));
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.clone());
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".to_string())), &[]));
m.insert("maker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&makerPercent, &Value::Str("100".to_string())), &[]));
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".to_string()), &[]));
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.clone(), "min_base_amount", &[amountPrecision.clone()]));
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(), ternary(is_true(&margin), self.safe_number_k(market.clone(), "max_quote_amount", &[]), Value::Null));
m
}));
m
}));
m.insert("created".to_string(), createdTs.clone());
m.insert("info".to_string(), market.clone());
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::List(vec![]);
let mut swapSettlementCurrencies: Value = self.get_settlement_currencies(Value::Str("swap".to_string()), Value::Str("fetchMarkets".to_string()));
if is_equal(&get_value(&self.options, &Value::Str("sandboxMode".to_string())), &Value::Bool(true)) {
swapSettlementCurrencies = Value::List(vec![Value::Str("usdt".to_string())]); // gate sandbox only has usdt-margined swaps
}
{
let mut c: Value = Value::Int(0);
let mut __for_first_678: bool = true;
while { if !__for_first_678 { c = add(&c, &Value::Int(1)); } __for_first_678 = false; is_less_than(&c, &get_array_length(&swapSettlementCurrencies)) } {
let mut settleId: Value = get_value(&swapSettlementCurrencies, &c);
let mut settleId: Value = get_value(&swapSettlementCurrencies, &c);
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.clone(), &[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_677: bool = true;
while { if !__for_first_677 { i = add(&i, &Value::Int(1)); } __for_first_677 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), settleId.clone());
append_to_array(&mut result, parsedMarket.clone());
}
}
}
}
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 is_equal(&get_value(&self.options, &Value::Str("sandboxMode".to_string())), &Value::Bool(true)) {
return Value::List(vec![]);
}
let mut result: Value = Value::List(vec![]);
let mut futureSettlementCurrencies: Value = self.get_settlement_currencies(Value::Str("future".to_string()), Value::Str("fetchMarkets".to_string()));
{
let mut c: Value = Value::Int(0);
let mut __for_first_680: bool = true;
while { if !__for_first_680 { c = add(&c, &Value::Int(1)); } __for_first_680 = false; is_less_than(&c, &get_array_length(&futureSettlementCurrencies)) } {
let mut settleId: Value = get_value(&futureSettlementCurrencies, &c);
let mut settleId: Value = get_value(&futureSettlementCurrencies, &c);
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.clone(), &[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_679: bool = true;
while { if !__for_first_679 { i = add(&i, &Value::Int(1)); } __for_first_679 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), settleId.clone());
append_to_array(&mut result, parsedMarket.clone());
}
}
}
}
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("_".to_string()));
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: Value = self.safe_string(parts.clone(), Value::Int(2), &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut expiry: Value = self.safe_timestamp(market.clone(), Value::Str("expire_time".to_string()), &[]);
let mut symbol: Value = Value::Str("".to_string());
let mut marketType: Value = Value::Str("swap".to_string());
if !is_equal(&date, &Value::Null) {
symbol = add(&add(&add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle), &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[Value::Str("".to_string())]));
marketType = Value::Str("future".to_string());
} else {
symbol = add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
}
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".to_string()), &priceDeviate);
let mut maxMultiplier: Value = crate::precise::Precise::stringAdd(&Value::Str("1".to_string()), &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(is_equal("e, &settle));
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 is_equal(&contractSize, &Value::Str("0".to_string())) {
contractSize = Value::Str("1".to_string()); // 1 USD in WEB: https://i.imgur.com/MBBUI04.png
}
let mut status: Value = self.safe_string_k(market.clone(), "status", &[Value::Str("trading".to_string())]); // or "suspend"
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), 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(is_equal(&marketType, &Value::Str("swap".to_string()))));
m.insert("future".to_string(), Value::Bool(is_equal(&marketType, &Value::Str("future".to_string()))));
m.insert("option".to_string(), Value::Bool(is_equal(&marketType, &Value::Str("option".to_string()))));
m.insert("active".to_string(), Value::Bool(is_equal(&status, &Value::Str("trading".to_string()))));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), isLinear.clone());
m.insert("inverse".to_string(), Value::Bool(!is_true(&isLinear)));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0005".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSize.clone(), &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
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.clone(), &[]));
m.insert("max".to_string(), self.parse_number(maxPrice.clone(), &[]));
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(market.clone(), Value::Str("create_time".to_string()), Value::Int(1000), &[]));
m.insert("info".to_string(), market.clone());
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::List(vec![]);
let mut underlyings: Value = self.fetch_option_underlyings().await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_682: bool = true;
while { if !__for_first_682 { i = add(&i, &Value::Int(1)); } __for_first_682 = false; is_less_than(&i, &get_array_length(&underlyings)) } {
let mut underlying: Value = get_value(&underlyings, &i);
let mut underlying: Value = get_value(&underlyings, &i);
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".to_string()), underlying.clone());
let mut response: Value = self.public_options_get_contracts(&[query.clone()]).await;
{
let mut j: Value = Value::Int(0);
let mut __for_first_681: bool = true;
while { if !__for_first_681 { j = add(&j, &Value::Int(1)); } __for_first_681 = false; is_less_than(&j, &get_array_length(&response)) } {
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("_".to_string()));
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 base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut expiry: Value = self.safe_timestamp(market.clone(), Value::Str("expiration_time".to_string()), &[]);
let mut strike: Value = self.safe_string_k(market.clone(), "strike_price", &[]);
let mut isCall: Value = self.safe_value_k(market.clone(), "is_call", &[]);
let mut optionLetter: Value = ternary(is_true(&(is_equal(&isCall, &Value::Bool(true)))), Value::Str("C".to_string()), Value::Str("P".to_string()));
let mut optionType: Value = ternary(is_true(&(is_equal(&isCall, &Value::Bool(true)))), Value::Str("call".to_string()), Value::Str("put".to_string()));
symbol = add(&add(&add(&add(&add(&add(&add(&add(&symbol, &Value::Str(":".to_string())), "e), &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[])), &Value::Str("-".to_string())), &strike), &Value::Str("-".to_string())), &optionLetter);
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".to_string()), &priceDeviate);
let mut maxMultiplier: Value = crate::precise::Precise::stringAdd(&Value::Str("1".to_string()), &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(market.clone(), Value::Str("create_time".to_string()), &[]);
if is_equal(&createdTs, &Value::Int(0)) {
createdTs = Value::Null;
}
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), quote.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), quoteId.clone());
m.insert("type".to_string(), Value::Str("option".to_string()));
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".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0003".to_string()), &[]));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), self.parse_number(strike.clone(), &[]));
m.insert("optionType".to_string(), optionType.clone());
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
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.clone(), &[]));
m.insert("max".to_string(), self.parse_number(maxPrice.clone(), &[]));
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.clone());
m.insert("info".to_string(), market.clone());
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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_683: bool = true;
while { if !__for_first_683 { i = add(&i, &Value::Int(1)); } __for_first_683 = false; is_less_than(&i, &get_array_length(&underlyingsResponse)) } {
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.clone(), "name", &[]);
if !is_equal(&name, &Value::Null) {
append_to_array(&mut underlyings, name.clone());
}
}
}
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 !is_equal(&market, &Value::Null) {
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract".to_string()), get_value(&market, &Value::Str("id".to_string())));
if !is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("settle".to_string()), get_value(&market, &Value::Str("settleId".to_string())));
}
} else {
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
} else {
let mut swap: bool = is_equal(&type_var, &Value::Str("swap".to_string()));
let mut future: bool = is_equal(&type_var, &Value::Str("future".to_string()));
if is_true(&swap) || is_true(&future) {
let mut defaultSettle: Value = ternary(is_true(&swap), Value::Str("usdt".to_string()), Value::Str("btc".to_string()));
let mut settle: Value = self.safe_string_lower(params.clone(), Value::Str("settle".to_string()), &[defaultSettle.clone()]);
params = self.omit(params.clone(), Value::Str("settle".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("settle".to_string()), settle.clone());
}
}
return Value::List(vec![request.clone(), params.clone()]);
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 = get_value(&marginModequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marginModequeryVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_true(&trigger) {
if is_equal(&market, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" spotOrderPrepareRequest() requires a market argument for non-trigger orders".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("account".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string()))); // Should always be set for non-trigger
}
return Value::List(vec![request.clone(), query.clone()]);
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 = get_value(&marginModequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marginModequeryVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account".to_string(), marginMode.clone());
m
});
if !is_equal(&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
add_element_to_object(&mut request, &Value::Str("market".to_string()), get_value(&market, &Value::Str("id".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
return Value::List(vec![request.clone(), query.clone()]);
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".to_string()), Value::Str("marginMode".to_string()), &[Value::Str("spot".to_string())]); // 'margin' is isolated margin on gate's api
let mut marginMode: Value = self.safe_string_lower2(params.clone(), Value::Str("marginMode".to_string()), Value::Str("account".to_string()), &[defaultMarginMode.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("marginMode".to_string()), Value::Str("account".to_string())]), &[]);
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
marginMode = Value::Str("cross_margin".to_string());
} else if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
marginMode = Value::Str("margin".to_string());
} else if is_equal(&marginMode, &Value::Str("".to_string())) {
marginMode = Value::Str("spot".to_string());
}
if is_equal(&trigger, &Value::Bool(true)) {
if is_equal(&marginMode, &Value::Str("spot".to_string())) {
// gate spot trigger orders use the term normal instead of spot
marginMode = Value::Str("normal".to_string());
}
if is_equal(&marginMode, &Value::Str("cross_margin".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" getMarginMode() does not support trigger orders for cross margin".to_string()))));
}
}
let mut isUnifiedAccount: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("getMarginMode".to_string()), Value::Str("unifiedAccount".to_string()), &[]); isUnifiedAccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&isUnifiedAccount) {
marginMode = Value::Str("unified".to_string());
}
return Value::List(vec![marginMode.clone(), params.clone()]);
Value::Null
}
pub fn get_settlement_currencies(&self, mut type_var: Value, mut method: Value) -> Value {
let mut options: Value = self.safe_value(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_value(options.clone(), method.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultSettle: Value = ternary(is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))), Value::List(vec![Value::Str("usdt".to_string())]), Value::List(vec![Value::Str("btc".to_string())]));
return self.safe_value_k(fetchMarketsContractOptions.clone(), "settlementCurrencies", &[defaultSettle.clone()]);
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_value_k(self.urls.clone(), "apiBackup", &[]);
if !is_equal(&apiBackup, &Value::Null) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut response: Value = self.public_spot_get_currencies(&[params.clone()]).await;
return self.parse_currencies(response.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut currencyId: Value = self.safe_string_k(rawCurrency.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
// check leveraged tokens (e.g. BTC3S, ETH5L)
let mut type_var: Value = ternary(is_true(&self.is_leveraged_currency(currencyId.clone(), &[])), Value::Str("leveraged".to_string()), Value::Str("crypto".to_string()));
let mut chains: Value = self.safe_list_k(rawCurrency.clone(), "chains", &[Value::List(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_684: bool = true;
while { if !__for_first_684 { j = add(&j, &Value::Int(1)); } __for_first_684 = false; is_less_than(&j, &get_array_length(&chains)) } {
let mut chain: Value = get_value(&chains, &j);
let mut chain: Value = get_value(&chains, &j);
let mut networkId: Value = self.safe_string_k(chain.clone(), "name", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool(!is_equal(&self.safe_bool_k(chain.clone(), "deposit_disabled", &[]), &Value::Bool(true))));
m.insert("withdraw".to_string(), Value::Bool(!is_equal(&self.safe_bool_k(chain.clone(), "withdraw_disabled", &[]), &Value::Bool(true))));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
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.clone());
m.insert("code".to_string(), code.clone());
m.insert("name".to_string(), self.safe_string_k(rawCurrency.clone(), "name", &[]));
m.insert("type".to_string(), type_var.clone());
m.insert("active".to_string(), Value::Bool(!is_equal(&self.safe_bool_k(rawCurrency.clone(), "delisted", &[]), &Value::Bool(true))));
m.insert("deposit".to_string(), Value::Bool(!is_equal(&self.safe_bool_k(rawCurrency.clone(), "deposit_disabled", &[]), &Value::Bool(true))));
m.insert("withdraw".to_string(), Value::Bool(!is_equal(&self.safe_bool_k(rawCurrency.clone(), "withdraw_disabled", &[]), &Value::Bool(true))));
m.insert("fee".to_string(), Value::Null);
m.insert("networks".to_string(), networks.clone());
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
m.insert("info".to_string(), rawCurrency.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" fetchFundingRate() supports swap contracts only".to_string()))));
}
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
let __ws_arg_2 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.public_futures_get_settle_contracts_contract(&[__ws_arg_2]).await;
return self.parse_funding_rate(response.clone(), &[]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
market = self.market(firstSymbol.clone());
}
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Str("swap".to_string()), params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
let __ws_arg_3 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.public_futures_get_settle_contracts(&[__ws_arg_3]).await;
return self.parse_funding_rates(response.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "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.clone(), &[market.clone(), Value::Str("_".to_string()), Value::Str("swap".to_string())]);
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(contract.clone(), Value::Str("funding_next_apply".to_string()), &[]);
let mut fundingRateIndicative: Value = self.safe_number_k(contract.clone(), "funding_rate_indicative", &[]);
let mut fundingInterval: Value = crate::precise::Precise::stringMul(&Value::Str("1000".to_string()), &self.safe_string_k(contract.clone(), "funding_interval", &[]));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("markPrice".to_string(), markPrice.clone());
m.insert("indexPrice".to_string(), indexPrice.clone());
m.insert("interestRate".to_string(), interestRate.clone());
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.clone());
m.insert("fundingTimestamp".to_string(), fundingTime.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTime.clone()));
m.insert("nextFundingRate".to_string(), fundingRateIndicative.clone());
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.clone()));
m
});
Value::Null
}
pub fn parse_funding_interval(&self, mut interval: Value) -> Value {
let mut intervals: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("3600000".to_string(), Value::Str("1h".to_string()));
m.insert("14400000".to_string(), Value::Str("4h".to_string()));
m.insert("28800000".to_string(), Value::Str("8h".to_string()));
m.insert("57600000".to_string(), Value::Str("16h".to_string()));
m.insert("86400000".to_string(), Value::Str("24h".to_string()));
m
});
return self.safe_string(intervals.clone(), interval.clone(), &[interval.clone()]);
Value::Null
}
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 is_equal(&self.markets, &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(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
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.clone(), "currency", &[]);
code = self.safe_currency_code(currencyId.clone(), &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_685: bool = true;
while { if !__for_first_685 { i = add(&i, &Value::Int(1)); } __for_first_685 = false; is_less_than(&i, &get_array_length(&addresses)) } {
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: Value = self.safe_integer_k(entry.clone(), "obtain_failed", &[]);
if is_true(&(!is_equal(&obtainFailed, &Value::Null))) && is_true(&(!is_equal(&obtainFailed, &Value::Int(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", &[]);
add_element_to_object(&mut result, &network, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("code".to_string(), code.clone());
m.insert("currency".to_string(), code.clone());
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
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 is_equal(&self.markets, &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(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_wallet_get_deposit_address(&[__ws_arg_5]).await;
let mut chains: Value = self.safe_value_k(response.clone(), "multichain_addresses", &[Value::List(vec![])]);
let mut currencyId: Value = self.safe_string_k(response.clone(), "currency", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut parsed: Value = self.parse_deposit_addresses(chains.clone(), &[Value::Null, Value::Bool(false)]);
return self.index_by(parsed.clone(), Value::Str("network".to_string()));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut chainsIndexedByIdRaw: Value = self.fetch_deposit_addresses_by_network(code.clone(), &[params.clone()]).await;
let mut chainsIndexedById: Value = chainsIndexedByIdRaw.clone();
let mut selectedNetworkIdOrCode: Value = self.select_network_code_from_unified_networks(code.clone(), networkCode.clone(), chainsIndexedById.clone());
return get_value(&chainsIndexedById, &selectedNetworkIdOrCode);
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);
//
// {
// 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 = self.safe_string_k(currency.clone(), "code", &[]);
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.clone());
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.clone(), "chain", &[]), code.clone()]));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency_pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_wallet_get_fee(&[__ws_arg_6]).await;
return self.parse_trading_fee(response.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_wallet_get_fee(&[params.clone()]).await;
return self.parse_trading_fees(response.clone());
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_686: bool = true;
while { if !__for_first_686 { i = add(&i, &Value::Int(1)); } __for_first_686 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut result, &symbol, self.parse_trading_fee(response.clone(), &[market.clone()]));
}
}
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_value_k(info.clone(), "gt_discount", &[]);
let mut taker: Value = ternary(is_true(&(is_equal(>Discount, &Value::Bool(true)))), Value::Str("gt_taker_fee".to_string()), Value::Str("taker_fee".to_string()));
let mut maker: Value = ternary(is_true(&(is_equal(>Discount, &Value::Bool(true)))), Value::Str("gt_maker_fee".to_string()), Value::Str("maker_fee".to_string()));
let mut contract: Value = self.safe_value_k(market.clone(), "contract", &[]);
let mut takerKey: Value = ternary(is_true(&(is_equal(&contract, &Value::Bool(true)))), Value::Str("futures_taker_fee".to_string()), taker.clone());
let mut makerKey: Value = ternary(is_true(&(is_equal(&contract, &Value::Bool(true)))), Value::Str("futures_maker_fee".to_string()), maker.clone());
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.clone(), "symbol", &[]));
m.insert("maker".to_string(), self.safe_number(info.clone(), makerKey.clone(), &[]));
m.insert("taker".to_string(), self.safe_number(info.clone(), takerKey.clone(), &[]));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_wallet_get_withdraw_status(&[params.clone()]).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_688: bool = true;
while { if !__for_first_688 { i = add(&i, &Value::Int(1)); } __for_first_688 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), &[]);
if is_true(&(!is_equal(&codes, &Value::Null))) && !is_true(&self.in_array(code.clone(), codes.clone())) {
continue;
}
let mut withdrawFixOnChains: Value = self.safe_value_k(entry.clone(), "withdraw_fix_on_chains", &[]);
if is_equal(&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_687: bool = true;
while { if !__for_first_687 { j = add(&j, &Value::Int(1)); } __for_first_687 = false; is_less_than(&j, &get_array_length(&networkIds)) } {
let mut networkId: Value = get_value(&networkIds, &j);
let mut networkId: Value = get_value(&networkIds, &j);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut withdrawFees, &networkCode, self.parse_number(get_value(&withdrawFixOnChains, &networkId), &[]));
}
}
}
}
add_element_to_object(&mut result, &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.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_wallet_get_withdraw_status(&[params.clone()]).await;
return self.parse_deposit_withdraw_fees(response.clone(), &[codes.clone(), Value::Str("currency".to_string())]);
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_value_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 !is_equal(&withdrawFixOnChains, &Value::Null) {
let mut chainKeys: Value = object_keys(&withdrawFixOnChains);
{
let mut i: Value = Value::Int(0);
let mut __for_first_689: bool = true;
while { if !__for_first_689 { i = add(&i, &Value::Int(1)); } __for_first_689 = false; is_less_than(&i, &get_array_length(&chainKeys)) } {
let mut chainKey: Value = get_value(&chainKeys, &i);
let mut chainKey: Value = get_value(&chainKeys, &i);
let mut currencyId: Value = self.safe_string_k(fee.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut networkCode: Value = self.network_id_to_code(&[chainKey.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("networks".to_string())), &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(get_value(&withdrawFixOnChains, &chainKey), &[]));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
// let defaultType = 'future';
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchFundingHistory".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut requestrequestParamsVariable = self.prepare_request(&[market.clone(), type_var.clone(), query.clone()]);
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("fund".to_string())); // 'dnw' 'pnl' 'fee' 'refr' 'fund' 'point_dnw' 'point_fee' 'point_refr'
if !is_equal(&since, &Value::Null) {
// from should be integer
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_7 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_futures_get_settle_account_book(&[__ws_arg_7]).await;
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_8 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_delivery_get_settle_account_book(&[__ws_arg_8]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingHistory() only support swap & future market type".to_string()))));
}
return self.parse_funding_histories(response.clone(), symbol.clone(), since.clone(), limit.clone());
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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_690: bool = true;
while { if !__for_first_690 { i = add(&i, &Value::Int(1)); } __for_first_690 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
let mut funding: Value = self.parse_funding_history(entry.clone(), &[]);
append_to_array(&mut result, funding.clone());
}
}
let mut sorted: Value = self.sort_by(result.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
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(info.clone(), Value::Str("time".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(info.clone(), "text", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string()), Value::Str("swap".to_string())]);
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.clone(), "symbol", &[]));
m.insert("code".to_string(), self.safe_string_k(market.clone(), "settle", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "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 is_equal(&self.markets, &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(), get_value(&market, &Value::Str("type".to_string())), params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
if !is_equal(&limit, &Value::Null) {
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
limit = crate::runtime::Math::min(&limit, &Value::Int(1000));
} else {
limit = crate::runtime::Math::min(&limit, &Value::Int(300));
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
add_element_to_object(&mut request, &Value::Str("with_id".to_string()), Value::Bool(true));
let mut response: Value = Value::Null;
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("margin".to_string())), &Value::Bool(true)))) {
let __ws_arg_9 = self.extend(request.clone(), &[query.clone()]);
response = self.public_spot_get_order_book(&[__ws_arg_9]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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 is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(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 is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
let __ws_arg_12 = self.extend(request.clone(), &[query.clone()]);
response = self.public_options_get_order_book(&[__ws_arg_12]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrderBook() not support this market type".to_string()))));
}
//
// 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 is_equal(×tamp, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing timestamp".to_string()))));
}
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
timestamp = multiply(×tamp, &Value::Int(1000));
}
let mut priceKey: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Int(0), Value::Str("p".to_string()));
let mut amountKey: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Int(1), Value::Str("s".to_string()));
let mut nonce: Value = self.safe_integer_k(response.clone(), "id", &[]);
let mut result: Value = self.parse_order_book(response.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), priceKey.clone(), amountKey.clone()]);
add_element_to_object(&mut result, &Value::Str("nonce".to_string()), nonce.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
let mut response: Value = Value::Null;
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("margin".to_string())), &Value::Bool(true)))) {
let __ws_arg_13 = self.extend(request.clone(), &[query.clone()]);
response = self.public_spot_get_tickers(&[__ws_arg_13]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_14 = self.extend(request.clone(), &[query.clone()]);
response = self.public_futures_get_settle_tickers(&[__ws_arg_14]).await;
} else if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
let __ws_arg_15 = self.extend(request.clone(), &[query.clone()]);
response = self.public_delivery_get_settle_tickers(&[__ws_arg_15]).await;
} else if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
let mut marketId: Value = get_value(&market, &Value::Str("id".to_string()));
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
add_element_to_object(&mut request, &Value::Str("underlying".to_string()), self.safe_string(optionParts.clone(), Value::Int(0), &[]));
let __ws_arg_16 = self.extend(request.clone(), &[query.clone()]);
response = self.public_options_get_tickers(&[__ws_arg_16]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTicker() not support this market type".to_string()))));
}
let mut ticker: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_691: bool = true;
while { if !__for_first_691 { i = add(&i, &Value::Int(1)); } __for_first_691 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut entry: Value = get_value(&response, &i);
let mut entry: Value = get_value(&response, &i);
if is_equal(&get_value(&entry, &Value::Str("name".to_string())), &get_value(&market, &Value::Str("id".to_string()))) {
ticker = entry.clone();
break;
}
}
}
} else {
ticker = self.safe_value(response.clone(), Value::Int(0), &[]);
}
if is_equal(&ticker, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" fetchTicker() returned empty response".to_string()))));
}
return self.parse_ticker(ticker.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// 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::List(vec![Value::Str("currency_pair".to_string()), Value::Str("contract".to_string()), Value::Str("name".to_string())]), &[]);
let mut marketType: Value = ternary(is_true(&(Value::Bool(in_op(&ticker, &Value::Str("mark_price".to_string()))))), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("_".to_string()), marketType.clone()]);
let mut last: Value = self.safe_string2(ticker.clone(), Value::Str("last".to_string()), Value::Str("last_price".to_string()), &[]);
let mut ask: Value = self.safe_string_n(ticker.clone(), Value::List(vec![Value::Str("lowest_ask".to_string()), Value::Str("a".to_string()), Value::Str("ask1_price".to_string())]), &[]);
let mut bid: Value = self.safe_string_n(ticker.clone(), Value::List(vec![Value::Str("highest_bid".to_string()), Value::Str("b".to_string()), Value::Str("bid1_price".to_string())]), &[]);
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".to_string()), Value::Str("bid1_size".to_string()), &[]);
let mut askVolume: Value = self.safe_string2(ticker.clone(), Value::Str("A".to_string()), Value::Str("ask1_size".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
let mut baseVolume: Value = self.safe_string2(ticker.clone(), Value::Str("base_volume".to_string()), Value::Str("volume_24h_base".to_string()), &[]);
if is_equal(&baseVolume, &Value::Str("nan".to_string())) {
baseVolume = Value::Str("0".to_string());
}
let mut quoteVolume: Value = self.safe_string2(ticker.clone(), Value::Str("quote_volume".to_string()), Value::Str("volume_24h_quote".to_string()), &[]);
if is_equal("eVolume, &Value::Str("nan".to_string())) {
quoteVolume = Value::Str("0".to_string());
}
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.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), high.clone());
m.insert("low".to_string(), low.clone());
m.insert("bid".to_string(), bid.clone());
m.insert("bidVolume".to_string(), bidVolume.clone());
m.insert("ask".to_string(), ask.clone());
m.insert("askVolume".to_string(), askVolume.clone());
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), percentage.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
m.insert("markPrice".to_string(), self.safe_string_k(ticker.clone(), "mark_price", &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "index_price", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut first: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
let mut market: Value = Value::Null;
if !is_equal(&first, &Value::Null) {
market = self.market(first.clone());
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut requestrequestParamsVariable = self.prepare_request(&[Value::Null, type_var.clone(), query.clone()]);
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
let mut response: Value = Value::Null;
add_element_to_object(&mut request, &Value::Str("timezone".to_string()), Value::Str("utc0".to_string())); // default to utc
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())) {
let __ws_arg_17 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_spot_get_tickers(&[__ws_arg_17]).await;
} else if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_18 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_futures_get_settle_tickers(&[__ws_arg_18]).await;
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_19 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_delivery_get_settle_tickers(&[__ws_arg_19]).await;
} else if is_equal(&type_var, &Value::Str("option".to_string())) {
self.check_required_argument(Value::Str("fetchTickers".to_string()), symbols.clone(), Value::Str("symbols".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(market.clone(), "id", &[]);
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
add_element_to_object(&mut request, &Value::Str("underlying".to_string()), self.safe_string(optionParts.clone(), Value::Int(0), &[]));
let __ws_arg_20 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_options_get_tickers(&[__ws_arg_20]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTickers() not support this market type, provide symbols or set params[\"defaultType\"] to one from spot/margin/swap/future/option".to_string()))));
}
return self.parse_tickers(response.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_balance_helper(&self, mut entry: Value) -> Value {
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string2(entry.clone(), Value::Str("freeze".to_string()), Value::Str("locked".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(entry.clone(), "available", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(entry.clone(), "total", &[]));
if is_true(&Value::Bool(in_op(&entry, &Value::Str("borrowed".to_string())))) {
add_element_to_object(&mut account, &Value::Str("debt".to_string()), 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut symbol: Value = self.safe_string_k(params.clone(), "symbol", &[]);
params = self.omit(params.clone(), Value::Str("symbol".to_string()), &[]);
let mut isUnifiedAccount: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("unifiedAccount".to_string()), &[]); isUnifiedAccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut requestrequestParamsVariable = self.prepare_request(&[Value::Null, type_var.clone(), query.clone()]);
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
let mut marginModerequestQueryVariable = self.get_margin_mode(Value::Bool(false), requestParams.clone());
let mut marginMode: Value = get_value(&marginModerequestQueryVariable, &Value::Int(0));
let mut requestQuery: Value = get_value(&marginModerequestQueryVariable, &Value::Int(1));
if !is_equal(&symbol, &Value::Null) {
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut response: Value = Value::Null;
if is_true(&isUnifiedAccount) {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.private_unified_get_accounts(&[__ws_arg_21]).await;
} else if is_equal(&type_var, &Value::Str("spot".to_string())) {
if is_equal(&marginMode, &Value::Str("spot".to_string())) {
let __ws_arg_22 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_spot_get_accounts(&[__ws_arg_22]).await;
} else if is_equal(&marginMode, &Value::Str("margin".to_string())) {
let __ws_arg_23 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_margin_get_accounts(&[__ws_arg_23]).await;
} else if is_equal(&marginMode, &Value::Str("cross_margin".to_string())) {
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(add(&self.id, &Value::Str(" fetchBalance() not support this marginMode".to_string()))));
}
} else if is_equal(&type_var, &Value::Str("funding".to_string())) {
let __ws_arg_25 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_margin_get_funding_accounts(&[__ws_arg_25]).await;
} else if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_26 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_futures_get_settle_accounts(&[__ws_arg_26]).await;
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_27 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_delivery_get_settle_accounts(&[__ws_arg_27]).await;
} else if is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_28 = self.extend(request.clone(), &[requestQuery.clone()]);
response = self.private_options_get_accounts(&[__ws_arg_28]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchBalance() not support this market type".to_string()))));
}
let mut contract: bool = is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("option".to_string()))));
if is_true(&contract) {
response = Value::List(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 = is_equal(&marginMode, &Value::Str("margin".to_string())) && is_equal(&type_var, &Value::Str("spot".to_string()));
let mut data: Value = response.clone();
if is_true(&Value::Bool(in_op(&data, &Value::Str("balances".to_string())))) {
let mut flatBalances: Value = Value::List(vec![]);
let mut balances: Value = self.safe_value_k(data.clone(), "balances", &[Value::List(vec![])]);
// 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_692: bool = true;
while { if !__for_first_692 { i = add(&i, &Value::Int(1)); } __for_first_692 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut currencyId: Value = get_value(&keys, &i);
let mut currencyId: Value = get_value(&keys, &i);
let mut content: Value = get_value(&balances, ¤cyId);
add_element_to_object(&mut content, &Value::Str("currency".to_string()), currencyId.clone());
crate::set_value(&mut balances, ¤cyId, content.clone());
append_to_array(&mut flatBalances, content.clone());
}
}
data = flatBalances.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_693: bool = true;
while { if !__for_first_693 { i = add(&i, &Value::Int(1)); } __for_first_693 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
if is_true(&isolated) {
let mut base: Value = self.safe_value_k(entry.clone(), "base", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut quote: Value = self.safe_value_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.clone(), self.parse_balance_helper(base.clone()));
result = self.merge_balance_account(result.clone(), quoteCode.clone(), self.parse_balance_helper(quote.clone()));
} else {
let mut code: Value = self.safe_currency_code(self.safe_string_k(entry.clone(), "currency", &[]), &[]);
add_element_to_object(&mut result, &code, self.parse_balance_helper(entry.clone()));
}
}
}
return self.safe_balance(result.clone());
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".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(1000)]).await;
}
if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
return self.fetch_option_ohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut price: Value = self.safe_string_k(params.clone(), "price", &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.prepare_request(&[market.clone(), Value::Null, params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("interval".to_string()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
let mut maxLimit: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))), Value::Int(1999), Value::Int(1000));
limit = ternary(is_true(&(is_equal(&limit, &Value::Null))), maxLimit.clone(), crate::runtime::Math::min(&limit, &maxLimit));
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
until = self.parse_to_int(divide(&until, &Value::Int(1000)));
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
}
if !is_equal(&since, &Value::Null) {
let mut duration: Value = self.parse_timeframe(timeframe.clone());
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
let mut distance: Value = multiply(&(subtract(&limit, &Value::Int(1))), &duration);
let mut toTimestamp: Value = self.sum(&[get_value(&request, &Value::Str("from".to_string())), distance.clone()]);
let mut currentTimestamp: Value = self.seconds();
let mut to: Value = crate::runtime::Math::min(&toTimestamp, ¤tTimestamp);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".to_string()), crate::runtime::Math::min(&to, &until));
} else {
add_element_to_object(&mut request, &Value::Str("to".to_string()), to.clone());
}
} else {
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".to_string()), until.clone());
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::List(vec![]);
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let mut isMark: bool = is_equal(&price, &Value::Str("mark".to_string()));
let mut isIndex: bool = is_equal(&price, &Value::Str("index".to_string()));
if is_true(&isMark) || is_true(&isIndex) {
add_element_to_object(&mut request, &Value::Str("contract".to_string()), add(&add(&price, &Value::Str("_".to_string())), &get_value(&market, &Value::Str("id".to_string()))));
params = self.omit(params.clone(), Value::Str("price".to_string()), &[]);
}
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.public_delivery_get_settle_candlesticks(&[__ws_arg_29]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.public_futures_get_settle_candlesticks(&[__ws_arg_30]).await;
}
} else {
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
response = self.public_spot_get_candlesticks(&[__ws_arg_31]).await;
}
return self.parse_ohlc_vs(self.to_array(response.clone()), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
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".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// separated option logic because the from, to and limit parameters weren't functioning
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.prepare_request(&[market.clone(), Value::Null, params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("interval".to_string()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_options_get_candlesticks(&[__ws_arg_32]).await;
return self.parse_ohlc_vs(self.to_array(response.clone()), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" fetchFundingRateHistory() supports swap contracts only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.prepare_request(&[market.clone(), Value::Null, params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_694: bool = true;
while { if !__for_first_694 { i = add(&i, &Value::Int(1)); } __for_first_694 = false; is_less_than(&i, &get_array_length(&response)) } {
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(entry.clone(), Value::Str("t".to_string()), &[]);
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.clone(), "r", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
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 is_true(&Value::Bool(is_array(&ohlcv))) {
return Value::List(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::List(vec![self.safe_timestamp(ohlcv.clone(), Value::Str("t".to_string()), &[]), 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.clone(), "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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
//
// 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, params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
let mut until: Value = self.safe_integer2(params.clone(), Value::Str("to".to_string()), Value::Str("until".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000))); // default 100, max 1000
}
if !is_equal(&since, &Value::Null) && is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("spot".to_string())) || is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("margin".to_string())) {
let __ws_arg_34 = self.extend(request.clone(), &[query.clone()]);
response = self.public_spot_get_trades(&[__ws_arg_34]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_35 = self.extend(request.clone(), &[query.clone()]);
response = self.public_futures_get_settle_trades(&[__ws_arg_35]).await;
} else if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
let __ws_arg_36 = self.extend(request.clone(), &[query.clone()]);
response = self.public_delivery_get_settle_trades(&[__ws_arg_36]).await;
} else if is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("option".to_string())) {
let __ws_arg_37 = self.extend(request.clone(), &[query.clone()]);
response = self.public_options_get_trades(&[__ws_arg_37]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTrades() not support this market type.".to_string()))));
}
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrderTrades() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &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.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut type_var: Value = Value::Null;
let mut marginMode: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = ternary(is_true(&(!is_equal(&symbol, &Value::Null))), self.market(symbol.clone()), Value::Null);
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut contract: bool = is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("option".to_string()))));
if is_true(&contract) {
{ let __destr_tmp = self.prepare_request(&[market.clone(), type_var.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("option".to_string())) {
params = self.omit(params.clone(), Value::Str("order_id".to_string()), &[]);
}
} else {
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string()))); // Should always be set for non-trigger
}
{ let __destr_tmp = self.get_margin_mode(Value::Bool(false), params.clone()); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("account".to_string()), marginMode.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 100, max 1000
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())) {
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_get_my_trades(&[__ws_arg_38]).await;
} else if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_39 = self.extend(request.clone(), &[params.clone()]);
response = self.private_futures_get_settle_my_trades_timerange(&[__ws_arg_39]).await;
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delivery_get_settle_my_trades(&[__ws_arg_40]).await;
} else if is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
response = self.private_options_get_my_trades(&[__ws_arg_41]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchMyTrades() not support this market type.".to_string()))));
}
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// 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".to_string()), Value::Str("trade_id".to_string()), &[]);
let mut timestamp: Value = Value::Null;
let mut msString: Value = self.safe_string_k(trade.clone(), "create_time_ms", &[]);
if !is_equal(&msString, &Value::Null) {
msString = crate::precise::Precise::stringMul(&msString, &Value::Str("1000".to_string()));
msString = slice(&msString, &Value::Int(0), &Value::Int(13));
timestamp = self.parse_to_int(msString.clone());
} else {
timestamp = self.safe_timestamp2(trade.clone(), Value::Str("time".to_string()), Value::Str("create_time".to_string()), &[]);
}
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("currency_pair".to_string()), Value::Str("contract".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(Value::Bool(in_op(&trade, &Value::Str("contract".to_string()))))), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string()), marketType.clone()]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("amount".to_string()), Value::Str("size".to_string()), &[]);
let mut priceString: Value = self.safe_string_k(trade.clone(), "price", &[]);
let mut contractSide: Value = ternary(is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".to_string()))), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
amountString = crate::precise::Precise::stringAbs(&amountString);
let mut side: Value = self.safe_string2(trade.clone(), Value::Str("side".to_string()), Value::Str("type".to_string()), &[contractSide.clone()]);
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::List(vec![]);
if !is_equal(&feeAmount, &Value::Null) {
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "fee_currency", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
if is_equal(&feeCurrencyCode, &Value::Null) {
feeCurrencyCode = self.safe_string_k(market.clone(), "settle", &[]);
}
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeAmount.clone());
m.insert("currency".to_string(), feeCurrencyCode.clone());
m
}));
}
if !is_equal(>Fee, &Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), gtFee.clone());
m.insert("currency".to_string(), Value::Str("GT".to_string()));
m
}));
}
if !is_equal(&pointFee, &Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), pointFee.clone());
m.insert("currency".to_string(), Value::Str("GATEPOINT".to_string()));
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.clone());
m.insert("id".to_string(), id.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("order".to_string(), orderId.clone());
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("fees".to_string(), fees.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchDeposits".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchDeposits".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string()))); // todo: currencies have network-junctions
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
let mut start: Value = self.parse_to_int(divide(&since, &Value::Int(1000)));
add_element_to_object(&mut request, &Value::Str("from".to_string()), start.clone());
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.sum(&[start.clone(), multiply(&multiply(&multiply(&Value::Int(30), &Value::Int(24)), &Value::Int(60)), &Value::Int(60))]));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("to".to_string()), request.clone(), params.clone(), &[Value::Float(0.001)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_wallet_get_deposits(&[__ws_arg_42]).await;
return self.parse_transactions(response.clone(), &[currency.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchWithdrawals".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchWithdrawals".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string()))); // todo: currencies have network-junctions
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
let mut start: Value = self.parse_to_int(divide(&since, &Value::Int(1000)));
add_element_to_object(&mut request, &Value::Str("from".to_string()), start.clone());
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.sum(&[start.clone(), multiply(&multiply(&multiply(&Value::Int(30), &Value::Int(24)), &Value::Int(60)), &Value::Int(60))]));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("to".to_string()), request.clone(), params.clone(), &[Value::Float(0.001)]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_wallet_get_withdrawals(&[__ws_arg_43]).await;
return self.parse_transactions(response.clone(), &[currency.clone()]);
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 __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
self.check_address(&[address.clone()]);
if is_equal(&self.markets, &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(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("address".to_string(), address.clone());
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("memo".to_string()), tag.clone());
}
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), self.network_code_to_id(networkCode.clone(), &[code.clone()]));
}
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_withdrawals_post_withdrawals(&[__ws_arg_44]).await;
return self.parse_transaction(response.clone(), &[currency.clone()]);
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".to_string()));
m.insert("REQUEST".to_string(), Value::Str("pending".to_string()));
m.insert("DMOVE".to_string(), Value::Str("pending".to_string()));
m.insert("MANUAL".to_string(), Value::Str("pending".to_string()));
m.insert("VERIFY".to_string(), Value::Str("pending".to_string()));
m.insert("PROCES".to_string(), Value::Str("pending".to_string()));
m.insert("EXTPEND".to_string(), Value::Str("pending".to_string()));
m.insert("SPLITPEND".to_string(), Value::Str("pending".to_string()));
m.insert("CANCEL".to_string(), Value::Str("canceled".to_string()));
m.insert("FAIL".to_string(), Value::Str("failed".to_string()));
m.insert("INVALID".to_string(), Value::Str("failed".to_string()));
m.insert("DONE".to_string(), Value::Str("ok".to_string()));
m.insert("BCODE".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transaction_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("d".to_string(), Value::Str("deposit".to_string()));
m.insert("w".to_string(), Value::Str("withdrawal".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// 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 !is_equal(&id, &Value::Null) {
if is_equal(&get_value(&id, &Value::Int(0)), &Value::Str("b".to_string())) {
// GateCode handling
type_var = ternary(is_true(&crate::precise::Precise::stringGt(&amountString, &Value::Str("0".to_string()))), Value::Str("deposit".to_string()), Value::Str("withdrawal".to_string()));
amountString = crate::precise::Precise::stringAbs(&amountString);
} else {
type_var = self.parse_transaction_type(get_value(&id, &Value::Int(0)));
}
}
let mut feeCostString: Value = self.safe_string2(transaction.clone(), Value::Str("fee".to_string()), Value::Str("fee_amount".to_string()), &[]);
if is_equal(&type_var, &Value::Str("withdrawal".to_string())) {
amountString = crate::precise::Precise::stringSub(&amountString, &feeCostString);
}
let mut networkId: Value = self.safe_string_upper(transaction.clone(), Value::Str("chain".to_string()), &[]);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
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.clone());
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(transaction.clone(), Value::Str("timestamp".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.clone());
m.insert("txid".to_string(), txid.clone());
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(amountString.clone(), &[]));
m.insert("network".to_string(), self.network_id_to_code(&[networkId.clone(), code.clone()]));
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), tag.clone());
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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.clone());
m.insert("cost".to_string(), self.parse_number(feeCostString.clone(), &[]));
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 is_equal(&self.markets, &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".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossPrice: Value = self.safe_value_k(params.clone(), "stopLossPrice", &[triggerPrice.clone()]);
let mut takeProfitPrice: Value = self.safe_value_k(params.clone(), "takeProfitPrice", &[]);
let mut isStopLossOrder: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isTakeProfitOrder: bool = !is_equal(&takeProfitPrice, &Value::Null);
let mut isTpsl: bool = is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder);
let mut nonTriggerOrder: bool = !is_true(&isTpsl) && is_true(&(is_equal(&trigger, &Value::Null)));
let mut orderRequest: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = Value::Null;
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("margin".to_string())), &Value::Bool(true)))) {
if is_true(&nonTriggerOrder) {
response = self.private_spot_post_orders(&[orderRequest.clone()]).await;
} else {
response = self.private_spot_post_price_orders(&[orderRequest.clone()]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_true(&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 is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
if is_true(&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.clone()]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
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::List(vec![]);
let mut orderSymbols: Value = Value::List(vec![]);
let mut ordersLength: Value = get_array_length(&orders);
if is_equal(&ordersLength, &Value::Int(0)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() requires at least one order".to_string()))));
}
if is_greater_than(&ordersLength, &Value::Int(10)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() accepts a maximum of 10 orders at a time".to_string()))));
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_695: bool = true;
while { if !__for_first_695 { i = add(&i, &Value::Int(1)); } __for_first_695 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
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_value_k(rawOrder.clone(), "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.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("stopLossPrice".to_string())]), &[]);
if !is_equal(&triggerValue, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() does not support advanced order properties (stopPrice, takeProfitPrice, stopLossPrice)".to_string()))));
}
add_element_to_object(&mut extendedParams, &Value::Str("textIsRequired".to_string()), Value::Bool(true)); // the exchange requires a text parameter for each order here
let mut orderRequest: Value = self.create_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), extendedParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut symbols: Value = self.market_symbols(&[orderSymbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
if is_true(&(is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() does not support futures or options markets".to_string()))));
}
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut ordersRequests: Value = self.create_orders_request(orders.clone(), &[params.clone()]);
let mut firstOrder: Value = get_value(&orders, &Value::Int(0));
let mut market: Value = self.market(get_value(&firstOrder, &Value::Str("symbol".to_string())));
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
response = self.private_spot_post_batch_orders(&[ordersRequests.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
response = self.private_futures_post_settle_batch_orders(&[ordersRequests.clone()]).await;
}
return self.parse_orders(response.clone(), &[]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut contract: Value = get_value(&market, &Value::Str("contract".to_string()));
let mut trigger: Value = self.safe_value_k(params.clone(), "trigger", &[]);
let mut triggerPrice: Value = self.safe_value2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossPrice: Value = self.safe_value_k(params.clone(), "stopLossPrice", &[triggerPrice.clone()]);
let mut takeProfitPrice: Value = self.safe_value_k(params.clone(), "takeProfitPrice", &[]);
let mut isStopLossOrder: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isTakeProfitOrder: bool = !is_equal(&takeProfitPrice, &Value::Null);
let mut isTpsl: bool = is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder);
if is_true(&isStopLossOrder) && is_true(&isTakeProfitOrder) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" createOrder() stopLossPrice and takeProfitPrice cannot both be defined".to_string()))));
}
let mut reduceOnly: Value = self.safe_value_k(params.clone(), "reduceOnly", &[]);
let mut exchangeSpecificTimeInForce: Value = self.safe_string_lower_n(params.clone(), Value::List(vec![Value::Str("timeInForce".to_string()), Value::Str("tif".to_string()), Value::Str("time_in_force".to_string())]), &[]);
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(is_equal(&exchangeSpecificTimeInForce, &Value::Str("poc".to_string()))), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut timeInForce: Value = self.handle_time_in_force(&[params.clone()]);
if is_equal(&postOnly, &Value::Bool(true)) {
timeInForce = Value::Str("poc".to_string());
}
// 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(params.clone(), Value::Str("text".to_string()), Value::Str("clientOrderId".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("timeInForce".to_string()), Value::Str("postOnly".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut isLimitOrder: bool = is_equal(&type_var, &Value::Str("limit".to_string()));
let mut isMarketOrder: bool = is_equal(&type_var, &Value::Str("market".to_string()));
if is_true(&isLimitOrder) && is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" createOrder () requires a price argument for ".to_string())), &type_var), &Value::Str(" orders".to_string()))));
}
if is_true(&isMarketOrder) {
if is_true(&(is_equal(&timeInForce, &Value::Str("poc".to_string())))) || is_true(&(is_equal(&timeInForce, &Value::Str("gtc".to_string())))) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" createOrder () timeInForce for market order can only be \"FOK\" or \"IOC\"".to_string()))));
} else {
if is_equal(&timeInForce, &Value::Null) {
let mut defaultTif: Value = self.safe_string_k(self.options.clone(), "defaultTimeInForce", &[Value::Str("IOC".to_string())]);
let mut exchangeSpecificTif: Value = self.safe_string(get_value(&self.options, &Value::Str("timeInForce".to_string())), defaultTif.clone(), &[Value::Str("ioc".to_string())]);
timeInForce = exchangeSpecificTif.clone();
}
}
if is_equal(&contract, &Value::Bool(true)) {
price = Value::Int(0);
}
}
if is_equal(&contract, &Value::Bool(true)) {
let mut isClose: Value = self.safe_value_k(params.clone(), "close", &[]);
if is_equal(&isClose, &Value::Bool(true)) {
amount = Value::Int(0);
} else {
let mut amountToPrecision: Value = self.amount_to_precision(symbol.clone(), amount.clone());
let mut signedAmount: Value = ternary(is_true(&(is_equal(&side, &Value::Str("sell".to_string())))), crate::precise::Precise::stringNeg(&amountToPrecision), amountToPrecision.clone());
amount = crate::runtime::parse_int(&signedAmount);
}
}
let mut request: Value = Value::Null;
let mut nonTriggerOrder: bool = !is_true(&isTpsl) && is_true(&(is_equal(&trigger, &Value::Null)));
if is_true(&nonTriggerOrder) {
if is_equal(&contract, &Value::Bool(true)) {
// contract order
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("size".to_string(), amount.clone());
m
});
if !is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("settle".to_string()), get_value(&market, &Value::Str("settleId".to_string()))); // filled in prepareRequest above
}
if is_true(&isMarketOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), Value::Str("0".to_string())); // set to 0 for market orders
} else {
add_element_to_object(&mut request, &Value::Str("price".to_string()), ternary(is_true(&(is_equal(&price, &Value::Int(0)))), Value::Str("0".to_string()), self.price_to_precision(symbol.clone(), price.clone())));
}
if !is_equal(&reduceOnly, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("reduce_only".to_string()), reduceOnly.clone());
}
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tif".to_string()), timeInForce.clone());
}
} else {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.get_margin_mode(Value::Bool(false), params.clone()); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
// spot order
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency_pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("account".to_string(), marginMode.clone());
m.insert("side".to_string(), side.clone());
m
});
if is_true(&isMarketOrder) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
let mut quoteAmount: Value = Value::Null;
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("createMarketBuyOrderRequiresPrice".to_string()), &[Value::Bool(true)]); createMarketBuyOrderRequiresPrice = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut cost: Value = self.safe_number_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if !is_equal(&cost, &Value::Null) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost.clone());
} else if is_true(&createMarketBuyOrderRequiresPrice) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &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".to_string()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
let mut costRequest: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
quoteAmount = self.cost_to_precision(symbol.clone(), costRequest.clone());
}
} else {
quoteAmount = self.cost_to_precision(symbol.clone(), amount.clone());
}
add_element_to_object(&mut request, &Value::Str("amount".to_string()), quoteAmount.clone());
} else {
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if is_true(&isLimitOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), timeInForce.clone());
}
}
let mut textIsRequired: Value = self.safe_bool_k(params.clone(), "textIsRequired", &[Value::Bool(false)]);
if !is_equal(&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 is_greater_than(&get_array_length(&clientOrderId), &Value::Int(28)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder () clientOrderId or text param must be up to 28 characters".to_string()))));
}
params = self.omit(params.clone(), Value::Str("textIsRequired".to_string()), &[]);
if !is_equal(&get_value(&clientOrderId, &Value::Int(0)), &Value::Str("t".to_string())) {
clientOrderId = add(&Value::Str("t-".to_string()), &clientOrderId);
}
add_element_to_object(&mut request, &Value::Str("text".to_string()), clientOrderId.clone());
} else {
if is_equal(&textIsRequired, &Value::Bool(true)) {
// batchOrders requires text in the request
add_element_to_object(&mut request, &Value::Str("text".to_string()), add(&Value::Str("t-".to_string()), &self.uuid16(&[])));
}
}
} else {
if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() conditional option orders are not supported".to_string()))));
}
if is_equal(&contract, &Value::Bool(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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("size".to_string(), amount.clone());
m
}));
m.insert("settle".to_string(), get_value(&market, &Value::Str("settleId".to_string())));
m
});
if is_equal(&type_var, &Value::Str("market".to_string())) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".to_string())), &Value::Str("price".to_string()), Value::Str("0".to_string()));
} else {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".to_string())), &Value::Str("price".to_string()), ternary(is_true(&(is_equal(&price, &Value::Int(0)))), Value::Str("0".to_string()), self.price_to_precision(symbol.clone(), price.clone())));
}
if is_equal(&trigger, &Value::Null) {
let mut rule: Value = Value::Null;
let mut triggerOrderPrice: Value = Value::Null;
if is_true(&isStopLossOrder) {
// we let trigger orders be aliases for stopLoss orders because
// gateio doesn't accept conventional trigger orders for spot markets
rule = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Int(1), Value::Int(2));
triggerOrderPrice = self.price_to_precision(symbol.clone(), stopLossPrice.clone());
} else if is_true(&isTakeProfitOrder) {
rule = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Int(2), Value::Int(1));
triggerOrderPrice = self.price_to_precision(symbol.clone(), takeProfitPrice.clone());
}
let mut priceType: Value = self.safe_integer_k(params.clone(), "price_type", &[Value::Int(0)]);
if is_less_than(&priceType, &Value::Int(0)) || is_greater_than(&priceType, &Value::Int(2)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder () price_type should be 0 latest deal price, 1 mark price, 2 index price".to_string()))));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("price_type".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("trigger".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price_type".to_string(), priceType.clone());
m.insert("price".to_string(), self.price_to_precision(symbol.clone(), triggerOrderPrice.clone()));
m.insert("rule".to_string(), rule.clone());
m
}));
}
if !is_equal(&reduceOnly, &Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".to_string())), &Value::Str("reduce_only".to_string()), reduceOnly.clone());
}
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".to_string())), &Value::Str("tif".to_string()), timeInForce.clone());
}
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("initial".to_string())), &Value::Str("text".to_string()), clientOrderId.clone());
}
} else {
// spot conditional order
let mut options: Value = self.safe_value_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), params.clone()); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&timeInForce, &Value::Null) {
timeInForce = Value::Str("gtc".to_string());
}
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.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m.insert("amount".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("account".to_string(), marginMode.clone());
m.insert("time_in_force".to_string(), timeInForce.clone());
m
}));
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if is_equal(&trigger, &Value::Null) {
let mut defaultExpiration: Value = self.safe_integer_k(options.clone(), "expiration", &[]);
let mut expiration: Value = self.safe_integer_k(params.clone(), "expiration", &[defaultExpiration.clone()]);
let mut rule: Value = Value::Null;
let mut triggerOrderPrice: Value = Value::Null;
if is_true(&isStopLossOrder) {
// we let trigger orders be aliases for stopLoss orders because
// gateio doesn't accept conventional trigger orders for spot markets
rule = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str(">=".to_string()), Value::Str("<=".to_string()));
triggerOrderPrice = self.price_to_precision(symbol.clone(), stopLossPrice.clone());
} else if is_true(&isTakeProfitOrder) {
rule = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("<=".to_string()), Value::Str(">=".to_string()));
triggerOrderPrice = self.price_to_precision(symbol.clone(), takeProfitPrice.clone());
}
add_element_to_object(&mut request, &Value::Str("trigger".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), self.price_to_precision(symbol.clone(), triggerOrderPrice.clone()));
m.insert("rule".to_string(), rule.clone());
m.insert("expiration".to_string(), expiration.clone());
m
}));
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(get_value_mut(&mut request, &Value::Str("trigger".to_string())), &Value::Str("text".to_string()), clientOrderId.clone());
}
}
}
}
return self.extend(request.clone(), &[params.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketBuyOrderWithCost() supports spot orders only".to_string()))));
}
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(false));
m
})]);
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), cost.clone(), &[Value::Null, params.clone()]).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 marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("editOrder".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut account: Value = self.convert_type_to_account(marketType.clone());
let mut isUnifiedAccount: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("editOrder".to_string()), Value::Str("unifiedAccount".to_string()), &[]); isUnifiedAccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&isUnifiedAccount) {
account = Value::Str("unified".to_string());
}
let mut isLimitOrder: bool = is_equal(&type_var, &Value::Str("limit".to_string()));
if is_equal(&account, &Value::Str("spot".to_string())) {
if !is_true(&isLimitOrder) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&add(&add(&self.id, &Value::Str(" editOrder() does not support ".to_string())), &type_var), &Value::Str(" orders for ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
}
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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("account".to_string(), account.clone());
m
});
if !is_equal(&amount, &Value::Null) {
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("amount".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
} else {
if is_equal(&side, &Value::Str("sell".to_string())) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), self.parse_to_numeric(crate::precise::Precise::stringNeg(&self.amount_to_precision(symbol.clone(), amount.clone()))));
} else {
add_element_to_object(&mut request, &Value::Str("size".to_string()), self.parse_to_numeric(self.amount_to_precision(symbol.clone(), amount.clone())));
}
}
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("settle".to_string()), get_value(&market, &Value::Str("settleId".to_string())));
}
return self.extend(request.clone(), &[params.clone()]);
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 is_equal(&self.markets, &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.clone(), symbol.clone(), type_var.clone(), side.clone(), &[amount.clone(), price.clone(), params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
response = self.private_spot_patch_orders_order_id(&[extendedRequest.clone()]).await;
} else {
response = self.private_futures_put_settle_orders_order_id(&[extendedRequest.clone()]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("open".to_string(), Value::Str("open".to_string()));
m.insert("_new".to_string(), Value::Str("open".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("cancelled".to_string(), Value::Str("canceled".to_string()));
m.insert("liquidated".to_string(), Value::Str("closed".to_string()));
m.insert("ioc".to_string(), Value::Str("canceled".to_string()));
m.insert("failed".to_string(), Value::Str("canceled".to_string()));
m.insert("expired".to_string(), Value::Str("canceled".to_string()));
m.insert("finished".to_string(), Value::Str("closed".to_string()));
m.insert("finish".to_string(), Value::Str("closed".to_string()));
m.insert("succeeded".to_string(), Value::Str("closed".to_string()));
m
});
return self.safe_string(statuses.clone(), 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 !is_equal(&succeeded, &Value::Bool(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".to_string()));
m.insert("id".to_string(), self.safe_string_k(order.clone(), "id", &[]));
m
}), &[]);
}
let mut put: Value = self.safe_value2(order.clone(), Value::Str("put".to_string()), Value::Str("initial".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trigger: Value = self.safe_value_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".to_string()), Value::Str("tif".to_string()), &[]);
let mut amount: Value = self.safe_string2(put.clone(), Value::Str("amount".to_string()), Value::Str("size".to_string()), &[]);
let mut side: Value = self.safe_string_k(put.clone(), "side", &[]);
let mut price: Value = self.safe_string_k(put.clone(), "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".to_string()), Value::Str("tif".to_string()), &[timeInForce.clone()]);
if is_equal(&timeInForce, &Value::Str("POC".to_string())) {
timeInForce = Value::Str("PO".to_string());
}
let mut postOnly: Value = Value::Bool(is_equal(&timeInForce, &Value::Str("PO".to_string())));
amount = self.safe_string2(order.clone(), Value::Str("amount".to_string()), Value::Str("size".to_string()), &[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.clone(), "price", &[]);
let mut average: Value = self.safe_number2(order.clone(), Value::Str("avg_deal_price".to_string()), Value::Str("fill_price".to_string()), &[]);
if is_true(&(!is_equal(&triggerPrice, &Value::Null))) && is_true(&(!is_equal(&triggerPrice, &Value::Int(0)))) {
remainingString = amount.clone();
cost = Value::Str("0".to_string());
}
if is_true(&(!is_equal(&contract, &Value::Null))) && is_true(&(!is_equal(&contract, &Value::Str("".to_string())))) {
let mut isMarketOrder: bool = is_true(&crate::precise::Precise::stringEquals(&price, &Value::Str("0".to_string()))) && is_true(&(is_equal(&timeInForce, &Value::Str("IOC".to_string()))));
type_var = ternary(is_true(&isMarketOrder), Value::Str("market".to_string()), Value::Str("limit".to_string()));
side = ternary(is_true(&crate::precise::Precise::stringGt(&amount, &Value::Str("0".to_string()))), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
}
let mut rawStatus: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("finish_as".to_string()), Value::Str("status".to_string()), Value::Str("open".to_string())]), &[]);
let mut timestampStr: Value = self.safe_string_k(order.clone(), "create_time_ms", &[]);
if is_equal(×tampStr, &Value::Null) {
timestampStr = self.safe_string2(order.clone(), Value::Str("create_time".to_string()), Value::Str("ctime".to_string()), &[]);
if !is_equal(×tampStr, &Value::Null) {
if is_equal(&get_array_length(×tampStr), &Value::Int(10)) || is_greater_than_or_equal(&get_index_of(×tampStr, &Value::Str(".".to_string())), &Value::Int(0)) {
// ts in seconds, multiply to ms
timestampStr = crate::precise::Precise::stringMul(×tampStr, &Value::Str("1000".to_string()));
} else if is_equal(&get_array_length(×tampStr), &Value::Int(16)) {
// ts in microseconds, divide to ms
timestampStr = crate::precise::Precise::stringDiv(×tampStr, &Value::Str("1000".to_string()));
}
}
}
let mut lastTradeTimestampStr: Value = self.safe_string_k(order.clone(), "update_time_ms", &[]);
if is_equal(&lastTradeTimestampStr, &Value::Null) {
lastTradeTimestampStr = self.safe_string2(order.clone(), Value::Str("update_time".to_string()), Value::Str("finish_time".to_string()), &[]);
if !is_equal(&lastTradeTimestampStr, &Value::Null) {
if is_equal(&get_array_length(&lastTradeTimestampStr), &Value::Int(10)) || is_greater_than_or_equal(&get_index_of(&lastTradeTimestampStr, &Value::Str(".".to_string())), &Value::Int(0)) {
// ts in seconds, multiply to ms
lastTradeTimestampStr = crate::precise::Precise::stringMul(&lastTradeTimestampStr, &Value::Str("1000".to_string()));
} else if is_equal(&get_array_length(&lastTradeTimestampStr), &Value::Int(16)) {
// ts in microseconds, divide to ms
lastTradeTimestampStr = crate::precise::Precise::stringDiv(&lastTradeTimestampStr, &Value::Str("1000".to_string()));
}
}
}
let mut marketType: Value = Value::Str("contract".to_string());
if is_true(&(Value::Bool(in_op(&order, &Value::Str("currency_pair".to_string()))))) || is_true(&(Value::Bool(in_op(&order, &Value::Str("market".to_string()))))) {
marketType = Value::Str("spot".to_string());
}
let mut exchangeSymbol: Value = self.safe_string2(order.clone(), Value::Str("currency_pair".to_string()), Value::Str("market".to_string()), &[contract.clone()]);
let mut symbol: Value = self.safe_symbol(exchangeSymbol.clone(), &[market.clone(), Value::Str("_".to_string()), marketType.clone()]);
let mut fees: Value = Value::List(vec![]);
let mut gtFee: Value = self.safe_string_k(order.clone(), "gt_fee", &[]);
if !is_equal(>Fee, &Value::Null) {
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), Value::Str("GT".to_string()));
m.insert("cost".to_string(), gtFee.clone());
m
}));
}
let mut fee: Value = self.safe_string_k(order.clone(), "fee", &[]);
if !is_equal(&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.clone());
m
}));
}
let mut rebate: Value = self.safe_string_k(order.clone(), "rebated_fee", &[]);
if !is_equal(&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: Value = get_array_length(&fees);
let mut multipleFeeCurrencies: bool = is_greater_than(&numFeeCurrencies, &Value::Int(1));
let mut status: Value = self.parse_order_status(rawStatus.clone());
let mut remaining: Value = crate::precise::Precise::stringAbs(&remainingString);
// handle spot market buy
let mut account: Value = self.safe_string_k(order.clone(), "account", &[]); // using this instead of market type because of the conflicting ids
if is_true(&(is_equal(&account, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&account, &Value::Str("unified".to_string())))) {
let mut averageString: Value = self.safe_string_k(order.clone(), "avg_deal_price", &[]);
average = self.parse_number(averageString.clone(), &[]);
if is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
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 !is_equal(×tampStr, &Value::Null) {
timestamp = self.parse_to_int(timestampStr.clone());
}
if !is_equal(&lastTradeTimestampStr, &Value::Null) {
lastTradeTimestamp = self.parse_to_int(lastTradeTimestampStr.clone());
}
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.clone(), "is_reduce_only", &[]);
let mut reduceOnly: Value = self.safe_bool_k(order.clone(), "is_reduce_only", &[reduceOnlyInitial.clone()]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "text", &[]);
if is_equal(&clientOrderId, &Value::Null) {
if is_true(&Value::Bool(in_op(&order, &Value::Str("initial".to_string())))) {
clientOrderId = self.safe_string(get_value(&order, &Value::Str("initial".to_string())), Value::Str("text".to_string()), &[]);
} else if is_true(&Value::Bool(in_op(&order, &Value::Str("trigger".to_string())))) {
clientOrderId = self.safe_string(get_value(&order, &Value::Str("trigger".to_string())), Value::Str("text".to_string()), &[]);
}
}
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.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), lastTradeTimestamp.clone());
m.insert("status".to_string(), status.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("reduceOnly".to_string(), reduceOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("average".to_string(), average.clone());
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.clone());
m.insert("fee".to_string(), ternary(is_true(&multipleFeeCurrencies), Value::Null, self.safe_value(fees.clone(), Value::Int(0), &[])));
m.insert("fees".to_string(), ternary(is_true(&multipleFeeCurrencies), fees.clone(), Value::List(vec![])));
m.insert("trades".to_string(), Value::Null);
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
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 = ternary(is_true(&(is_equal(&symbol, &Value::Null))), Value::Null, self.market(symbol.clone()));
let mut trigger: Value = self.safe_bool_n(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("is_stop_order".to_string()), Value::Str("stop".to_string())]), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("is_stop_order".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("text".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut orderId: Value = id.clone();
if !is_equal(&clientOrderId, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("text".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
if !is_equal(&get_value(&clientOrderId, &Value::Int(0)), &Value::Str("t".to_string())) {
clientOrderId = add(&Value::Str("t-".to_string()), &clientOrderId);
}
orderId = clientOrderId.clone();
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut contract: bool = is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("option".to_string()))));
let mut requestrequestParamsVariable = ternary(is_true(&contract), self.prepare_request(&[market.clone(), type_var.clone(), query.clone()]), self.spot_order_prepare_request(&[market.clone(), trigger.clone(), query.clone()]));
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), to_string_val(&orderId));
return Value::List(vec![request.clone(), requestParams.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = ternary(is_true(&(is_equal(&symbol, &Value::Null))), Value::Null, self.market(symbol.clone()));
let mut result: Value = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = self.safe_string(result.clone(), Value::Int(0), &[]);
let mut trigger: Value = self.safe_bool_n(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("is_stop_order".to_string()), Value::Str("stop".to_string())]), &[Value::Bool(false)]);
let mut requestrequestParamsVariable = self.fetch_order_request(id.clone(), &[symbol.clone(), params.clone()]);
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("swap".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("future".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_51 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_options_get_orders_order_id(&[__ws_arg_51]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrder() not support this market type".to_string()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
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".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchClosedOrders".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchClosedOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
let mut res: Value = self.handle_market_type_and_params(Value::Str("fetchClosedOrders".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = self.safe_string(res.clone(), Value::Int(0), &[]);
let mut useHistorical: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchClosedOrders".to_string()), Value::Str("historical".to_string()), &[Value::Bool(false)]); useHistorical = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_true(&useHistorical) && is_true(&(is_true(&(is_equal(&since, &Value::Null) && is_equal(&until, &Value::Null))) || is_true(&(!is_equal(&type_var, &Value::Str("swap".to_string())))))) {
return self.fetch_orders_by_status(Value::Str("finished".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
params = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.prepare_request(&[market.clone(), type_var.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_52 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_futures_get_settle_orders_timerange(&[__ws_arg_52]).await;
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
let mut trigger: Value = Value::Null;
{ let __destr_tmp = self.handle_param_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]); trigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut spot: bool = is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string()))));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = ternary(is_true(&spot), self.multi_order_spot_prepare_request(&[market.clone(), trigger.clone(), params.clone()]), self.prepare_request(&[market.clone(), type_var.clone(), params.clone()])); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&spot) && is_true(&(is_equal(&trigger, &Value::Bool(true)))) {
request = self.omit(request.clone(), Value::Str("account".to_string()), &[]);
}
if is_equal(&status, &Value::Str("closed".to_string())) {
status = Value::Str("finished".to_string());
}
add_element_to_object(&mut request, &Value::Str("status".to_string()), status.clone());
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if is_true(&spot) {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
}
let mut lastIdfinalParamsVariable = self.handle_param_string2(params.clone(), Value::Str("lastId".to_string()), Value::Str("last_id".to_string()), &[]);
let mut lastId: Value = get_value(&lastIdfinalParamsVariable, &Value::Int(0));
let mut finalParams: Value = get_value(&lastIdfinalParamsVariable, &Value::Int(1));
if !is_equal(&lastId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("last_id".to_string()), lastId.clone());
}
return Value::List(vec![request.clone(), finalParams.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
// don't omit here, omits done in prepareOrdersByStatusRequest
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
let mut res: Value = self.handle_market_type_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = self.safe_string(res.clone(), Value::Int(0), &[]);
let mut requestrequestParamsVariable = self.prepare_orders_by_status_request(status.clone(), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]);
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
let mut spot: bool = is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string()))));
let mut openStatus: bool = is_equal(&status, &Value::Str("open".to_string()));
let mut openSpotOrders: bool = is_true(&spot) && is_true(&openStatus) && is_true(&(!is_equal(&trigger, &Value::Bool(true))));
let mut response: Value = Value::Null;
if is_true(&spot) {
if !is_equal(&trigger, &Value::Bool(true)) {
if is_true(&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 is_equal(&type_var, &Value::Str("swap".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("future".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_60 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_options_get_orders(&[__ws_arg_60]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrders() not support this market type".to_string()))));
}
//
// 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 is_true(&openSpotOrders) {
let mut spotResult: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_696: bool = true;
while { if !__for_first_696 { i = add(&i, &Value::Int(1)); } __for_first_696 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), "orders", &[]);
spotResult = self.array_concat(spotResult.clone(), ordersInner.clone());
}
}
result = spotResult.clone();
}
let mut orders: Value = self.parse_orders(result.clone(), &[market.clone(), since.clone(), limit.clone()]);
return self.filter_by_symbol_since_limit(orders.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = ternary(is_true(&(is_equal(&symbol, &Value::Null))), Value::Null, self.market(symbol.clone()));
let mut trigger: Value = self.safe_bool_n(params.clone(), Value::List(vec![Value::Str("is_stop_order".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("is_stop_order".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut requestrequestParamsVariable = ternary(is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())))), self.spot_order_prepare_request(&[market.clone(), trigger.clone(), query.clone()]), self.prepare_request(&[market.clone(), type_var.clone(), query.clone()]));
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), id.clone());
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("swap".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("future".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_67 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_options_delete_orders_order_id(&[__ws_arg_67]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrder() not support this market type".to_string()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut type_var: Value = Value::Null;
let mut defaultSettle: Value = ternary(is_true(&(is_equal(&market, &Value::Null))), Value::Str("usdt".to_string()), get_value(&market, &Value::Str("settle".to_string())));
let mut settle: Value = self.safe_string_lower(params.clone(), Value::Str("settle".to_string()), &[defaultSettle.clone()]);
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrders".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isSpot: bool = is_equal(&type_var, &Value::Str("spot".to_string()));
if is_true(&isSpot) && is_true(&(is_equal(&symbol, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders requires a symbol argument for spot markets".to_string()))));
}
if is_true(&isSpot) {
let mut ordersRequests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_697: bool = true;
while { if !__for_first_697 { i = add(&i, &Value::Int(1)); } __for_first_697 = false; is_less_than(&i, &get_array_length(&ids)) } {
let mut id: Value = get_value(&ids, &i);
let mut id: Value = get_value(&ids, &i);
let mut orderItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m
});
append_to_array(&mut ordersRequests, orderItem.clone());
}
}
return self.cancel_orders_for_symbols(ordersRequests.clone(), &[params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settle".to_string(), settle.clone());
m
});
let mut finalList: Value = Value::List(vec![request.clone()]); // hacky but needs to be done here
{
let mut i: Value = Value::Int(0);
let mut __for_first_698: bool = true;
while { if !__for_first_698 { i = add(&i, &Value::Int(1)); } __for_first_698 = false; is_less_than(&i, &get_array_length(&ids)) } {
append_to_array(&mut finalList, get_value(&ids, &i));
}
}
let mut response: Value = self.private_futures_post_settle_batch_cancel_orders(&[finalList.clone()]).await;
return self.parse_orders(response.clone(), &[]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut ordersRequests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_699: bool = true;
while { if !__for_first_699 { i = add(&i, &Value::Int(1)); } __for_first_699 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = get_value(&orders, &i);
let mut order: Value = get_value(&orders, &i);
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrdersForSymbols() supports only spot markets".to_string()))));
}
let mut id: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut orderItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("currency_pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
append_to_array(&mut ordersRequests, orderItem.clone());
}
}
let mut response: Value = self.private_spot_post_cancel_batch_orders(&[ordersRequests.clone()]).await;
return self.parse_orders(response.clone(), &[]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut market: Value = ternary(is_true(&(is_equal(&symbol, &Value::Null))), Value::Null, self.market(symbol.clone()));
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut requestrequestParamsVariable = ternary(is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))), self.multi_order_spot_prepare_request(&[market.clone(), trigger.clone(), query.clone()]), self.prepare_request(&[market.clone(), type_var.clone(), query.clone()]));
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("swap".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("future".to_string())) {
if is_equal(&trigger, &Value::Bool(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 is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_74 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.private_options_delete_orders(&[__ws_arg_74]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelAllOrders() not support this market type".to_string()))));
}
return self.parse_orders(response.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut fromId: Value = self.convert_type_to_account(fromAccount.clone());
let mut toId: Value = self.convert_type_to_account(toAccount.clone());
let mut truncated: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), truncated.clone());
m
});
if !is_true(&(Value::Bool(in_op(&get_value(&self.options, &Value::Str("accountsByType".to_string())), &fromId)))) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), Value::Str("margin".to_string()));
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), fromId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("from".to_string()), fromId.clone());
}
if !is_true(&(Value::Bool(in_op(&get_value(&self.options, &Value::Str("accountsByType".to_string())), &toId)))) {
add_element_to_object(&mut request, &Value::Str("to".to_string()), Value::Str("margin".to_string()));
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), toId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("to".to_string()), toId.clone());
}
if is_equal(&fromId, &Value::Str("margin".to_string())) || is_equal(&toId, &Value::Str("margin".to_string())) {
let mut symbol: Value = self.safe_string2(params.clone(), Value::Str("symbol".to_string()), Value::Str("currency_pair".to_string()), &[]);
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" transfer requires params[\"symbol\"] for isolated margin transfers".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
params = self.omit(params.clone(), Value::Str("symbol".to_string()), &[]);
}
if is_true(&(is_equal(&toId, &Value::Str("futures".to_string())))) || is_true(&(is_equal(&toId, &Value::Str("delivery".to_string())))) || is_true(&(is_equal(&fromId, &Value::Str("futures".to_string())))) || is_true(&(is_equal(&fromId, &Value::Str("delivery".to_string())))) {
add_element_to_object(&mut request, &Value::Str("settle".to_string()), get_value(¤cy, &Value::Str("id".to_string()))); // todo: currencies have network-junctions
}
let __ws_arg_75 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_wallet_post_transfers(&[__ws_arg_75]).await;
return self.parse_transfer(response.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
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.clone()]));
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m.insert("info".to_string(), transfer.clone());
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
// WARNING: THIS WILL INCREASE LIQUIDATION PRICE FOR OPEN ISOLATED LONG POSITIONS
// AND DECREASE LIQUIDATION PRICE FOR OPEN ISOLATED SHORT POSITIONS
if is_true(&(is_less_than(&leverage, &Value::Int(0)))) || is_true(&(is_greater_than(&leverage, &Value::Int(100)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setLeverage() leverage should be between 1 and 100".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
let mut defaultMarginMode: Value = self.safe_string2(self.options.clone(), Value::Str("marginMode".to_string()), Value::Str("defaultMarginMode".to_string()), &[]);
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.clone()]);
let mut stringifiedMargin: Value = self.number_to_string(leverage.clone());
if !is_equal(&crossLeverageLimit, &Value::Null) {
marginMode = Value::Str("cross".to_string());
stringifiedMargin = crossLeverageLimit.clone();
}
if is_equal(&marginMode, &Value::Str("cross".to_string())) || is_equal(&marginMode, &Value::Str("cross_margin".to_string())) {
add_element_to_object(&mut request, &Value::Str("cross_leverage_limit".to_string()), stringifiedMargin.clone());
add_element_to_object(&mut request, &Value::Str("leverage".to_string()), Value::Str("0".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("leverage".to_string()), stringifiedMargin.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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 is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
let __ws_arg_77 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delivery_post_settle_positions_contract_leverage(&[__ws_arg_77]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setLeverage() not support this market type".to_string()))));
}
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", &[]);
market = self.safe_market(&[contract.clone(), market.clone(), Value::Str("_".to_string()), Value::Str("contract".to_string())]);
let mut size: Value = self.safe_string2(position.clone(), Value::Str("size".to_string()), Value::Str("accum_size".to_string()), &[]);
let mut side: Value = self.safe_string_k(position.clone(), "side", &[]);
if is_equal(&side, &Value::Null) {
if is_true(&crate::precise::Precise::stringGt(&size, &Value::Str("0".to_string()))) {
side = Value::Str("long".to_string());
} else if is_true(&crate::precise::Precise::stringLt(&size, &Value::Str("0".to_string()))) {
side = Value::Str("short".to_string());
}
}
let mut notional: Value = self.safe_string_k(position.clone(), "value", &[]);
let mut leverage: Value = self.safe_string_k(position.clone(), "leverage", &[]);
let mut marginMode: Value = Value::Null;
if !is_equal(&leverage, &Value::Null) {
if is_equal(&leverage, &Value::Str("0".to_string())) {
marginMode = Value::Str("cross".to_string());
} else {
marginMode = Value::Str("isolated".to_string());
}
}
// 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 is_true(&(!is_equal(&marginBalance, &Value::Null))) && is_true(&(!is_equal(&unrealisedPnl, &Value::Null))) {
collateral = crate::precise::Precise::stringAdd(&marginBalance, &unrealisedPnl);
}
let mut timestamp: Value = self.safe_timestamp2(position.clone(), Value::Str("open_time".to_string()), Value::Str("first_open_time".to_string()), &[]);
if is_equal(×tamp, &Value::Int(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(market.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), self.safe_timestamp2(position.clone(), Value::Str("update_time".to_string()), Value::Str("time".to_string()), &[]));
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.clone(), &[]));
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("unrealizedPnl".to_string(), self.parse_number(unrealisedPnl.clone(), &[]));
m.insert("realizedPnl".to_string(), self.safe_number2(position.clone(), Value::Str("realised_pnl".to_string()), Value::Str("pnl".to_string()), &[]));
m.insert("contracts".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&size), &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "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.clone(), "mark_price", &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("collateral".to_string(), self.parse_number(collateral.clone(), &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("side".to_string(), side.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchPosition() supports contract markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.prepare_request(&[market.clone(), get_value(&market, &Value::Str("type".to_string())), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut extendedRequest: Value = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
response = self.private_futures_get_settle_positions_contract(&[extendedRequest.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
response = self.private_delivery_get_settle_positions_contract(&[extendedRequest.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("option".to_string())) {
response = self.private_options_get_positions_contract(&[extendedRequest.clone()]).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 is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" fetchPosition() returned empty response".to_string()))));
}
return self.parse_position(response.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
if !is_equal(&symbols, &Value::Null) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(0)) {
market = self.market(get_value(&symbols, &Value::Int(0)));
}
}
let mut type_var: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchPositions".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&type_var, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) {
type_var = Value::Str("swap".to_string()); // default to swap
}
if is_equal(&type_var, &Value::Str("option".to_string())) {
if !is_equal(&symbols, &Value::Null) {
let mut marketId: Value = self.safe_string_k(market.clone(), "id", &[]);
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
add_element_to_object(&mut request, &Value::Str("underlying".to_string()), self.safe_string(optionParts.clone(), Value::Int(0), &[]));
}
} else {
{ let __destr_tmp = self.prepare_request(&[Value::Null, type_var.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
}
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_78 = self.extend(request.clone(), &[params.clone()]);
response = self.private_futures_get_settle_positions(&[__ws_arg_78]).await;
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_79 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delivery_get_settle_positions(&[__ws_arg_79]).await;
} else if is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_80 = self.extend(request.clone(), &[params.clone()]);
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::List(vec![]);
if !is_equal(&response, &Value::Null) {
responseList = self.to_array(response.clone());
}
return self.parse_positions(responseList.clone(), &[symbols.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchLeverageTiers".to_string()), &[Value::Null, params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut requestrequestParamsVariable = self.prepare_request(&[Value::Null, type_var.clone(), query.clone()]);
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
if !is_equal(&type_var, &Value::Str("future".to_string())) && !is_equal(&type_var, &Value::Str("swap".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchLeverageTiers only supports swap and future".to_string()))));
}
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_81 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_futures_get_settle_contracts(&[__ws_arg_81]).await;
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_82 = self.extend(request.clone(), &[requestParams.clone()]);
response = self.public_delivery_get_settle_contracts(&[__ws_arg_82]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLeverageTiers() not support this market type".to_string()))));
}
return self.parse_leverage_tiers(response.clone(), &[symbols.clone(), Value::Str("name".to_string())]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchMarketLeverageTiers".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut requestrequestParamsVariable = self.prepare_request(&[market.clone(), type_var.clone(), query.clone()]);
let mut request: Value = get_value(&requestrequestParamsVariable, &Value::Int(0));
let mut requestParams: Value = get_value(&requestrequestParamsVariable, &Value::Int(1));
if !is_equal(&type_var, &Value::Str("future".to_string())) && !is_equal(&type_var, &Value::Str("swap".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchMarketLeverageTiers only supports swap and future".to_string()))));
}
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("swap".to_string())) {
//
// [
// {
// "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.clone(), &[requestParams.clone()]);
response = self.public_delivery_get_settle_risk_limit_tiers(&[__ws_arg_84]).await;
}
return self.parse_market_leverage_tiers(response.clone(), &[market.clone()]);
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".to_string()), &leverageMax);
let mut maintenanceMarginRate: Value = maintenanceMarginUnit.clone();
let mut initialMarginRatio: Value = initialMarginUnit.clone();
let mut floor: Value = Value::Str("0".to_string());
let mut tiers: Value = Value::List(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".to_string())]));
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".to_string()), &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.clone();
}
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 !is_true(&Value::Bool(is_array(&info))) {
return self.parse_emulated_leverage_tiers(info.clone(), &[market.clone()]);
}
let mut minNotional: Value = Value::Int(0);
let mut tiers: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_700: bool = true;
while { if !__for_first_700 { i = add(&i, &Value::Int(1)); } __for_first_700 = false; is_less_than(&i, &get_array_length(&info)) } {
let mut item: Value = get_value(&info, &i);
let mut item: Value = get_value(&info, &i);
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.clone());
m
}));
minNotional = maxNotional.clone();
}
}
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 is_equal(&self.markets, &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".to_string()))));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("repay".to_string()));
let __ws_arg_85 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_margin_post_uni_loans(&[__ws_arg_85]).await;
return self.parse_margin_loan(response.clone(), &[currency.clone()]);
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 is_equal(&self.markets, &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".to_string()))));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let mut isUnifiedAccount: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("repayCrossMargin".to_string()), Value::Str("unifiedAccount".to_string()), &[]); isUnifiedAccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&isUnifiedAccount) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("repay".to_string()));
let __ws_arg_86 = self.extend(request.clone(), &[params.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.clone(), &[params.clone()]);
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.clone(), &[currency.clone()]);
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 is_equal(&self.markets, &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".to_string()))));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("borrow".to_string()));
let __ws_arg_88 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_margin_post_uni_loans(&[__ws_arg_88]).await;
return self.parse_margin_loan(response.clone(), &[currency.clone()]);
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 is_equal(&self.markets, &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".to_string()))));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let mut isUnifiedAccount: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("borrowCrossMargin".to_string()), Value::Str("unifiedAccount".to_string()), &[]); isUnifiedAccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&isUnifiedAccount) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("borrow".to_string()));
let __ws_arg_89 = self.extend(request.clone(), &[params.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.clone(), &[params.clone()]);
response = self.private_margin_post_cross_loans(&[__ws_arg_90]).await;
}
return self.parse_margin_loan(response.clone(), &[currency.clone()]);
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: Value = self.safe_string2(self.options.clone(), Value::Str("defaultMarginMode".to_string()), Value::Str("marginMode".to_string()), &[Value::Str("cross".to_string())]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "create_time", &[]);
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
timestamp = self.safe_timestamp(info.clone(), Value::Str("create_time".to_string()), &[]);
}
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.clone(), &[currency.clone()]));
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "amount", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[Value::Null, Value::Str("_".to_string()), Value::Str("margin".to_string())]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), info.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_unified_status(&[]).await;
let mut isUnifiedAccount: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchBorrowInterest".to_string()), Value::Str("unifiedAccount".to_string()), &[]); isUnifiedAccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.handle_until_option(Value::Str("to".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::Null;
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBorrowInterest".to_string()), &[params.clone(), Value::Str("cross".to_string())]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&isUnifiedAccount) {
let __ws_arg_91 = self.extend(request.clone(), &[params.clone()]);
response = self.private_unified_get_interest_records(&[__ws_arg_91]).await;
} else if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_92 = self.extend(request.clone(), &[params.clone()]);
response = self.private_margin_get_uni_interest_records(&[__ws_arg_92]).await;
} else if is_equal(&marginMode, &Value::Str("cross".to_string())) {
// deprecated and not present in the exchange's docs but still works
let __ws_arg_93 = self.extend(request.clone(), &[params.clone()]);
response = self.private_margin_get_cross_interest_records(&[__ws_arg_93]).await;
}
let mut interest: Value = self.parse_borrow_interests(response.clone(), &[market.clone()]);
return self.filter_by_currency_since_limit(interest.clone(), &[code.clone(), since.clone(), limit.clone()]);
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", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut marginMode: Value = ternary(is_true(&(!is_equal(&marketId, &Value::Null))), Value::Str("isolated".to_string()), Value::Str("cross".to_string()));
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(market.clone(), "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.clone(), "actual_rate", &[]));
m.insert("amountBorrowed".to_string(), Value::Null);
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::List(vec![]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut 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 containsSettle: bool = is_greater_than(&get_index_of(&path, &Value::Str("settle".to_string())), &negate(&Value::Int(1)));
if is_true(&containsSettle) && is_true(&(is_equal(&Value::Bool(ends_with(&path, &Value::Str("batch_cancel_orders".to_string()))), &Value::Bool(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), &[]);
path = self.implode_params(path.clone(), settle.clone());
// remove the first element from params
let mut newParams: Value = Value::List(vec![]);
let mut anyParams: Value = self.to_array(params.clone());
{
let mut i: Value = Value::Int(1);
let mut __for_first_701: bool = true;
while { if !__for_first_701 { i = add(&i, &Value::Int(1)); } __for_first_701 = false; is_less_than(&i, &get_array_length(&anyParams)) } {
append_to_array(&mut newParams, get_value(¶ms, &i));
}
}
params = newParams.clone();
query = newParams.clone();
} else if is_true(&Value::Bool(is_array(¶ms))) {
// 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_value(params.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
path = self.implode_params(path.clone(), first.clone());
} else {
path = self.implode_params(path.clone(), params.clone());
}
let mut endPart: Value = ternary(is_true(&(is_equal(&path, &Value::Str("".to_string())))), Value::Str("".to_string()), (add(&Value::Str("/".to_string()), &path)));
let mut entirePath: Value = add(&add(&Value::Str("/".to_string()), &type_var), &endPart);
if is_true(&(is_equal(&type_var, &Value::Str("subAccounts".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("withdrawals".to_string())))) {
entirePath = endPart.clone();
}
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &authentication), &type_var);
if is_equal(&url, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" does not have a testnet for the ".to_string())), &type_var), &Value::Str(" market type.".to_string()))));
}
url = add(&url, &entirePath);
if is_equal(&authentication, &Value::Str("public".to_string())) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
} else {
self.check_required_credentials(&[]);
let mut queryString: Value = Value::Str("".to_string());
let mut rawQueryString: Value = Value::Str("".to_string());
let mut requiresURLEncoding: bool = false;
if is_true(&(is_true(&(is_equal(&type_var, &Value::Str("futures".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("delivery".to_string())))))) && is_equal(&method, &Value::Str("POST".to_string())) {
let mut pathParts: Value = split(&path, &Value::Str("/".to_string()));
let mut secondPart: Value = self.safe_string(pathParts.clone(), Value::Int(1), &[Value::Str("".to_string())]);
requiresURLEncoding = is_true(&(is_greater_than_or_equal(&get_index_of(&secondPart, &Value::Str("dual".to_string())), &Value::Int(0)))) || is_true(&(is_greater_than_or_equal(&get_index_of(&secondPart, &Value::Str("positions".to_string())), &Value::Int(0))));
}
if is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))) || is_true(&requiresURLEncoding) || is_true(&(is_equal(&method, &Value::Str("PATCH".to_string())))) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
// https://github.com/ccxt/ccxt/issues/27663
rawQueryString = self.rawencode(query.clone(), &[]);
queryString = self.urlencode(query.clone(), &[]);
// https://github.com/ccxt/ccxt/issues/25570
if is_greater_than_or_equal(&get_index_of(&queryString, &Value::Str("currencies=".to_string())), &Value::Int(0)) && is_greater_than_or_equal(&get_index_of(&queryString, &Value::Str("%2C".to_string())), &Value::Int(0)) {
queryString = replace_all_str(&queryString, &Value::Str("%2C".to_string()), &Value::Str(",".to_string()));
}
url = add(&url, &add(&Value::Str("?".to_string()), &queryString));
}
if is_equal(&method, &Value::Str("PATCH".to_string())) {
body = self.json(query.clone());
}
} else {
let mut urlQueryParams: Value = self.safe_value_k(query.clone(), "query", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_greater_than(&get_array_length(&object_keys(&urlQueryParams)), &Value::Int(0)) {
queryString = self.urlencode(urlQueryParams.clone(), &[]);
url = add(&url, &add(&Value::Str("?".to_string()), &queryString));
}
query = self.omit(query.clone(), Value::Str("query".to_string()), &[]);
body = self.json(query.clone());
}
let mut bodyPayload: Value = ternary(is_true(&(is_equal(&body, &Value::Null))), Value::Str("".to_string()), body.clone());
let mut bodySignature: Value = self.hash(self.encode(bodyPayload.clone()), Value::Str("sha512".to_string()), &[]);
let mut nonce: Value = self.nonce();
let mut timestamp: Value = self.parse_to_int(divide(&nonce, &Value::Int(1000)));
let mut timestampString: Value = to_string_val(×tamp);
let mut signaturePath: Value = add(&add(&Value::Str("/api/".to_string()), &self.version), &entirePath);
let mut payloadArray: Value = Value::List(vec![to_upper(&method), signaturePath.clone(), rawQueryString.clone(), bodySignature.clone(), timestampString.clone()]);
// eslint-disable-next-line quotes
let mut payload: Value = join(&payloadArray, &Value::Str("\n".to_string()));
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha512".to_string()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("KEY".to_string(), self.apiKey.clone());
m.insert("Timestamp".to_string(), timestampString.clone());
m.insert("SIGN".to_string(), signature.clone());
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Null, params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
add_element_to_object(&mut request, &Value::Str("change".to_string()), self.number_to_string(amount.clone()));
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(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 is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
let __ws_arg_95 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delivery_post_settle_positions_contract_margin(&[__ws_arg_95]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" modifyMarginHelper() not support this market type".to_string()))));
}
return self.parse_margin_modification(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "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", &[]);
market = self.safe_market(&[contract.clone(), market.clone(), Value::Str("_".to_string()), Value::Str("contract".to_string())]);
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.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), total.clone());
m.insert("code".to_string(), self.safe_value_k(market.clone(), "quote", &[]));
m.insert("status".to_string(), Value::Str("ok".to_string()));
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.clone(), negate(&amount), &[params.clone()]).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.clone(), amount.clone(), &[params.clone()]).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".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOpenInterestHistory".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOpenInterestHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(100)]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOpenInterest() supports swap markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("settle".to_string(), get_value(&market, &Value::Str("settleId".to_string())));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let __ws_arg_96 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_futures_get_settle_contract_stats(&[__ws_arg_96]).await;
return self.parse_open_interests_history(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "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(interest.clone(), Value::Str("time".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "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.clone()));
m.insert("info".to_string(), interest.clone());
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchSettlementHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchSettlementHistory".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&type_var, &Value::Str("option".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchSettlementHistory() supports option markets only".to_string()))));
}
let mut marketId: Value = get_value(&market, &Value::Str("id".to_string()));
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("underlying".to_string(), self.safe_string(optionParts.clone(), Value::Int(0), &[]));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_97 = self.extend(request.clone(), &[params.clone()]);
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.clone(), market.clone());
let mut sorted: Value = self.sort_by(settlements.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMySettlementHistory".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isOption: bool = is_equal(&type_var, &Value::Str("option".to_string()));
let mut isFuture: bool = is_equal(&type_var, &Value::Str("future".to_string()));
if !is_true(&isOption) && !is_true(&isFuture) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchMySettlementHistory() supports option and future markets only".to_string()))));
}
let mut requestqueryVariable = self.prepare_request(&[market.clone(), type_var.clone(), params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::Null;
if is_true(&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.clone()]);
response = self.private_delivery_get_settle_settlements(&[__ws_arg_98]).await;
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
}
if is_equal(&market, &Value::Null) {
let mut underlying: Value = self.safe_string_k(params.clone(), "underlying", &[]);
if is_equal(&underlying, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMySettlementHistory() requires a symbol argument or an underlying parameter in params".to_string()))));
}
} else {
let mut marketId: Value = get_value(&market, &Value::Str("id".to_string()));
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
add_element_to_object(&mut request, &Value::Str("underlying".to_string()), self.safe_string(optionParts.clone(), 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.clone(), &[params.clone()]);
response = self.private_options_get_my_settlements(&[__ws_arg_99]).await;
}
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_value_k(result.clone(), "list", &[Value::List(vec![])]);
let mut settlements: Value = self.parse_settlements(data.clone(), market.clone());
let mut sorted: Value = self.sort_by(settlements.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_settlement(&self, mut settlement: Value, mut market: Value) -> Value {
//
// 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(settlement.clone(), Value::Str("time".to_string()), &[]);
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.clone(), &[market.clone()]));
m.insert("price".to_string(), self.safe_number_k(settlement.clone(), "settle_price", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
pub fn parse_settlements(&self, mut settlements: Value, mut market: Value) -> Value {
//
// 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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_702: bool = true;
while { if !__for_first_702 { i = add(&i, &Value::Int(1)); } __for_first_702 = false; is_less_than(&i, &get_array_length(&settlements)) } {
append_to_array(&mut result, self.parse_settlement(get_value(&settlements, &i), 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLedger".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchLedger".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut type_var: Value = Value::Null;
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 __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string())))) {
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string()))); // todo: currencies have network-junctions
}
}
if is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
let mut defaultSettle: Value = ternary(is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))), Value::Str("usdt".to_string()), Value::Str("btc".to_string()));
let mut settle: Value = self.safe_string_lower(params.clone(), Value::Str("settle".to_string()), &[defaultSettle.clone()]);
params = self.omit(params.clone(), Value::Str("settle".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("settle".to_string()), settle.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("to".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("spot".to_string())) {
let __ws_arg_100 = self.extend(request.clone(), &[params.clone()]);
response = self.private_spot_get_account_book(&[__ws_arg_100]).await;
} else if is_equal(&type_var, &Value::Str("margin".to_string())) {
let __ws_arg_101 = self.extend(request.clone(), &[params.clone()]);
response = self.private_margin_get_account_book(&[__ws_arg_101]).await;
} else if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_102 = self.extend(request.clone(), &[params.clone()]);
response = self.private_futures_get_settle_account_book(&[__ws_arg_102]).await;
} else if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_103 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delivery_get_settle_account_book(&[__ws_arg_103]).await;
} else if is_equal(&type_var, &Value::Str("option".to_string())) {
let __ws_arg_104 = self.extend(request.clone(), &[params.clone()]);
response = self.private_options_get_account_book(&[__ws_arg_104]).await;
}
return self.parse_ledger(response.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// 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".to_string()))) {
direction = Value::Str("out".to_string());
amount = crate::precise::Precise::stringAbs(&amount);
} else {
direction = Value::Str("in".to_string());
}
let mut currencyId: Value = self.safe_string_k(item.clone(), "currency", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
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 is_greater_than(&get_array_length(&rawTimestamp), &Value::Int(10)) {
timestamp = crate::runtime::parse_int(&rawTimestamp);
} else {
timestamp = multiply(&crate::runtime::parse_int(&rawTimestamp), &Value::Int(1000));
}
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.clone());
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.clone()));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("before".to_string(), before.clone());
m.insert("after".to_string(), self.safe_number_k(item.clone(), "balance", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut ledgerType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Str("deposit".to_string()));
m.insert("withdraw".to_string(), Value::Str("withdrawal".to_string()));
m.insert("sub_account_transfer".to_string(), Value::Str("transfer".to_string()));
m.insert("margin_in".to_string(), Value::Str("transfer".to_string()));
m.insert("margin_out".to_string(), Value::Str("transfer".to_string()));
m.insert("margin_funding_in".to_string(), Value::Str("transfer".to_string()));
m.insert("margin_funding_out".to_string(), Value::Str("transfer".to_string()));
m.insert("cross_margin_in".to_string(), Value::Str("transfer".to_string()));
m.insert("cross_margin_out".to_string(), Value::Str("transfer".to_string()));
m.insert("copy_trading_in".to_string(), Value::Str("transfer".to_string()));
m.insert("copy_trading_out".to_string(), Value::Str("transfer".to_string()));
m.insert("quant_in".to_string(), Value::Str("transfer".to_string()));
m.insert("quant_out".to_string(), Value::Str("transfer".to_string()));
m.insert("futures_in".to_string(), Value::Str("transfer".to_string()));
m.insert("futures_out".to_string(), Value::Str("transfer".to_string()));
m.insert("delivery_in".to_string(), Value::Str("transfer".to_string()));
m.insert("delivery_out".to_string(), Value::Str("transfer".to_string()));
m.insert("new_order".to_string(), Value::Str("trade".to_string()));
m.insert("order_fill".to_string(), Value::Str("trade".to_string()));
m.insert("referral_fee".to_string(), Value::Str("rebate".to_string()));
m.insert("order_fee".to_string(), Value::Str("fee".to_string()));
m.insert("interest".to_string(), Value::Str("interest".to_string()));
m.insert("lend".to_string(), Value::Str("loan".to_string()));
m.insert("redeem".to_string(), Value::Str("loan".to_string()));
m.insert("profit".to_string(), Value::Str("interest".to_string()));
m.insert("flash_swap_buy".to_string(), Value::Str("trade".to_string()));
m.insert("flash_swap_sell".to_string(), Value::Str("trade".to_string()));
m.insert("unknown".to_string(), Value::Str("unknown".to_string()));
m.insert("set".to_string(), Value::Str("settlement".to_string()));
m.insert("prem".to_string(), Value::Str("trade".to_string()));
m.insert("point_refr".to_string(), Value::Str("rebate".to_string()));
m.insert("point_fee".to_string(), Value::Str("fee".to_string()));
m.insert("point_dnw".to_string(), Value::Str("deposit/withdraw".to_string()));
m.insert("fund".to_string(), Value::Str("fee".to_string()));
m.insert("refr".to_string(), Value::Str("rebate".to_string()));
m.insert("fee".to_string(), Value::Str("fee".to_string()));
m.insert("pnl".to_string(), Value::Str("trade".to_string()));
m.insert("dnw".to_string(), Value::Str("deposit/withdraw".to_string()));
m
});
return self.safe_string(ledgerType.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @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 = ternary(is_true(&(!is_equal(&symbol, &Value::Null))), self.market(symbol.clone()), Value::Null);
let mut requestqueryVariable = self.prepare_request(&[market.clone(), Value::Str("swap".to_string()), params.clone()]);
let mut request: Value = get_value(&requestqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&requestqueryVariable, &Value::Int(1));
add_element_to_object(&mut request, &Value::Str("dual_mode".to_string()), hedged.clone());
let __ws_arg_105 = self.extend(request.clone(), &[query.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchUnderlyingAssets".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&marketType, &Value::Null))) || is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) {
marketType = Value::Str("option".to_string());
}
if !is_equal(&marketType, &Value::Str("option".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchUnderlyingAssets() supports option markets only".to_string()))));
}
let mut response: Value = self.public_options_get_underlyings(&[params.clone()]).await;
//
// [
// {
// "index_time": "1646915796",
// "name": "BTC_USDT",
// "index_price": "39142.73"
// }
// ]
//
let mut underlyings: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_703: bool = true;
while { if !__for_first_703 { i = add(&i, &Value::Int(1)); } __for_first_703 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), "name", &[]);
if !is_equal(&name, &Value::Null) {
append_to_array(&mut underlyings, name.clone());
}
}
}
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLiquidations() supports swap markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("settle".to_string(), get_value(&market, &Value::Str("settleId".to_string())));
m.insert("contract".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("to".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_106 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_futures_get_settle_liq_orders(&[__ws_arg_106]).await;
return self.parse_liquidations(self.to_array(response.clone()), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyLiquidations() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)))) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
add_element_to_object(&mut request, &Value::Str("settle".to_string()), get_value(&market, &Value::Str("settleId".to_string())));
} else if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
let mut marketId: Value = get_value(&market, &Value::Str("id".to_string()));
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
add_element_to_object(&mut request, &Value::Str("underlying".to_string()), self.safe_string(optionParts.clone(), Value::Int(0), &[]));
}
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_107 = self.extend(request.clone(), &[params.clone()]);
response = self.private_futures_get_settle_liquidates(&[__ws_arg_107]).await;
} else if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
let __ws_arg_108 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delivery_get_settle_liquidates(&[__ws_arg_108]).await;
} else if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
let __ws_arg_109 = self.extend(request.clone(), &[params.clone()]);
response = self.private_options_get_position_close(&[__ws_arg_109]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchMyLiquidations() does not support ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" orders".to_string()))));
}
return self.parse_liquidations(self.to_array(response.clone()), &[market.clone(), since.clone(), limit.clone()]);
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(liquidation.clone(), Value::Str("time".to_string()), &[]);
let mut size: Value = self.safe_string2(liquidation.clone(), Value::Str("size".to_string()), Value::Str("settle_size".to_string()), &[]);
let mut left: Value = self.safe_string_k(liquidation.clone(), "left", &[Value::Str("0".to_string())]);
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".to_string()), Value::Str("fill_price".to_string()), &[]);
let mut baseValueString: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
let mut quoteValueString: Value = self.safe_string_k(liquidation.clone(), "pnl", &[]);
if is_equal("eValueString, &Value::Null) {
quoteValueString = crate::precise::Precise::stringMul(&baseValueString, &priceString);
}
// --- derive side ---
// 1) options payload has explicit 'side': 'long' | 'short'
let mut optPos: Value = self.safe_string_lower(liquidation.clone(), Value::Str("side".to_string()), &[]);
let mut side: Value = Value::Null;
if is_equal(&optPos, &Value::Str("long".to_string())) {
side = Value::Str("buy".to_string());
} else if is_equal(&optPos, &Value::Str("short".to_string())) {
side = Value::Str("sell".to_string());
} else {
if !is_equal(&size, &Value::Null) {
if is_true(&crate::precise::Precise::stringGt(&size, &Value::Str("0".to_string()))) {
side = Value::Str("buy".to_string());
} else if is_true(&crate::precise::Precise::stringLt(&size, &Value::Str("0".to_string()))) {
side = Value::Str("sell".to_string());
}
}
}
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), liquidation.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("contracts".to_string(), self.parse_number(contractsString.clone(), &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSizeString.clone(), &[]));
m.insert("price".to_string(), self.parse_number(priceString.clone(), &[]));
m.insert("side".to_string(), side.clone());
m.insert("baseValue".to_string(), self.parse_number(baseValueString.clone(), &[]));
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.clone()));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("underlying".to_string(), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("underlying".to_string())));
m
});
let __ws_arg_110 = self.extend(request.clone(), &[params.clone()]);
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 = get_value(&market, &Value::Str("id".to_string()));
{
let mut i: Value = Value::Int(0);
let mut __for_first_704: bool = true;
while { if !__for_first_704 { i = add(&i, &Value::Int(1)); } __for_first_704 = false; is_less_than(&i, &get_array_length(&response)) } {
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 is_equal(&entryMarketId, &marketId) {
return self.parse_greeks(entry.clone(), &[market.clone()]);
}
}
}
panic!("{}", crate::exchange_errors::null_response(add(&add(&self.id, &Value::Str(" fetchGreeks() could not find greeks for ".to_string())), &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.clone(), &[market.clone()]);
if is_equal(&market, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseGreeks() could not resolve market".to_string()))));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
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(get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("underlying_price".to_string())), &[]));
m.insert("info".to_string(), greeks.clone());
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
});
params = self.extend(request.clone(), &[params.clone()]);
if is_equal(&side, &Value::Null) {
side = Value::Str("".to_string()); // side is not used but needs to be present, otherwise crashes in php
}
return self.create_order(symbol.clone(), Value::Str("market".to_string()), side.clone(), Value::Int(0), &[Value::Null, params.clone()]).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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
// unified account does not require a symbol
market = self.market(symbol.clone());
}
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", &[]);
params = self.omit(params.clone(), Value::Str("unified".to_string()), &[]);
if is_equal(&self.safe_bool_k(market.clone(), "spot", &[]), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("currency_pair".to_string()), self.safe_string_k(market.clone(), "id", &[]));
if is_equal(&isUnified, &Value::Bool(true)) {
let __ws_arg_111 = self.extend(request.clone(), &[params.clone()]);
response = self.public_margin_get_uni_currency_pairs_currency_pair(&[__ws_arg_111]).await;
} else {
let __ws_arg_112 = self.extend(request.clone(), &[params.clone()]);
response = self.public_margin_get_currency_pairs_currency_pair(&[__ws_arg_112]).await; // deprecated
}
} else if is_equal(&isUnified, &Value::Bool(true)) {
let __ws_arg_113 = self.extend(request.clone(), &[params.clone()]);
response = self.private_unified_get_accounts(&[__ws_arg_113]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchLeverage() does not support ".to_string())), &self.safe_string_k(market.clone(), "type", &[])), &Value::Str(" markets".to_string()))));
}
return self.parse_leverage(response.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = Value::Null;
let mut isUnified: Value = self.safe_bool_k(params.clone(), "unified", &[]);
params = self.omit(params.clone(), Value::Str("unified".to_string()), &[]);
let mut marketIdRequest: Value = Value::Str("id".to_string());
if is_equal(&isUnified, &Value::Bool(true)) {
marketIdRequest = Value::Str("currency_pair".to_string());
response = self.public_margin_get_uni_currency_pairs(&[params.clone()]).await;
} else {
response = self.public_margin_get_currency_pairs(&[params.clone()]).await; // deprecated
}
return self.parse_leverages(self.to_array(response.clone()), &[symbols.clone(), marketIdRequest.clone(), Value::Str("spot".to_string())]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string2(leverage.clone(), Value::Str("currency_pair".to_string()), Value::Str("id".to_string()), &[]);
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.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("_".to_string()), Value::Str("spot".to_string())]));
m.insert("marginMode".to_string(), Value::Null);
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_114 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_options_get_contracts_contract(&[__ws_arg_114]).await;
return self.parse_option(response.clone(), &[Value::Null, market.clone()]);
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 is_equal(&self.markets, &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("underlying".to_string(), add(&get_value(¤cy, &Value::Str("code".to_string())), &Value::Str("_USDT".to_string())));
m
});
let __ws_arg_115 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_options_get_contracts(&[__ws_arg_115]).await;
return self.parse_option_chain(self.to_array(response.clone()), &[Value::Null, Value::Str("name".to_string())]);
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", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_timestamp(chain.clone(), Value::Str("create_time".to_string()), &[]);
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(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("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.clone(), "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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_equal(&symbolsLength, &Value::Int(1)) {
market = self.market(get_value(&symbols, &Value::Int(0)));
}
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchPositionsHistory".to_string()), &[market.clone(), params.clone(), Value::Str("swap".to_string())]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.prepare_request(&[market.clone(), marketType.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
let __ws_arg_116 = self.extend(request.clone(), &[params.clone()]);
response = self.private_futures_get_settle_position_close(&[__ws_arg_116]).await;
} else if is_equal(&marketType, &Value::Str("future".to_string())) {
let __ws_arg_117 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delivery_get_settle_position_close(&[__ws_arg_117]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&self.id, &Value::Str(" fetchPositionsHistory() does not support markets of type ".to_string())), &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::List(vec![]);
if !is_equal(&response, &Value::Null) {
responseList = self.to_array(response.clone());
}
return self.parse_positions(responseList.clone(), &[symbols.clone(), params.clone()]);
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 is_equal(&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.clone(), "label", &[]);
if !is_equal(&label, &Value::Null) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), label.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}