// 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 HtxCore {
pub exchange: crate::exchange::Exchange,
}
impl HtxCore {
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 = HtxCore::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 HtxCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_order(self, order, &[market.clone()])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::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 HtxCore.
HtxCore::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 HtxCore.
HtxCore::parse_deposit_address(self, depositAddress, &[currency.clone()])
}
fn parse_last_price(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_last_price(self, entry, &[market.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::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 HtxCore.
HtxCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::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 HtxCore.
HtxCore::parse_liquidation(self, liquidation, &[market.clone()])
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_account(self, account)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::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 HtxCore.
HtxCore::parse_borrow_interest(self, info, &[market.clone()])
}
fn parse_adl_rank(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_adl_rank(self, info, &[market.clone()])
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::parse_income(self, info, &[market.clone()])
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::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 HtxCore.
HtxCore::parse_deposit_withdraw_fee(self, fee, &[currency.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on HtxCore.
HtxCore::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 HtxCore.
HtxCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for HtxCore {
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 {
"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_all_orders_after" => self.cancel_all_orders_after(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cost_to_precision" => self.cost_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"create_contract_order_request" => self.create_contract_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_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_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_spot_order_request" => self.create_spot_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_trailing_percent_order" => self.create_trailing_percent_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_account_id_by_type" => self.fetch_account_id_by_type(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_accounts" => self.fetch_accounts(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"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_canceled_orders" => self.fetch_canceled_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_contract_orders" => self.fetch_closed_contract_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_spot_orders" => self.fetch_closed_spot_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_orders" => self.fetch_contract_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_isolated_borrow_rates" => self.fetch_isolated_borrow_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_last_prices" => self.fetch_last_prices(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&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_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets_by_type_and_sub_type" => self.fetch_markets_by_type_and_sub_type(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,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_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_interests" => self.fetch_open_interests(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_adl_rank" => self.fetch_positions_adl_rank(&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_order_trades" => self.fetch_spot_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_orders" => self.fetch_spot_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_orders_by_states" => self.fetch_spot_orders_by_states(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_status" => self.fetch_status(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_limits" => self.fetch_trading_limits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_limits_by_id" => self.fetch_trading_limits_by_id(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transfers" => self.fetch_transfers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdraw_addresses" => self.fetch_withdraw_addresses(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"network_code_to_id" => self.network_code_to_id(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"network_id_to_code" => self.network_id_to_code(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"nonce" => self.nonce(),
"parse_account" => self.parse_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_adl_rank" => self.parse_adl_rank(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_borrow_interest" => self.parse_borrow_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_cancel_orders" => self.parse_cancel_orders(args.get(0).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_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_income" => self.parse_income(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_isolated_borrow_rate" => self.parse_isolated_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_last_price" => self.parse_last_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_liquidation" => self.parse_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_balance_helper" => self.parse_margin_balance_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)),
"parse_margin_loan" => self.parse_margin_loan(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_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_limits" => self.parse_trading_limits(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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,
"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()[..]),
"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,
"try_get_symbol_from_future_markets" => self.try_get_symbol_from_future_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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 HtxCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for HtxCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl HtxCore {
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("htx".to_string()));
m.insert("name".to_string(), Value::Str("HTX".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("CN".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("userAgent".to_string(), get_value(&self.userAgents, &Value::Str("chrome100".to_string())));
m.insert("certified".to_string(), Value::Bool(true));
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("hostname".to_string(), Value::Str("api.huobi.pro".to_string()));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Null);
m.insert("addMargin".to_string(), Value::Null);
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("cancelAllOrdersAfter".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Null);
m.insert("createMarketBuyOrderWithCost".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("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(true));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Null);
m.insert("fetchBorrowInterest".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistories".to_string(), Value::Null);
m.insert("fetchBorrowRateHistory".to_string(), Value::Null);
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrder".to_string(), Value::Null);
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("fetchDeposit".to_string(), Value::Null);
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Null);
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("fetchIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(true));
m.insert("fetchL3OrderBook".to_string(), Value::Null);
m.insert("fetchLastPrices".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Null);
m.insert("fetchLeverage".to_string(), Value::Bool(false));
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("fetchMarketLeverageTiers".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(true));
m.insert("fetchOpenInterests".to_string(), Value::Bool(true));
m.insert("fetchOpenOrder".to_string(), Value::Null);
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Null);
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionADLRank".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsADLRank".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(true));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTradingLimits".to_string(), Value::Bool(true));
m.insert("fetchTransactionFee".to_string(), Value::Null);
m.insert("fetchTransactionFees".to_string(), Value::Null);
m.insert("fetchTransactions".to_string(), Value::Null);
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchWithdrawAddresses".to_string(), Value::Bool(true));
m.insert("fetchWithdrawal".to_string(), Value::Null);
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Null);
m.insert("reduceMargin".to_string(), Value::Null);
m.insert("repayCrossMargin".to_string(), Value::Bool(true));
m.insert("repayIsolatedMargin".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::Null);
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1min".to_string()));
m.insert("5m".to_string(), Value::Str("5min".to_string()));
m.insert("15m".to_string(), Value::Str("15min".to_string()));
m.insert("30m".to_string(), Value::Str("30min".to_string()));
m.insert("1h".to_string(), Value::Str("60min".to_string()));
m.insert("4h".to_string(), Value::Str("4hour".to_string()));
m.insert("1d".to_string(), Value::Str("1day".to_string()));
m.insert("1w".to_string(), Value::Str("1week".to_string()));
m.insert("1M".to_string(), Value::Str("1mon".to_string()));
m.insert("1y".to_string(), Value::Str("1year".to_string()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/1294454/76137448-22748a80-604e-11ea-8069-6e389271911d.jpg".to_string()));
m.insert("hostnames".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".to_string(), Value::Str("api.hbdm.vn".to_string()));
m.insert("spot".to_string(), Value::Str("api.huobi.pro".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("https://{hostname}".to_string()));
m.insert("contract".to_string(), Value::Str("https://{hostname}".to_string()));
m.insert("spot".to_string(), Value::Str("https://{hostname}".to_string()));
m.insert("public".to_string(), Value::Str("https://{hostname}".to_string()));
m.insert("private".to_string(), Value::Str("https://{hostname}".to_string()));
m.insert("v2Public".to_string(), Value::Str("https://{hostname}".to_string()));
m.insert("v2Private".to_string(), Value::Str("https://{hostname}".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.huobi.com".to_string()));
m.insert("referral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Str("https://www.htx.com/invite/en-us/1h?invite_code=6rmm2223".to_string()));
m.insert("discount".to_string(), Value::Float(0.15));
m
}));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://huobiapi.github.io/docs/spot/v1/en/".to_string()), Value::Str("https://huobiapi.github.io/docs/dm/v1/en/".to_string()), Value::Str("https://huobiapi.github.io/docs/coin_margined_swap/v1/en/".to_string()), Value::Str("https://huobiapi.github.io/docs/usdt_swap/v1/en/".to_string()), Value::Str("https://www.huobi.com/en-us/opend/newApiPages/".to_string())]));
m.insert("fees".to_string(), Value::Str("https://www.huobi.com/about/fee/".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2Public".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("reference/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("v2Private".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("account/ledger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/withdraw/quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/withdraw/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("reference/transact-fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/asset-valuation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("point/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("sub-user/user-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/user-state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/account-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/query-deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("user/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("user/uid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("algo-orders/opening".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("algo-orders/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("algo-orders/specific".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/offers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/offer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("etp/reference".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("etp/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("etp/transaction".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("etp/rebalance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("etp/limit".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("account/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("point/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("sub-user/management".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/creation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/tradable-market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/transferability".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/api-key-generation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/api-key-modification".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/api-key-deletion".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sub-user/deduct-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("algo-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("algo-orders/cancel-all-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("algo-orders/cancellation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/offer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/cancellation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("c2c/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("etp/creation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("etp/redemption".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("etp/{transactId}/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("etp/batch-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m
}));
m
}));
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("common/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/currencys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/timestamp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/exchange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("settings/currencys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("account/accounts/{id}/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("account/accounts/{sub-uid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("cross-margin/loan-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/loan-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fee/fee-rate/get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("order/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("order/orders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("order/orders/{id}/matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("order/orders/getClientOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("query/deposit-withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/loan-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("margin/accounts/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("cross-margin/loan-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cross-margin/accounts/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("points/actions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("points/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("subuser/aggregate-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("stable-coin/exchange_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("stable-coin/quote".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("account/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/batch-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("order/orders/place".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("order/orders/submitCancelClientOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("order/orders/batchCancelOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("order/orders/{id}/submitcancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("order/orders/batchcancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("dw/withdraw/api/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("dw/withdraw-virtual/{id}/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("dw/transfer-in/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("dw/transfer-out/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("margin/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("margin/orders/{id}/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("cross-margin/transfer-in".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cross-margin/transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cross-margin/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("cross-margin/orders/{id}/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("stable-coin/exchange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("subuser/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2/market-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/common/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/common/currencys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/settings/common/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/reference/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/common/timestamp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/common/exchange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/settings/common/chains".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/settings/common/currencys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/settings/common/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/settings/common/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/settings/common/market-symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/history/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/history/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/detail/merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/history/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/etp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/etp/reference".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/etp/rebalance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1/account/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/account/accounts/{account-id}/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v2/account/valuation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/account/asset-valuation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/account/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("v2/account/ledger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/point/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/account/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/account/withdraw/quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/account/withdraw/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/reference/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/query/deposit-withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/query/withdraw/client-order-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/user/uid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/user-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/user-state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/account-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/query-deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/subuser/aggregate-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v1/account/accounts/{sub-uid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/order/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/orders/{order-id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/orders/getClientOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/orders/{order-id}/matchresult".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/orders/{order-id}/matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/order/matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/reference/transact-fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/algo-orders/opening".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/algo-orders/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/algo-orders/specific".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/margin/loan-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/margin/loan-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/margin/accounts/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/cross-margin/loan-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/cross-margin/loan-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/cross-margin/accounts/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/account/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/universal_transfer_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("v1/stable-coin/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/stable_coin/exchange_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/etp/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/etp/transaction".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/etp/limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1/account/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/futures/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/point/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/account/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/dw/withdraw/api/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/dw/withdraw-virtual/{withdraw-id}/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/deduct-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/creation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/management".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/tradable-market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/transferability".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/api-key-generation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/api-key-modification".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/sub-user/api-key-deletion".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/subuser/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v1/trust/user/active/credit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v1/order/orders/place".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/order/batch-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/auto/place".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/order/orders/{order-id}/submitcancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/order/orders/submitCancelClientOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.2));
m
}));
m.insert("v1/order/orders/batchCancelOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v1/order/orders/batchcancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("v2/algo-orders/cancel-all-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/algo-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/algo-orders/cancellation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/account/repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v1/dw/transfer-in/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v1/dw/transfer-out/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v1/margin/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v1/margin/orders/{order-id}/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v1/cross-margin/transfer-in".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/cross-margin/transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/cross-margin/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/cross-margin/orders/{order-id}/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/stable-coin/exchange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/etp/creation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/etp/redemption".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/etp/{transactId}/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v2/etp/batch-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m
}));
m
}));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/timestamp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("heartbeat/".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_contract_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_query_elements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_price_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_open_interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_delivery_price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/bbo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/history/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/mark_price_kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/detail/merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/detail/batch_merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/market/detail/batch_merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/history/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_risk_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_insurance_fund".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_adjustfactor".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_his_open_interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_ladder_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_api_state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_elite_account_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_elite_position_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_liquidation_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_settlement_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/basis".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_estimated_settlement_price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/contract_liquidation_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_contract_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_query_elements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_price_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_open_interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-ex/market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-ex/market/bbo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-ex/market/history/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/swap_mark_price_kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-ex/market/detail/merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/swap-ex/market/detail/batch_merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/swap_premium_index_kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-ex/market/detail/batch_merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-ex/market/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-ex/market/history/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_risk_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_insurance_fund".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_adjustfactor".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_his_open_interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_ladder_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_api_state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_elite_account_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_elite_position_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_estimated_settlement_price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_liquidation_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_settlement_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_funding_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_batch_funding_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_historical_funding_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v3/swap_liquidation_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/swap_estimated_rate_kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/swap_basis".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_contract_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_query_elements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_price_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-ex/market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-ex/market/bbo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-ex/market/history/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/linear_swap_mark_price_kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-ex/market/detail/merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-ex/market/detail/batch_merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/linear-swap-ex/market/detail/batch_merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-ex/market/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-ex/market/history/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/linear-swap-api/v1/swap_insurance_fund".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_adjustfactor".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_cross_adjustfactor".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_his_open_interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_ladder_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_cross_ladder_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_api_state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_elite_account_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_elite_position_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_settlement_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v3/swap_liquidation_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/linear_swap_premium_index_kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/linear_swap_estimated_rate_kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("index/market/history/linear_swap_basis".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("linear-swap-api/v1/swap_estimated_settlement_price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/market/funding_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/funding_rate_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/open_interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/liquidation_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/settlement_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/elite_account_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/elite_position_ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/estimated_settlement_price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/price_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m
}));
m
}));
m.insert("private".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("api/v1/contract_sub_auth_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_api_trading_status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_sub_auth_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_api_trading_status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/asset_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/account/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/account/fee_deduction_currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/trade/position/opens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/order/opens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/order/details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/position/lever".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/position/mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/position/risk/limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/position/risk/limit_tier".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/market/risk/limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/assets_deduction_currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/market/multi_assets_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.125));
m
}));
m.insert("v5/algo/order/opens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/algo/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/algo/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/contract_balance_valuation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_account_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_position_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_sub_auth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_sub_account_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_sub_account_info_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_sub_account_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_sub_position_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_financial_record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_financial_record_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_user_settlement_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_order_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_transfer_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_position_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_account_position_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_master_sub_transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_master_sub_transfer_record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_available_level_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/contract_financial_record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/contract_financial_record_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract-cancel-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_batchorder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_switch_lever_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("api/v1/lightning_close_position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_order_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_order_detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_hisorders_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_matchresults_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/contract_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/contract_hisorders_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/contract_matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/contract_matchresults_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_trigger_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_trigger_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_trigger_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_trigger_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_trigger_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_tpsl_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_tpsl_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_tpsl_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_tpsl_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_tpsl_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_relation_tpsl_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_track_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_track_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_track_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_track_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/contract_track_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_balance_valuation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_account_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_position_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_account_position_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_sub_auth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_sub_account_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_sub_account_info_list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_sub_account_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_sub_position_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_financial_record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_financial_record_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_user_settlement_records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_available_level_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_order_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_transfer_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_position_limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_master_sub_transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_master_sub_transfer_record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v3/swap_financial_record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v3/swap_financial_record_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap-cancel-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_batchorder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_lightning_close_position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_switch_lever_rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("swap-api/v1/swap_order_info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_order_detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_hisorders_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_matchresults_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v3/swap_matchresults".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v3/swap_matchresults_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v3/swap_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v3/swap_hisorders_exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_trigger_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_trigger_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_trigger_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_trigger_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_trigger_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_tpsl_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_tpsl_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_tpsl_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_tpsl_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_tpsl_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_relation_tpsl_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_track_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_track_cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_track_cancelall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_track_openorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("swap-api/v1/swap_track_hisorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/asset_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("v5/trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/batch_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/cancel_order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/cancel_batch_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/cancel_all_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/cancel-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/trade/position_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/position/lever".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/position/mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/position/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/account/fee_deduction_currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.20834));
m
}));
m.insert("v5/algo/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m.insert("v5/algo/cancel_orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.41679));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("get".to_string()));
m.insert("tierBased".to_string(), Value::Bool(false));
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
}));
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract is restricted of closing positions on API. Please contact customer service".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("maintain".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("API key has no permission".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m
}));
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("403".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1010".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("1003".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1013".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("1017".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("1034".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1036".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1039".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1041".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1047".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("1048".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("1061".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("1051".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1066".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("1067".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1094".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1220".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("1303".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("1461".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("4007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("bad-request".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("validation-format-error".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("validation-constraints-required".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("base-date-limit-error".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("api-not-support-temp-addr".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("timeout".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("gateway-internal-error".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("account-frozen-balance-insufficient-error".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("invalid-amount".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-amount-min-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-amount-max-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-marketorder-amount-min-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-price-min-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-price-max-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-price-buy-min-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-price-buy-max-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-price-sell-min-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-limitorder-price-sell-max-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-stop-order-hit-trigger".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-value-min-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-invalid-price".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-holding-limit-failed".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-orderprice-precision-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-etp-nav-price-max-error".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("order-orderstate-error".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("order-queryorder-invalid".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("order-update-error".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("api-signature-check-failed".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("api-signature-not-valid".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("base-record-invalid".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("base-symbol-trade-disabled".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("base-symbol-error".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("system-maintenance".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("base-request-exceed-frequency-limit".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("rate-too-many-requests".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("invalid symbol".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("symbol trade not open now".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("require-symbol".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("invalid-address".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("base-currency-chain-error".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("dw-insufficient-balance".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("base-withdraw-fee-error".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("dw-withdraw-min-limit".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("request limit".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("include_OS_certificates".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("types".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Bool(true));
m.insert("linear".to_string(), Value::Bool(true));
m.insert("inverse".to_string(), Value::Bool(true));
m
}));
m
}));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("useHistoricalEndpointForSpot".to_string(), Value::Bool(true));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("includeFee".to_string(), Value::Bool(false));
m
}));
m.insert("defaultType".to_string(), Value::Str("spot".to_string()));
m.insert("defaultSubType".to_string(), Value::Str("linear".to_string()));
m.insert("defaultNetwork".to_string(), Value::Str("ERC20".to_string()));
m.insert("defaultNetworks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("USDT".to_string(), Value::Str("TRC20".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TRC20".to_string(), Value::Str("TRX".to_string()));
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("SOL".to_string(), Value::Str("SOLANA".to_string()));
m.insert("HRC20".to_string(), Value::Str("HECO".to_string()));
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("XMR".to_string(), Value::Str("XMR".to_string()));
m.insert("LTC".to_string(), Value::Str("LTC".to_string()));
m.insert("XRP".to_string(), Value::Str("XRP".to_string()));
m.insert("XLM".to_string(), Value::Str("XLM".to_string()));
m.insert("CRONOS".to_string(), Value::Str("CRO".to_string()));
m.insert("CRO".to_string(), Value::Str("CRO".to_string()));
m.insert("GLMR".to_string(), Value::Str("GLMR".to_string()));
m.insert("POLYGON".to_string(), Value::Str("MATIC".to_string()));
m.insert("MATIC".to_string(), Value::Str("MATIC".to_string()));
m.insert("BTT".to_string(), Value::Str("BTT".to_string()));
m.insert("CUBE".to_string(), Value::Str("CUBE".to_string()));
m.insert("IOST".to_string(), Value::Str("IOST".to_string()));
m.insert("NEO".to_string(), Value::Str("NEO".to_string()));
m.insert("KLAY".to_string(), Value::Str("KLAY".to_string()));
m.insert("EOS".to_string(), Value::Str("EOS".to_string()));
m.insert("THETA".to_string(), Value::Str("THETA".to_string()));
m.insert("NAS".to_string(), Value::Str("NAS".to_string()));
m.insert("NULS".to_string(), Value::Str("NULS".to_string()));
m.insert("QTUM".to_string(), Value::Str("QTUM".to_string()));
m.insert("FTM".to_string(), Value::Str("FTM".to_string()));
m.insert("CELO".to_string(), Value::Str("CELO".to_string()));
m.insert("DOGE".to_string(), Value::Str("DOGE".to_string()));
m.insert("DOGECHAIN".to_string(), Value::Str("DOGECHAIN".to_string()));
m.insert("NEAR".to_string(), Value::Str("NEAR".to_string()));
m.insert("STEP".to_string(), Value::Str("STEP".to_string()));
m.insert("BITCI".to_string(), Value::Str("BITCI".to_string()));
m.insert("CARDANO".to_string(), Value::Str("ADA".to_string()));
m.insert("ADA".to_string(), Value::Str("ADA".to_string()));
m.insert("ETC".to_string(), Value::Str("ETC".to_string()));
m.insert("LUK".to_string(), Value::Str("LUK".to_string()));
m.insert("MINEPLEX".to_string(), Value::Str("MINEPLEX".to_string()));
m.insert("DASH".to_string(), Value::Str("DASH".to_string()));
m.insert("ZEC".to_string(), Value::Str("ZEC".to_string()));
m.insert("IOTA".to_string(), Value::Str("IOTA".to_string()));
m.insert("NEON3".to_string(), Value::Str("NEON3".to_string()));
m.insert("XEM".to_string(), Value::Str("XEM".to_string()));
m.insert("HC".to_string(), Value::Str("HC".to_string()));
m.insert("LSK".to_string(), Value::Str("LSK".to_string()));
m.insert("DCR".to_string(), Value::Str("DCR".to_string()));
m.insert("BTG".to_string(), Value::Str("BTG".to_string()));
m.insert("STEEM".to_string(), Value::Str("STEEM".to_string()));
m.insert("BTS".to_string(), Value::Str("BTS".to_string()));
m.insert("ICX".to_string(), Value::Str("ICX".to_string()));
m.insert("WAVES".to_string(), Value::Str("WAVES".to_string()));
m.insert("CMT".to_string(), Value::Str("CMT".to_string()));
m.insert("BTM".to_string(), Value::Str("BTM".to_string()));
m.insert("VET".to_string(), Value::Str("VET".to_string()));
m.insert("XZC".to_string(), Value::Str("XZC".to_string()));
m.insert("ACT".to_string(), Value::Str("ACT".to_string()));
m.insert("SMT".to_string(), Value::Str("SMT".to_string()));
m.insert("BCD".to_string(), Value::Str("BCD".to_string()));
m.insert("WAX".to_string(), Value::Str("WAX1".to_string()));
m.insert("WICC".to_string(), Value::Str("WICC".to_string()));
m.insert("ELF".to_string(), Value::Str("ELF".to_string()));
m.insert("ZIL".to_string(), Value::Str("ZIL".to_string()));
m.insert("ELA".to_string(), Value::Str("ELA".to_string()));
m.insert("BCX".to_string(), Value::Str("BCX".to_string()));
m.insert("SBTC".to_string(), Value::Str("SBTC".to_string()));
m.insert("BIFI".to_string(), Value::Str("BIFI".to_string()));
m.insert("CTXC".to_string(), Value::Str("CTXC".to_string()));
m.insert("WAN".to_string(), Value::Str("WAN".to_string()));
m.insert("POLYX".to_string(), Value::Str("POLYX".to_string()));
m.insert("PAI".to_string(), Value::Str("PAI".to_string()));
m.insert("WTC".to_string(), Value::Str("WTC".to_string()));
m.insert("DGB".to_string(), Value::Str("DGB".to_string()));
m.insert("XVG".to_string(), Value::Str("XVG".to_string()));
m.insert("AAC".to_string(), Value::Str("AAC".to_string()));
m.insert("AE".to_string(), Value::Str("AE".to_string()));
m.insert("SEELE".to_string(), Value::Str("SEELE".to_string()));
m.insert("BCV".to_string(), Value::Str("BCV".to_string()));
m.insert("GRS".to_string(), Value::Str("GRS".to_string()));
m.insert("ARDR".to_string(), Value::Str("ARDR".to_string()));
m.insert("NANO".to_string(), Value::Str("NANO".to_string()));
m.insert("ZEN".to_string(), Value::Str("ZEN".to_string()));
m.insert("RBTC".to_string(), Value::Str("RBTC".to_string()));
m.insert("BSV".to_string(), Value::Str("BSV".to_string()));
m.insert("GAS".to_string(), Value::Str("GAS".to_string()));
m.insert("XTZ".to_string(), Value::Str("XTZ".to_string()));
m.insert("LAMB".to_string(), Value::Str("LAMB".to_string()));
m.insert("CVNT1".to_string(), Value::Str("CVNT1".to_string()));
m.insert("DOCK".to_string(), Value::Str("DOCK".to_string()));
m.insert("SC".to_string(), Value::Str("SC".to_string()));
m.insert("KMD".to_string(), Value::Str("KMD".to_string()));
m.insert("ETN".to_string(), Value::Str("ETN".to_string()));
m.insert("TOP".to_string(), Value::Str("TOP".to_string()));
m.insert("IRIS".to_string(), Value::Str("IRIS".to_string()));
m.insert("UGAS".to_string(), Value::Str("UGAS".to_string()));
m.insert("TT".to_string(), Value::Str("TT".to_string()));
m.insert("NEWTON".to_string(), Value::Str("NEWTON".to_string()));
m.insert("VSYS".to_string(), Value::Str("VSYS".to_string()));
m.insert("FSN".to_string(), Value::Str("FSN".to_string()));
m.insert("BHD".to_string(), Value::Str("BHD".to_string()));
m.insert("ONE".to_string(), Value::Str("ONE".to_string()));
m.insert("EM".to_string(), Value::Str("EM".to_string()));
m.insert("CKB".to_string(), Value::Str("CKB".to_string()));
m.insert("EOSS".to_string(), Value::Str("EOSS".to_string()));
m.insert("HIVE".to_string(), Value::Str("HIVE".to_string()));
m.insert("RVN".to_string(), Value::Str("RVN".to_string()));
m.insert("DOT".to_string(), Value::Str("DOT".to_string()));
m.insert("KSM".to_string(), Value::Str("KSM".to_string()));
m.insert("BAND".to_string(), Value::Str("BAND".to_string()));
m.insert("OEP4".to_string(), Value::Str("OEP4".to_string()));
m.insert("NBS".to_string(), Value::Str("NBS".to_string()));
m.insert("FIS".to_string(), Value::Str("FIS".to_string()));
m.insert("AR".to_string(), Value::Str("AR".to_string()));
m.insert("HBAR".to_string(), Value::Str("HBAR".to_string()));
m.insert("FIL".to_string(), Value::Str("FIL".to_string()));
m.insert("MASS".to_string(), Value::Str("MASS".to_string()));
m.insert("KAVA".to_string(), Value::Str("KAVA".to_string()));
m.insert("XYM".to_string(), Value::Str("XYM".to_string()));
m.insert("ENJ".to_string(), Value::Str("ENJ".to_string()));
m.insert("CRUST".to_string(), Value::Str("CRUST".to_string()));
m.insert("ICP".to_string(), Value::Str("ICP".to_string()));
m.insert("CSPR".to_string(), Value::Str("CSPR".to_string()));
m.insert("FLOW".to_string(), Value::Str("FLOW".to_string()));
m.insert("IOTX".to_string(), Value::Str("IOTX".to_string()));
m.insert("LAT".to_string(), Value::Str("LAT".to_string()));
m.insert("APT".to_string(), Value::Str("APT".to_string()));
m.insert("XCH".to_string(), Value::Str("XCH".to_string()));
m.insert("MINA".to_string(), Value::Str("MINA".to_string()));
m.insert("XEC".to_string(), Value::Str("ECASH".to_string()));
m.insert("XPRT".to_string(), Value::Str("XPRT".to_string()));
m.insert("CCA".to_string(), Value::Str("ACA".to_string()));
m.insert("AOTI".to_string(), Value::Str("COTI".to_string()));
m.insert("AKT".to_string(), Value::Str("AKT".to_string()));
m.insert("ARS".to_string(), Value::Str("ARS".to_string()));
m.insert("ASTR".to_string(), Value::Str("ASTR".to_string()));
m.insert("AZERO".to_string(), Value::Str("AZERO".to_string()));
m.insert("BLD".to_string(), Value::Str("BLD".to_string()));
m.insert("BRISE".to_string(), Value::Str("BRISE".to_string()));
m.insert("CORE".to_string(), Value::Str("CORE".to_string()));
m.insert("DESO".to_string(), Value::Str("DESO".to_string()));
m.insert("DFI".to_string(), Value::Str("DFI".to_string()));
m.insert("EGLD".to_string(), Value::Str("EGLD".to_string()));
m.insert("ERG".to_string(), Value::Str("ERG".to_string()));
m.insert("ETHF".to_string(), Value::Str("ETHFAIR".to_string()));
m.insert("ETHW".to_string(), Value::Str("ETHW".to_string()));
m.insert("EVMOS".to_string(), Value::Str("EVMOS".to_string()));
m.insert("FIO".to_string(), Value::Str("FIO".to_string()));
m.insert("FLR".to_string(), Value::Str("FLR".to_string()));
m.insert("FINSCHIA".to_string(), Value::Str("FINSCHIA".to_string()));
m.insert("KMA".to_string(), Value::Str("KMA".to_string()));
m.insert("KYVE".to_string(), Value::Str("KYVE".to_string()));
m.insert("MEV".to_string(), Value::Str("MEV".to_string()));
m.insert("MOVR".to_string(), Value::Str("MOVR".to_string()));
m.insert("NODL".to_string(), Value::Str("NODL".to_string()));
m.insert("OAS".to_string(), Value::Str("OAS".to_string()));
m.insert("OSMO".to_string(), Value::Str("OSMO".to_string()));
m.insert("PAYCOIN".to_string(), Value::Str("PAYCOIN".to_string()));
m.insert("POKT".to_string(), Value::Str("POKT".to_string()));
m.insert("PYG".to_string(), Value::Str("PYG".to_string()));
m.insert("REI".to_string(), Value::Str("REI".to_string()));
m.insert("SCRT".to_string(), Value::Str("SCRT".to_string()));
m.insert("SDN".to_string(), Value::Str("SDN".to_string()));
m.insert("SEI".to_string(), Value::Str("SEI".to_string()));
m.insert("SGB".to_string(), Value::Str("SGB".to_string()));
m.insert("SUI".to_string(), Value::Str("SUI".to_string()));
m.insert("SXP".to_string(), Value::Str("SOLAR".to_string()));
m.insert("SYS".to_string(), Value::Str("SYS".to_string()));
m.insert("TENET".to_string(), Value::Str("TENET".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("UNQ".to_string(), Value::Str("UNQ".to_string()));
m.insert("UYU".to_string(), Value::Str("UYU".to_string()));
m.insert("WEMIX".to_string(), Value::Str("WEMIX".to_string()));
m.insert("XDC".to_string(), Value::Str("XDC".to_string()));
m.insert("XPLA".to_string(), Value::Str("XPLA".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MATIC".to_string(), Value::Str("MATIC".to_string()));
m
}));
m.insert("fetchOrdersByStatesMethod".to_string(), Value::Str("spot_private_get_v1_order_orders".to_string()));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("language".to_string(), Value::Str("en-US".to_string()));
m.insert("broker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("AA03022abc".to_string()));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("pro".to_string()));
m.insert("funding".to_string(), Value::Str("pro".to_string()));
m.insert("future".to_string(), Value::Str("futures".to_string()));
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("spot".to_string()));
m.insert("margin".to_string(), Value::Str("margin".to_string()));
m.insert("otc".to_string(), Value::Str("otc".to_string()));
m.insert("point".to_string(), Value::Str("point".to_string()));
m.insert("super-margin".to_string(), Value::Str("super-margin".to_string()));
m.insert("investment".to_string(), Value::Str("investment".to_string()));
m.insert("borrow".to_string(), Value::Str("borrow".to_string()));
m.insert("grid-trading".to_string(), Value::Str("grid-trading".to_string()));
m.insert("deposit-earning".to_string(), Value::Str("deposit-earning".to_string()));
m.insert("otc-options".to_string(), Value::Str("otc-options".to_string()));
m.insert("linear-swap".to_string(), Value::Str("swap".to_string()));
m.insert("swap".to_string(), Value::Str("swap".to_string()));
m.insert("futures".to_string(), Value::Str("future".to_string()));
m
}));
m.insert("typesByAccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pro".to_string(), Value::Str("spot".to_string()));
m.insert("futures".to_string(), Value::Str("future".to_string()));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopOrderTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stop-limit".to_string(), Value::Bool(true));
m.insert("buy-stop-limit".to_string(), Value::Bool(true));
m.insert("sell-stop-limit".to_string(), Value::Bool(true));
m.insert("stop-limit-fok".to_string(), Value::Bool(true));
m.insert("buy-stop-limit-fok".to_string(), Value::Bool(true));
m.insert("sell-stop-limit-fok".to_string(), Value::Bool(true));
m
}));
m.insert("limitOrderTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Bool(true));
m.insert("buy-limit".to_string(), Value::Bool(true));
m.insert("sell-limit".to_string(), Value::Bool(true));
m.insert("ioc".to_string(), Value::Bool(true));
m.insert("buy-ioc".to_string(), Value::Bool(true));
m.insert("sell-ioc".to_string(), Value::Bool(true));
m.insert("limit-maker".to_string(), Value::Bool(true));
m.insert("buy-limit-maker".to_string(), Value::Bool(true));
m.insert("sell-limit-maker".to_string(), Value::Bool(true));
m.insert("stop-limit".to_string(), Value::Bool(true));
m.insert("buy-stop-limit".to_string(), Value::Bool(true));
m.insert("sell-stop-limit".to_string(), Value::Bool(true));
m.insert("limit-fok".to_string(), Value::Bool(true));
m.insert("buy-limit-fok".to_string(), Value::Bool(true));
m.insert("sell-limit-fok".to_string(), Value::Bool(true));
m.insert("stop-limit-fok".to_string(), Value::Bool(true));
m.insert("buy-stop-limit-fok".to_string(), Value::Bool(true));
m.insert("sell-stop-limit-fok".to_string(), Value::Bool(true));
m
}));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("NGL".to_string(), Value::Str("GFNGL".to_string()));
m.insert("GET".to_string(), Value::Str("THEMIS".to_string()));
m.insert("GTC".to_string(), Value::Str("GAMECOM".to_string()));
m.insert("HIT".to_string(), Value::Str("HITCHAIN".to_string()));
m.insert("PNT".to_string(), Value::Str("PENTA".to_string()));
m.insert("SBTC".to_string(), Value::Str("SUPERBITCOIN".to_string()));
m.insert("SOUL".to_string(), Value::Str("SOULSAVER".to_string()));
m.insert("BIFI".to_string(), Value::Str("BITCOINFILE".to_string()));
m.insert("FUD".to_string(), Value::Str("FTX Users Debt".to_string()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(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(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
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(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("leverage".to_string(), Value::Bool(true));
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(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("limit".to_string(), Value::Int(500));
m.insert("daysBack".to_string(), Value::Int(120));
m.insert("untilDays".to_string(), Value::Int(2));
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(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".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("limit".to_string(), Value::Int(500));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(500));
m.insert("untilDays".to_string(), Value::Int(2));
m.insert("daysBack".to_string(), Value::Int(180));
m.insert("symbolRequired".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("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("untilDays".to_string(), Value::Int(2));
m.insert("limit".to_string(), Value::Int(500));
m.insert("daysBack".to_string(), Value::Int(180));
m.insert("daysBackCanceled".to_string(), divide(&Value::Int(1), &Value::Int(12)));
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("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("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("hedged".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(25));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".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(true));
m.insert("limit".to_string(), Value::Int(50));
m
}));
m.insert("fetchOrders".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(true));
m.insert("limit".to_string(), Value::Int(50));
m.insert("daysBack".to_string(), Value::Int(90));
m
}));
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(true));
m.insert("untilDays".to_string(), Value::Int(2));
m.insert("limit".to_string(), Value::Int(50));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("daysBackCanceled".to_string(), divide(&Value::Int(1), &Value::Int(12)));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(2000));
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("rollingWindowSize".to_string(), Value::Int(2000));
m
})]);
Value::Null
}
/*
* @method
* @name htx#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-market-status
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#query-whether-the-system-is-available // contractPublicGetHeartbeat
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// the former statuspage endpoints (status*.huobigroup.com) were
// decommissioned after the huobi -> htx rebrand and no longer resolve,
// so this method uses the live native endpoints instead
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchStatus".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut status: Value = Value::Null;
let mut eta: Value = Value::Null;
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.spot_public_get_v2_market_status(&[params.clone()]).await;
//
// {
// "code": 200,
// "message": "success",
// "data": {
// "marketStatus": 1, // 1 normal, 2 halted, 3 cancel-only
// "haltStartTime": 1614852011000, // only when halted
// "haltEndTime": 1614852400000 // only when the end time is estimable
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketStatus: Value = self.safe_integer_k(data.clone(), "marketStatus", &[]);
status = ternary(is_true(&(is_equal(&marketStatus, &Value::Int(1)))), Value::Str("ok".to_string()), Value::Str("maintenance".to_string()));
eta = self.safe_integer_k(data.clone(), "haltEndTime", &[]);
} else {
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchStatus".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
response = self.contract_public_get_heartbeat(&[params.clone()]).await;
//
// {
// "status": "ok",
// "data": {
// "heartbeat": 1, // 1 available, 0 unavailable
// "estimated_recovery_time": null,
// "swap_heartbeat": 1,
// "swap_estimated_recovery_time": null,
// "option_heartbeat": 1,
// "option_estimated_recovery_time": null,
// "linear_swap_heartbeat": 1,
// "linear_swap_estimated_recovery_time": null
// },
// "ts": 1557714418033 // stale on the exchange side, do not trust as an update time
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut heartbeatKey: Value = Value::Str("heartbeat".to_string());
let mut etaKey: Value = Value::Str("estimated_recovery_time".to_string());
if is_equal(&subType, &Value::Str("linear".to_string())) {
heartbeatKey = Value::Str("linear_swap_heartbeat".to_string());
etaKey = Value::Str("linear_swap_estimated_recovery_time".to_string());
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
heartbeatKey = Value::Str("swap_heartbeat".to_string());
etaKey = Value::Str("swap_estimated_recovery_time".to_string());
}
let mut heartbeat: Value = self.safe_integer(data.clone(), heartbeatKey.clone(), &[]);
status = ternary(is_true(&(is_equal(&heartbeat, &Value::Int(1)))), Value::Str("ok".to_string()), Value::Str("maintenance".to_string()));
eta = self.safe_integer(data.clone(), etaKey.clone(), &[]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), status.clone());
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), eta.clone());
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
m
});
Value::Null
}
/*
* @method
* @name htx#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-current-timestamp
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-current-system-timestamp
* @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 options: Value = self.safe_value_k(self.options.clone(), "fetchTime", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultType: Value = self.safe_string_k(self.options.clone(), "defaultType", &[Value::Str("spot".to_string())]);
let mut type_var: Value = self.safe_string_k(options.clone(), "type", &[defaultType.clone()]);
type_var = self.safe_string_k(params.clone(), "type", &[type_var.clone()]);
let mut response: Value = Value::Null;
if is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) {
response = self.contract_public_get_api_v1_timestamp(&[params.clone()]).await;
} else {
response = self.spot_public_get_v1_common_timestamp(&[params.clone()]).await;
}
return self.safe_integer2(response.clone(), Value::Str("data".to_string()), Value::Str("ts".to_string()), &[]);
Value::Null
}
pub fn parse_trading_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol":"btcusdt",
// "actualMakerRate":"0.002",
// "actualTakerRate":"0.002",
// "takerFeeRate":"0.002",
// "makerFeeRate":"0.002"
// }
//
let mut marketId: Value = self.safe_string_k(fee.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("maker".to_string(), self.safe_number_k(fee.clone(), "actualMakerRate", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee.clone(), "actualTakerRate", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name htx#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-current-fee-rate-applied-to-the-user
* @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("symbols".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v2_reference_transact_fee_rate(&[__ws_arg_0]).await;
//
// {
// "code":200,
// "data":[
// {
// "symbol":"btcusdt",
// "actualMakerRate":"0.002",
// "actualTakerRate":"0.002",
// "takerFeeRate":"0.002",
// "makerFeeRate":"0.002"
// }
// ],
// "success":true
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_value(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(first.clone(), &[market.clone()]);
Value::Null
}
pub async fn fetch_trading_limits(&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
}));
// this method should not be called directly, use loadTradingLimits () instead
// by default it will try load withdrawal fees of all currencies (with separate requests)
// however if you define symbols = [ 'ETH/BTC', 'LTC/BTC' ] in args it will only load those
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&symbols, &Value::Null) {
symbols = self.symbols.clone();
}
if is_equal(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" markets not loaded".to_string()))));
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_759: bool = true;
while { if !__for_first_759 { i = add(&i, &Value::Int(1)); } __for_first_759 = 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);
add_element_to_object(&mut result, &symbol, self.fetch_trading_limits_by_id(self.market_id(symbol.clone()), &[params.clone()]).await);
}
}
return result;
Value::Null
}
/*
* @ignore
* @method
* @name htx#fetchTradingLimitsById
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-current-fee-rate-applied-to-the-user
* @param {string} id market id
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the limits object of a market structure
*/
pub async fn fetch_trading_limits_by_id(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), id.clone());
m
});
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_public_get_v1_common_exchange(&[__ws_arg_1]).await;
return self.parse_trading_limits(self.safe_value_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), &[]);
Value::Null
}
pub fn parse_trading_limits(&self, mut limits: 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
}));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), limits.clone());
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(), self.safe_number_k(limits.clone(), "limit-order-must-greater-than", &[]));
m.insert("max".to_string(), self.safe_number_k(limits.clone(), "limit-order-must-less-than", &[]));
m
}));
m
}));
m
});
Value::Null
}
pub fn cost_to_precision(&self, mut symbol: Value, mut cost: Value) -> Value {
return self.decimal_to_precision(cost.clone(), Value::Int(crate::runtime::TRUNCATE), get_value(&get_value(&self.market(symbol.clone()), &Value::Str("precision".to_string())), &Value::Str("cost".to_string())), &[self.precisionMode.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchMarkets
* @description retrieves data on all markets for huobi
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-trading-symbol-v1-deprecated
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-contract-info
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-swap-info
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-swap-info
* @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;
}
let mut types: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMarkets".to_string()), Value::Str("types".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]); types = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut allMarkets: Value = Value::List(vec![]);
let mut promises: Value = Value::List(vec![]);
let mut keys: Value = object_keys(&types);
{
let mut i: Value = Value::Int(0);
let mut __for_first_760: bool = true;
while { if !__for_first_760 { i = add(&i, &Value::Int(1)); } __for_first_760 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
if is_equal(&self.safe_bool(types.clone(), key.clone(), &[]), &Value::Bool(true)) {
if is_equal(&key, &Value::Str("spot".to_string())) {
append_to_array(&mut promises, self.fetch_markets_by_type_and_sub_type(Value::Str("spot".to_string()), Value::Null, &[params.clone()]).await);
} else if is_equal(&key, &Value::Str("linear".to_string())) {
append_to_array(&mut promises, self.fetch_markets_by_type_and_sub_type(Value::Null, Value::Str("linear".to_string()), &[params.clone()]).await);
} else if is_equal(&key, &Value::Str("inverse".to_string())) {
append_to_array(&mut promises, self.fetch_markets_by_type_and_sub_type(Value::Str("swap".to_string()), Value::Str("inverse".to_string()), &[params.clone()]).await);
append_to_array(&mut promises, self.fetch_markets_by_type_and_sub_type(Value::Str("future".to_string()), Value::Str("inverse".to_string()), &[params.clone()]).await);
}
}
}
}
promises = promise_all(&promises).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_761: bool = true;
while { if !__for_first_761 { i = add(&i, &Value::Int(1)); } __for_first_761 = false; is_less_than(&i, &get_array_length(&promises)) } {
allMarkets = self.array_concat(allMarkets.clone(), get_value(&promises, &i));
}
}
return allMarkets;
Value::Null
}
/*
* @ignore
* @method
* @name htx#fetchMarketsByTypeAndSubType
* @description retrieves data on all markets of a certain type and/or subtype
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-trading-symbol-v1-deprecated
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-contract-info
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-swap-info
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-swap-info
* @param {string} [type] 'spot', 'swap' or 'future'
* @param {string} [subType] 'linear' or 'inverse'
* @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_by_type_and_sub_type(&mut self, mut type_var: Value, mut subType: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut isSpot: bool = is_equal(&type_var, &Value::Str("spot".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if !is_true(&isSpot) {
if is_equal(&subType, &Value::Str("linear".to_string())) {
add_element_to_object(&mut request, &Value::Str("business_type".to_string()), Value::Str("all".to_string())); // override default to fetch all linear markets
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_api_v1_swap_contract_info(&[__ws_arg_2]).await;
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
if is_equal(&type_var, &Value::Str("future".to_string())) {
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_api_v1_contract_contract_info(&[__ws_arg_3]).await;
} else if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_contract_info(&[__ws_arg_4]).await;
}
}
} else {
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_public_get_v1_common_symbols(&[__ws_arg_5]).await;
}
//
// spot
//
// {
// "status":"ok",
// "data":[
// {
// "base-currency":"xrp3s",
// "quote-currency":"usdt",
// "price-precision":4,
// "amount-precision":4,
// "symbol-partition":"innovation",
// "symbol":"xrp3susdt",
// "state":"online",
// "value-precision":8,
// "min-order-amt":0.01,
// "max-order-amt":1616.4353,
// "min-order-value":5,
// "limit-order-min-order-amt":0.01,
// "limit-order-max-order-amt":1616.4353,
// "limit-order-max-buy-amt":1616.4353,
// "limit-order-max-sell-amt":1616.4353,
// "sell-market-min-order-amt":0.01,
// "sell-market-max-order-amt":1616.4353,
// "buy-market-max-order-value":2500,
// "max-order-value":2500,
// "underlying":"xrpusdt",
// "mgmt-fee-rate":0.035000000000000000,
// "charge-time":"23:55:00",
// "rebal-time":"00:00:00",
// "rebal-threshold":-5,
// "init-nav":10.000000000000000000,
// "api-trading":"enabled",
// "tags":"etp,nav,holdinglimit"
// },
// ]
// }
//
// inverse (swap & future)
//
// {
// "status":"ok",
// "data":[
// {
// "symbol":"BTC",
// "contract_code":"BTC211126", /// BTC-USD in swap
// "contract_type":"this_week", // only in future
// "contract_size":100,
// "price_tick":0.1,
// "delivery_date":"20211126", // only in future
// "delivery_time":"1637913600000", // empty in swap
// "create_date":"20211112",
// "contract_status":1,
// "settlement_time":"1637481600000" // only in future
// "settlement_date":"16xxxxxxxxxxx" // only in swap
// },
// ...
// ],
// "ts":1637474595140
// }
//
// linear (swap & future)
//
// {
// "status":"ok",
// "data":[
// {
// "symbol":"BTC",
// "contract_code":"BTC-USDT-211231", // or "BTC-USDT" in swap
// "contract_size":0.001,
// "price_tick":0.1,
// "delivery_date":"20211231", // empty in swap
// "delivery_time":"1640937600000", // empty in swap
// "create_date":"20211228",
// "contract_status":1,
// "settlement_date":"1640764800000",
// "support_margin_mode":"cross", // "all" or "cross"
// "business_type":"futures", // "swap" or "futures"
// "pair":"BTC-USDT",
// "contract_type":"this_week", // "swap", "this_week", "next_week", "quarter"
// "trade_partition":"USDT",
// }
// ],
// "ts":1640736207263
// }
//
let mut markets: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut numMarkets: Value = get_array_length(&markets);
if is_less_than(&numMarkets, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::operation_failed(add(&add(&self.id, &Value::Str(" fetchMarkets() returned an empty response: ".to_string())), &self.json(response.clone()))));
}
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_762: bool = true;
while { if !__for_first_762 { i = add(&i, &Value::Int(1)); } __for_first_762 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut market: Value = get_value(&markets, &i);
let mut market: Value = get_value(&markets, &i);
let mut baseId: Value = Value::Null;
let mut quoteId: Value = Value::Null;
let mut settleId: Value = Value::Null;
let mut id: Value = Value::Null;
let mut lowercaseId: Value = Value::Null;
let mut contract: Value = (Value::Bool(in_op(&market, &Value::Str("contract_code".to_string()))));
let mut spot: Value = Value::Bool(!is_true(&contract));
let mut swap: Value = Value::Bool(false);
let mut future: Value = Value::Bool(false);
let mut linear: Value = Value::Null;
let mut inverse: Value = Value::Null;
// check if parsed market is contract
if is_true(&contract) {
id = self.safe_string_k(market.clone(), "contract_code", &[]);
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing id".to_string()))));
}
lowercaseId = to_lower(&id);
let mut delivery_date: Value = self.safe_string_k(market.clone(), "delivery_date", &[]);
let mut business_type: Value = self.safe_string_k(market.clone(), "business_type", &[]);
future = Value::Bool(!is_equal(&delivery_date, &Value::Null));
swap = Value::Bool(!is_true(&future));
linear = Value::Bool(!is_equal(&business_type, &Value::Null));
inverse = Value::Bool(!is_true(&linear));
if is_true(&swap) {
type_var = Value::Str("swap".to_string());
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing id".to_string()))));
}
let mut parts: Value = split(&id, &Value::Str("-".to_string()));
baseId = self.safe_string_lower(market.clone(), Value::Str("symbol".to_string()), &[]);
quoteId = self.safe_string_lower(parts.clone(), Value::Int(1), &[]);
settleId = ternary(is_true(&inverse), baseId.clone(), quoteId.clone());
} else if is_true(&future) {
type_var = Value::Str("future".to_string());
baseId = self.safe_string_lower(market.clone(), Value::Str("symbol".to_string()), &[]);
if is_true(&inverse) {
quoteId = Value::Str("USD".to_string());
settleId = baseId.clone();
} else {
let mut pair: Value = self.safe_string_k(market.clone(), "pair", &[]);
if is_equal(&pair, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing pair".to_string()))));
}
let mut parts: Value = split(&pair, &Value::Str("-".to_string()));
quoteId = self.safe_string_lower(parts.clone(), Value::Int(1), &[]);
settleId = quoteId.clone();
}
}
} else {
type_var = Value::Str("spot".to_string());
baseId = self.safe_string_k(market.clone(), "base-currency", &[]);
quoteId = self.safe_string_k(market.clone(), "quote-currency", &[]);
if is_equal("eId, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing quoteId".to_string()))));
}
if is_equal(&baseId, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing baseId".to_string()))));
}
id = add(&baseId, "eId);
lowercaseId = to_lower(&id);
}
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 symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut expiry: Value = Value::Null;
if is_true(&contract) {
if is_equal(&inverse, &Value::Bool(true)) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &base));
} else if is_equal(&linear, &Value::Bool(true)) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), "e));
}
if is_true(&future) {
expiry = self.safe_integer_k(market.clone(), "delivery_time", &[]);
symbol = add(&symbol, &add(&Value::Str("-".to_string()), &self.yymmdd(expiry.clone(), &[])));
}
}
let mut contractSize: Value = self.safe_number_k(market.clone(), "contract_size", &[]);
let mut minCost: Value = self.safe_number_k(market.clone(), "min-order-value", &[]);
let mut maxAmount: Value = self.safe_number_k(market.clone(), "max-order-amt", &[]);
let mut minAmount: Value = self.safe_number_k(market.clone(), "min-order-amt", &[]);
if is_true(&contract) {
if is_equal(&linear, &Value::Bool(true)) {
minAmount = contractSize.clone();
} else if is_equal(&inverse, &Value::Bool(true)) {
minCost = contractSize.clone();
}
}
let mut pricePrecision: Value = Value::Null;
let mut amountPrecision: Value = Value::Null;
let mut costPrecision: Value = Value::Null;
let mut maker: Value = Value::Null;
let mut taker: Value = Value::Null;
let mut active: Value = Value::Null;
if is_true(&spot) {
pricePrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "price-precision", &[])]), &[]);
amountPrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "amount-precision", &[])]), &[]);
costPrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "value-precision", &[])]), &[]);
maker = self.parse_number(Value::Str("0.002".to_string()), &[]);
taker = self.parse_number(Value::Str("0.002".to_string()), &[]);
let mut state: Value = self.safe_string_k(market.clone(), "state", &[]);
active = Value::Bool(is_equal(&state, &Value::Str("online".to_string())));
} else {
pricePrecision = self.safe_number_k(market.clone(), "price_tick", &[]);
amountPrecision = self.parse_number(Value::Str("1".to_string()), &[]); // other markets have step size of 1 contract
maker = self.parse_number(Value::Str("0.0002".to_string()), &[]);
taker = self.parse_number(Value::Str("0.0005".to_string()), &[]);
let mut contractStatus: Value = self.safe_integer_k(market.clone(), "contract_status", &[]);
active = Value::Bool(is_equal(&contractStatus, &Value::Int(1)));
}
let mut leverageRatio: Value = self.safe_string_k(market.clone(), "leverage-ratio", &[Value::Str("1".to_string())]);
let mut superLeverageRatio: Value = self.safe_string_k(market.clone(), "super-margin-leverage-ratio", &[Value::Str("1".to_string())]);
let mut hasLeverage: bool = is_true(&crate::precise::Precise::stringGt(&leverageRatio, &Value::Str("1".to_string()))) || is_true(&crate::precise::Precise::stringGt(&superLeverageRatio, &Value::Str("1".to_string())));
// 0 Delisting
// 1 Listing
// 2 Pending Listing
// 3 Suspension
// 4 Suspending of Listing
// 5 In Settlement
// 6 Delivering
// 7 Settlement Completed
// 8 Delivered
// 9 Suspending of Trade
let mut created: Value = Value::Null;
let mut createdDate: Value = self.safe_string_k(market.clone(), "create_date", &[]); // i.e 20230101
if !is_equal(&createdDate, &Value::Null) {
let mut createdArray: Value = self.string_to_chars_array(createdDate.clone());
createdDate = add(&add(&add(&add(&add(&add(&add(&add(&add(&add(&get_value(&createdArray, &Value::Int(0)), &get_value(&createdArray, &Value::Int(1))), &get_value(&createdArray, &Value::Int(2))), &get_value(&createdArray, &Value::Int(3))), &Value::Str("-".to_string())), &get_value(&createdArray, &Value::Int(4))), &get_value(&createdArray, &Value::Int(5))), &Value::Str("-".to_string())), &get_value(&createdArray, &Value::Int(6))), &get_value(&createdArray, &Value::Int(7))), &Value::Str(" 00:00:00".to_string()));
created = self.parse8601(createdDate.clone());
}
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("lowercaseId".to_string(), lowercaseId.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(), type_var.clone());
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), Value::Bool((is_true(&spot) && is_true(&hasLeverage))));
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), future.clone());
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active.clone());
m.insert("contract".to_string(), contract.clone());
m.insert("linear".to_string(), linear.clone());
m.insert("inverse".to_string(), inverse.clone());
m.insert("taker".to_string(), taker.clone());
m.insert("maker".to_string(), maker.clone());
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amountPrecision.clone());
m.insert("price".to_string(), pricePrecision.clone());
m.insert("cost".to_string(), costPrecision.clone());
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
m.insert("max".to_string(), self.parse_number(leverageRatio.clone(), &[]));
m.insert("superMax".to_string(), self.parse_number(superLeverageRatio.clone(), &[]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minAmount.clone());
m.insert("max".to_string(), maxAmount.clone());
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minCost.clone());
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), created.clone());
m.insert("info".to_string(), market.clone());
m
}));
}
}
return result;
Value::Null
}
pub fn try_get_symbol_from_future_markets(&self, mut symbolOrMarketId: Value) -> Value {
if is_true(&(!is_equal(&self.markets, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.markets, &symbolOrMarketId)))) {
return symbolOrMarketId;
}
// only on "future" market type (inverse & linear), market-id differs between "fetchMarkets" and "fetchTicker"
// so we have to create a mapping
// - market-id from fetchMarkts: `BTC-USDT-240419` (linear future) or `BTC240412` (inverse future)
// - market-id from fetchTciker[s]: `BTC-USDT-CW` (linear future) or `BTC_CW` (inverse future)
if !is_true(&(Value::Bool(in_op(&self.options, &Value::Str("futureMarketIdsForSymbols".to_string()))))) {
add_element_to_object(&mut self.options.clone(), &Value::Str("futureMarketIdsForSymbols".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
let mut futureMarketIdsForSymbols: Value = self.safe_dict_k(self.options.clone(), "futureMarketIdsForSymbols", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&Value::Bool(in_op(&futureMarketIdsForSymbols, &symbolOrMarketId))) {
return get_value(&futureMarketIdsForSymbols, &symbolOrMarketId);
}
let mut futureMarkets: Value = self.filter_by(self.markets.clone(), Value::Str("future".to_string()), Value::Bool(true), &[]);
let mut futuresCharsMaps: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("this_week".to_string(), Value::Str("CW".to_string()));
m.insert("next_week".to_string(), Value::Str("NW".to_string()));
m.insert("quarter".to_string(), Value::Str("CQ".to_string()));
m.insert("next_quarter".to_string(), Value::Str("NQ".to_string()));
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_763: bool = true;
while { if !__for_first_763 { i = add(&i, &Value::Int(1)); } __for_first_763 = false; is_less_than(&i, &get_array_length(&futureMarkets)) } {
let mut market: Value = get_value(&futureMarkets, &i);
let mut market: Value = get_value(&futureMarkets, &i);
let mut info: Value = self.safe_value_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractType: Value = self.safe_string_k(info.clone(), "contract_type", &[]);
let mut contractSuffix: Value = self.safe_value(futuresCharsMaps.clone(), contractType.clone(), &[]);
// see comment on formats a bit above
let mut constructedId: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))), add(&add(&add(&add(&get_value(&market, &Value::Str("base".to_string())), &Value::Str("-".to_string())), &get_value(&market, &Value::Str("quote".to_string()))), &Value::Str("-".to_string())), &contractSuffix), add(&add(&get_value(&market, &Value::Str("base".to_string())), &Value::Str("_".to_string())), &contractSuffix));
if is_equal(&constructedId, &symbolOrMarketId) {
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("futureMarketIdsForSymbols".to_string())), &symbolOrMarketId, symbol.clone());
return symbol;
}
}
}
// if not found, just save it to avoid unnecessary future iterations
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("futureMarketIdsForSymbols".to_string())), &symbolOrMarketId, symbolOrMarketId.clone());
return symbolOrMarketId;
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTicker
//
// {
// "amount": 26228.672978342216,
// "open": 9078.95,
// "close": 9146.86,
// "high": 9155.41,
// "id": 209988544334,
// "count": 265846,
// "low": 8988.0,
// "version": 209988544334,
// "ask": [ 9146.87, 0.156134 ],
// "vol": 2.3822168242201668E8,
// "bid": [ 9146.86, 0.080758 ],
// }
//
// fetchTickers
//
// {
// "symbol": "bhdht",
// "open": 2.3938,
// "high": 2.4151,
// "low": 2.3323,
// "close": 2.3909,
// "amount": 628.992,
// "vol": 1493.71841095,
// "count": 2088,
// "bid": 2.3643,
// "bidSize": 0.7136,
// "ask": 2.4061,
// "askSize": 0.4156
// }
//
// watchTikcer - bbo
// {
// "seqId": 161499562790,
// "ask": 16829.51,
// "askSize": 0.707776,
// "bid": 16829.5,
// "bidSize": 1.685945,
// "quoteTime": 1671941599612,
// "symbol": "btcusdt"
// }
//
let mut marketId: Value = self.safe_string2(ticker.clone(), Value::Str("symbol".to_string()), Value::Str("contract_code".to_string()), &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
symbol = self.try_get_symbol_from_future_markets(symbol.clone());
let mut timestamp: Value = self.safe_integer2(ticker.clone(), Value::Str("ts".to_string()), Value::Str("quoteTime".to_string()), &[]);
let mut bid: Value = Value::Null;
let mut bidVolume: Value = Value::Null;
let mut ask: Value = Value::Null;
let mut askVolume: Value = Value::Null;
if is_true(&Value::Bool(in_op(&ticker, &Value::Str("bid".to_string())))) {
if !is_equal(&get_value(&ticker, &Value::Str("bid".to_string())), &Value::Null) && is_true(&Value::Bool(is_array(&get_value(&ticker, &Value::Str("bid".to_string()))))) {
bid = self.safe_string(get_value(&ticker, &Value::Str("bid".to_string())), Value::Int(0), &[]);
bidVolume = self.safe_string(get_value(&ticker, &Value::Str("bid".to_string())), Value::Int(1), &[]);
} else {
bid = self.safe_string_k(ticker.clone(), "bid", &[]);
bidVolume = self.safe_string_k(ticker.clone(), "bidSize", &[]);
}
}
if is_true(&Value::Bool(in_op(&ticker, &Value::Str("ask".to_string())))) {
if !is_equal(&get_value(&ticker, &Value::Str("ask".to_string())), &Value::Null) && is_true(&Value::Bool(is_array(&get_value(&ticker, &Value::Str("ask".to_string()))))) {
ask = self.safe_string(get_value(&ticker, &Value::Str("ask".to_string())), Value::Int(0), &[]);
askVolume = self.safe_string(get_value(&ticker, &Value::Str("ask".to_string())), Value::Int(1), &[]);
} else {
ask = self.safe_string_k(ticker.clone(), "ask", &[]);
askVolume = self.safe_string_k(ticker.clone(), "askSize", &[]);
}
}
let mut open: Value = self.safe_string_k(ticker.clone(), "open", &[]);
let mut close: Value = self.safe_string_k(ticker.clone(), "close", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "amount", &[]);
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "vol", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "low", &[]));
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(), open.clone());
m.insert("close".to_string(), close.clone());
m.insert("last".to_string(), close.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-latest-aggregated-ticker
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-market-data-overview
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-market-data-overview
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-market-data-overview
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_ex_market_detail_merged(&[__ws_arg_6]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_market_detail_merged(&[__ws_arg_7]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_ex_market_detail_merged(&[__ws_arg_8]).await;
}
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_public_get_market_detail_merged(&[__ws_arg_9]).await;
}
//
// spot
//
// {
// "status": "ok",
// "ch": "market.btcusdt.detail.merged",
// "ts": 1583494336669,
// "tick": {
// "amount": 26228.672978342216,
// "open": 9078.95,
// "close": 9146.86,
// "high": 9155.41,
// "id": 209988544334,
// "count": 265846,
// "low": 8988.0,
// "version": 209988544334,
// "ask": [ 9146.87, 0.156134 ],
// "vol": 2.3822168242201668E8,
// "bid": [ 9146.86, 0.080758 ],
// }
// }
//
// future, swap
//
// {
// "ch":"market.BTC211126.detail.merged",
// "status":"ok",
// "tick":{
// "amount":"669.3385682049668320322569544150680718474",
// "ask":[59117.44,48],
// "bid":[59082,48],
// "close":"59087.97",
// "count":5947,
// "high":"59892.62",
// "id":1637502670,
// "low":"57402.87",
// "open":"57638",
// "ts":1637502670059,
// "vol":"394598"
// },
// "ts":1637502670059
// }
//
let mut tick: Value = self.safe_value_k(response.clone(), "tick", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ticker: Value = self.parse_ticker(tick.clone(), &[market.clone()]);
let mut timestamp: Value = self.safe_integer_k(response.clone(), "ts", &[]);
add_element_to_object(&mut ticker, &Value::Str("timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut ticker, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
return ticker;
Value::Null
}
/*
* @method
* @name htx#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-latest-tickers-for-all-pairs
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-a-batch-of-market-data-overview
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-a-batch-of-market-data-overview
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-a-batch-of-market-data-overview-v2
* @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 isSubTypeRequested: bool = is_true(&(Value::Bool(in_op(¶ms, &Value::Str("subType".to_string()))))) || is_true(&(Value::Bool(in_op(¶ms, &Value::Str("business_type".to_string())))));
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); subType = 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 mut isSpot: bool = is_equal(&type_var, &Value::Str("spot".to_string()));
let mut future: bool = is_equal(&type_var, &Value::Str("future".to_string()));
let mut swap: bool = is_equal(&type_var, &Value::Str("swap".to_string()));
let mut linear: bool = is_equal(&subType, &Value::Str("linear".to_string()));
let mut inverse: bool = is_equal(&subType, &Value::Str("inverse".to_string()));
let mut response: Value = Value::Null;
if !is_true(&isSpot) || is_true(&isSubTypeRequested) {
if is_true(&linear) {
// independently of type, supports calling all linear symbols i.e. fetchTickers(undefined, {subType:'linear'})
if is_true(&future) {
add_element_to_object(&mut request, &Value::Str("business_type".to_string()), Value::Str("futures".to_string()));
} else if is_true(&swap) {
add_element_to_object(&mut request, &Value::Str("business_type".to_string()), Value::Str("swap".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("business_type".to_string()), Value::Str("all".to_string()));
}
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_ex_market_detail_batch_merged(&[__ws_arg_10]).await;
} else if is_true(&inverse) {
if is_true(&future) {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_market_detail_batch_merged(&[__ws_arg_11]).await;
} else if is_true(&swap) {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_ex_market_detail_batch_merged(&[__ws_arg_12]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTickers() you have to set params[\"type\"] to either \"swap\" or \"future\" for inverse contracts".to_string()))));
}
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTickers() you have to set params[\"subType\"] to either \"linear\" or \"inverse\" for contracts".to_string()))));
}
} else {
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_public_get_market_tickers(&[__ws_arg_13]).await;
}
//
// spot
//
// {
// "data":[
// {
// "symbol":"hbcbtc",
// "open":5.313E-5,
// "high":5.34E-5,
// "low":5.112E-5,
// "close":5.175E-5,
// "amount":1183.87,
// "vol":0.0618599229,
// "count":205,
// "bid":5.126E-5,
// "bidSize":5.25,
// "ask":5.214E-5,
// "askSize":150.0
// },
// ],
// "status":"ok",
// "ts":1639547261293
// }
//
// linear swap, linear future, inverse swap, inverse future
//
// {
// "status":"ok",
// "ticks":[
// {
// "id":1637504679,
// "ts":1637504679372,
// "ask":[0.10644,100],
// "bid":[0.10624,26],
// "symbol":"TRX_CW",
// "open":"0.10233",
// "close":"0.10644",
// "low":"0.1017",
// "high":"0.10725",
// "amount":"2340267.415144052378486261756692535687481566",
// "count":882,
// "vol":"24706",
// "trade_turnover":"840726.5048", // only in linear futures
// "business_type":"futures", // only in linear futures
// "contract_code":"BTC-USDT-CW", // only in linear futures, instead of 'symbol'
// }
// ],
// "ts":1637504679376
// }
//
let mut rawTickers: Value = self.safe_list2(response.clone(), Value::Str("data".to_string()), Value::Str("ticks".to_string()), &[Value::List(vec![])]);
let mut tickers: Value = self.parse_tickers(rawTickers.clone(), &[symbols.clone(), params.clone()]);
return self.filter_by_array_tickers(tickers.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchLastPrices
* @description fetches the last price for multiple markets
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb81024-77b5-11ed-9966-0242ac110003 linear swap & linear future
* @see https://www.htx.com/en-us/opend/newApiPages/?id=28c2e8fc-77ae-11ed-9966-0242ac110003 inverse future
* @see https://www.htx.com/en-us/opend/newApiPages/?id=5d517ef5-77b6-11ed-9966-0242ac110003 inverse swap
* @param {string[]} [symbols] unified symbols of the markets to fetch the last prices
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of lastprices structures
*/
pub async fn fetch_last_prices(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchLastPrices".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLastPrices".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 response: Value = Value::Null;
if is_true(&(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(&subType, &Value::Str("linear".to_string())))) {
response = self.contract_public_get_linear_swap_ex_market_trade(&[params.clone()]).await;
} else if is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) && is_true(&(is_equal(&subType, &Value::Str("inverse".to_string())))) {
response = self.contract_public_get_swap_ex_market_trade(&[params.clone()]).await;
} else if is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) && is_true(&(is_equal(&subType, &Value::Str("inverse".to_string())))) {
response = self.contract_public_get_market_trade(&[params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchLastPrices() does not support ".to_string())), &type_var), &Value::Str(" markets yet".to_string()))));
}
let mut tick: Value = self.safe_value_k(response.clone(), "tick", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(tick.clone(), "data", &[Value::List(vec![])]);
return self.parse_last_prices(data.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_last_price(&self, mut entry: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
// example responses are documented in fetchLastPrices
let mut marketId: Value = self.safe_string2(entry.clone(), Value::Str("symbol".to_string()), Value::Str("contract_code".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut price: Value = self.safe_number_k(entry.clone(), "price", &[]);
let mut direction: Value = self.safe_string_k(entry.clone(), "direction", &[]); // "buy" or "sell"
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("price".to_string(), price.clone());
m.insert("side".to_string(), direction.clone());
m.insert("info".to_string(), entry.clone());
m
});
Value::Null
}
/*
* @method
* @name htx#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-market-depth
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-market-depth
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-market-depth
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-market-depth
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("step0".to_string()));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_ex_market_depth(&[__ws_arg_14]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_market_depth(&[__ws_arg_15]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_ex_market_depth(&[__ws_arg_16]).await;
}
} else {
if !is_equal(&limit, &Value::Null) {
// Valid depths are 5, 10, 20 or empty https://huobiapi.github.io/docs/spot/v1/en/#get-market-depth
if is_true(&(!is_equal(&limit, &Value::Int(5)))) && is_true(&(!is_equal(&limit, &Value::Int(10)))) && is_true(&(!is_equal(&limit, &Value::Int(20)))) && is_true(&(!is_equal(&limit, &Value::Int(150)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOrderBook() limit argument must be undefined, 5, 10, 20, or 150, default is 150".to_string()))));
}
// only set the depth if it is not 150
// 150 is the implicit default on the exchange side for step0 and no orderbook aggregation
// it is not accepted by the exchange if you set it explicitly
if !is_equal(&limit, &Value::Int(150)) {
add_element_to_object(&mut request, &Value::Str("depth".to_string()), limit.clone());
}
}
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_public_get_market_depth(&[__ws_arg_17]).await;
}
//
// spot, future, swap
//
// {
// "status": "ok",
// "ch": "market.btcusdt.depth.step0",
// "ts": 1583474832790,
// "tick": {
// "bids": [
// [ 9100.290000000000000000, 0.200000000000000000 ],
// [ 9099.820000000000000000, 0.200000000000000000 ],
// [ 9099.610000000000000000, 0.205000000000000000 ],
// ],
// "asks": [
// [ 9100.640000000000000000, 0.005904000000000000 ],
// [ 9101.010000000000000000, 0.287311000000000000 ],
// [ 9101.030000000000000000, 0.012121000000000000 ],
// ],
// "ch":"market.BTC-USD.depth.step0",
// "ts":1583474832008,
// "id":1637554816,
// "mrid":121654491624,
// "version":104999698781
// }
// }
//
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" fetchOrderBook() returned empty response".to_string()))));
}
if is_true(&Value::Bool(in_op(&response, &Value::Str("tick".to_string())))) {
if is_true(&(is_equal(&get_value(&response, &Value::Str("tick".to_string())), &Value::Null))) || is_true(&(is_equal(&get_value(&response, &Value::Str("tick".to_string())), &Value::Null))) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&add(&self.id, &Value::Str(" fetchOrderBook() returned empty response: ".to_string())), &self.json(response.clone()))));
}
let mut tick: Value = self.safe_value_k(response.clone(), "tick", &[]);
let mut timestamp: Value = self.safe_integer_k(tick.clone(), "ts", &[self.safe_integer(response.clone(), Value::Str("ts".to_string()), &[])]);
let mut result: Value = self.parse_order_book(tick.clone(), symbol.clone(), &[timestamp.clone()]);
add_element_to_object(&mut result, &Value::Str("nonce".to_string()), self.safe_integer_k(tick.clone(), "version", &[]));
return result;
}
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" fetchOrderBook() returned unrecognized response: ".to_string())), &self.json(response.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);
//
// spot fetchTrades (public)
//
// {
// "amount": 0.010411000000000000,
// "trade-id": 102090736910,
// "ts": 1583497692182,
// "id": 10500517034273194594947,
// "price": 9096.050000000000000000,
// "direction": "sell"
// }
//
// spot fetchMyTrades (private)
//
// {
// "symbol": "swftcbtc",
// "fee-currency": "swftc",
// "filled-fees": "0",
// "source": "spot-api",
// "id": 83789509854000,
// "type": "buy-limit",
// "order-id": 83711103204909,
// 'filled-points': "0.005826843283532154",
// "fee-deduct-currency": "ht",
// 'filled-amount': "45941.53",
// "price": "0.0000001401",
// "created-at": 1597933260729,
// "match-id": 100087455560,
// "role": "maker",
// "trade-id": 100050305348
// }
//
// linear swap isolated margin fetchOrder details
//
// {
// "trade_id": 131560927,
// "trade_price": 13059.800000000000000000,
// "trade_volume": 1.000000000000000000,
// "trade_turnover": 13.059800000000000000,
// "trade_fee": -0.005223920000000000,
// "created_at": 1603703614715,
// "role": "taker",
// "fee_asset": "USDT",
// "profit": 0,
// "real_profit": 0,
// "id": "131560927-770334322963152896-1"
// }
//
// inverse swap cross margin fetchMyTrades
//
// {
// "contract_type":"swap",
// "pair":"O3-USDT",
// "business_type":"swap",
// "query_id":652123190,
// "match_id":28306009409,
// "order_id":941137865226903553,
// "symbol":"O3",
// "contract_code":"O3-USDT",
// "direction":"sell",
// "offset":"open",
// "trade_volume":100.000000000000000000,
// "trade_price":0.398500000000000000,
// "trade_turnover":39.850000000000000000,
// "trade_fee":-0.007970000000000000,
// "offset_profitloss":0E-18,
// "create_date":1644426352999,
// "role":"Maker",
// "order_source":"api",
// "order_id_str":"941137865226903553",
// "id":"28306009409-941137865226903553-1",
// "fee_asset":"USDT",
// "margin_mode":"cross",
// "margin_account":"USDT",
// "real_profit":0E-18,
// "trade_partition":"USDT"
// }
//
// linear swap fetchMyTrades
//
// {
// "id": "1513834754679549965",
// "contract_code": "BTC-USDT",
// "order_id": "1513834754585190400",
// "trade_id": "152022944",
// "side": "sell",
// "position_side": "long",
// "order_type": "1",
// "margin_mode": "cross",
// "type": "market",
// "role": "TAKER",
// "trade_price": "62688.2",
// "trade_volume": "2",
// "trade_turnover": "125.3764",
// "created_time": "1780967931197",
// "updated_time": "1780967931197",
// "order_source": "api",
// "fee_currency": "USDT",
// "trade_fee": "0.07522584",
// "deduction_price": "",
// "profit": "-0.3656",
// "contract_type": "swap"
// }
//
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("contract_code".to_string()), Value::Str("symbol".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer_n(trade.clone(), Value::List(vec![Value::Str("ts".to_string()), Value::Str("created-at".to_string()), Value::Str("created_at".to_string()), Value::Str("create_date".to_string()), Value::Str("created_time".to_string())]), &[]);
let mut order: Value = self.safe_string2(trade.clone(), Value::Str("order-id".to_string()), Value::Str("order_id".to_string()), &[]);
let mut side: Value = self.safe_string2(trade.clone(), Value::Str("direction".to_string()), Value::Str("side".to_string()), &[]);
let mut type_var: Value = self.safe_string_k(trade.clone(), "type", &[]);
if is_true(&(!is_equal(&type_var, &Value::Null))) && is_true(&(is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("-".to_string())), &Value::Int(0)))) {
let mut typeParts: Value = split(&type_var, &Value::Str("-".to_string()));
side = get_value(&typeParts, &Value::Int(0));
type_var = get_value(&typeParts, &Value::Int(1));
}
let mut takerOrMaker: Value = self.safe_string_lower(trade.clone(), Value::Str("role".to_string()), &[]);
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("price".to_string()), Value::Str("trade_price".to_string()), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("filled-amount".to_string()), Value::Str("amount".to_string()), &[]);
amountString = self.safe_string_k(trade.clone(), "trade_volume", &[amountString.clone()]);
let mut costString: Value = self.safe_string_k(trade.clone(), "trade_turnover", &[]);
let mut fee: Value = Value::Null;
let mut feeCost: Value = self.safe_string_k(trade.clone(), "filled-fees", &[]);
if is_equal(&feeCost, &Value::Null) {
feeCost = crate::precise::Precise::stringNeg(&self.safe_string_k(trade.clone(), "trade_fee", &[]));
}
let mut feeCurrencyId: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("fee-currency".to_string()), Value::Str("fee_asset".to_string()), Value::Str("fee_currency".to_string())]), &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
let mut filledPoints: Value = self.safe_string_k(trade.clone(), "filled-points", &[]);
if !is_equal(&filledPoints, &Value::Null) {
if is_true(&(is_equal(&feeCost, &Value::Null))) || is_true(&crate::precise::Precise::stringEquals(&feeCost, &Value::Str("0".to_string()))) {
let mut feeDeductCurrency: Value = self.safe_string_k(trade.clone(), "fee-deduct-currency", &[]);
if !is_equal(&feeDeductCurrency, &Value::Null) {
feeCost = filledPoints.clone();
feeCurrency = self.safe_currency_code(feeDeductCurrency.clone(), &[]);
}
}
}
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), feeCurrency.clone());
m
});
}
// htx's multi-market trade-id is a bit complex to parse accordingly.
// - for `id` which contains hyphen, it would be the unique id, eg. xxxxxx-1, xxxxxx-2 (this happens mostly for contract markets)
// - otherwise the least priority is given to the `id` key
let mut id: Value = Value::Null;
let mut safeId: Value = self.safe_string_k(trade.clone(), "id", &[]);
if !is_equal(&safeId, &Value::Null) && is_greater_than_or_equal(&get_index_of(&safeId, &Value::Str("-".to_string())), &Value::Int(0)) {
id = safeId.clone();
} else {
id = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("trade_id".to_string()), Value::Str("trade-id".to_string()), Value::Str("id".to_string())]), &[]);
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("info".to_string(), trade.clone());
m.insert("order".to_string(), order.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), costString.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-the-match-result-of-an-order
* @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
}));
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrderTrades".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marketType, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrderTrades() is only supported for spot markets".to_string()))));
}
return self.fetch_spot_order_trades(id.clone(), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @ignore
* @method
* @name htx#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-the-match-result-of-an-order
* @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_spot_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order-id".to_string(), id.clone());
m
});
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v1_order_orders_order_id_matchresults(&[__ws_arg_18]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(data.clone(), &[Value::Null, since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchMyTrades
* @description fetch all trades made by the user
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-195898804f0
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-match-results
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades for
* @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 {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone()); // default 100, max 500
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start-time".to_string()), since.clone()); // a date within 120 days from today
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end-time".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_19 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_order_matchresults(&[__ws_arg_19]).await;
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol argument".to_string()))));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".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(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), self.safe_string_k(market.clone(), "id", &[]));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 100, max 500
}
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_trade_order_details(&[__ws_arg_20]).await;
} else if is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true)) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone()); // default 100, max 500
}
add_element_to_object(&mut request, &Value::Str("contract".to_string()), self.safe_string_k(market.clone(), "id", &[]));
add_element_to_object(&mut request, &Value::Str("trade_type".to_string()), Value::Int(0)); // 0 all, 1 open long, 2 open short, 3 close short, 4 close long, 5 liquidate long positions, 6 liquidate short positions
if is_equal(&marketType, &Value::Str("future".to_string())) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "settleId", &[]));
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v3_contract_matchresults_exact(&[__ws_arg_21]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v3_swap_matchresults_exact(&[__ws_arg_22]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchMyTrades() does not support ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
}
}
//
// spot
//
// {
// "status": "ok",
// "data": [
// {
// "symbol": "polyusdt",
// "fee-currency": "poly",
// "source": "spot-web",
// "price": "0.338",
// "created-at": 1629443051839,
// "role": "taker",
// "order-id": 345487249132375,
// "match-id": 5014,
// "trade-id": 1085,
// "filled-amount": "147.928994082840236",
// "filled-fees": "0",
// "filled-points": "0.1",
// "fee-deduct-currency": "hbpoint",
// "fee-deduct-state": "done",
// "id": 313288753120940,
// "type": "buy-market"
// }
// ]
// }
//
// contracts
//
// {
// "status": "ok",
// "data": {
// "trades": [
// {
// "query_id": 2424420723,
// "match_id": 113891764710,
// "order_id": 773135295142658048,
// "symbol": "ADA",
// "contract_type": "quarter", // swap
// "business_type": "futures", // swap
// "contract_code": "ADA201225",
// "direction": "buy",
// "offset": "open",
// "trade_volume": 1,
// "trade_price": 0.092,
// "trade_turnover": 10,
// "trade_fee": -0.021739130434782608,
// "offset_profitloss": 0,
// "create_date": 1604371703183,
// "role": "Maker",
// "order_source": "web",
// "order_id_str": "773135295142658048",
// "fee_asset": "ADA",
// "margin_mode": "isolated", // cross
// "margin_account": "BTC-USDT",
// "real_profit": 0,
// "id": "113891764710-773135295142658048-1",
// "trade_partition":"USDT",
// }
// ],
// "remain_size": 15,
// "next_id": 2424413094
// },
// "ts": 1604372202243
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "id": "1513834754679549965",
// "contract_code": "BTC-USDT",
// "order_id": "1513834754585190400",
// "trade_id": "152022944",
// "side": "sell",
// "position_side": "long",
// "order_type": "1",
// "margin_mode": "cross",
// "type": "market",
// "role": "TAKER",
// "trade_price": "62688.2",
// "trade_volume": "2",
// "trade_turnover": "125.3764",
// "created_time": "1780967931197",
// "updated_time": "1780967931197",
// "order_source": "api",
// "fee_currency": "USDT",
// "trade_fee": "0.07522584",
// "deduction_price": "",
// "profit": "-0.3656",
// "contract_type": "swap"
// }
// ],
// "ts": 1781066959396
// }
//
let mut trades: Value = self.safe_value_k(response.clone(), "data", &[]);
if !is_true(&Value::Bool(is_array(&trades))) {
trades = self.safe_value_k(trades.clone(), "trades", &[]);
}
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchTrades
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-the-most-recent-trades
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-a-batch-of-trade-records-of-a-contract
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-a-batch-of-trade-records-of-a-contract
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-a-batch-of-trade-records-of-a-contract
* @description get the list of most recent trades for a particular symbol
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Int(1000));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), crate::runtime::Math::min(&limit, &Value::Int(2000))); // max 2000
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_market_history_trade(&[__ws_arg_23]).await;
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_ex_market_history_trade(&[__ws_arg_24]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_ex_market_history_trade(&[__ws_arg_25]).await;
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_ex_market_history_trade(&[__ws_arg_26]).await;
}
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_public_get_market_history_trade(&[__ws_arg_27]).await;
}
//
// {
// "status": "ok",
// "ch": "market.btcusdt.trade.detail",
// "ts": 1583497692365,
// "data": [
// {
// "id": 105005170342,
// "ts": 1583497692182,
// "data": [
// {
// "amount": 0.010411000000000000,
// "trade-id": 102090736910,
// "ts": 1583497692182,
// "id": 10500517034273194594947,
// "price": 9096.050000000000000000,
// "direction": "sell"
// }
// ]
// },
// // ...
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_765: bool = true;
while { if !__for_first_765 { i = add(&i, &Value::Int(1)); } __for_first_765 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut trades: Value = self.safe_value_k(get_value(&data, &i), "data", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_764: bool = true;
while { if !__for_first_764 { j = add(&j, &Value::Int(1)); } __for_first_764 = false; is_less_than(&j, &get_array_length(&trades)) } {
let mut trade: Value = self.parse_trade(get_value(&trades, &j), &[market.clone()]);
append_to_array(&mut result, trade.clone());
}
}
}
}
result = self.sort_by(result.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(result.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);
return Value::List(vec![self.safe_timestamp(ohlcv.clone(), Value::Str("id".to_string()), &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv.clone(), "amount", &[])]);
Value::Null
}
/*
* @method
* @name htx#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-klines-candles
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-kline-data
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-kline-data
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-get-kline-data
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {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)
* @param {string} [params.useHistoricalEndpointForSpot] true/false - whether use the historical candles endpoint for spot markets or default klines endpoint
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("period".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut priceType: Value = self.safe_string2(params.clone(), Value::Str("priceType".to_string()), Value::Str("price".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("priceType".to_string()), Value::Str("price".to_string())]), &[]);
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_param_integer(params.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut untilSeconds: Value = ternary(is_true(&(!is_equal(&until, &Value::Null))), self.parse_to_int(divide(&until, &Value::Int(1000))), Value::Null);
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), crate::runtime::Math::min(&limit, &Value::Int(2000))); // when using limit: from & to are ignored
} else {
limit = Value::Int(2000); // only used for from/to calculation
}
if is_equal(&priceType, &Value::Null) {
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut calcualtedEnd: Value = Value::Null;
if is_equal(&since, &Value::Null) {
let mut now: Value = self.seconds();
add_element_to_object(&mut request, &Value::Str("from".to_string()), subtract(&now, &multiply(&duration, &(subtract(&limit, &Value::Int(1))))));
calcualtedEnd = now.clone();
} else {
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());
calcualtedEnd = self.sum(&[start.clone(), multiply(&duration, &(subtract(&limit, &Value::Int(1))))]);
}
add_element_to_object(&mut request, &Value::Str("to".to_string()), ternary(is_true(&(!is_equal(&untilSeconds, &Value::Null))), untilSeconds.clone(), calcualtedEnd.clone()));
}
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_equal(&priceType, &Value::Str("mark".to_string())) {
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_mark_price_kline(&[__ws_arg_28]).await;
} else if is_equal(&priceType, &Value::Str("index".to_string())) {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_index(&[__ws_arg_29]).await;
} else if is_equal(&priceType, &Value::Str("premiumIndex".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" has no api endpoint for ".to_string())), &priceType), &Value::Str(" kline data".to_string()))));
} else {
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_market_history_kline(&[__ws_arg_30]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_equal(&priceType, &Value::Str("mark".to_string())) {
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_linear_swap_mark_price_kline(&[__ws_arg_31]).await;
} else if is_equal(&priceType, &Value::Str("index".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" has no api endpoint for ".to_string())), &priceType), &Value::Str(" kline data".to_string()))));
} else if is_equal(&priceType, &Value::Str("premiumIndex".to_string())) {
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_linear_swap_premium_index_kline(&[__ws_arg_32]).await;
} else {
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_ex_market_history_kline(&[__ws_arg_33]).await;
}
}
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
if is_equal(&priceType, &Value::Str("mark".to_string())) {
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_swap_mark_price_kline(&[__ws_arg_34]).await;
} else if is_equal(&priceType, &Value::Str("index".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" has no api endpoint for ".to_string())), &priceType), &Value::Str(" kline data".to_string()))));
} else if is_equal(&priceType, &Value::Str("premiumIndex".to_string())) {
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_swap_premium_index_kline(&[__ws_arg_35]).await;
} else {
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_ex_market_history_kline(&[__ws_arg_36]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
if is_equal(&priceType, &Value::Str("mark".to_string())) {
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_linear_swap_mark_price_kline(&[__ws_arg_37]).await;
} else if is_equal(&priceType, &Value::Str("index".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" has no api endpoint for ".to_string())), &priceType), &Value::Str(" kline data".to_string()))));
} else if is_equal(&priceType, &Value::Str("premiumIndex".to_string())) {
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_index_market_history_linear_swap_premium_index_kline(&[__ws_arg_38]).await;
} else {
let __ws_arg_39 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_ex_market_history_kline(&[__ws_arg_39]).await;
}
}
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let mut useHistorical: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("useHistoricalEndpointForSpot".to_string()), &[Value::Bool(true)]); useHistorical = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_true(&useHistorical) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), crate::runtime::Math::min(&limit, &Value::Int(2000))); // max 2000
}
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_public_get_market_history_kline(&[__ws_arg_40]).await;
} else {
// "from & to" only available for the this endpoint
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(&untilSeconds, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("to".to_string()), untilSeconds.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), crate::runtime::Math::min(&Value::Int(1000), &limit)); // max 1000, otherwise default returns 150
}
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_public_get_market_history_candles(&[__ws_arg_41]).await;
}
}
//
// {
// "status":"ok",
// "ch":"market.ethbtc.kline.1min",
// "ts":1591515374371,
// "data":[
// {"amount":0.0,"open":0.025095,"close":0.025095,"high":0.025095,"id":1591515360,"count":0,"low":0.025095,"vol":0.0},
// {"amount":1.2082,"open":0.025096,"close":0.025095,"high":0.025096,"id":1591515300,"count":6,"low":0.025095,"vol":0.0303205097},
// {"amount":0.0648,"open":0.025096,"close":0.025096,"high":0.025096,"id":1591515240,"count":2,"low":0.025096,"vol":0.0016262208},
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-all-accounts-of-the-current-user
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/?id=account-structure} indexed by the account type
*/
pub async fn fetch_accounts(&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.spot_private_get_v1_account_accounts(&[params.clone()]).await;
//
// {
// "status":"ok",
// "data":[
// {"id":5202591,"type":"point","subtype":"","state":"working"},
// {"id":1528640,"type":"spot","subtype":"","state":"working"},
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
return self.parse_accounts(data.clone(), &[]);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
//
// {
// "id": 5202591,
// "type": "point", // spot, margin, otc, point, super-margin, investment, borrow, grid-trading, deposit-earning, otc-options
// "subtype": "", // The corresponding trading symbol (currency pair) the isolated margin is based on, e.g. btcusdt
// "state": "working" // working, lock
// }
//
let mut typeId: Value = self.safe_string_k(account.clone(), "type", &[]);
let mut accountsById: Value = self.safe_value_k(self.options.clone(), "accountsById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut type_var: Value = self.safe_value(accountsById.clone(), typeId.clone(), &[typeId.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), account.clone());
m.insert("id".to_string(), self.safe_string_k(account.clone(), "id", &[]));
m.insert("type".to_string(), type_var.clone());
m.insert("code".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name htx#fetchAccountIdByType
* @description fetch all the accounts by a type and marginModeassociated with a profile
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-all-accounts-of-the-current-user
* @param {string} type 'spot', 'swap' or 'future
* @param {string} [marginMode] 'cross' or 'isolated'
* @param {string} [symbol] unified ccxt market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/?id=account-structure} indexed by the account type
*/
pub async fn fetch_account_id_by_type(&mut self, mut type_var: Value, optional_args: &[Value]) -> Value {
let mut marginMode = get_arg(optional_args, 0, Value::Null);
let mut symbol = 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 accounts: Value = self.load_accounts(&[]).await;
let mut accountId: Value = self.safe_string2(params.clone(), Value::Str("accountId".to_string()), Value::Str("account-id".to_string()), &[]);
if !is_equal(&accountId, &Value::Null) {
return accountId;
}
if is_equal(&type_var, &Value::Str("spot".to_string())) {
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
type_var = Value::Str("super-margin".to_string());
} else if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
type_var = Value::Str("margin".to_string());
}
}
let mut marketId: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
marketId = self.market_id(symbol.clone());
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_766: bool = true;
while { if !__for_first_766 { i = add(&i, &Value::Int(1)); } __for_first_766 = false; is_less_than(&i, &get_array_length(&accounts)) } {
let mut account: Value = get_value(&accounts, &i);
let mut account: Value = get_value(&accounts, &i);
let mut info: Value = self.safe_value_k(account.clone(), "info", &[]);
let mut subtype: Value = self.safe_string_k(info.clone(), "subtype", &[]);
let mut typeFromAccount: Value = self.safe_string_k(account.clone(), "type", &[]);
if is_equal(&type_var, &Value::Str("margin".to_string())) {
if is_equal(&subtype, &marketId) {
return self.safe_string_k(account.clone(), "id", &[]);
}
} else if is_equal(&type_var, &typeFromAccount) {
return self.safe_string_k(account.clone(), "id", &[]);
}
}
}
let mut defaultAccount: Value = self.safe_value(accounts.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_string_k(defaultAccount.clone(), "id", &[]);
Value::Null
}
/*
* @method
* @name htx#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://huobiapi.github.io/docs/spot/v1/en/#apiv2-currency-amp-chains
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.spot_public_get_v2_reference_currencies(&[params.clone()]).await;
//
// {
// "code": 200,
// "data": [
// {
// "currency": "sxp",
// "assetType": "1",
// "chains": [
// {
// "chain": "sxp",
// "displayName": "ERC20",
// "baseChain": "ETH",
// "baseChainProtocol": "ERC20",
// "isDynamic": true,
// "numOfConfirmations": "12",
// "numOfFastConfirmations": "12",
// "depositStatus": "allowed",
// "minDepositAmt": "0.23",
// "withdrawStatus": "allowed",
// "minWithdrawAmt": "0.23",
// "withdrawPrecision": "8",
// "maxWithdrawAmt": "227000.000000000000000000",
// "withdrawQuotaPerDay": "227000.000000000000000000",
// "withdrawQuotaPerYear": null,
// "withdrawQuotaTotal": null,
// "withdrawFeeType": "fixed",
// "transactFeeWithdraw": "11.1654",
// "addrWithTag": false,
// "addrDepositTag": false
// }
// ],
// "instStatus": "normal"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
add_element_to_object(&mut self.options, &Value::Str("networkNamesByChainIds".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
add_element_to_object(&mut self.options, &Value::Str("networkChainIdsByNames".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.parse_currencies(data.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
if !is_true(&(Value::Bool(in_op(&self.options, &Value::Str("networkNamesByChainIds".to_string()))))) {
add_element_to_object(&mut self.options.clone(), &Value::Str("networkNamesByChainIds".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
if !is_true(&(Value::Bool(in_op(&self.options, &Value::Str("networkChainIdsByNames".to_string()))))) {
add_element_to_object(&mut self.options.clone(), &Value::Str("networkChainIdsByNames".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
let mut currencyId: Value = self.safe_string_k(rawCurrency.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut assetType: Value = self.safe_string_k(rawCurrency.clone(), "assetType", &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&assetType, &Value::Str("1".to_string())))), Value::Str("crypto".to_string()), Value::Str("fiat".to_string()));
if !is_equal(&code, &Value::Null) {
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("networkChainIdsByNames".to_string())), &code, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
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_767: bool = true;
while { if !__for_first_767 { j = add(&j, &Value::Int(1)); } __for_first_767 = false; is_less_than(&j, &get_array_length(&chains)) } {
let mut chainEntry: Value = get_value(&chains, &j);
let mut chainEntry: Value = get_value(&chains, &j);
let mut uniqueChainId: Value = self.safe_string_k(chainEntry.clone(), "chain", &[]); // i.e. usdterc20, trc20usdt ...
let mut title: Value = self.safe_string2(chainEntry.clone(), Value::Str("baseChain".to_string()), Value::Str("displayName".to_string()), &[]); // baseChain and baseChainProtocol are together existent or inexistent in entries, but baseChain is preferred. when they are both inexistent, then we use generic displayName
if !is_equal(&code, &Value::Null) && !is_equal(&title, &Value::Null) {
add_element_to_object(get_value_mut(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("networkChainIdsByNames".to_string())), &code), &title, uniqueChainId.clone());
}
if !is_equal(&uniqueChainId, &Value::Null) {
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("networkNamesByChainIds".to_string())), &uniqueChainId, title.clone());
}
let mut networkCode: Value = self.network_id_to_code(&[uniqueChainId.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(), chainEntry.clone());
m.insert("id".to_string(), uniqueChainId.clone());
m.insert("network".to_string(), networkCode.clone());
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(), self.safe_number_k(chainEntry.clone(), "minDepositAmt", &[]));
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(), self.safe_number_k(chainEntry.clone(), "minWithdrawAmt", &[]));
m.insert("max".to_string(), self.safe_number_k(chainEntry.clone(), "maxWithdrawAmt", &[]));
m
}));
m
}));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool(is_equal(&self.safe_string_k(chainEntry.clone(), "depositStatus", &[]), &Value::Str("allowed".to_string()))));
m.insert("withdraw".to_string(), Value::Bool(is_equal(&self.safe_string_k(chainEntry.clone(), "withdrawStatus", &[]), &Value::Str("allowed".to_string()))));
m.insert("fee".to_string(), self.safe_number_k(chainEntry.clone(), "transactFeeWithdraw", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(chainEntry.clone(), "withdrawPrecision", &[])]), &[]));
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rawCurrency.clone());
m.insert("code".to_string(), code.clone());
m.insert("id".to_string(), currencyId.clone());
m.insert("active".to_string(), Value::Bool(is_equal(&self.safe_string_k(rawCurrency.clone(), "instStatus", &[]), &Value::Str("normal".to_string()))));
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("name".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("precision".to_string(), Value::Null);
m.insert("networks".to_string(), networks.clone());
m
}));
Value::Null
}
pub fn network_id_to_code(&self, optional_args: &[Value]) -> Value {
let mut networkId = get_arg(optional_args, 0, Value::Null);
let mut currencyCode = get_arg(optional_args, 1, Value::Null);
// here network-id is provided as a pair of currency & chain (i.e. trc20usdt)
let mut keys: Value = object_keys(&get_value(&self.options, &Value::Str("networkNamesByChainIds".to_string())));
let mut keysLength: Value = get_array_length(&keys);
if is_equal(&keysLength, &Value::Int(0)) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" networkIdToCode() - markets need to be loaded at first".to_string()))));
}
let mut networkTitle: Value = self.safe_value(get_value(&self.options, &Value::Str("networkNamesByChainIds".to_string())), networkId.clone(), &[networkId.clone()]);
return self.super_network_id_to_code(&[networkTitle.clone(), currencyCode.clone()]);
Value::Null
}
pub fn network_code_to_id(&self, mut networkCode: Value, optional_args: &[Value]) -> Value {
let mut currencyCode = get_arg(optional_args, 0, Value::Null);
if is_equal(&networkCode, &Value::Null) {
return Value::Null;
}
if is_equal(¤cyCode, &Value::Null) {
return self.super_network_code_to_id(networkCode.clone(), &[]);
}
let mut keys: Value = object_keys(&get_value(&self.options, &Value::Str("networkChainIdsByNames".to_string())));
let mut keysLength: Value = get_array_length(&keys);
if is_equal(&keysLength, &Value::Int(0)) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" networkCodeToId() - markets need to be loaded at first".to_string()))));
}
let mut uniqueNetworkIds: Value = self.safe_value(get_value(&self.options, &Value::Str("networkChainIdsByNames".to_string())), currencyCode.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&Value::Bool(in_op(&uniqueNetworkIds, &networkCode))) {
return get_value(&uniqueNetworkIds, &networkCode);
} else {
let mut networkTitle: Value = self.super_network_code_to_id(networkCode.clone(), &[currencyCode.clone()]);
return self.safe_value(uniqueNetworkIds.clone(), networkTitle.clone(), &[networkTitle.clone()]);
}
Value::Null
}
/*
* @method
* @name htx#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-account-balance-of-a-specific-account
* @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4b429-7773-11ed-9966-0242ac110003
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-asset-valuation
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-user-s-account-information
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19588469969
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] spot, margin, future or swap
* @param {string} [params.subType] linear or inverse
* @param {bool} [params.multiAssetMode] set to true if you are using multi-asset mode for USDT-margined contracts
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut isUnifiedAccount: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("unified".to_string()), Value::Str("uta".to_string()), &[Value::Bool(false)]); isUnifiedAccount = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&isUnifiedAccount) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchBalance() unified account has been deprecated on htx".to_string()))));
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subType: Value = Value::Null;
let mut isMultiAssetMode: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("defaultSubType".to_string()), Value::Str("subType".to_string()), &[]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Null) {
subType = Value::Str("linear".to_string());
}
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("multiAssetMode".to_string()), &[Value::Bool(false)]); isMultiAssetMode = 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 mut spot: bool = is_equal(&type_var, &Value::Str("spot".to_string()));
let mut future: bool = is_equal(&type_var, &Value::Str("future".to_string()));
let mut swap: bool = is_equal(&type_var, &Value::Str("swap".to_string()));
let mut inverse: bool = is_equal(&subType, &Value::Str("inverse".to_string()));
let mut linear: bool = is_equal(&subType, &Value::Str("linear".to_string()));
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBalance".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isolated: bool = is_equal(&marginMode, &Value::Str("isolated".to_string()));
let mut cross: bool = is_equal(&marginMode, &Value::Str("cross".to_string()));
let mut margin: bool = is_true(&(is_equal(&type_var, &Value::Str("margin".to_string())))) || is_true(&(is_true(&spot) && is_true(&(is_true(&cross) || is_true(&isolated)))));
let mut response: Value = Value::Null;
if is_true(&isMultiAssetMode) || is_true(&(is_true(&linear) && is_true(&(is_true(&swap) || is_true(&future))))) {
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_account_balance(&[__ws_arg_42]).await;
} else if is_true(&spot) || is_true(&margin) {
if is_true(&margin) {
if is_true(&isolated) {
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_margin_accounts_balance(&[__ws_arg_43]).await;
} else {
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_cross_margin_accounts_balance(&[__ws_arg_44]).await;
}
} else {
self.load_accounts(&[]).await;
let mut accountId: Value = self.fetch_account_id_by_type(type_var.clone(), &[Value::Null, Value::Null, params.clone()]).await;
add_element_to_object(&mut request, &Value::Str("account-id".to_string()), accountId.clone());
let __ws_arg_45 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_account_accounts_account_id_balance(&[__ws_arg_45]).await;
}
} else if is_true(&inverse) {
if is_true(&future) {
let __ws_arg_46 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_account_info(&[__ws_arg_46]).await;
} else {
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_account_info(&[__ws_arg_47]).await;
}
}
//
// spot
//
// {
// "status": "ok",
// "data": {
// "id": 1528640,
// "type": "spot",
// "state": "working",
// "list": [
// { "currency": "lun", "type": "trade", "balance": "0", "seq-num": "0" },
// { "currency": "lun", "type": "frozen", "balance": "0", "seq-num": "0" },
// { "currency": "ht", "type": "frozen", "balance": "0", "seq-num": "145" },
// ]
// },
// "ts":1637644827566
// }
//
// cross margin
//
// {
// "status": "ok",
// "data": {
// "id": 51015302,
// "type": "cross-margin",
// "state": "working",
// "risk-rate": "2",
// "acct-balance-sum": "100",
// "debt-balance-sum": "0",
// "list": [
// { "currency": "usdt", "type": "trade", "balance": "100" },
// { "currency": "usdt", "type": "frozen", "balance": "0" },
// { "currency": "usdt", "type": "loan-available", "balance": "200" },
// { "currency": "usdt", "type": "transfer-out-available", "balance": "-1" },
// { "currency": "ht", "type": "loan-available", "balance": "36.60724091" },
// { "currency": "ht", "type": "transfer-out-available", "balance": "-1" },
// { "currency": "btc", "type": "trade", "balance": "1168.533000000000000000" },
// { "currency": "btc", "type": "frozen", "balance": "0.000000000000000000" },
// { "currency": "btc", "type": "loan", "balance": "-2.433000000000000000" },
// { "currency": "btc", "type": "interest", "balance": "-0.000533000000000000" },
// { "currency": "btc", "type": "transfer-out-available", "balance": "1163.872174670000000000" },
// { "currency": "btc", "type": "loan-available", "balance": "8161.876538350676000000" }
// ]
// },
// "code": 200
// }
//
// isolated margin
//
// {
// "data": [
// {
// "id": 18264,
// "type": "margin",
// "state": "working",
// "symbol": "btcusdt",
// "fl-price": "0",
// "fl-type": "safe",
// "risk-rate": "475.952571086994250554",
// "list": [
// { "currency": "btc","type": "trade","balance": "1168.533000000000000000" },
// { "currency": "btc","type": "frozen","balance": "0.000000000000000000" },
// { "currency": "btc","type": "loan","balance": "-2.433000000000000000" },
// { "currency": "btc","type": "interest","balance": "-0.000533000000000000" },
// { "currency": "btc","type": "transfer-out-available", "balance": "1163.872174670000000000" },
// { "currency": "btc","type": "loan-available", "balance": "8161.876538350676000000" }
// ]
// }
// ]
// }
//
// future, swap isolated
//
// {
// "status": "ok",
// "data": [
// {
// "symbol": "BTC",
// "margin_balance": 0,
// "margin_position": 0E-18,
// "margin_frozen": 0,
// "margin_available": 0E-18,
// "profit_real": 0,
// "profit_unreal": 0,
// "risk_rate": null,
// "withdraw_available": 0,
// "liquidation_price": null,
// "lever_rate": 5,
// "adjust_factor": 0.025000000000000000,
// "margin_static": 0,
// "is_debit": 0, // future only
// "contract_code": "BTC-USD", // swap only
// "margin_asset": "USDT", // linear only
// "margin_mode": "isolated", // linear only
// "margin_account": "BTC-USDT" // linear only
// "transfer_profit_ratio": null // inverse only
// },
// ],
// "ts": 1637644827566
// }
//
// linear swap and multi asset mode
//
// {
// "code": 200,
// "message": "Success",
// "data": {
// "state": "normal",
// "equity": "174.216697577770536136",
// "details": [
// {
// "currency": "USDT",
// "equity": "174.216697577770536136",
// "available": "174.216697577770536136",
// "profit_unreal": "0",
// "initial_margin": "0",
// "maintenance_margin": "0",
// "maintenance_margin_rate": "0",
// "initial_margin_rate": "0",
// "available_margin": "174.216697577770536136",
// "voucher": "0",
// "voucher_value": "0",
// "withdraw_available": "174.216697577770536136",
// "created_time": 1770293270932,
// "updated_time": 1770293270932,
// "isolated_equity": "0",
// "isolated_profit_unreal": "0"
// }
// ],
// "initial_margin": "0",
// "maintenance_margin": "0",
// "maintenance_margin_rate": "0",
// "profit_unreal": "0",
// "available_margin": "174.216697577770536136",
// "voucher_value": "0",
// "created_time": 1770293268881,
// "updated_time": 1770293270932
// },
// "ts": 1770293281344
// }
//
let mut finalResponse: Value = response.clone();
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), finalResponse.clone());
m
});
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
if is_true(&isMultiAssetMode) || is_true(&(is_true(&linear) && is_true(&(is_true(&swap) || is_true(&future))))) {
let mut details: Value = self.safe_list_k(data.clone(), "details", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_768: bool = true;
while { if !__for_first_768 { i = add(&i, &Value::Int(1)); } __for_first_768 = false; is_less_than(&i, &get_array_length(&details)) } {
let mut balance: Value = get_value(&details, &i);
let mut balance: Value = get_value(&details, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "available_margin", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "equity", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
result = self.safe_balance(result.clone());
} else if is_true(&spot) || is_true(&margin) {
if is_true(&isolated) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_771: bool = true;
while { if !__for_first_771 { i = add(&i, &Value::Int(1)); } __for_first_771 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut balances: Value = self.safe_value_k(entry.clone(), "list", &[]);
let mut subResult: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_769: bool = true;
while { if !__for_first_769 { j = add(&j, &Value::Int(1)); } __for_first_769 = false; is_less_than(&j, &get_array_length(&balances)) } {
let mut balance: Value = get_value(&balances, &j);
let mut balance: Value = get_value(&balances, &j);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
if !is_equal(&code, &Value::Null) {
{ let __be_tmp = self.parse_margin_balance_helper(balance.clone(), code.clone(), subResult.clone()); add_element_to_object(&mut subResult, &code, __be_tmp); };
}
}
}
let mut subCodes: Value = object_keys(&subResult);
{
let mut j: Value = Value::Int(0);
let mut __for_first_770: bool = true;
while { if !__for_first_770 { j = add(&j, &Value::Int(1)); } __for_first_770 = false; is_less_than(&j, &get_array_length(&subCodes)) } {
let mut subCode: Value = get_value(&subCodes, &j);
let mut subCode: Value = get_value(&subCodes, &j);
result = self.merge_balance_account(result.clone(), subCode.clone(), get_value(&subResult, &subCode));
}
}
}
}
result = self.safe_balance(result.clone());
} else {
let mut balances: Value = self.safe_value_k(data.clone(), "list", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_772: bool = true;
while { if !__for_first_772 { i = add(&i, &Value::Int(1)); } __for_first_772 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut balance: Value = get_value(&balances, &i);
let mut balance: Value = get_value(&balances, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
if !is_equal(&code, &Value::Null) {
{ let __be_tmp = self.parse_margin_balance_helper(balance.clone(), code.clone(), result.clone()); add_element_to_object(&mut result, &code, __be_tmp); };
}
}
}
result = self.safe_balance(result.clone());
}
} else if is_true(&inverse) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_773: bool = true;
while { if !__for_first_773 { i = add(&i, &Value::Int(1)); } __for_first_773 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut balance: Value = get_value(&data, &i);
let mut balance: Value = get_value(&data, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "symbol", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "margin_available", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "margin_frozen", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
result = self.safe_balance(result.clone());
}
return result;
Value::Null
}
/*
* @method
* @name htx#fetchOrder
* @description fetches information on an order made by the user
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-the-order-detail-of-an-order-based-on-client-order-id
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-the-order-detail-of-an-order
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-196a8401f83
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-information-of-an-order
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-information-of-an-order
* @param {string} id order id
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] *linear only* set to true if you want to fetch a trigger order
* @param {bool} [params.stopLossTakeProfit] *linear only* set to true if you want to fetch a stop-loss take-profit order
* @param {bool} [params.stopLoss] *linear only* set to true if you want to fetch a stop-loss order
* @param {bool} [params.takeProfit] *linear only* set to true if you want to fetch a take-profit order
* @param {bool} [params.trailing] *linear only* set to true if you want to fetch a trailing order
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]); marketType = 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 mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
// will be filled below in extend ()
// they expect clientOrderId instead of client-order-id
// request['clientOrderId'] = clientOrderId;
let __ws_arg_48 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_order_orders_get_client_order(&[__ws_arg_48]).await;
} else {
add_element_to_object(&mut request, &Value::Str("order-id".to_string()), id.clone());
let __ws_arg_49 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_order_orders_order_id(&[__ws_arg_49]).await;
}
} else {
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(params.clone(), "stopLossTakeProfit", &[]);
let mut stopLoss: Value = self.safe_bool_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_bool_k(params.clone(), "takeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[]);
let mut isAlgo: Value = Value::Bool(is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLoss, &Value::Bool(true)))) || is_true(&(is_equal(&takeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))));
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("stopLossTakeProfit".to_string()), Value::Str("trailing".to_string()), Value::Str("trigger".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
let mut clientOrderId: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("algo_client_order_id".to_string())]), &[]);
if is_equal(&clientOrderId, &Value::Null) {
if is_equal(&isAlgo, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("algo_id".to_string()), id.clone());
} else {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), id.clone());
}
} else {
if is_equal(&isAlgo, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("algo_client_order_id".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderId.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("algo_client_order_id".to_string())]), &[]);
}
if is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)) {
if is_equal(&isAlgo, &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trigger".to_string()));
} else if is_equal(&trailing, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trailing_stop".to_string()));
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("tpsl".to_string()));
} else if is_equal(&stopLoss, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("sl".to_string()));
} else if is_equal(&takeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("tp".to_string()));
}
let __ws_arg_50 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_algo_order(&[__ws_arg_50]).await;
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol argument".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), self.safe_string_k(market.clone(), "id", &[]));
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
marginMode = ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Str("cross".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("margin_mode".to_string()), marginMode.clone());
let __ws_arg_51 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_trade_order(&[__ws_arg_51]).await;
}
} else if is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true)) {
if is_equal(&marketType, &Value::Str("future".to_string())) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "settleId", &[]));
let __ws_arg_52 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_order_info(&[__ws_arg_52]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), self.safe_string_k(market.clone(), "id", &[]));
let __ws_arg_53 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_order_info(&[__ws_arg_53]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchOrder() does not support ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
}
}
//
// spot
//
// {
// "status":"ok",
// "data":{
// "id":438398393065481,
// "symbol":"ethusdt",
// "account-id":1528640,
// "client-order-id":"AA03022abc2163433e-006b-480e-9ad1-d4781478c5e7",
// "amount":"0.100000000000000000",
// "price":"3000.000000000000000000",
// "created-at":1640549994642,
// "type":"buy-limit",
// "field-amount":"0.0",
// "field-cash-amount":"0.0",
// "field-fees":"0.0",
// "finished-at":0,
// "source":"spot-api",
// "state":"submitted",
// "canceled-at":0
// }
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": {
// "id": "1513828877079584768",
// "side": "buy",
// "type": "limit",
// "price": "50000",
// "volume": "1",
// "state": "new",
// "profit": null,
// "contract_code": "BTC-USDT",
// "position_side": "long",
// "price_match": null,
// "order_id": "1513828877079584768",
// "client_order_id": "1513828877079584768",
// "margin_mode": "cross",
// "lever_rate": 20,
// "order_source": "api",
// "reduce_only": false,
// "time_in_force": "gtc",
// "tp_trigger_price": "",
// "tp_order_price": "",
// "tp_type": "0",
// "tp_trigger_price_type": "",
// "sl_trigger_price": "",
// "sl_order_price": "",
// "sl_type": "0",
// "sl_trigger_price_type": "",
// "trade_avg_price": "0",
// "trade_volume": "0",
// "trade_turnover": "0",
// "fee_currency": "",
// "fee": "0",
// "price_protect": false,
// "real_profit": null,
// "contract_type": "swap",
// "created_time": "1780966529876",
// "updated_time": "1780966572409",
// "cancel_reason": null,
// "self_match_prevent": "cancel_taker"
// },
// "ts": 1780966573200
// }
//
// linear swap algo
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "id": "162320614",
// "volume": "2",
// "type": "tp",
// "state": "active",
// "side": "sell",
// "algo_id": "1513832307038027776",
// "contract_code": "BTC-USDT",
// "position_side": "long",
// "margin_mode": "cross",
// "created_time": "1780967347642",
// "updated_time": "1780967347848",
// "order_source": "api",
// "tp_trigger_price": "101000",
// "tp_order_price": "0",
// "tp_type": "market",
// "tp_trigger_price_type": "last"
// }
// ],
// "ts": 1780967407144
// }
//
let mut order: Value = self.safe_value_k(response.clone(), "data", &[]);
if is_true(&Value::Bool(is_array(&order))) {
order = self.safe_value(order.clone(), Value::Int(0), &[]);
}
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_balance_helper(&self, mut balance: Value, mut code: Value, mut result: Value) -> Value {
let mut account: Value = Value::Null;
if is_true(&Value::Bool(in_op(&result, &code))) {
account = get_value(&result, &code);
} else {
account = self.account();
}
if is_equal(&account, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseMarginBalanceHelper() could not resolve account".to_string()))));
}
if is_equal(&get_value(&balance, &Value::Str("type".to_string())), &Value::Str("trade".to_string())) {
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "balance", &[]));
}
if is_equal(&account, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseMarginBalanceHelper() could not resolve account".to_string()))));
}
if is_equal(&get_value(&balance, &Value::Str("type".to_string())), &Value::Str("frozen".to_string())) {
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "balance", &[]));
}
return account;
Value::Null
}
pub async fn fetch_spot_orders_by_states(&mut self, mut states: 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 method: Value = self.safe_string_k(self.options.clone(), "fetchOrdersByStatesMethod", &[Value::Str("spot_private_get_v1_order_orders".to_string())]); // spot_private_get_v1_order_history
if is_equal(&method, &Value::Str("spot_private_get_v1_order_orders".to_string())) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrders() requires a symbol argument".to_string()))));
}
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("states".to_string(), states.clone());
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start-time".to_string()), since.clone()); // a window of 48 hours within 180 days
add_element_to_object(&mut request, &Value::Str("end-time".to_string()), self.sum(&[since.clone(), multiply(&multiply(&multiply(&Value::Int(48), &Value::Int(60)), &Value::Int(60)), &Value::Int(1000))]));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end-time".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(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone());
}
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("spot_private_get_v1_order_orders".to_string())) {
let __ws_arg_54 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_order_orders(&[__ws_arg_54]).await;
} else {
let __ws_arg_55 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_order_history(&[__ws_arg_55]).await;
}
//
// spot_private_get_v1_order_orders GET /v1/order/orders
//
// {
// "status": "ok",
// "data": [
// {
// "id": 13997833014,
// "symbol": "ethbtc",
// "account-id": 3398321,
// "client-order-id": "23456",
// "amount": "0.045000000000000000",
// "price": "0.034014000000000000",
// "created-at": 1545836976871,
// "type": "sell-limit",
// "field-amount": "0.045000000000000000",
// "field-cash-amount": "0.001530630000000000",
// "field-fees": "0.000003061260000000",
// "finished-at": 1545837948214,
// "source": "spot-api",
// "state": "filled",
// "canceled-at": 0
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub async fn fetch_spot_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_spot_orders_by_states(Value::Str("pre-submitted,submitted,partial-filled,filled,partial-canceled,canceled".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
pub async fn fetch_closed_spot_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_spot_orders_by_states(Value::Str("filled".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
pub async fn fetch_contract_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchContractOrders() 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
});
let mut response: Value = Value::Null;
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_value_k(params.clone(), "stopLossTakeProfit", &[]);
let mut stopLoss: Value = self.safe_bool_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_bool_k(params.clone(), "takeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isAlgo: Value = Value::Bool(is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLoss, &Value::Bool(true)))) || is_true(&(is_equal(&takeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))));
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("stopLossTakeProfit".to_string()), Value::Str("trailing".to_string()), Value::Str("trigger".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".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(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchContractOrders".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
marginMode = ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Str("cross".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("margin_mode".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_equal(&isAlgo, &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trigger".to_string()));
} else if is_equal(&trailing, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trailing_stop".to_string()));
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("tpsl".to_string()));
} else if is_equal(&stopLoss, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("sl".to_string()));
} else if is_equal(&takeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("tp".to_string()));
}
let __ws_arg_56 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_algo_order_history(&[__ws_arg_56]).await;
} else {
let __ws_arg_57 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_trade_order_history(&[__ws_arg_57]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Int(1)); // 1:All Orders,2:Order in Finished Status
add_element_to_object(&mut request, &Value::Str("trade_type".to_string()), Value::Int(0)); // 0:All; 1: Open long; 2: Open short; 3: Close short; 4: Close long; 5: Liquidate long positions; 6: Liquidate short positions, 17:buy(one-way mode), 18:sell(one-way mode)
add_element_to_object(&mut request, &Value::Str("status".to_string()), Value::Str("0".to_string())); // support multiple query separated by ',',such as '3,4,5', 0: all. 3. Have submitted the orders; 4. Orders partially matched; 5. Orders cancelled with partially matched; 6. Orders fully matched; 7. Orders cancelled;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_58 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_trigger_hisorders(&[__ws_arg_58]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_59 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_tpsl_hisorders(&[__ws_arg_59]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_60 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_track_hisorders(&[__ws_arg_60]).await;
} else {
let __ws_arg_61 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v3_swap_hisorders(&[__ws_arg_61]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("settleId".to_string())));
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_62 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_trigger_hisorders(&[__ws_arg_62]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_63 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_tpsl_hisorders(&[__ws_arg_63]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_64 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_track_hisorders(&[__ws_arg_64]).await;
} else {
let __ws_arg_65 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v3_contract_hisorders(&[__ws_arg_65]).await;
}
}
}
let mut orders: Value = self.safe_value_k(response.clone(), "data", &[]);
if !is_true(&Value::Bool(is_array(&orders))) {
orders = self.safe_value_k(orders.clone(), "orders", &[Value::List(vec![])]);
}
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub async fn fetch_closed_contract_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchClosedContractOrders() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_value_k(params.clone(), "stopLossTakeProfit", &[]);
let mut stopLoss: Value = self.safe_bool_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_bool_k(params.clone(), "takeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isAlgo: Value = Value::Bool(is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLoss, &Value::Bool(true)))) || is_true(&(is_equal(&takeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))));
if is_equal(&isAlgo, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("states".to_string()), Value::Str("effective".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("states".to_string()), Value::Str("filled".to_string()));
}
} else {
add_element_to_object(&mut request, &Value::Str("status".to_string()), Value::Str("6".to_string()));
}
let __ws_arg_66 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_contract_orders(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_66]).await;
Value::Null
}
/*
* @method
* @name htx#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19589bc57bc
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b979b0aa2
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-history-orders-new
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-history-orders-via-multiple-fields-new
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {bool} [params.trigger] *contract only* if the orders are trigger trigger orders or not
* @param {bool} [params.trailing] *contract only* set to true if you want to fetch trailing stop orders
* @param {bool} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss and take-profit orders
* @param {bool} [params.stopLoss] *contract only* set to true if you want to fetch stop loss orders
* @param {bool} [params.takeProfit] *contract only* set to true if you want to fetch take profit orders
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut contract: bool = is_true(&(is_equal(&marketType, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("future".to_string()))));
if is_true(&contract) && is_true(&(is_equal(&symbol, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" fetchOrders() requires a symbol argument for ".to_string())), &marketType), &Value::Str(" orders".to_string()))));
}
if is_true(&contract) {
return self.fetch_contract_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
return self.fetch_spot_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name htx#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19589bc57bc
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b979b0aa2
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-history-orders-new
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-history-orders-via-multiple-fields-new
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @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_canceled_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchCanceledOrders".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("fetchCanceledOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Int(100)]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchCanceledOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
return self.fetch_spot_orders_by_states(Value::Str("partial-canceled,canceled".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" fetchCanceledOrders() requires a symbol argument for ".to_string())), &marketType), &Value::Str(" orders".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)) {
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_value_k(params.clone(), "stopLossTakeProfit", &[]);
let mut stopLoss: Value = self.safe_bool_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_bool_k(params.clone(), "takeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isAlgo: Value = Value::Bool(is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLoss, &Value::Bool(true)))) || is_true(&(is_equal(&takeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))));
if is_equal(&isAlgo, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("states".to_string()), Value::Str("canceled".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("states".to_string()), Value::Str("partially_canceled,canceled".to_string()));
}
} else {
add_element_to_object(&mut request, &Value::Str("status".to_string()), Value::Str("5,7".to_string())); // comma separated, 0 all, 3 submitted orders, 4 partially matched, 5 partially cancelled, 6 fully matched and closed, 7 canceled
}
let __ws_arg_67 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_contract_orders(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_67]).await;
}
Value::Null
}
/*
* @method
* @name htx#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-past-orders
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-historical-orders-within-48-hours
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19589bc57bc
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b979b0aa2
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-history-orders-new
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-history-orders-via-multiple-fields-new
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @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 {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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(), Value::Int(100)]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchClosedOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
return self.fetch_closed_spot_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
return self.fetch_closed_contract_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name htx#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-all-open-orders
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19589587da5
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b9754d736
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] *contract only* if the orders are trigger trigger orders or not
* @param {bool} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss or take-profit orders
* @param {bool} [params.stopLoss] *linear swap contract only* if the orders are stop-loss orders
* @param {bool} [params.takeProfit] *linear swap contract only* if the orders are take-profit orders
* @param {bool} [params.trailing] *contract only* set to true if you want to fetch trailing stop 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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isLinear: bool = is_equal(&subType, &Value::Str("linear".to_string()));
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
// todo replace with fetchAccountIdByType
let mut accountId: Value = self.safe_string_k(params.clone(), "account-id", &[]);
if is_equal(&accountId, &Value::Null) {
// pick the first account
self.load_accounts(&[]).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_774: bool = true;
while { if !__for_first_774 { i = add(&i, &Value::Int(1)); } __for_first_774 = false; is_less_than(&i, &get_array_length(&self.accounts)) } {
let mut account: Value = get_value(&self.accounts, &i);
if is_equal(&self.safe_string_k(account.clone(), "type", &[]), &Value::Str("spot".to_string())) {
accountId = self.safe_string_k(account.clone(), "id", &[]);
if !is_equal(&accountId, &Value::Null) {
break;
}
}
}
}
}
add_element_to_object(&mut request, &Value::Str("account-id".to_string()), accountId.clone());
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone());
}
params = self.omit(params.clone(), Value::Str("account-id".to_string()), &[]);
let __ws_arg_68 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_get_v1_order_open_orders(&[__ws_arg_68]).await;
} else {
if !is_equal(&symbol, &Value::Null) {
// throw new crate::exchange_errors::arguments_required (this.id + ' fetchOpenOrders() requires a symbol argument');
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
if !is_equal(&limit, &Value::Null) {
if is_true(&isLinear) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
}
}
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_k(params.clone(), "stopLossTakeProfit", &[]);
let mut stopLoss: Value = self.safe_bool_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_bool_k(params.clone(), "takeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("stopLossTakeProfit".to_string()), Value::Str("trailing".to_string()), Value::Str("trigger".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
if is_true(&isLinear) {
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&stopLoss, &Value::Bool(true)))) || is_true(&(is_equal(&takeProfit, &Value::Bool(true)))) {
if is_equal(&trigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trigger".to_string()));
} else if is_equal(&trailing, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trailing_stop".to_string()));
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("tpsl".to_string()));
} else if is_equal(&stopLoss, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("sl".to_string()));
} else if is_equal(&takeProfit, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("tp".to_string()));
}
let __ws_arg_69 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_algo_order_opens(&[__ws_arg_69]).await;
} else {
let __ws_arg_70 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_trade_order_opens(&[__ws_arg_70]).await;
}
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
if is_equal(&marketType, &Value::Str("swap".to_string())) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_71 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_trigger_openorders(&[__ws_arg_71]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_72 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_tpsl_openorders(&[__ws_arg_72]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_73 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_track_openorders(&[__ws_arg_73]).await;
} else {
let __ws_arg_74 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_openorders(&[__ws_arg_74]).await;
}
} else if is_equal(&marketType, &Value::Str("future".to_string())) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "settleId", &[Value::Str("usdt".to_string())]));
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_75 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_trigger_openorders(&[__ws_arg_75]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_76 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_tpsl_openorders(&[__ws_arg_76]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_77 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_track_openorders(&[__ws_arg_77]).await;
} else {
let __ws_arg_78 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_openorders(&[__ws_arg_78]).await;
}
}
}
}
//
// spot
//
// {
// "status":"ok",
// "data":[
// {
// "symbol":"ethusdt",
// "source":"api",
// "amount":"0.010000000000000000",
// "account-id":1528640,
// "created-at":1561597491963,
// "price":"400.000000000000000000",
// "filled-amount":"0.0",
// "filled-cash-amount":"0.0",
// "filled-fees":"0.0",
// "id":38477101630,
// "state":"submitted",
// "type":"sell-limit"
// }
// ]
// }
//
// futures
//
// {
// "status": "ok",
// "data": {
// "orders": [
// {
// "symbol": "ADA",
// "contract_code": "ADA201225",
// "contract_type": "quarter",
// "volume": 1,
// "price": 0.0925,
// "order_price_type": "post_only",
// "order_type": 1,
// "direction": "buy",
// "offset": "close",
// "lever_rate": 20,
// "order_id": 773131315209248768,
// "client_order_id": null,
// "created_at": 1604370469629,
// "trade_volume": 0,
// "trade_turnover": 0,
// "fee": 0,
// "trade_avg_price": null,
// "margin_frozen": 0,
// "profit": 0,
// "status": 3,
// "order_source": "web",
// "order_id_str": "773131315209248768",
// "fee_asset": "ADA",
// "liquidation_type": null,
// "canceled_at": null,
// "is_tpsl": 0,
// "update_time": 1606975980467,
// "real_profit": 0
// }
// ],
// "total_page": 1,
// "current_page": 1,
// "total_size": 1
// },
// "ts": 1604370488518
// }
//
// trigger
//
// {
// "status": "ok",
// "data": {
// "orders": [
// {
// "contract_type": "swap",
// "business_type": "swap",
// "pair": "BTC-USDT",
// "symbol": "BTC",
// "contract_code": "BTC-USDT",
// "trigger_type": "le",
// "volume": 1.000000000000000000,
// "order_type": 1,
// "direction": "buy",
// "offset": "open",
// "lever_rate": 1,
// "order_id": 1103670703588327424,
// "order_id_str": "1103670703588327424",
// "order_source": "web",
// "trigger_price": 25000.000000000000000000,
// "order_price": 24000.000000000000000000,
// "created_at": 1683177200945,
// "order_price_type": "limit",
// "status": 2,
// "margin_mode": "cross",
// "margin_account": "USDT",
// "trade_partition": "USDT",
// "reduce_only": 0
// }
// ],
// "total_page": 1,
// "current_page": 1,
// "total_size": 1
// },
// "ts": 1683177805320
// }
//
// stop-loss and take-profit
//
// {
// "status": "ok",
// "data": {
// "orders": [
// {
// "contract_type": "swap",
// "business_type": "swap",
// "pair": "BTC-USDT",
// "symbol": "BTC",
// "contract_code": "BTC-USDT",
// "margin_mode": "cross",
// "margin_account": "USDT",
// "volume": 1.000000000000000000,
// "order_type": 1,
// "direction": "sell",
// "order_id": 1103680386844839936,
// "order_id_str": "1103680386844839936",
// "order_source": "web",
// "trigger_type": "le",
// "trigger_price": 25000.000000000000000000,
// "order_price": 0E-18,
// "created_at": 1683179509613,
// "order_price_type": "market",
// "status": 2,
// "tpsl_order_type": "sl",
// "source_order_id": null,
// "relation_tpsl_order_id": "-1",
// "trade_partition": "USDT"
// }
// ],
// "total_page": 1,
// "current_page": 1,
// "total_size": 1
// },
// "ts": 1683179527011
// }
//
// trailing
//
// {
// "status": "ok",
// "data": {
// "orders": [
// {
// "contract_type": "swap",
// "business_type": "swap",
// "pair": "BTC-USDT",
// "symbol": "BTC",
// "contract_code": "BTC-USDT",
// "volume": 1.000000000000000000,
// "order_type": 1,
// "direction": "sell",
// "offset": "close",
// "lever_rate": 1,
// "order_id": 1192021437253877761,
// "order_id_str": "1192021437253877761",
// "order_source": "api",
// "created_at": 1704241657328,
// "order_price_type": "formula_price",
// "status": 2,
// "callback_rate": 0.050000000000000000,
// "active_price": 50000.000000000000000000,
// "is_active": 0,
// "margin_mode": "cross",
// "margin_account": "USDT",
// "trade_partition": "USDT",
// "reduce_only": 1
// },
// ],
// "total_page": 1,
// "current_page": 1,
// "total_size": 2
// },
// "ts": 1704242440106
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "id": "1512509978516443136",
// "side": "buy",
// "type": "limit",
// "price": "30",
// "volume": "1",
// "state": "new",
// "profit": null,
// "contract_code": "LTC-USDT",
// "position_side": "long",
// "price_match": null,
// "order_id": "1512509978516443136",
// "client_order_id": "1512509978516443136",
// "margin_mode": "isolated",
// "lever_rate": 10,
// "order_source": "api",
// "reduce_only": false,
// "time_in_force": "gtc",
// "tp_trigger_price": "",
// "tp_order_price": "",
// "tp_type": "0",
// "tp_trigger_price_type": "",
// "sl_trigger_price": "",
// "sl_order_price": "",
// "sl_type": "0",
// "sl_trigger_price_type": "",
// "trade_avg_price": "0",
// "trade_volume": "0",
// "trade_turnover": "0",
// "fee_currency": "",
// "fee": "0",
// "price_protect": false,
// "contract_type": "swap",
// "created_time": "1780652079954",
// "updated_time": "1780652079954",
// "cancel_reason": null,
// "self_match_prevent": "cancel_taker"
// }
// ],
// "ts": 1780652167077
// }
//
// linear swap algo
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "id": "162173672",
// "volume": "1",
// "type": "tp",
// "state": "active",
// "side": "sell",
// "algo_id": "1512871666507657216",
// "contract_code": "BTC-USDT",
// "position_side": "long",
// "margin_mode": "cross",
// "created_time": "1780738313091",
// "updated_time": "1780738313187",
// "order_source": "api",
// "tp_trigger_price": "101000",
// "tp_order_price": "0",
// "tp_type": "market",
// "tp_trigger_price_type": "last"
// }
// ],
// "ts": 1780739390596
// }
//
let mut orders: Value = self.safe_value_k(response.clone(), "data", &[]);
if !is_true(&Value::Bool(is_array(&orders))) {
orders = self.safe_value_k(orders.clone(), "orders", &[Value::List(vec![])]);
}
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.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("partial-filled".to_string(), Value::Str("open".to_string()));
m.insert("partial-canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("submitted".to_string(), Value::Str("open".to_string()));
m.insert("created".to_string(), Value::Str("open".to_string()));
m.insert("1".to_string(), Value::Str("open".to_string()));
m.insert("2".to_string(), Value::Str("open".to_string()));
m.insert("3".to_string(), Value::Str("open".to_string()));
m.insert("4".to_string(), Value::Str("open".to_string()));
m.insert("5".to_string(), Value::Str("canceled".to_string()));
m.insert("6".to_string(), Value::Str("closed".to_string()));
m.insert("7".to_string(), Value::Str("canceled".to_string()));
m.insert("11".to_string(), Value::Str("canceling".to_string()));
m.insert("active".to_string(), Value::Str("open".to_string()));
m.insert("new".to_string(), Value::Str("open".to_string()));
m.insert("partially_filled".to_string(), Value::Str("open".to_string()));
m.insert("partially_canceled".to_string(), Value::Str("canceled".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
//
// {
// "id": 13997833014,
// "symbol": "ethbtc",
// "account-id": 3398321,
// "amount": "0.045000000000000000",
// "price": "0.034014000000000000",
// "created-at": 1545836976871,
// "type": "sell-limit",
// "field-amount": "0.045000000000000000", // they have fixed it for filled-amount
// "field-cash-amount": "0.001530630000000000", // they have fixed it for filled-cash-amount
// "field-fees": "0.000003061260000000", // they have fixed it for filled-fees
// "finished-at": 1545837948214,
// "source": "spot-api",
// "state": "filled",
// "canceled-at": 0
// }
//
// {
// "id": 20395337822,
// "symbol": "ethbtc",
// "account-id": 5685075,
// "amount": "0.001000000000000000",
// "price": "0.0",
// "created-at": 1545831584023,
// "type": "buy-market",
// "field-amount": "0.029100000000000000", // they have fixed it for filled-amount
// "field-cash-amount": "0.000999788700000000", // they have fixed it for filled-cash-amount
// "field-fees": "0.000058200000000000", // they have fixed it for filled-fees
// "finished-at": 1545831584181,
// "source": "spot-api",
// "state": "filled",
// "canceled-at": 0
// }
//
// linear swap createOrder, closePosition
//
// {
// "order_id": "1512501029504577536",
// "client_order_id": "1512501029504577536"
// }
//
// linear swap algo createOrder
//
// {
// "algo_id": "1512871666507657216",
// "algo_client_order_id": null
// }
//
// future and swap: fetchOrders
//
// {
// "order_id": 773131315209248768,
// "contract_code": "ADA201225",
// "symbol": "ADA",
// "lever_rate": 20,
// "direction": "buy",
// "offset": "close",
// "volume": 1,
// "price": 0.0925,
// "create_date": 1604370469629,
// "update_time": 1603704221118,
// "order_source": "web",
// "order_price_type": 6,
// "order_type": 1,
// "margin_frozen": 0,
// "profit": 0,
// "contract_type": "quarter",
// "trade_volume": 0,
// "trade_turnover": 0,
// "fee": 0,
// "trade_avg_price": 0,
// "status": 3,
// "order_id_str": "773131315209248768",
// "fee_asset": "ADA",
// "liquidation_type": "0",
// "is_tpsl": 0,
// "real_profit": 0
// "margin_asset": "USDT",
// "margin_mode": "cross",
// "margin_account": "USDT",
// "trade_partition": "USDT", // only in isolated & cross of linear
// "reduce_only": "1", // only in isolated & cross of linear
// "contract_type": "quarter", // only in cross-margin (inverse & linear)
// "pair": "BTC-USDT", // only in cross-margin (inverse & linear)
// "business_type": "futures" // only in cross-margin (inverse & linear)
// }
//
// spot: createOrders
//
// [
// {
// "order-id": 936847569789079,
// "client-order-id": "AA03022abc3a55e82c-0087-4fc2-beac-112fdebb1ee9"
// },
// {
// "client-order-id": "AA03022abcdb3baefb-3cfa-4891-8009-082b3d46ca82",
// "err-code": "account-frozen-balance-insufficient-error",
// "err-msg": "trade account balance is not enough, left: `89`"
// }
// ]
//
// swap and future: createOrders
//
// [
// {
// "index": 2,
// "err_code": 1047,
// "err_msg": "Insufficient margin available."
// },
// {
// "order_id": 1172923090632953857,
// "index": 1,
// "order_id_str": "1172923090632953857"
// }
// ]
//
// linear swap fetchOpenOrders, fetchOrder, fetchOrders
//
// {
// "id": "1512509978516443136",
// "side": "buy",
// "type": "limit",
// "price": "30",
// "volume": "1",
// "state": "new",
// "profit": null,
// "contract_code": "LTC-USDT",
// "position_side": "long",
// "price_match": null,
// "order_id": "1512509978516443136",
// "client_order_id": "1512509978516443136",
// "margin_mode": "isolated",
// "lever_rate": 10,
// "order_source": "api",
// "reduce_only": false,
// "time_in_force": "gtc",
// "tp_trigger_price": "",
// "tp_order_price": "",
// "tp_type": "0",
// "tp_trigger_price_type": "",
// "sl_trigger_price": "",
// "sl_order_price": "",
// "sl_type": "0",
// "sl_trigger_price_type": "",
// "trade_avg_price": "0",
// "trade_volume": "0",
// "trade_turnover": "0",
// "fee_currency": "",
// "fee": "0",
// "price_protect": false,
// "real_profit": null,
// "contract_type": "swap",
// "created_time": "1780652079954",
// "updated_time": "1780652079954",
// "cancel_reason": null,
// "self_match_prevent": "cancel_taker"
// }
//
// linear swap algo fetchOpenOrders, fetchOrder, fetchOrders
//
// {
// "id": "162173672",
// "volume": "1",
// "type": "tp",
// "state": "active",
// "side": "sell",
// "algo_id": "1512871666507657216",
// "contract_code": "BTC-USDT",
// "position_side": "long",
// "margin_mode": "cross",
// "created_time": "1780738313091",
// "updated_time": "1780738313187",
// "order_source": "api",
// "tp_trigger_price": "101000",
// "tp_order_price": "0",
// "tp_type": "market",
// "tp_trigger_price_type": "last"
// }
//
// linear swap trailing fetchOpenOrders, fetchOrder, fetchOrders
//
// {
// "id": "1163773",
// "volume": "1",
// "type": "trailing_stop",
// "state": "active",
// "side": "sell",
// "algo_id": "1512889773167009792",
// "contract_code": "BTC-USDT",
// "position_side": "long",
// "margin_mode": "cross",
// "created_time": "1780742630055",
// "updated_time": "1780742630223",
// "order_source": "api",
// "active_price": "90000",
// "callback_rate": "0.05",
// "reduce_only": true,
// "order_price_type": "formula_price"
// }
//
let mut marketId: Value = self.safe_string2(order.clone(), Value::Str("contract_code".to_string()), Value::Str("symbol".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut rejectedCreateOrders: Value = self.safe_string2(order.clone(), Value::Str("err_code".to_string()), Value::Str("err-code".to_string()), &[]);
let mut status: Value = self.parse_order_status(self.safe_string2(order.clone(), Value::Str("state".to_string()), Value::Str("status".to_string()), &[]));
if !is_equal(&rejectedCreateOrders, &Value::Null) {
status = Value::Str("rejected".to_string());
}
let mut id: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("algo_id".to_string()), Value::Str("id".to_string()), Value::Str("order_id_str".to_string()), Value::Str("order-id".to_string()), Value::Str("order_id".to_string())]), &[]);
let mut side: Value = self.safe_string2(order.clone(), Value::Str("direction".to_string()), Value::Str("side".to_string()), &[]);
let mut contractCode: Value = self.safe_string_k(order.clone(), "contract_code", &[]);
let mut isLinearOrder: Value = Value::Bool(is_true(&(!is_equal(&contractCode, &Value::Null))) && is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))) && is_true(&(!is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))));
let mut type_var: Value = Value::Null;
if is_equal(&isLinearOrder, &Value::Bool(true)) {
type_var = self.safe_string_k(order.clone(), "type", &[]);
if is_true(&(is_equal(&type_var, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("tp".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("sl".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("tpsl".to_string())))) {
type_var = self.safe_string2(order.clone(), Value::Str("tp_type".to_string()), Value::Str("sl_type".to_string()), &[]);
}
if is_equal(&type_var, &Value::Str("0".to_string())) {
type_var = Value::Null;
}
} else {
type_var = self.safe_string_k(order.clone(), "order_price_type", &[]);
let mut rawType: Value = self.safe_string_k(order.clone(), "type", &[]);
if !is_equal(&rawType, &Value::Null) {
if is_greater_than_or_equal(&get_index_of(&rawType, &Value::Str("-".to_string())), &Value::Int(0)) {
let mut orderType: Value = split(&rawType, &Value::Str("-".to_string()));
side = get_value(&orderType, &Value::Int(0));
type_var = get_value(&orderType, &Value::Int(1));
} else if is_equal(&type_var, &Value::Null) {
type_var = rawType.clone();
}
}
}
let mut timestamp: Value = self.safe_integer_n(order.clone(), Value::List(vec![Value::Str("created_at".to_string()), Value::Str("created-at".to_string()), Value::Str("create_date".to_string()), Value::Str("created_time".to_string())]), &[]);
let mut clientOrderId: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), add(&Value::Str("client-or".to_string()), &Value::Str("der-id".to_string())), Value::Str("algo_client_order_id".to_string())]), &[]); // transpiler regex trick for php issue
let mut cost: Value = Value::Null;
let mut amount: Value = Value::Null;
if is_true(&(!is_equal(&type_var, &Value::Null))) && is_true(&(is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("market".to_string())), &Value::Int(0)))) && is_true(&(!is_equal(&isLinearOrder, &Value::Bool(true)))) {
cost = self.safe_string_k(order.clone(), "field-cash-amount", &[]);
} else {
amount = self.safe_string2(order.clone(), Value::Str("volume".to_string()), Value::Str("amount".to_string()), &[]);
cost = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("filled-cash-amount".to_string()), Value::Str("field-cash-amount".to_string()), Value::Str("trade_turnover".to_string())]), &[]); // same typo here
}
let mut filled: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("filled-amount".to_string()), Value::Str("field-amount".to_string()), Value::Str("trade_volume".to_string())]), &[]); // typo in their API, filled amount
let mut price: Value = self.safe_string2(order.clone(), Value::Str("price".to_string()), Value::Str("order_price".to_string()), &[]);
let mut feeCost: Value = self.safe_string2(order.clone(), Value::Str("filled-fees".to_string()), Value::Str("field-fees".to_string()), &[]); // typo in their API, filled feeSide
feeCost = self.safe_string_k(order.clone(), "fee", &[feeCost.clone()]);
let mut fee: Value = Value::Null;
if is_true(&(!is_equal(&feeCost, &Value::Null))) && is_true(&(!is_equal(&feeCost, &Value::Str("0".to_string())))) && is_true(&(!is_equal(&feeCost, &Value::Str("0.0".to_string())))) {
let mut feeCurrency: Value = Value::Null;
let mut feeCurrencyId: Value = self.safe_string2(order.clone(), Value::Str("fee_asset".to_string()), Value::Str("fee_currency".to_string()), &[]);
if !is_equal(&feeCurrencyId, &Value::Null) {
feeCurrency = self.safe_currency_code(feeCurrencyId.clone(), &[]);
} else {
feeCurrency = ternary(is_true(&(is_equal(&side, &Value::Str("sell".to_string())))), get_value(&market, &Value::Str("quote".to_string())), get_value(&market, &Value::Str("base".to_string())));
}
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), feeCurrency.clone());
m
});
}
let mut average: Value = self.safe_string_k(order.clone(), "trade_avg_price", &[]);
let mut trades: Value = self.safe_value_k(order.clone(), "trades", &[]);
let mut reduceOnly: Value = Value::Null;
if is_equal(&isLinearOrder, &Value::Bool(true)) {
reduceOnly = self.safe_bool_k(order.clone(), "reduce_only", &[]);
} else {
let mut reduceOnlyInteger: Value = self.safe_integer_k(order.clone(), "reduce_only", &[]);
if !is_equal(&reduceOnlyInteger, &Value::Null) {
reduceOnly = ternary(is_true(&(is_equal(&reduceOnlyInteger, &Value::Int(0)))), Value::Bool(false), Value::Bool(true));
}
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), self.safe_string_upper(order.clone(), Value::Str("time_in_force".to_string()), &[]));
m.insert("postOnly".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), self.safe_string2(order.clone(), Value::Str("stop-price".to_string()), Value::Str("trigger_price".to_string()), &[]));
m.insert("stopLossPrice".to_string(), self.safe_string2(order.clone(), Value::Str("sl_trigger_price".to_string()), Value::Str("sl_order_price".to_string()), &[]));
m.insert("takeProfitPrice".to_string(), self.safe_string2(order.clone(), Value::Str("tp_trigger_price".to_string()), Value::Str("tp_order_price".to_string()), &[]));
m.insert("average".to_string(), average.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("reduceOnly".to_string(), reduceOnly.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("trades".to_string(), trades.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4ee16-7773-11ed-9966-0242ac110003
* @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
* @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;
}
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()))));
}
add_element_to_object(&mut params, &Value::Str("createMarketBuyOrderRequiresPrice".to_string()), Value::Bool(false));
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
}
/*
* @method
* @name htx#createTrailingPercentOrder
* @description create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency, or number of contracts
* @param {float} [price] the price for the order to be filled at, in units of the quote currency, ignored in market orders
* @param {float} trailingPercent the percent to trail away from the current market price
* @param {float} trailingTriggerPrice the price to activate a trailing order, default uses the price argument
* @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_trailing_percent_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 trailingPercent = get_arg(optional_args, 1, Value::Null);
let mut trailingTriggerPrice = 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(&trailingPercent, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createTrailingPercentOrder() requires a trailingPercent argument".to_string()))));
}
if is_equal(&trailingTriggerPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createTrailingPercentOrder() requires a trailingTriggerPrice argument".to_string()))));
}
add_element_to_object(&mut params, &Value::Str("trailingPercent".to_string()), trailingPercent.clone());
add_element_to_object(&mut params, &Value::Str("trailingTriggerPrice".to_string()), trailingTriggerPrice.clone());
return self.create_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @ignore
* @name htx#createSpotOrderRequest
* @description helper function to build request
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
* @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount for market buy orders
* @returns {object} request to be sent to the exchange
*/
pub async fn create_spot_order_request(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_accounts(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountId: Value = self.fetch_account_id_by_type(get_value(&market, &Value::Str("type".to_string())), &[marginMode.clone(), symbol.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account-id".to_string(), accountId.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut orderType: Value = replace_str(&type_var, &Value::Str("buy-".to_string()), &Value::Str("".to_string()));
orderType = replace_str(&orderType, &Value::Str("sell-".to_string()), &Value::Str("".to_string()));
let mut options: Value = self.safe_value(self.options.clone(), get_value(&market, &Value::Str("type".to_string())), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut triggerPrice: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("stop-price".to_string())]), &[]);
if is_equal(&triggerPrice, &Value::Null) {
let mut stopOrderTypes: Value = self.safe_value_k(options.clone(), "stopOrderTypes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&Value::Bool(in_op(&stopOrderTypes, &orderType))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a triggerPrice for a trigger order".to_string()))));
}
} else {
let mut defaultOperator: Value = ternary(is_true(&(is_equal(&side, &Value::Str("sell".to_string())))), Value::Str("lte".to_string()), Value::Str("gte".to_string()));
let mut stopOperator: Value = self.safe_string_k(params.clone(), "operator", &[defaultOperator.clone()]);
add_element_to_object(&mut request, &Value::Str("stop-price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("operator".to_string()), stopOperator.clone());
if is_true(&(is_equal(&orderType, &Value::Str("limit".to_string())))) || is_true(&(is_equal(&orderType, &Value::Str("limit-fok".to_string())))) {
orderType = add(&Value::Str("stop-".to_string()), &orderType);
} else if is_true(&(!is_equal(&orderType, &Value::Str("stop-limit".to_string())))) && is_true(&(!is_equal(&orderType, &Value::Str("stop-limit-fok".to_string())))) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" createOrder() does not support ".to_string())), &type_var), &Value::Str(" orders".to_string()))));
}
}
let mut postOnly: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&orderType, &Value::Str("market".to_string()))), Value::Bool(is_equal(&orderType, &Value::Str("limit-maker".to_string()))), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&postOnly, &Value::Bool(true)) {
orderType = Value::Str("limit-maker".to_string());
}
let mut timeInForce: Value = self.safe_string_k(params.clone(), "timeInForce", &[Value::Str("GTC".to_string())]);
if is_equal(&timeInForce, &Value::Str("FOK".to_string())) {
orderType = add(&orderType, &Value::Str("-fok".to_string()));
} else if is_equal(&timeInForce, &Value::Str("IOC".to_string())) {
orderType = Value::Str("ioc".to_string());
}
add_element_to_object(&mut request, &Value::Str("type".to_string()), add(&add(&side, &Value::Str("-".to_string())), &orderType));
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("client-order-id".to_string()), &[]); // must be 64 chars max and unique within 24 hours
if is_equal(&clientOrderId, &Value::Null) {
let mut broker: Value = self.safe_value_k(self.options.clone(), "broker", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut brokerId: Value = self.safe_string_k(broker.clone(), "id", &[]);
add_element_to_object(&mut request, &Value::Str("client-order-id".to_string()), add(&brokerId, &self.uuid(&[])));
} else {
add_element_to_object(&mut request, &Value::Str("client-order-id".to_string()), clientOrderId.clone());
}
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
add_element_to_object(&mut request, &Value::Str("source".to_string()), Value::Str("super-margin-api".to_string()));
} else if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
add_element_to_object(&mut request, &Value::Str("source".to_string()), Value::Str("margin-api".to_string()));
} else if is_equal(&marginMode, &Value::Str("c2c".to_string())) {
add_element_to_object(&mut request, &Value::Str("source".to_string()), Value::Str("c2c-margin-api".to_string()));
}
if is_true(&(is_equal(&orderType, &Value::Str("market".to_string())))) && 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.amount_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 in the amount argument".to_string()))));
} else {
// despite that cost = amount * price is in quote currency and should have quote precision
// the exchange API requires the cost supplied in 'amount' to be of base precision
// more about it here:
// https://github.com/ccxt/ccxt/pull/4395
// https://github.com/ccxt/ccxt/issues/7611
// we use amountToPrecision here because the exchange requires cost in base precision
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
quoteAmount = self.amount_to_precision(symbol.clone(), crate::precise::Precise::stringMul(&amountString, &priceString));
}
} else {
quoteAmount = self.amount_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()));
}
let mut limitOrderTypes: Value = self.safe_value_k(options.clone(), "limitOrderTypes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&Value::Bool(in_op(&limitOrderTypes, &orderType))) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("stop-price".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("client-order-id".to_string()), Value::Str("operator".to_string()), Value::Str("timeInForce".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
pub fn create_contract_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
/*
* @method
* @ignore
* @name htx#createContractOrderRequest
* @description helper function to build request
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
* @param {float} [params.trailingPercent] *contract only* the percent to trail away from the current market price
* @param {float} [params.trailingTriggerPrice] *contract only* the price to trigger a trailing order, default uses the price argument
* @param {object} [params.takeProfit] *takeProfit object in params, linear swap only* containing the triggerPrice at which the attached take profit order will be triggered
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {float} [params.takeProfit.price] take profit order price take profit orders
* @param {string} [params.takeProfit.type] market is the default, limit, optimal_5, optimal_10, optimal_20
* @param {object} [params.stopLoss] *stopLoss object in params, linear swap only* containing the triggerPrice at which the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {float} [params.stopLoss.price] stop loss order price for stop loss orders
* @param {string} [params.stopLoss.type] market is the default, limit, optimal_5, optimal_10, optimal_20
* @returns {object} request to be sent to the exchange
*/
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract_code".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("volume".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
let mut postOnly: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(is_equal(&type_var, &Value::Str("post_only".to_string()))), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&postOnly, &Value::Bool(true)) {
type_var = Value::Str("post_only".to_string());
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("createOrder".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isLinear: bool = is_equal(&subType, &Value::Str("linear".to_string()));
let mut reduceOnly: Value = self.safe_bool2(params.clone(), Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), &[Value::Bool(false)]);
let mut hedged: Value = self.safe_bool_k(params.clone(), "hedged", &[Value::Bool(false)]);
let mut timeInForce: Value = self.safe_string_lower2(params.clone(), Value::Str("timeInForce".to_string()), Value::Str("time_in_force".to_string()), &[Value::Str("gtc".to_string())]);
if is_true(&isLinear) {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".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)); }
add_element_to_object(&mut request, &Value::Str("margin_mode".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("side".to_string()), side.clone());
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("time_in_force".to_string()), to_lower(&timeInForce));
}
let mut stopLoss: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut stopLossTriggerPriceAttached: Value = self.safe_number_k(stopLoss.clone(), "triggerPrice", &[]);
let mut stopLossOrderPrice: Value = self.safe_number_k(stopLoss.clone(), "price", &[]);
let mut stopLossType: Value = self.safe_string_k(stopLoss.clone(), "type", &[]);
let mut takeProfitTriggerPriceAttached: Value = self.safe_number_k(takeProfit.clone(), "triggerPrice", &[]);
let mut takeProfitOrderPrice: Value = self.safe_number_k(takeProfit.clone(), "price", &[]);
let mut takeProfitType: Value = self.safe_string_k(takeProfit.clone(), "type", &[]);
// on htx for attached tpsl orders sl_order_price or tp_order_price need to be filled and the sl_trigger_price or tp_trigger_price are optional
if !is_equal(&stopLoss, &Value::Null) {
if !is_equal(&stopLossTriggerPriceAttached, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("sl_trigger_price".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPriceAttached.clone()));
}
if !is_equal(&stopLossOrderPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("sl_order_price".to_string()), self.price_to_precision(symbol.clone(), stopLossOrderPrice.clone()));
}
if !is_equal(&stopLossType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("sl_type".to_string()), stopLossType.clone());
}
params = self.omit(params.clone(), Value::Str("stopLoss".to_string()), &[]);
}
if !is_equal(&takeProfit, &Value::Null) {
if !is_equal(&takeProfitTriggerPriceAttached, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tp_trigger_price".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPriceAttached.clone()));
}
if !is_equal(&takeProfitOrderPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tp_order_price".to_string()), self.price_to_precision(symbol.clone(), takeProfitOrderPrice.clone()));
}
if !is_equal(&takeProfitType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tp_type".to_string()), takeProfitType.clone());
}
params = self.omit(params.clone(), Value::Str("takeProfit".to_string()), &[]);
}
} else {
if is_equal(&hedged, &Value::Bool(true)) {
if is_equal(&reduceOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("offset".to_string()), Value::Str("close".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("offset".to_string()), Value::Str("open".to_string()));
}
}
if is_equal(&timeInForce, &Value::Str("fok".to_string())) {
type_var = Value::Str("fok".to_string());
} else if is_equal(&timeInForce, &Value::Str("ioc".to_string())) {
type_var = Value::Str("ioc".to_string());
}
add_element_to_object(&mut request, &Value::Str("direction".to_string()), side.clone());
}
let mut triggerPrice: Value = self.safe_number_n(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("trigger_price".to_string())]), &[]);
let mut stopLossTriggerPrice: Value = self.safe_number2(params.clone(), Value::Str("stopLossPrice".to_string()), Value::Str("sl_trigger_price".to_string()), &[]);
let mut takeProfitTriggerPrice: Value = self.safe_number2(params.clone(), Value::Str("takeProfitPrice".to_string()), Value::Str("tp_trigger_price".to_string()), &[]);
let mut trailingPercent: Value = self.safe_string2(params.clone(), Value::Str("trailingPercent".to_string()), Value::Str("callback_rate".to_string()), &[]);
let mut trailingTriggerPrice: Value = self.safe_number_k(params.clone(), "trailingTriggerPrice", &[price.clone()]);
let mut isTrailingPercentOrder: bool = !is_equal(&trailingPercent, &Value::Null);
let mut isTrigger: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossTriggerOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitTriggerOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
let mut clientOrderId: Value = self.safe_integer_n(params.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("algo_client_order_id".to_string())]), &[]);
if is_true(&isLinear) && is_true(&(is_true(&isTrailingPercentOrder) || is_true(&isTrigger) || is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder))) {
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("algo_client_order_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("client_order_id".to_string())]), &[]);
}
}
if is_true(&isTrigger) {
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
if is_true(&isLinear) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trigger".to_string()));
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()));
}
} else {
let mut triggerType: Value = self.safe_string2(params.clone(), Value::Str("triggerType".to_string()), Value::Str("trigger_type".to_string()), &[Value::Str("le".to_string())]);
add_element_to_object(&mut request, &Value::Str("trigger_type".to_string()), triggerType.clone());
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order_price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
}
} else if is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder) {
if is_true(&isStopLossTriggerOrder) {
if !is_true(&isLinear) {
add_element_to_object(&mut request, &Value::Str("sl_order_price_type".to_string()), type_var.clone());
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("sl".to_string()));
}
add_element_to_object(&mut request, &Value::Str("sl_trigger_price".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("sl_order_price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
} else {
if !is_true(&isLinear) {
add_element_to_object(&mut request, &Value::Str("tp_order_price_type".to_string()), type_var.clone());
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("tp".to_string()));
}
add_element_to_object(&mut request, &Value::Str("tp_trigger_price".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tp_order_price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
}
} else if is_true(&isTrailingPercentOrder) {
let mut trailingPercentString: Value = crate::precise::Precise::stringDiv(&trailingPercent, &Value::Str("100".to_string()));
add_element_to_object(&mut request, &Value::Str("callback_rate".to_string()), self.parse_to_numeric(trailingPercentString.clone()));
add_element_to_object(&mut request, &Value::Str("order_price_type".to_string()), self.safe_string_k(params.clone(), "order_price_type", &[Value::Str("formula_price".to_string())]));
add_element_to_object(&mut request, &Value::Str("active_price".to_string()), trailingTriggerPrice.clone());
if is_true(&isLinear) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("trailing_stop".to_string()));
}
} else {
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string())]), &[]);
}
if is_equal(&type_var, &Value::Str("limit".to_string())) || is_equal(&type_var, &Value::Str("ioc".to_string())) || is_equal(&type_var, &Value::Str("fok".to_string())) || is_equal(&type_var, &Value::Str("post_only".to_string())) {
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_true(&isStopLossTriggerOrder) && !is_true(&isTakeProfitTriggerOrder) {
if is_equal(&reduceOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("reduce_only".to_string()), Value::Int(1));
}
if is_true(&isLinear) {
if !is_true(&isTrailingPercentOrder) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), type_var.clone());
}
} else {
if !is_true(&isTrailingPercentOrder) {
add_element_to_object(&mut request, &Value::Str("order_price_type".to_string()), type_var.clone());
}
add_element_to_object(&mut request, &Value::Str("lever_rate".to_string()), self.safe_integer_n(params.clone(), Value::List(vec![Value::Str("leverRate".to_string()), Value::Str("lever_rate".to_string()), Value::Str("leverage".to_string())]), &[Value::Int(1)]));
}
}
let mut broker: Value = self.safe_value_k(self.options.clone(), "broker", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut brokerId: Value = self.safe_string_k(broker.clone(), "id", &[]);
add_element_to_object(&mut request, &Value::Str("channel_code".to_string()), brokerId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("triggerType".to_string()), Value::Str("leverRate".to_string()), Value::Str("timeInForce".to_string()), Value::Str("leverage".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("trailingTriggerPrice".to_string()), Value::Str("hedged".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name htx#createOrder
* @description create a trade order
* @see https://huobiapi.github.io/docs/spot/v1/en/#place-a-new-order // spot, margin
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-an-order // coin-m swap
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-trigger-order // coin-m swap trigger
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19588768fe7 // usdt-m swap cross and isolated
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b933812c9 // usdt-m swap cross and isolated trigger and trailing orders
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#isolated-set-a-take-profit-and-stop-loss-order-for-an-existing-position
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#cross-set-a-take-profit-and-stop-loss-order-for-an-existing-position
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-an-order // coin-m futures
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-trigger-order // coin-m futures contract trigger
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price 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 a trigger order is triggered at
* @param {string} [params.triggerType] *contract trigger orders only* ge: greater than or equal to, le: less than or equal to
* @param {float} [params.stopLossPrice] *contract only* the price a stop-loss order is triggered at
* @param {float} [params.takeProfitPrice] *contract only* the price a take-profit order is triggered at
* @param {string} [params.operator] *spot and margin only* gte or lte, trigger price condition
* @param {string} [params.offset] *contract only* 'both' (linear only), 'open', or 'close', required in hedge mode and for inverse markets
* @param {bool} [params.postOnly] *contract only* true or false
* @param {int} [params.leverRate] *contract only* required for all contract orders except tpsl, leverage greater than 20x requires prior approval of high-leverage agreement
* @param {string} [params.timeInForce] supports 'IOC' and 'FOK'
* @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
* @param {float} [params.trailingPercent] *contract only* the percent to trail away from the current market price
* @param {float} [params.trailingTriggerPrice] *contract only* the price to trigger a trailing order, default uses the price argument
* @param {bool} [params.hedged] *contract only* true for hedged mode, false for one way mode, default is false
* @param {string} [params.marginMode] linear swap supports 'cross' and 'isolated', 'cross' is the default
* @param {string} [params.position_side] linear swap supports 'long', 'short' and 'both', 'both' is the default
* @param {object} [params.takeProfit] *takeProfit object in params, linear swap only* containing the triggerPrice at which the attached take profit order will be triggered
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {float} [params.takeProfit.price] take profit price for take profit orders
* @param {string} [params.takeProfit.type] market is the default, limit, optimal_5, optimal_10, optimal_20
* @param {object} [params.stopLoss] *stopLoss object in params, linear swap only* containing the triggerPrice at which the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {float} [params.stopLoss.price] stop loss price for stop loss orders
* @param {string} [params.stopLoss.type] market is the default, limit, optimal_5, optimal_10, optimal_20
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut triggerPrice: Value = self.safe_number_n(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("trigger_price".to_string())]), &[]);
let mut stopLossTriggerPrice: Value = self.safe_number2(params.clone(), Value::Str("stopLossPrice".to_string()), Value::Str("sl_trigger_price".to_string()), &[]);
let mut takeProfitTriggerPrice: Value = self.safe_number2(params.clone(), Value::Str("takeProfitPrice".to_string()), Value::Str("tp_trigger_price".to_string()), &[]);
let mut trailingPercent: Value = self.safe_number_k(params.clone(), "trailingPercent", &[]);
let mut isTrailingPercentOrder: bool = !is_equal(&trailingPercent, &Value::Null);
let mut isTrigger: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossTriggerOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitTriggerOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if is_true(&isTrailingPercentOrder) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() does not support trailing orders for spot markets".to_string()))));
}
let mut spotRequest: Value = self.create_spot_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
response = self.spot_private_post_v1_order_orders_place(&[spotRequest.clone()]).await;
} else {
let mut contractRequest: Value = self.create_contract_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
if is_true(&isTrigger) || is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder) || is_true(&isTrailingPercentOrder) {
response = self.contract_private_post_v5_algo_order(&[contractRequest.clone()]).await;
} else {
response = self.contract_private_post_v5_trade_order(&[contractRequest.clone()]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let mut offset: Value = self.safe_string_k(params.clone(), "offset", &[]);
if is_equal(&offset, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder () requires an extra parameter params[\"offset\"] to be set to \"open\" or \"close\" when placing orders in inverse markets".to_string()))));
}
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_true(&isTrigger) {
response = self.contract_private_post_swap_api_v1_swap_trigger_order(&[contractRequest.clone()]).await;
} else if is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder) {
response = self.contract_private_post_swap_api_v1_swap_tpsl_order(&[contractRequest.clone()]).await;
} else if is_true(&isTrailingPercentOrder) {
response = self.contract_private_post_swap_api_v1_swap_track_order(&[contractRequest.clone()]).await;
} else {
response = self.contract_private_post_swap_api_v1_swap_order(&[contractRequest.clone()]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
if is_true(&isTrigger) {
response = self.contract_private_post_api_v1_contract_trigger_order(&[contractRequest.clone()]).await;
} else if is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder) {
response = self.contract_private_post_api_v1_contract_tpsl_order(&[contractRequest.clone()]).await;
} else if is_true(&isTrailingPercentOrder) {
response = self.contract_private_post_api_v1_contract_track_order(&[contractRequest.clone()]).await;
} else {
response = self.contract_private_post_api_v1_contract_order(&[contractRequest.clone()]).await;
}
}
}
}
//
// spot
//
// {"status":"ok","data":"438398393065481"}
//
// swap and future
//
// {
// "status": "ok",
// "data": {
// "order_id": 924660854912552960,
// "order_id_str": "924660854912552960"
// },
// "ts": 1640497927185
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": {
// "order_id": "1512501029504577536",
// "client_order_id": "1512501029504577536"
// },
// "ts": 1780649946353
// }
//
// linear swap algo
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "algo_id": "1512871666507657216",
// "algo_client_order_id": null
// }
// ],
// "ts": 1780738313102
// }
//
// stop-loss and take-profit
//
// {
// "status": "ok",
// "data": {
// "tp_order": {
// "order_id": 1101494204040163328,
// "order_id_str": "1101494204040163328"
// },
// "sl_order": null
// },
// "ts": :1682658283024
// }
//
let mut data: Value = Value::Null;
let mut result: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("id".to_string(), self.safe_string_k(response.clone(), "data", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m.insert("symbol".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("clientOrderId".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m
}), &[market.clone()]);
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
if is_true(&isTrigger) || is_true(&isTrailingPercentOrder) || is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder) {
data = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
result = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
result = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
if is_equal(&result, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseOrder() returned empty response".to_string()))));
}
let __ws_arg_79 = self.parse_order(result.clone(), &[market.clone()]);
return self.extend(__ws_arg_79, &[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(), price.clone());
m.insert("amount".to_string(), amount.clone());
m
})]);
} else if is_true(&isStopLossTriggerOrder) {
data = self.safe_value_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
result = self.safe_value_k(data.clone(), "sl_order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else if is_true(&isTakeProfitTriggerOrder) {
data = self.safe_value_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
result = self.safe_value_k(data.clone(), "tp_order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
result = self.safe_value_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
if is_equal(&result, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseOrder() returned empty response".to_string()))));
}
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#createOrders
* @description create a list of trade orders
* @see https://huobiapi.github.io/docs/spot/v1/en/#place-a-batch-of-orders
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-a-batch-of-orders
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-a-batch-of-orders
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1958935dae1
* @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;
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut symbol: Value = Value::Null;
let mut market: Value = Value::Null;
let mut marginMode: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_775: bool = true;
while { if !__for_first_775 { i = add(&i, &Value::Int(1)); } __for_first_775 = 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", &[]);
if is_equal(&symbol, &Value::Null) {
symbol = marketId.clone();
} else {
if !is_equal(&symbol, &marketId) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() requires all orders to have the same symbol".to_string()))));
}
}
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_value_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marginResult: Value = self.handle_margin_mode_and_params(Value::Str("createOrders".to_string()), &[orderParams.clone()]);
let mut currentMarginMode: Value = get_value(&marginResult, &Value::Int(0));
if !is_equal(¤tMarginMode, &Value::Null) {
if is_equal(&marginMode, &Value::Null) {
marginMode = currentMarginMode.clone();
} else {
if !is_equal(&marginMode, ¤tMarginMode) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() requires all orders to have the same margin mode (isolated or cross)".to_string()))));
}
}
}
market = self.market(symbol.clone());
let mut orderRequest: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
orderRequest = self.create_spot_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]).await;
} else {
orderRequest = self.create_contract_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
}
orderRequest = self.omit(orderRequest.clone(), Value::Str("marginMode".to_string()), &[]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&self.safe_bool_k(market.clone(), "spot", &[]), &Value::Bool(true)) {
response = self.private_post_order_batch_orders(&[ordersRequests.clone()]).await;
} else {
if is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)) {
response = self.contract_private_post_v5_trade_batch_orders(&[ordersRequests.clone()]).await;
} else if is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("orders_data".to_string()), ordersRequests.clone());
if is_equal(&self.safe_bool_k(market.clone(), "swap", &[]), &Value::Bool(true)) {
response = self.contract_private_post_swap_api_v1_swap_batchorder(&[request.clone()]).await;
} else if is_equal(&self.safe_bool_k(market.clone(), "future", &[]), &Value::Bool(true)) {
response = self.contract_private_post_api_v1_contract_batchorder(&[request.clone()]).await;
}
}
}
//
// spot
//
// {
// "status": "ok",
// "data": [
// {
// "order-id": 936847569789079,
// "client-order-id": "AA03022abc3a55e82c-0087-4fc2-beac-112fdebb1ee9"
// },
// {
// "client-order-id": "AA03022abcdb3baefb-3cfa-4891-8009-082b3d46ca82",
// "err-code": "account-frozen-balance-insufficient-error",
// "err-msg": "trade account balance is not enough, left: `89`"
// }
// ]
// }
//
// swap and future
//
// {
// "status": "ok",
// "data": {
// "errors": [
// {
// "index": 2,
// "err_code": 1047,
// "err_msg": "Insufficient margin available."
// }
// ],
// "success": [
// {
// "order_id": 1172923090632953857,
// "index": 1,
// "order_id_str": "1172923090632953857"
// }
// ]
// },
// "ts": 1699688256671
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "code": 200,
// "message": "Success",
// "order_id": "1513217421638275072",
// "client_order_id": "1513217421638275072"
// },
// {
// "code": 200,
// "message": "Success",
// "order_id": "1513217421638275073",
// "client_order_id": "1513217421638275073"
// }
// ],
// "ts": 1780820747555
// }
//
//
let mut result: Value = Value::Null;
if is_equal(&self.safe_bool_k(market.clone(), "spot", &[]), &Value::Bool(true)) {
result = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
} else {
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
if is_true(&Value::Bool(is_array(&data))) {
result = data.clone();
} else {
let mut batchData: Value = self.safe_value_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut success: Value = self.safe_value_k(batchData.clone(), "success", &[Value::List(vec![])]);
let mut errors: Value = self.safe_value_k(batchData.clone(), "errors", &[Value::List(vec![])]);
result = self.array_concat(success.clone(), errors.clone());
}
}
return self.parse_orders(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#cancelOrder
* @description cancels an open order
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1958947efe6
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b935d4997
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] *contract only* if the order is a trigger trigger order or not
* @param {bool} [params.stopLossTakeProfit] *contract only* if the order is a stop-loss or take-profit order
* @param {bool} [params.stopLoss] *contract only* if the order is a stop-loss order
* @param {bool} [params.takeProfit] *contract only* if the order is a take-profit order
* @param {bool} [params.trailing] *contract only* set to true if you want to cancel a trailing order
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isLinear: bool = is_equal(&subType, &Value::Str("linear".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_bool_n(params.clone(), Value::List(vec![Value::Str("stopLossTakeProfit".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("stopLossTakeProfit".to_string()), Value::Str("trailing".to_string()), Value::Str("trigger".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("client-order-id".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order-id".to_string()), id.clone());
let __ws_arg_80 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_post_v1_order_orders_order_id_submitcancel(&[__ws_arg_80]).await;
} else {
add_element_to_object(&mut request, &Value::Str("client-order-id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("client-order-id".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let __ws_arg_81 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_post_v1_order_orders_submit_cancel_client_order(&[__ws_arg_81]).await;
}
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
let mut clientOrderId: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("algo_client_order_id".to_string())]), &[]);
if !is_true(&(is_true(&isLinear) && is_true(&(is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))))))) {
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), id.clone());
} else {
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
}
}
if is_equal(&self.safe_bool_k(market.clone(), "future", &[]), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "settleId", &[]));
} else {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
if is_true(&isLinear) {
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))) {
let mut requestItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract_code".to_string(), self.safe_string_k(market.clone(), "id", &[]));
m
});
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut requestItem, &Value::Str("algo_id".to_string()), id.clone());
params = self.omit(params.clone(), Value::Str("algo_id".to_string()), &[]);
} else {
add_element_to_object(&mut requestItem, &Value::Str("algo_client_order_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("algo_client_order_id".to_string())]), &[]);
}
let mut requestBody: Value = Value::List(vec![self.extend(requestItem.clone(), &[params.clone()])]);
response = self.contract_private_post_v5_algo_cancel_orders(&[requestBody.clone()]).await;
} else {
let __ws_arg_82 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_v5_trade_cancel_order(&[__ws_arg_82]).await;
}
} else if is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true)) {
if is_equal(&self.safe_bool_k(market.clone(), "swap", &[]), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_83 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_trigger_cancel(&[__ws_arg_83]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_84 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_tpsl_cancel(&[__ws_arg_84]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_85 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_track_cancel(&[__ws_arg_85]).await;
} else {
let __ws_arg_86 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_cancel(&[__ws_arg_86]).await;
}
} else if is_equal(&self.safe_bool_k(market.clone(), "future", &[]), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_87 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_trigger_cancel(&[__ws_arg_87]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_88 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_tpsl_cancel(&[__ws_arg_88]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_89 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_track_cancel(&[__ws_arg_89]).await;
} else {
let __ws_arg_90 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_cancel(&[__ws_arg_90]).await;
}
}
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" cancelOrder() does not support ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
}
//
// spot
//
// {
// "status": "ok",
// "data": "10138899000",
// }
//
// future and swap
//
// {
// "status": "ok",
// "data": {
// "errors": [],
// "successes": "924660854912552960"
// },
// "ts": 1640504486089
// }
//
// linear swap
//
// {
// "code": 200,
// "data": {
// "client_order_id": "1512509978516443136",
// "order_id": "1512509978516443136"
// },
// "message": "Success",
// "ts": 1780653244729
// }
//
// linear swap algo
//
// {
// "code": 200,
// "data": [
// {
// "algo_client_order_id": "1329854623927160832",
// "code": 200,
// "message": "Success",
// "algo_id": "1329854623927160832"
// },
// ],
// "message": "Success",
// "ts": 1737103890390
// }
//
let mut result: Value = Value::Null;
if is_true(&isLinear) {
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&stopLossTakeProfit, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))) {
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
result = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
result = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
} else {
result = response.clone();
}
if is_equal(&result, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseOrder() returned empty response".to_string()))));
}
let __ws_arg_91 = self.parse_order(result.clone(), &[market.clone()]);
return self.extend(__ws_arg_91, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name htx#cancelOrders
* @description cancel multiple orders
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-195894d0de8
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] *contract only* if the orders are trigger trigger orders or not
* @param {bool} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss or take-profit 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;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrders".to_string()), &[market.clone(), params.clone()]); marketType = 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 mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_value_k(params.clone(), "stopLossTakeProfit", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("stopLossTakeProfit".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let mut clientOrderIds: Value = self.safe_value2(params.clone(), Value::Str("client-order-id".to_string()), Value::Str("clientOrderId".to_string()), &[]);
clientOrderIds = self.safe_value2(params.clone(), Value::Str("client-order-ids".to_string()), Value::Str("clientOrderIds".to_string()), &[clientOrderIds.clone()]);
if is_equal(&clientOrderIds, &Value::Null) {
if is_string(&clientOrderIds) {
add_element_to_object(&mut request, &Value::Str("order-ids".to_string()), Value::List(vec![ids.clone()]));
} else {
add_element_to_object(&mut request, &Value::Str("order-ids".to_string()), ids.clone());
}
} else {
if is_string(&clientOrderIds) {
add_element_to_object(&mut request, &Value::Str("client-order-ids".to_string()), Value::List(vec![clientOrderIds.clone()]));
} else {
add_element_to_object(&mut request, &Value::Str("client-order-ids".to_string()), clientOrderIds.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("client-order-id".to_string()), Value::Str("client-order-ids".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("clientOrderIds".to_string())]), &[]);
}
let __ws_arg_92 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_post_v1_order_orders_batchcancel(&[__ws_arg_92]).await;
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol argument".to_string()))));
}
let mut clientOrderIds: Value = self.safe_value2(params.clone(), Value::Str("client_order_id".to_string()), Value::Str("clientOrderId".to_string()), &[]);
clientOrderIds = self.safe_value2(params.clone(), Value::Str("client_order_ids".to_string()), Value::Str("clientOrderIds".to_string()), &[clientOrderIds.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("client_order_id".to_string()), Value::Str("client_order_ids".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("clientOrderIds".to_string())]), &[]);
if !is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)) {
if is_equal(&clientOrderIds, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), join(&ids, &Value::Str(",".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderIds.clone());
}
}
if is_equal(&self.safe_bool_k(market.clone(), "future", &[]), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "settleId", &[]));
} else {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
if is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)) {
if is_equal(&clientOrderIds, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order_id".to_string()), ids.clone());
} else {
if is_string(&clientOrderIds) {
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), split(&clientOrderIds, &Value::Str(",".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderIds.clone());
}
}
let __ws_arg_93 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_v5_trade_cancel_batch_orders(&[__ws_arg_93]).await;
} else if is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true)) {
if is_equal(&self.safe_bool_k(market.clone(), "swap", &[]), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_94 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_trigger_cancel(&[__ws_arg_94]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_95 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_tpsl_cancel(&[__ws_arg_95]).await;
} else {
let __ws_arg_96 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_cancel(&[__ws_arg_96]).await;
}
} else if is_equal(&self.safe_bool_k(market.clone(), "future", &[]), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_97 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_trigger_cancel(&[__ws_arg_97]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_98 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_tpsl_cancel(&[__ws_arg_98]).await;
} else {
let __ws_arg_99 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_cancel(&[__ws_arg_99]).await;
}
}
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" cancelOrders() does not support ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
}
//
// spot
//
// {
// "status": "ok",
// "data": {
// "success": [
// "5983466"
// ],
// "failed": [
// {
// "err-msg": "Incorrect order state",
// "order-state": 7,
// "order-id": "",
// "err-code": "order-orderstate-error",
// "client-order-id": "first"
// },
// {
// "err-msg": "Incorrect order state",
// "order-state": 7,
// "order-id": "",
// "err-code": "order-orderstate-error",
// "client-order-id": "second"
// },
// {
// "err-msg": "The record is not found.",
// "order-id": "",
// "err-code": "base-not-found",
// "client-order-id": "third"
// }
// ]
// }
// }
//
// future and swap
//
// {
// "status": "ok",
// "data": {
// "errors": [
// {
// "order_id": "769206471845261312",
// "err_code": 1061,
// "err_msg": "This order doesnt exist."
// }
// ],
// "successes": "773120304138219520"
// },
// "ts": 1604367997451
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "code": 200,
// "message": "Success",
// "order_id": "1513217421638275072",
// "client_order_id": "1513217421638275072"
// },
// {
// "code": 200,
// "message": "Success",
// "order_id": "1513217421638275073",
// "client_order_id": "1513217421638275073"
// }
// ],
// "ts": 1780822053167
// }
//
if is_true(&(is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)))) && is_true(&(!is_equal(&trigger, &Value::Bool(true)))) && is_true(&(!is_equal(&stopLossTakeProfit, &Value::Bool(true)))) {
return self.parse_cancel_orders(response.clone());
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
return self.parse_cancel_orders(data.clone());
Value::Null
}
pub fn parse_cancel_orders(&self, mut orders: Value) -> Value {
//
// {
// "success": [
// "5983466"
// ],
// "failed": [
// {
// "err-msg": "Incorrect order state",
// "order-state": 7,
// "order-id": "",
// "err-code": "order-orderstate-error",
// "client-order-id": "first"
// },
// ...
// ]
// }
//
// {
// "errors": [
// {
// "order_id": "769206471845261312",
// "err_code": 1061,
// "err_msg": "This order doesnt exist."
// }
// ],
// "successes": "1258075374411399168,1258075393254871040"
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "code": 200,
// "message": "Success",
// "order_id": "1513217421638275072",
// "client_order_id": "1513217421638275072"
// },
// {
// "code": 200,
// "message": "Success",
// "order_id": "1513217421638275073",
// "client_order_id": "1513217421638275073"
// }
// ],
// "ts": 1780822053167
// }
//
let mut successes: Value = self.safe_string_k(orders.clone(), "successes", &[]);
let mut success: Value = Value::Null;
if !is_equal(&successes, &Value::Null) {
success = split(&successes, &Value::Str(",".to_string()));
} else {
success = self.safe_list_k(orders.clone(), "success", &[Value::List(vec![])]);
}
let mut failed: Value = self.safe_list2(orders.clone(), Value::Str("errors".to_string()), Value::Str("failed".to_string()), &[Value::List(vec![])]);
let mut data: Value = self.safe_list_k(orders.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_776: bool = true;
while { if !__for_first_776 { i = add(&i, &Value::Int(1)); } __for_first_776 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut order: Value = get_value(&data, &i);
let mut order: Value = get_value(&data, &i);
append_to_array(&mut result, self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string_k(order.clone(), "order_id", &[]));
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client_order_id", &[]));
m
}), &[]));
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_777: bool = true;
while { if !__for_first_777 { i = add(&i, &Value::Int(1)); } __for_first_777 = false; is_less_than(&i, &get_array_length(&success)) } {
let mut order: Value = get_value(&success, &i);
let mut order: Value = get_value(&success, &i);
append_to_array(&mut result, self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), order.clone());
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m
}), &[]));
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_778: bool = true;
while { if !__for_first_778 { i = add(&i, &Value::Int(1)); } __for_first_778 = false; is_less_than(&i, &get_array_length(&failed)) } {
let mut order: Value = get_value(&failed, &i);
let mut order: Value = get_value(&failed, &i);
append_to_array(&mut result, self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string2(order.clone(), Value::Str("order-id".to_string()), Value::Str("order_id".to_string()), &[]));
m.insert("status".to_string(), Value::Str("failed".to_string()));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client-order-id", &[]));
m
}), &[]));
}
}
return result;
Value::Null
}
/*
* @method
* @name htx#cancelAllOrders
* @description cancel all open orders
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-195894f0cf6
* @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 {boolean} [params.trigger] *contract only* if the orders are trigger trigger orders or not
* @param {boolean} [params.stopLossTakeProfit] *contract only* if the orders are stop-loss or take-profit orders
* @param {boolean} [params.trailing] *contract only* set to true if you want to cancel all trailing 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;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone()]); marketType = 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 mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
let __ws_arg_100 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_post_v1_order_orders_batch_cancel_open_orders(&[__ws_arg_100]).await;
//
// {
// "code": 200,
// "data": {
// "success-count": 2,
// "failed-count": 0,
// "next-id": 5454600
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m
}), &[])]);
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument".to_string()))));
}
if is_equal(&self.safe_bool_k(market.clone(), "future", &[]), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "settleId", &[]));
}
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), self.safe_string_k(market.clone(), "id", &[]));
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut stopLossTakeProfit: Value = self.safe_value_k(params.clone(), "stopLossTakeProfit", &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("stopLossTakeProfit".to_string()), Value::Str("trailing".to_string()), Value::Str("trigger".to_string())]), &[]);
if is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)) {
let __ws_arg_101 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_v5_trade_cancel_all_orders(&[__ws_arg_101]).await;
} else if is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true)) {
if is_equal(&self.safe_bool_k(market.clone(), "swap", &[]), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_102 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_trigger_cancelall(&[__ws_arg_102]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_103 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_tpsl_cancelall(&[__ws_arg_103]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_104 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_track_cancelall(&[__ws_arg_104]).await;
} else {
let __ws_arg_105 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_cancelall(&[__ws_arg_105]).await;
}
} else if is_equal(&self.safe_bool_k(market.clone(), "future", &[]), &Value::Bool(true)) {
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_106 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_trigger_cancelall(&[__ws_arg_106]).await;
} else if is_equal(&stopLossTakeProfit, &Value::Bool(true)) {
let __ws_arg_107 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_tpsl_cancelall(&[__ws_arg_107]).await;
} else if is_equal(&trailing, &Value::Bool(true)) {
let __ws_arg_108 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_track_cancelall(&[__ws_arg_108]).await;
} else {
let __ws_arg_109 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_contract_cancelall(&[__ws_arg_109]).await;
}
}
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" cancelAllOrders() does not support ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
//
// {
// "status": "ok",
// "data": {
// "errors": [],
// "successes": "1104754904426696704"
// },
// "ts": "1683435723755"
// }
//
if is_true(&(is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true)))) && is_true(&(is_true(&(!is_equal(&trigger, &Value::Bool(true)))) && is_true(&(!is_equal(&trailing, &Value::Bool(true)))) && is_true(&(!is_equal(&stopLossTakeProfit, &Value::Bool(true)))))) {
return self.parse_cancel_orders(response.clone());
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
return self.parse_cancel_orders(data.clone());
}
Value::Null
}
/*
* @method
* @name htx#cancelAllOrdersAfter
* @description dead man's switch, cancel all orders after the given timeout
* @see https://huobiapi.github.io/docs/spot/v1/en/#dead-man-s-switch
* @param {number} timeout time in milliseconds, 0 represents cancel the timer
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the api result
*/
pub async fn cancel_all_orders_after(&mut self, mut timeout: 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;
}
if is_equal(&timeout, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" cancelAllOrdersAfter() missing timeout".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeout".to_string(), ternary(is_true(&(is_greater_than(&timeout, &Value::Int(0)))), self.parse_to_int(divide(&timeout, &Value::Int(1000))), Value::Int(0)));
m
});
let __ws_arg_110 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v2_private_post_algo_orders_cancel_all_after(&[__ws_arg_110]).await;
return response;
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);
//
// {
// "currency": "usdt",
// "address": "0xf7292eb9ba7bc50358e27f0e025a4d225a64127b",
// "addressTag": "",
// "chain": "usdterc20", // trc20usdt, hrc20usdt, usdt, algousdt
// }
//
let mut address: Value = self.safe_string_k(depositAddress.clone(), "address", &[]);
let mut tag: Value = self.safe_string_k(depositAddress.clone(), "addressTag", &[]);
let mut currencyId: Value = self.safe_string_k(depositAddress.clone(), "currency", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut note: Value = self.safe_string_k(depositAddress.clone(), "note", &[]);
let mut networkId: Value = self.safe_string_k(depositAddress.clone(), "chain", &[]);
self.check_address(&[address.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m.insert("network".to_string(), self.network_id_to_code(&[networkId.clone(), code.clone()]));
m.insert("note".to_string(), note.clone());
m.insert("info".to_string(), depositAddress.clone());
m
});
Value::Null
}
/*
* @method
* @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec50029-7773-11ed-9966-0242ac110003
* @name htx#fetchDepositAddressesByNetwork
* @description fetch a dictionary of addresses for a currency, indexed by network
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange 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_111 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v2_account_deposit_address(&[__ws_arg_111]).await;
//
// {
// "code": 200,
// "data": [
// {
// "currency": "eth",
// "address": "0xf7292eb9ba7bc50358e27f0e025a4d225a64127b",
// "addressTag": "",
// "chain": "eth"
// }
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut parsed: Value = self.parse_deposit_addresses(data.clone(), &[Value::List(vec![get_value(¤cy, &Value::Str("code".to_string()))]), Value::Bool(false)]);
return self.index_by(parsed.clone(), Value::Str("network".to_string()));
Value::Null
}
/*
* @method
* @name htx#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec50029-7773-11ed-9966-0242ac110003
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 currency: Value = self.currency(code.clone());
let mut networkCodeparamsOmitedVariable = self.handle_network_code_and_params(params.clone());
let mut networkCode: Value = get_value(&networkCodeparamsOmitedVariable, &Value::Int(0));
let mut paramsOmited: Value = get_value(&networkCodeparamsOmitedVariable, &Value::Int(1));
let mut indexedAddresses: Value = self.fetch_deposit_addresses_by_network(code.clone(), &[paramsOmited.clone()]).await;
let mut selectedNetworkCode: Value = self.select_network_code_from_unified_networks(get_value(¤cy, &Value::Str("code".to_string())), networkCode.clone(), indexedAddresses.clone());
return self.safe_value(indexedAddresses.clone(), selectedNetworkCode.clone(), &[]);
Value::Null
}
pub async fn fetch_withdraw_addresses(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut note = get_arg(optional_args, 0, Value::Null);
let mut networkCode = 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 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_112 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v2_account_withdraw_address(&[__ws_arg_112]).await;
//
// {
// "code": 200,
// "data": [
// {
// "currency": "eth",
// "chain": "eth"
// "note": "Binance - TRC20",
// "addressTag": "",
// "address": "0xf7292eb9ba7bc50358e27f0e025a4d225a64127b",
// }
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut allAddresses: Value = self.parse_deposit_addresses(data.clone(), &[Value::List(vec![get_value(¤cy, &Value::Str("code".to_string()))]), Value::Bool(false)]);
let mut addresses: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_779: bool = true;
while { if !__for_first_779 { i = add(&i, &Value::Int(1)); } __for_first_779 = false; is_less_than(&i, &get_array_length(&allAddresses)) } {
let mut address: Value = get_value(&allAddresses, &i);
let mut address: Value = get_value(&allAddresses, &i);
let mut noteMatch: bool = is_true(&(is_equal(¬e, &Value::Null))) || is_true(&(is_equal(&get_value(&address, &Value::Str("note".to_string())), ¬e)));
let mut networkMatch: bool = is_true(&(is_equal(&networkCode, &Value::Null))) || is_true(&(is_equal(&get_value(&address, &Value::Str("network".to_string())), &networkCode)));
if is_true(¬eMatch) && is_true(&networkMatch) {
append_to_array(&mut addresses, address.clone());
}
}
}
return addresses;
Value::Null
}
/*
* @method
* @name htx#fetchDeposits
* @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4f050-7773-11ed-9966-0242ac110003
* @description fetch all deposits made to an account
* @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
* @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(&limit, &Value::Null) || is_greater_than(&limit, &Value::Int(100)) {
limit = Value::Int(100);
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("deposit".to_string()));
m.insert("direct".to_string(), Value::Str("next".to_string()));
m.insert("from".to_string(), Value::Int(0));
m
});
if !is_equal(¤cy, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone()); // max 100
}
let __ws_arg_113 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v1_query_deposit_withdraw(&[__ws_arg_113]).await;
//
// {
// "status": "ok",
// "data": [
// {
// "id": "75115912",
// "type": "deposit",
// "sub-type": "NORMAL",
// "request-id": "trc20usdt-a2e229a44ef2a948c874366230bb56aa73631cc0a03d177bd8b4c9d38262d7ff-200",
// "currency": "usdt",
// "chain": "trc20usdt",
// "tx-hash": "a2e229a44ef2a948c874366230bb56aa73631cc0a03d177bd8b4c9d38262d7ff",
// "amount": "12.000000000000000000",
// "from-addr-tag": "",
// "address-id": "0",
// "address": "TRFTd1FxepQE6CnpwzUEMEbFaLm5bJK67s",
// "address-tag": "",
// "fee": "0",
// "state": "safe",
// "wallet-confirm": "2",
// "created-at": "1621843808662",
// "updated-at": "1621843857137"
// },
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-for-existed-withdraws-and-deposits
* @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
* @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(&limit, &Value::Null) || is_greater_than(&limit, &Value::Int(100)) {
limit = Value::Int(100);
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("withdraw".to_string()));
m.insert("direct".to_string(), Value::Str("next".to_string()));
m.insert("from".to_string(), Value::Int(0));
m
});
if !is_equal(¤cy, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone()); // max 100
}
let __ws_arg_114 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v1_query_deposit_withdraw(&[__ws_arg_114]).await;
//
// {
// "status": "ok",
// "data": [
// {
// "id": "61335312",
// "type": "withdraw",
// "sub-type": "NORMAL",
// "currency": "usdt",
// "chain": "trc20usdt",
// "tx-hash": "30a3111f2fead74fae45c6218ca3150fc33cab2aa59cfe41526b96aae79ce4ec",
// "amount": "12.000000000000000000",
// "from-addr-tag": "",
// "address-id": "27321591",
// "address": "TRf5JacJQRsF4Nm2zu11W6maDGeiEWQu9e",
// "address-tag": "",
// "fee": "1.000000000000000000",
// "state": "confirmed",
// "created-at": "1621852316553",
// "updated-at": "1621852467041"
// },
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.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": "75115912",
// "type": "deposit",
// "sub-type": "NORMAL",
// "request-id": "trc20usdt-a2e229a44ef2a948c874366230bb56aa73631cc0a03d177bd8b4c9d38262d7ff-200",
// "currency": "usdt",
// "chain": "trc20usdt",
// "tx-hash": "a2e229a44ef2a948c874366230bb56aa73631cc0a03d177bd8b4c9d38262d7ff",
// "amount": "2849.000000000000000000",
// "from-addr-tag": "",
// "address-id": "0",
// "address": "TRFTd1FxepQE6CnpwzUEMEbFaLm5bJK67s",
// "address-tag": "",
// "fee": "0",
// "state": "safe",
// "wallet-confirm": "2",
// "created-at": "1621843808662",
// "updated-at": "1621843857137"
// },
//
// fetchWithdrawals
//
// {
// "id": "61335312",
// "type": "withdraw",
// "sub-type": "NORMAL",
// "currency": "usdt",
// "chain": "trc20usdt",
// "tx-hash": "30a3111f2fead74fae45c6218ca3150fc33cab2aa59cfe41526b96aae79ce4ec",
// "amount": "12.000000000000000000",
// "from-addr-tag": "",
// "address-id": "27321591",
// "address": "TRf5JacJQRsF4Nm2zu11W6maDGeiEWQu9e",
// "address-tag": "",
// "fee": "1.000000000000000000",
// "state": "confirmed",
// "created-at": "1621852316553",
// "updated-at": "1621852467041"
// }
//
// withdraw
//
// {
// "status": "ok",
// "data": "99562054"
// }
//
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "created-at", &[]);
let mut code: Value = self.safe_currency_code(self.safe_string_k(transaction.clone(), "currency", &[]), &[]);
let mut type_var: Value = self.safe_string_k(transaction.clone(), "type", &[]);
if is_equal(&type_var, &Value::Str("withdraw".to_string())) {
type_var = Value::Str("withdrawal".to_string());
}
let mut feeCost: Value = self.safe_string_k(transaction.clone(), "fee", &[]);
if !is_equal(&feeCost, &Value::Null) {
feeCost = crate::precise::Precise::stringAbs(&feeCost);
}
let mut networkId: Value = self.safe_string_k(transaction.clone(), "chain", &[]);
let mut txHash: Value = self.safe_string_k(transaction.clone(), "tx-hash", &[]);
if is_equal(&txHash, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseTransaction() missing txHash".to_string()))));
}
if is_equal(&networkId, &Value::Str("ETH".to_string())) && is_less_than(&get_index_of(&txHash, &Value::Str("0x".to_string())), &Value::Int(0)) {
txHash = add(&Value::Str("0x".to_string()), &txHash);
}
let mut subType: Value = self.safe_string_k(transaction.clone(), "sub-type", &[]);
let mut internal: Value = Value::Bool(is_equal(&subType, &Value::Str("FAST".to_string())));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string2(transaction.clone(), Value::Str("id".to_string()), Value::Str("data".to_string()), &[]));
m.insert("txid".to_string(), txHash.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("network".to_string(), self.network_id_to_code(&[networkId.clone(), code.clone()]));
m.insert("address".to_string(), self.safe_string_k(transaction.clone(), "address", &[]));
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), self.safe_string_k(transaction.clone(), "address-tag", &[]));
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "state", &[])));
m.insert("updated".to_string(), self.safe_integer_k(transaction.clone(), "updated-at", &[]));
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), internal.clone());
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(feeCost.clone(), &[]));
m.insert("rate".to_string(), Value::Null);
m
}));
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("unknown".to_string(), Value::Str("failed".to_string()));
m.insert("confirming".to_string(), Value::Str("pending".to_string()));
m.insert("confirmed".to_string(), Value::Str("ok".to_string()));
m.insert("safe".to_string(), Value::Str("ok".to_string()));
m.insert("orphan".to_string(), Value::Str("failed".to_string()));
m.insert("submitted".to_string(), Value::Str("pending".to_string()));
m.insert("canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("reexamine".to_string(), Value::Str("pending".to_string()));
m.insert("reject".to_string(), Value::Str("failed".to_string()));
m.insert("pass".to_string(), Value::Str("pending".to_string()));
m.insert("wallet-reject".to_string(), Value::Str("failed".to_string()));
m.insert("confirm-error".to_string(), Value::Str("failed".to_string()));
m.insert("repealed".to_string(), Value::Str("failed".to_string()));
m.insert("wallet-transfer".to_string(), Value::Str("pending".to_string()));
m.insert("pre-transfer".to_string(), Value::Str("pending".to_string()));
m.insert("verifying".to_string(), Value::Str("pending".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name htx#withdraw
* @see https://www.htx.com/en-us/opend/newApiPages/?id=7ec4cc41-7773-11ed-9966-0242ac110003
* @description make a withdrawal
* @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)); }
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.check_address(&[address.clone()]);
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("address".to_string(), address.clone());
m.insert("currency".to_string(), to_lower(&get_value(¤cy, &Value::Str("id".to_string()))));
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("addr-tag".to_string()), tag.clone()); // only for XRP?
}
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 mut amountPrecision: Value = self.currency_to_precision(code.clone(), amount.clone(), &[networkCode.clone()]);
if is_equal(&amountPrecision, &Value::Null) {
amountPrecision = Value::Str("0".to_string());
}
amount = crate::runtime::parse_float(&amountPrecision);
let mut withdrawOptions: Value = self.safe_value_k(self.options.clone(), "withdraw", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&self.safe_bool_k(withdrawOptions.clone(), "includeFee", &[Value::Bool(false)])) {
let mut fee: Value = self.safe_number_k(params.clone(), "fee", &[]);
if is_equal(&fee, &Value::Null) {
let mut currencies: Value = self.fetch_currencies(&[]).await;
{ let __t = self.map_to_safe_map(self.deep_extend(self.currencies.clone(), &[currencies.clone()])); self.currencies = __t; }
let mut targetNetwork: Value = self.safe_value(get_value(¤cy, &Value::Str("networks".to_string())), networkCode.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
fee = self.safe_number_k(targetNetwork.clone(), "fee", &[]);
if is_equal(&fee, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" withdraw() function can not find withdraw fee for chosen network. You need to re-load markets with \"exchange.load_markets(&[true.clone()])\", or provide the \"fee\" parameter".to_string()))));
}
}
// fee needs to be deducted from whole amount
let mut feeString: Value = self.currency_to_precision(code.clone(), fee.clone(), &[networkCode.clone()]);
params = self.omit(params.clone(), Value::Str("fee".to_string()), &[]);
let mut amountString: Value = self.number_to_string(amount.clone());
let mut amountSubtractedString: Value = crate::precise::Precise::stringSub(&amountString, &feeString);
let mut amountSubtractedParsed: Value = amountSubtractedString.clone();
if is_equal(&amountSubtractedParsed, &Value::Null) {
amountSubtractedParsed = Value::Str("0".to_string());
}
let mut amountSubtracted: Value = crate::runtime::parse_float(&amountSubtractedParsed);
let mut feeParsed: Value = feeString.clone();
if is_equal(&feeParsed, &Value::Null) {
feeParsed = Value::Str("0".to_string());
}
add_element_to_object(&mut request, &Value::Str("fee".to_string()), crate::runtime::parse_float(&feeParsed));
let mut amountAfterFee: Value = self.currency_to_precision(code.clone(), amountSubtracted.clone(), &[networkCode.clone()]);
if is_equal(&amountAfterFee, &Value::Null) {
amountAfterFee = Value::Str("0".to_string());
}
amount = crate::runtime::parse_float(&amountAfterFee);
}
add_element_to_object(&mut request, &Value::Str("amount".to_string()), amount.clone());
let __ws_arg_115 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_post_v1_dw_withdraw_api_create(&[__ws_arg_115]).await;
return self.parse_transaction(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);
//
// transfer
//
// {
// "data": 12345,
// "status": "ok"
// }
//
// fetchTransfers
//
// {
// "id": 12345,
// "transfer_id": "12345",
// "amount": "10",
// "currency": "USDT",
// "status": "success",
// "from_account_type": "spot",
// "to_account_type": "margin",
// "from_asset_type": "",
// "to_asset_type": "ETHUSDT",
// "transfer_time": 1770357494000
// }
//
let mut accountsById: Value = self.safe_dict_k(self.options.clone(), "accountsById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut id: Value = self.safe_string2(transfer.clone(), Value::Str("transfer_id".to_string()), Value::Str("data".to_string()), &[]);
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut amount: Value = self.safe_number_k(transfer.clone(), "amount", &[]);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "transfer_time", &[]);
let mut fromAccountRaw: Value = self.safe_string_k(transfer.clone(), "from_account_type", &[]);
let mut toAccountRaw: Value = self.safe_string_k(transfer.clone(), "to_account_type", &[]);
let mut fromAccount: Value = self.safe_string(accountsById.clone(), fromAccountRaw.clone(), &[fromAccountRaw.clone()]);
let mut toAccount: Value = self.safe_string(accountsById.clone(), toAccountRaw.clone(), &[toAccountRaw.clone()]);
let mut statusRaw: Value = self.safe_string_k(transfer.clone(), "status", &[]);
let mut status: Value = Value::Null;
if is_equal(&statusRaw, &Value::Str("success".to_string())) {
status = Value::Str("ok".to_string());
} else if is_equal(&statusRaw, &Value::Str("pending".to_string())) {
status = Value::Str("pending".to_string());
} else if is_equal(&statusRaw, &Value::Str("failed".to_string())) {
status = Value::Str("failed".to_string());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.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("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("fromAccount".to_string(), fromAccount.clone());
m.insert("toAccount".to_string(), toAccount.clone());
m.insert("status".to_string(), status.clone());
m
});
Value::Null
}
/*
* @method
* @name htx#transfer
* @description transfer currency internally between wallets on the same account
* @see https://huobiapi.github.io/docs/dm/v1/en/#transfer-margin-between-spot-account-and-future-account
* @see https://huobiapi.github.io/docs/spot/v1/en/#transfer-fund-between-spot-account-and-future-contract-account
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-transfer-margin-between-spot-account-and-usdt-margined-contracts-account
* @see https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-spot-trading-account-to-cross-margin-account-cross
* @see https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-spot-trading-account-to-isolated-margin-account-isolated
* @see https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-cross-margin-account-to-spot-trading-account-cross
* @see https://huobiapi.github.io/docs/spot/v1/en/#transfer-asset-from-isolated-margin-account-to-spot-trading-account-isolated
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from 'spot', 'future', 'swap'
* @param {string} toAccount account to transfer to 'spot', 'future', 'swap'
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.symbol] used for isolated margin transfer
* @param {string} [params.subType] 'linear' or 'inverse', only used when transfering to/from swap accounts
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut transferAmount: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
if is_equal(&transferAmount, &Value::Null) {
transferAmount = Value::Str("0".to_string());
}
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(), crate::runtime::parse_float(&transferAmount));
m
});
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("transfer".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut fromAccountId: Value = self.convert_type_to_account(fromAccount.clone());
let mut toAccountId: Value = self.convert_type_to_account(toAccount.clone());
let mut toCross: bool = is_equal(&toAccountId, &Value::Str("cross".to_string()));
let mut fromCross: bool = is_equal(&fromAccountId, &Value::Str("cross".to_string()));
let mut toIsolated: bool = is_true(&(!is_equal(&self.ids, &Value::Null))) && is_true(&self.in_array(toAccountId.clone(), self.ids.clone()));
let mut fromIsolated: bool = is_true(&(!is_equal(&self.ids, &Value::Null))) && is_true(&self.in_array(fromAccountId.clone(), self.ids.clone()));
let mut fromSpot: bool = is_equal(&fromAccountId, &Value::Str("pro".to_string()));
let mut toSpot: bool = is_equal(&toAccountId, &Value::Str("pro".to_string()));
if is_true(&fromSpot) && is_true(&toSpot) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&self.id, &Value::Str(" transfer () cannot make a transfer between ".to_string())), &fromAccount), &Value::Str(" and ".to_string())), &toAccount)));
}
let mut fromOrToFuturesAccount: bool = is_true(&(is_equal(&fromAccountId, &Value::Str("futures".to_string())))) || is_true(&(is_equal(&toAccountId, &Value::Str("futures".to_string()))));
let mut response: Value = Value::Null;
if is_true(&fromOrToFuturesAccount) {
let mut type_var: Value = add(&add(&fromAccountId, &Value::Str("-to-".to_string())), &toAccountId);
type_var = self.safe_string_k(params.clone(), "type", &[type_var.clone()]);
add_element_to_object(&mut request, &Value::Str("type".to_string()), type_var.clone());
let __ws_arg_116 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_private_post_v1_futures_transfer(&[__ws_arg_116]).await;
} else if is_true(&fromSpot) && is_true(&toCross) {
let __ws_arg_117 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cross_margin_transfer_in(&[__ws_arg_117]).await;
} else if is_true(&fromCross) && is_true(&toSpot) {
let __ws_arg_118 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cross_margin_transfer_out(&[__ws_arg_118]).await;
} else if is_true(&fromSpot) && is_true(&toIsolated) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), toAccountId.clone());
let __ws_arg_119 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_dw_transfer_in_margin(&[__ws_arg_119]).await;
} else if is_true(&fromIsolated) && is_true(&toSpot) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), fromAccountId.clone());
let __ws_arg_120 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_dw_transfer_out_margin(&[__ws_arg_120]).await;
} else {
if is_equal(&subType, &Value::Str("linear".to_string())) {
if is_true(&(is_equal(&fromAccountId, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&fromAccount, &Value::Str("linear-swap".to_string())))) {
fromAccountId = Value::Str("linear-swap".to_string());
} else {
toAccountId = Value::Str("linear-swap".to_string());
}
// check if cross-margin or isolated
let mut symbol: Value = self.safe_string_k(params.clone(), "symbol", &[]);
params = self.omit(params.clone(), Value::Str("symbol".to_string()), &[]);
if !is_equal(&symbol, &Value::Null) {
symbol = self.market_id(symbol.clone());
add_element_to_object(&mut request, &Value::Str("margin-account".to_string()), symbol.clone());
} else {
add_element_to_object(&mut request, &Value::Str("margin-account".to_string()), Value::Str("USDT".to_string())); // cross-margin
}
}
add_element_to_object(&mut request, &Value::Str("from".to_string()), ternary(is_true(&fromSpot), Value::Str("spot".to_string()), fromAccountId.clone()));
add_element_to_object(&mut request, &Value::Str("to".to_string()), ternary(is_true(&toSpot), Value::Str("spot".to_string()), toAccountId.clone()));
let __ws_arg_121 = self.extend(request.clone(), &[params.clone()]);
response = self.v2_private_post_account_transfer(&[__ws_arg_121]).await;
}
//
// {
// "code": "200",
// "data": "660150061",
// "message": "Succeed",
// "success": true,
// "print-log": true
// }
//
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseTransfer() returned empty response".to_string()))));
}
return self.parse_transfer(response.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://www.huobi.com/en-us/opend/newApiPages/
* @param {string} [code] unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfer structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.status] transfer status: 'success', 'pending', 'failed'
* @param {int} [params.from] the starting ID for pagination
* @param {string} [params.direct] pagination direction: 'prev' or 'next', default 'next'
* @param {int} [params.until] the latest time in ms to fetch transfers for
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn fetch_transfers(&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 currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
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())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
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("end_time".to_string()), until.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_122 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v5_account_universal_transfer_records(&[__ws_arg_122]).await;
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "id": 12345,
// "transfer_id": "12345",
// "amount": "10",
// "currency": "USDT",
// "status": "success",
// "from_account_type": "spot",
// "to_account_type": "margin",
// "from_asset_type": "",
// "to_asset_type": "ETHUSDT",
// "transfer_time": 1770357494000
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_transfers(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchIsolatedBorrowRates
* @description fetch the borrow interest rates of all currencies
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-loan-interest-rate-and-quota-isolated
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [isolated borrow rate structures]{@link https://docs.ccxt.com/?id=isolated-borrow-rate-structure}
*/
pub async fn fetch_isolated_borrow_rates(&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.spot_private_get_v1_margin_loan_info(&[params.clone()]).await;
//
// {
// "status": "ok",
// "data": [
// {
// "symbol": "1inchusdt",
// "currencies": [
// {
// "currency": "1inch",
// "interest-rate": "0.00098",
// "min-loan-amt": "90.000000000000000000",
// "max-loan-amt": "1000.000000000000000000",
// "loanable-amt": "0.0",
// "actual-rate": "0.00098"
// },
// {
// "currency": "usdt",
// "interest-rate": "0.00098",
// "min-loan-amt": "100.000000000000000000",
// "max-loan-amt": "1000.000000000000000000",
// "loanable-amt": "0.0",
// "actual-rate": "0.00098"
// }
// ]
// },
// ...
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_isolated_borrow_rates(data.clone());
Value::Null
}
pub fn parse_isolated_borrow_rate(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "1inchusdt",
// "currencies": [
// {
// "currency": "1inch",
// "interest-rate": "0.00098",
// "min-loan-amt": "90.000000000000000000",
// "max-loan-amt": "1000.000000000000000000",
// "loanable-amt": "0.0",
// "actual-rate": "0.00098"
// },
// {
// "currency": "usdt",
// "interest-rate": "0.00098",
// "min-loan-amt": "100.000000000000000000",
// "max-loan-amt": "1000.000000000000000000",
// "loanable-amt": "0.0",
// "actual-rate": "0.00098"
// }
// ]
// },
//
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut currencies: Value = self.safe_value_k(info.clone(), "currencies", &[Value::List(vec![])]);
let mut baseData: Value = self.safe_value(currencies.clone(), Value::Int(0), &[]);
let mut quoteData: Value = self.safe_value(currencies.clone(), Value::Int(1), &[]);
let mut baseId: Value = self.safe_string_k(baseData.clone(), "currency", &[]);
let mut quoteId: Value = self.safe_string_k(quoteData.clone(), "currency", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), self.safe_currency_code(baseId.clone(), &[]));
m.insert("baseRate".to_string(), self.safe_number_k(baseData.clone(), "actual-rate", &[]));
m.insert("quote".to_string(), self.safe_currency_code(quoteId.clone(), &[]));
m.insert("quoteRate".to_string(), self.safe_number_k(quoteData.clone(), "actual-rate", &[]));
m.insert("period".to_string(), Value::Int(86400000));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("info".to_string(), info.clone());
m
});
Value::Null
}
/*
* @method
* @name htx#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b97ea5941
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-historical-funding-rate
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-historical-funding-rate
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] the earliest time in ms to fetch funding rate history 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.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()))));
}
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_cursor(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("current_page".to_string()), Value::Str("page_index".to_string()), Value::Int(1), Value::Int(50)]).await;
}
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_code".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(100))); // max 100
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
} else {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), Value::Int(50)); // max
}
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_123 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_historical_funding_rate(&[__ws_arg_123]).await;
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_124 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_v5_market_funding_rate_history(&[__ws_arg_124]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRateHistory() supports inverse and linear swaps only".to_string()))));
}
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
let mut rates: Value = Value::List(vec![]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_780: bool = true;
while { if !__for_first_780 { i = add(&i, &Value::Int(1)); } __for_first_780 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut marketId: Value = self.safe_string_k(entry.clone(), "contract_code", &[]);
let mut symbolInner: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "funding_time", &[]);
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(), symbolInner.clone());
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "funding_rate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
} else {
let mut cursor: Value = self.safe_value_k(data.clone(), "current_page", &[]);
let mut result: Value = self.safe_value_k(data.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_781: bool = true;
while { if !__for_first_781 { i = add(&i, &Value::Int(1)); } __for_first_781 = false; is_less_than(&i, &get_array_length(&result)) } {
let mut entry: Value = get_value(&result, &i);
add_element_to_object(&mut entry, &Value::Str("current_page".to_string()), cursor.clone());
crate::set_value(&mut result, &i, entry.clone());
let mut marketId: Value = self.safe_string_k(entry.clone(), "contract_code", &[]);
let mut symbolInner: Value = self.safe_symbol(marketId.clone(), &[]);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "funding_time", &[]);
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(), symbolInner.clone());
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "funding_rate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// inverse swap
//
// {
// "estimated_rate": null,
// "funding_rate": "0.000100000000000000",
// "contract_code": "BTC-USD",
// "symbol": "BTC",
// "fee_asset": "BTC",
// "funding_time": "1781280000000",
// "next_funding_time": null
// }
//
// linear swap
//
// {
// "contract_code": "BTC-USDT",
// "funding_rate": "0.000083024939363172",
// "funding_time": "1781251200000",
// "next_funding_time": "1781280000000",
// "min_funding_rate": "-0.003750000000000000",
// "max_funding_rate": "0.003750000000000000"
// }
//
let mut nextFundingRate: Value = self.safe_number_k(contract.clone(), "estimated_rate", &[]);
let mut fundingTimestamp: Value = self.safe_integer_k(contract.clone(), "funding_time", &[]);
let mut nextFundingTimestamp: Value = self.safe_integer_k(contract.clone(), "next_funding_time", &[]);
let mut fundingTimeString: Value = self.safe_string_k(contract.clone(), "funding_time", &[]);
let mut nextFundingTimeString: Value = self.safe_string_k(contract.clone(), "next_funding_time", &[]);
let mut millisecondsInterval: Value = crate::precise::Precise::stringSub(&nextFundingTimeString, &fundingTimeString);
let mut marketId: Value = self.safe_string_k(contract.clone(), "contract_code", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "funding_rate", &[]));
m.insert("fundingTimestamp".to_string(), fundingTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTimestamp.clone()));
m.insert("nextFundingRate".to_string(), nextFundingRate.clone());
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), self.parse_funding_interval(millisecondsInterval.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
}
/*
* @method
* @name htx#fetchFundingRate
* @description fetch the current funding rate
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-funding-rate
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b97d0c0bf
* @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());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract_code".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_125 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_funding_rate(&[__ws_arg_125]).await;
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_126 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_v5_market_funding_rate(&[__ws_arg_126]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRate() supports inverse and linear swaps only".to_string()))));
}
let mut result: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
result = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
result = self.safe_value_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_funding_rate(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchFundingRates
* @description fetch the funding rate for multiple markets
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-a-batch-of-funding-rate
* @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 defaultSubType: Value = Value::Str("linear".to_string());
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRates".to_string()), Value::Str("subType".to_string()), &[defaultSubType.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&symbols, &Value::Null) {
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
let mut market: Value = self.market(firstSymbol.clone());
let mut isLinear: Value = get_value(&market, &Value::Str("linear".to_string()));
subType = ternary(is_true(&(is_equal(&isLinear, &Value::Bool(true)))), Value::Str("linear".to_string()), Value::Str("inverse".to_string()));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("linear".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRates() not support this market type".to_string()))));
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_127 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_batch_funding_rate(&[__ws_arg_127]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRates() not support this market type".to_string()))));
}
//
// {
// "status": "ok",
// "data": [
// {
// "estimated_rate": "0.000100000000000000",
// "funding_rate": "0.000100000000000000",
// "contract_code": "MANA-USDT",
// "symbol": "MANA",
// "fee_asset": "USDT",
// "funding_time": "1643356800000",
// "next_funding_time": "1643385600000",
// "trade_partition":"USDT"
// },
// ],
// "ts": 1643346173103
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_funding_rates(data.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchBorrowInterest
* @description fetch the interest owed by the user for borrowing currency for margin trading
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-past-margin-orders-cross
* @see https://huobiapi.github.io/docs/spot/v1/en/#search-past-margin-orders-isolated
* @param {string} code unified currency code
* @param {string} symbol unified market symbol when fetch interest in isolated markets
* @param {int} [since] the earliest time in ms to fetch borrrow interest for
* @param {int} [limit] the maximum number of structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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;
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBorrowInterest".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
marginMode = ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Str("cross".to_string()), marginMode.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start-date".to_string()), self.yyyymmdd(since.clone(), &[]));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone());
}
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_128 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_margin_loan_orders(&[__ws_arg_128]).await;
} else {
if !is_equal(&code, &Value::Null) {
let mut currency: Value = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let __ws_arg_129 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_cross_margin_loan_orders(&[__ws_arg_129]).await;
}
//
// {
// "status":"ok",
// "data":[
// {
// "loan-balance":"0.100000000000000000",
// "interest-balance":"0.000200000000000000",
// "loan-amount":"0.100000000000000000",
// "accrued-at":1511169724531,
// "interest-amount":"0.000200000000000000",
// "filled-points":"0.2",
// "filled-ht":"0.2",
// "currency":"btc",
// "id":394,
// "state":"accrual",
// "account-id":17747,
// "user-id":119913,
// "created-at":1511169724531
// }
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
let mut interest: Value = self.parse_borrow_interests(data.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);
// isolated
// {
// "interest-rate":"0.000040830000000000",
// "user-id":35930539,
// "account-id":48916071,
// "updated-at":1649320794195,
// "deduct-rate":"1",
// "day-interest-rate":"0.000980000000000000",
// "hour-interest-rate":"0.000040830000000000",
// "loan-balance":"100.790000000000000000",
// "interest-balance":"0.004115260000000000",
// "loan-amount":"100.790000000000000000",
// "paid-coin":"0.000000000000000000",
// "accrued-at":1649320794148,
// "created-at":1649320794148,
// "interest-amount":"0.004115260000000000",
// "deduct-amount":"0",
// "deduct-currency":"",
// "paid-point":"0.000000000000000000",
// "currency":"usdt",
// "symbol":"ltcusdt",
// "id":20242721,
// }
//
// cross
// {
// "id":3416576,
// "user-id":35930539,
// "account-id":48956839,
// "currency":"usdt",
// "loan-amount":"102",
// "loan-balance":"102",
// "interest-amount":"0.00416466",
// "interest-balance":"0.00416466",
// "created-at":1649322735333,
// "accrued-at":1649322735382,
// "state":"accrual",
// "filled-points":"0",
// "filled-ht":"0"
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut marginMode: Value = ternary(is_true(&(is_equal(&marketId, &Value::Null))), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
market = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "accrued-at", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), symbol.clone());
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-amount", &[]));
m.insert("interestRate".to_string(), self.safe_number_k(info.clone(), "interest-rate", &[]));
m.insert("amountBorrowed".to_string(), self.safe_number_k(info.clone(), "loan-amount", &[]));
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::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut pathString: Value = path.clone();
let mut url: Value = Value::Str("/".to_string());
let mut isArrayParams: bool = is_array(¶ms);
let mut query: Value = Value::Null;
if is_true(&isArrayParams) {
query = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
} else {
query = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
}
if is_string(&api) {
// signing implementation for the old endpoints
if is_true(&(is_equal(&api, &Value::Str("public".to_string())))) || is_true(&(is_equal(&api, &Value::Str("private".to_string())))) {
url = add(&url, &self.version);
} else if is_true(&(is_equal(&api, &Value::Str("v2Public".to_string())))) || is_true(&(is_equal(&api, &Value::Str("v2Private".to_string())))) {
url = add(&url, &Value::Str("v2".to_string()));
}
url = add(&url, &add(&Value::Str("/".to_string()), &self.implode_params(path.clone(), params.clone())));
if is_equal(&api, &Value::Str("private".to_string())) || is_equal(&api, &Value::Str("v2Private".to_string())) {
self.check_required_credentials(&[]);
let mut timestamp: Value = self.ymdhms(self.nonce(), &[Value::Str("T".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SignatureMethod".to_string(), Value::Str("HmacSHA256".to_string()));
m.insert("SignatureVersion".to_string(), Value::Str("2".to_string()));
m.insert("AccessKeyId".to_string(), self.apiKey.clone());
m.insert("Timestamp".to_string(), timestamp.clone());
m
});
if !is_equal(&method, &Value::Str("POST".to_string())) {
request = self.extend(request.clone(), &[query.clone()]);
}
let mut sortedRequest: Value = self.keysort(request.clone(), &[]);
let mut auth: Value = self.urlencode(sortedRequest.clone(), &[Value::Bool(true)]); // true is a go only requirement
// unfortunately, PHP demands double quotes for the escaped newline symbol
let mut content: Value = Value::List(vec![method.clone(), self.hostname.clone(), url.clone(), auth.clone()]);
let mut payload: Value = join(&content, &Value::Str("\n".to_string())); // eslint-disable-line quotes
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
auth = add(&auth, &add(&Value::Str("&".to_string()), &self.urlencode(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Signature".to_string(), signature.clone());
m
}), &[])));
url = add(&url, &add(&Value::Str("?".to_string()), &auth));
if is_equal(&method, &Value::Str("POST".to_string())) {
let mut bodyRequest: Value = Value::Null;
if is_true(&isArrayParams) {
bodyRequest = params.clone();
} else {
bodyRequest = query.clone();
}
body = self.json(bodyRequest.clone());
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
} else {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".to_string()));
m
});
}
} else {
if is_true(&(!is_equal(&query, &Value::Null))) && is_true(&(is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)))) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
}
url = add(&self.implode_params(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("hostname".to_string(), self.hostname.clone());
m
})), &url);
} else {
// signing implementation for the new endpoints
// const [ type, access ] = api;
let mut type_var: Value = self.safe_string(api.clone(), Value::Int(0), &[]);
let mut access: Value = self.safe_string(api.clone(), Value::Int(1), &[]);
let mut levelOneNestedPath: Value = self.safe_string(api.clone(), Value::Int(2), &[]);
let mut levelTwoNestedPath: Value = self.safe_string(api.clone(), Value::Int(3), &[]);
let mut hostname: Value = Value::Null;
let mut hostnames: Value = self.safe_value(get_value(&self.urls, &Value::Str("hostnames".to_string())), type_var.clone(), &[]);
if !is_string(&hostnames) {
hostnames = self.safe_value(hostnames.clone(), levelOneNestedPath.clone(), &[]);
if is_true(&(!is_string(&hostnames))) && is_true(&(!is_equal(&levelTwoNestedPath, &Value::Null))) {
hostnames = self.safe_value(hostnames.clone(), levelTwoNestedPath.clone(), &[]);
}
}
hostname = hostnames.clone();
url = add(&url, &self.implode_params(path.clone(), params.clone()));
if is_equal(&access, &Value::Str("public".to_string())) {
if is_true(&(!is_equal(&query, &Value::Null))) && is_true(&(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 if is_equal(&access, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
if is_equal(&method, &Value::Str("POST".to_string())) {
let mut options: Value = self.safe_value_k(self.options.clone(), "broker", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut id: Value = self.safe_string_k(options.clone(), "id", &[Value::Str("AA03022abc".to_string())]);
if !is_true(&isArrayParams) {
if is_true(&(is_equal(&get_index_of(&pathString, &Value::Str("cancel".to_string())), &negate(&Value::Int(1))))) && is_true(&Value::Bool(ends_with(&pathString, &Value::Str("order".to_string())))) {
// swap order placement
let mut channelCode: Value = self.safe_string_k(params.clone(), "channel_code", &[]);
if is_equal(&channelCode, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("channel_code".to_string()), id.clone());
}
} else if is_true(&Value::Bool(ends_with(&pathString, &Value::Str("orders/place".to_string())))) {
// spot order placement
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "client-order-id", &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("client-order-id".to_string()), add(&id, &self.uuid(&[])));
}
}
}
}
let mut timestamp: Value = self.ymdhms(self.nonce(), &[Value::Str("T".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SignatureMethod".to_string(), Value::Str("HmacSHA256".to_string()));
m.insert("SignatureVersion".to_string(), Value::Str("2".to_string()));
m.insert("AccessKeyId".to_string(), self.apiKey.clone());
m.insert("Timestamp".to_string(), timestamp.clone());
m
});
// sorting needs such flow exactly, before urlencoding (more at: https://github.com/ccxt/ccxt/issues/24930 )
request = self.keysort(request.clone(), &[]);
if !is_equal(&method, &Value::Str("POST".to_string())) {
let mut sortedQuery: Value = self.keysort(query.clone(), &[]);
request = self.extend(request.clone(), &[sortedQuery.clone()]);
}
let mut auth: Value = replace_str(&self.urlencode(request.clone(), &[Value::Bool(true)]), &Value::Str("%2c".to_string()), &Value::Str("%2C".to_string())); // in c# it manually needs to be uppercased
// unfortunately, PHP demands double quotes for the escaped newline symbol
let mut content2: Value = Value::List(vec![method.clone(), hostname.clone(), url.clone(), auth.clone()]);
let mut payload: Value = join(&content2, &Value::Str("\n".to_string())); // eslint-disable-line quotes
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
auth = add(&auth, &add(&Value::Str("&".to_string()), &self.urlencode(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Signature".to_string(), signature.clone());
m
}), &[])));
url = add(&url, &add(&Value::Str("?".to_string()), &auth));
if is_equal(&method, &Value::Str("POST".to_string())) {
let mut bodyRequest: Value = Value::Null;
if is_true(&isArrayParams) {
bodyRequest = params.clone();
} else {
bodyRequest = query.clone();
}
body = self.json(bodyRequest.clone());
if !is_true(&isArrayParams) && is_true(&(is_equal(&get_array_length(&body), &Value::Int(2)))) {
body = Value::Str("{}".to_string());
}
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
} else {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".to_string()));
m
});
}
}
let mut finalHostname: Value = hostname.clone(); // java req
url = add(&self.implode_params(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &type_var), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("hostname".to_string(), finalHostname.clone());
m
})), &url);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
if is_true(&Value::Bool(in_op(&response, &Value::Str("status".to_string())))) {
//
// {"status":"error","err-code":"o-amount-min-error","err-msg":"limit order amount error, min: `0.001`","data":null}
// {"status":"ok","data":{"errors":[{"order_id":"1349442392365359104","err_code":1061,"err_msg":"The order does not exist."}],"successes":""},"ts":1741773744526}
//
let mut status: Value = self.safe_string_k(response.clone(), "status", &[]);
if is_equal(&status, &Value::Str("error".to_string())) {
let mut code: Value = self.safe_string2(response.clone(), Value::Str("err-code".to_string()), Value::Str("err_code".to_string()), &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), body.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
let mut message: Value = self.safe_string2(response.clone(), Value::Str("err-msg".to_string()), Value::Str("err_msg".to_string()), &[]);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
}
if is_true(&Value::Bool(in_op(&response, &Value::Str("code".to_string())))) {
// {code: '1003', message: 'invalid signature'}
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
let mut code: Value = self.safe_string_k(response.clone(), "code", &[]);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut errorsList: Value = self.safe_list_k(data.clone(), "errors", &[]);
if !is_equal(&errorsList, &Value::Null) {
let mut first: Value = self.safe_dict(errorsList.clone(), Value::Int(0), &[]);
let mut errcode: Value = self.safe_string_k(first.clone(), "err_code", &[]);
let mut errmessage: Value = self.safe_string_k(first.clone(), "err_msg", &[]);
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())), errcode.clone(), feedBack.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errmessage.clone(), feedBack.clone());
}
return Value::Null;
Value::Null
}
/*
* @method
* @name htx#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b930b8bee // linear swaps
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-financial-records-via-multiple-fields-new // coin-m futures
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-financial-records-via-multiple-fields-new // coin-m swaps
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch funding history for
* @param {int} [limit] the maximum number of funding history structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @returns {object} a [funding history structure]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
pub async fn fetch_funding_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchFundingHistory".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("30,31".to_string()));
m
});
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
} else {
add_element_to_object(&mut request, &Value::Str("start_date".to_string()), since.clone());
}
}
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("swap".to_string())) {
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchFundingHistory".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
marginMode = ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Str("cross".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("margin_mode".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_130 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_v5_account_bills(&[__ws_arg_130]).await;
} else {
add_element_to_object(&mut request, &Value::Str("contract".to_string()), get_value(&market, &Value::Str("id".to_string())));
//
// {
// "code": 200,
// "msg": "",
// "data": [
// {
// "query_id": 138798248,
// "id": 117840,
// "type": 5,
// "amount": -0.024464850000000000,
// "ts": 1638758435635,
// "contract_code": "BTC-USDT-211210",
// "asset": "USDT",
// "margin_account": "USDT",
// "face_margin_account": ""
// }
// ],
// "ts": 1604312615051
// }
//
let __ws_arg_131 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v3_swap_financial_record_exact(&[__ws_arg_131]).await;
}
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_132 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v3_contract_financial_record_exact(&[__ws_arg_132]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_incomes(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#setLeverage
* @description set the level of leverage for a market
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1959439f997
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#switch-leverage
* @see https://huobiapi.github.io/docs/dm/v1/en/#switch-leverage // Coin-m futures
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.position_side] linear swap supports 'long', 'short' and 'both', 'both' is the default
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut marketTypequeryVariable = self.handle_market_type_and_params(Value::Str("setLeverage".to_string()), &[market.clone(), params.clone()]);
let mut marketType: Value = get_value(&marketTypequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marketTypequeryVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("lever_rate".to_string(), leverage.clone());
m
});
if is_equal(&marketType, &Value::Str("future".to_string())) && is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("settleId".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setLeverage".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
marginMode = ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Str("cross".to_string()), marginMode.clone());
add_element_to_object(&mut request, &Value::Str("margin_mode".to_string()), marginMode.clone());
let __ws_arg_133 = self.extend(request.clone(), &[query.clone()]);
response = self.contract_private_post_v5_position_lever(&[__ws_arg_133]).await;
} else {
if is_equal(&marketType, &Value::Str("future".to_string())) {
let __ws_arg_134 = self.extend(request.clone(), &[query.clone()]);
response = self.contract_private_post_api_v1_contract_switch_lever_rate(&[__ws_arg_134]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
let __ws_arg_135 = self.extend(request.clone(), &[query.clone()]);
response = self.contract_private_post_swap_api_v1_swap_switch_lever_rate(&[__ws_arg_135]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setLeverage() not support this market type".to_string()))));
}
}
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" setLeverage() returned empty response".to_string()))));
}
return response;
Value::Null
}
pub fn parse_income(&self, mut income: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": "1667161118",
// "symbol": "BTC",
// "type": "31",
// "amount": "-2.11306593188E-7",
// "ts": "1641139308983",
// "contract_code": "BTC-USD"
// }
//
// linear swap
//
// {
// "id": "2194774775",
// "type": "30",
// "currency": "USDT",
// "amount": "0.000433432461821856",
// "contract_code": "BTC-USDT",
// "margin_mode": "cross",
// "created_time": "1780963213165"
// }
//
let mut marketId: Value = self.safe_string_k(income.clone(), "contract_code", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut amount: Value = self.safe_number_k(income.clone(), "amount", &[]);
let mut timestamp: Value = self.safe_integer2(income.clone(), Value::Str("ts".to_string()), Value::Str("created_time".to_string()), &[]);
let mut id: Value = self.safe_string_k(income.clone(), "id", &[]);
let mut currencyId: Value = self.safe_string_n(income.clone(), Value::List(vec![Value::Str("symbol".to_string()), Value::Str("asset".to_string()), Value::Str("currency".to_string())]), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), income.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("code".to_string(), code.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), id.clone());
m.insert("amount".to_string(), amount.clone());
m
});
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTC",
// "contract_code": "BTC-USDT",
// "volume": "1.000000000000000000",
// "available": "1.000000000000000000",
// "frozen": "0E-18",
// "cost_open": "47162.000000000000000000",
// "cost_hold": "47151.300000000000000000",
// "profit_unreal": "0.007300000000000000",
// "profit_rate": "-0.000144183876850008",
// "lever_rate": "2",
// "position_margin": "23.579300000000000000",
// "direction": "buy",
// "profit": "-0.003400000000000000",
// "last_price": "47158.6",
// "margin_asset": "USDT",
// "margin_mode": "isolated",
// "margin_account": "BTC-USDT",
// "margin_balance": "24.973020070000000000",
// "margin_position": "23.579300000000000000",
// "margin_frozen": "0",
// "margin_available": "1.393720070000000000",
// "profit_real": "0E-18",
// "risk_rate": "1.044107779705080303",
// "withdraw_available": "1.386420070000000000000000000000000000",
// "liquidation_price": "22353.229148614609571788",
// "adjust_factor": "0.015000000000000000",
// "margin_static": "24.965720070000000000"
// }
//
// linear swap
//
// {
// "contract_code": "BTC-USDT",
// "position_side": "long",
// "direction": "buy",
// "margin_mode": "cross",
// "open_avg_price": "63204.5",
// "volume": "1",
// "available": "1",
// "lever_rate": 20,
// "adl_risk_percent": 3,
// "liquidation_price": "-110163.844268282697306843",
// "margin": "3.158275",
// "initial_margin": "3.158275",
// "maintenance_margin": "0.2147627",
// "profit_unreal": "-0.039",
// "profit_rate": "-0.0123",
// "margin_rate": "0.0012",
// "mark_price": "63165.5",
// "last_price": "63163.3",
// "margin_currency": "USDT",
// "contract_type": "swap",
// "created_time": "1780903703234",
// "updated_time": "1780903703234"
// }
//
market = self.safe_market(&[self.safe_string_k(position.clone(), "contract_code", &[])]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut contracts: Value = self.safe_string_k(position.clone(), "volume", &[]);
let mut contractSize: Value = self.safe_value_k(market.clone(), "contractSize", &[]);
let mut contractSizeString: Value = self.number_to_string(contractSize.clone());
let mut entryPrice: Value = self.safe_number2(position.clone(), Value::Str("cost_open".to_string()), Value::Str("open_avg_price".to_string()), &[]);
let mut initialMargin: Value = self.safe_string2(position.clone(), Value::Str("position_margin".to_string()), Value::Str("initial_margin".to_string()), &[]);
let mut rawSide: Value = self.safe_string_k(position.clone(), "direction", &[]);
let mut directionSide: Value = ternary(is_true(&(is_equal(&rawSide, &Value::Str("buy".to_string())))), Value::Str("long".to_string()), Value::Str("short".to_string()));
let mut rawPositionSide: Value = self.safe_string_k(position.clone(), "position_side", &[]);
// in one-way mode, "position_side" is "both" and the actual long/short signal is only present in "direction"
let mut side: Value = directionSide.clone();
let mut isHedgedPositionSide: bool = is_true(&(is_equal(&rawPositionSide, &Value::Str("long".to_string())))) || is_true(&(is_equal(&rawPositionSide, &Value::Str("short".to_string()))));
if is_true(&isHedgedPositionSide) {
side = rawPositionSide.clone();
}
let mut unrealizedProfit: Value = self.safe_number_k(position.clone(), "profit_unreal", &[]);
let mut marginMode: Value = self.safe_string_k(position.clone(), "margin_mode", &[]);
let mut leverage: Value = self.safe_string_k(position.clone(), "lever_rate", &[]);
let mut percentage: Value = crate::precise::Precise::stringMul(&self.safe_string_k(position.clone(), "profit_rate", &[]), &Value::Str("100".to_string()));
let mut lastPrice: Value = self.safe_string_k(position.clone(), "last_price", &[]);
let mut faceValue: Value = crate::precise::Precise::stringMul(&contracts, &contractSizeString);
let mut notional: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
notional = crate::precise::Precise::stringMul(&faceValue, &lastPrice);
} else {
notional = crate::precise::Precise::stringDiv(&faceValue, &lastPrice);
marginMode = Value::Str("cross".to_string());
}
let mut intialMarginPercentage: Value = crate::precise::Precise::stringDiv(&initialMargin, ¬ional);
let mut collateral: Value = self.safe_string2(position.clone(), Value::Str("margin_balance".to_string()), Value::Str("margin".to_string()), &[]);
let mut adjustmentFactor: Value = self.safe_string_k(position.clone(), "adjust_factor", &[]);
let mut maintenanceMarginLinear: Value = self.safe_string_k(position.clone(), "maintenance_margin", &[]);
let mut marginRatioLinear: Value = self.safe_string_k(position.clone(), "margin_rate", &[]);
let mut maintenanceMarginPercentage: Value = Value::Null;
let mut maintenanceMargin: Value = Value::Null;
let mut marginRatio: Value = Value::Null;
let mut maintenanceMarginPercentageResult: Value = Value::Null;
if is_equal(&maintenanceMarginLinear, &Value::Null) {
maintenanceMarginPercentage = crate::precise::Precise::stringDiv(&adjustmentFactor, &leverage);
maintenanceMargin = crate::precise::Precise::stringMul(&maintenanceMarginPercentage, ¬ional);
maintenanceMarginPercentageResult = self.parse_number(maintenanceMarginPercentage.clone(), &[]);
} else {
maintenanceMargin = maintenanceMarginLinear.clone();
}
if is_equal(&marginRatioLinear, &Value::Null) {
marginRatio = crate::precise::Precise::stringDiv(&maintenanceMargin, &collateral);
} else {
marginRatio = marginRatioLinear.clone();
}
let mut timestamp: Value = self.safe_integer_k(position.clone(), "created_time", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol.clone());
m.insert("contracts".to_string(), self.parse_number(contracts.clone(), &[]));
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("entryPrice".to_string(), entryPrice.clone());
m.insert("collateral".to_string(), self.parse_number(collateral.clone(), &[]));
m.insert("side".to_string(), side.clone());
m.insert("unrealizedPnl".to_string(), unrealizedProfit.clone());
m.insert("leverage".to_string(), self.parse_number(leverage.clone(), &[]));
m.insert("percentage".to_string(), self.parse_number(percentage.clone(), &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("notional".to_string(), self.parse_number(notional.clone(), &[]));
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "mark_price", &[]));
m.insert("lastPrice".to_string(), self.parse_number(lastPrice.clone(), &[]));
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liquidation_price", &[]));
m.insert("initialMargin".to_string(), self.parse_number(initialMargin.clone(), &[]));
m.insert("initialMarginPercentage".to_string(), self.parse_number(intialMarginPercentage.clone(), &[]));
m.insert("maintenanceMargin".to_string(), self.parse_number(maintenanceMargin.clone(), &[]));
m.insert("maintenanceMarginPercentage".to_string(), maintenanceMarginPercentageResult.clone());
m.insert("marginRatio".to_string(), self.parse_number(marginRatio.clone(), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("hedged".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "updated_time", &[]));
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name htx#fetchPositions
* @description fetch all open positions
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19594266bd8
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-user-s-position-information
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-user-s-position-information
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] 'linear' or 'inverse'
* @param {string} [params.type] *inverse only* 'future', or 'swap'
* @param {string} [params.marginMode] *linear only* 'cross' or 'isolated'
* @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;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(0)) {
let mut first: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
market = self.market(first.clone());
}
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPositions".to_string()), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchPositions".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
marketType = Value::Str("future".to_string());
}
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("linear".to_string())) {
response = self.contract_private_get_v5_trade_position_opens(&[params.clone()]).await;
} else {
if is_equal(&marketType, &Value::Str("future".to_string())) {
response = self.contract_private_post_api_v1_contract_position_info(&[params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.contract_private_post_swap_api_v1_swap_position_info(&[params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchPositions() not support this market type".to_string()))));
}
}
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut timestamp: Value = self.safe_integer_k(response.clone(), "ts", &[]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_782: bool = true;
while { if !__for_first_782 { i = add(&i, &Value::Int(1)); } __for_first_782 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut position: Value = get_value(&data, &i);
let mut position: Value = get_value(&data, &i);
let mut parsed: Value = self.parse_position(position.clone(), &[]);
let __ws_arg_136 = self.iso8601(timestamp.clone());
append_to_array(&mut result, self.extend(parsed.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), __ws_arg_136);
m
})]));
}
}
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
/*
* @method
* @name htx#fetchPosition
* @description fetch data on a single open contract trade position
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19594266bd8
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-assets-and-positions
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-assets-and-positions
* @param {string} symbol unified market symbol of the market the position is held in, default is undefined
* @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());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchPosition".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
marginMode = ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Str("cross".to_string()), marginMode.clone());
let mut marketTypequeryVariable = self.handle_market_type_and_params(Value::Str("fetchPosition".to_string()), &[market.clone(), params.clone()]);
let mut marketType: Value = get_value(&marketTypequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marketTypequeryVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
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("inverse".to_string())), &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("settleId".to_string())));
} else {
if is_true(&(!is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))) && is_true(&(is_equal(&marginMode, &Value::Str("cross".to_string())))) {
add_element_to_object(&mut request, &Value::Str("margin_account".to_string()), Value::Str("USDT".to_string())); // only allowed value
}
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_137 = self.extend(request.clone(), &[query.clone()]);
response = self.contract_private_get_v5_trade_position_opens(&[__ws_arg_137]).await;
} else {
if is_equal(&marketType, &Value::Str("future".to_string())) {
let __ws_arg_138 = self.extend(request.clone(), &[query.clone()]);
response = self.contract_private_post_api_v1_contract_account_position_info(&[__ws_arg_138]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
let __ws_arg_139 = self.extend(request.clone(), &[query.clone()]);
response = self.contract_private_post_swap_api_v1_swap_account_position_info(&[__ws_arg_139]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setLeverage() not support this market type".to_string()))));
}
}
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut linearPosition: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_position(linearPosition.clone(), &[market.clone()]);
}
let mut account: Value = Value::Null;
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
account = data.clone();
} else {
account = self.safe_value(data.clone(), Value::Int(0), &[]);
}
let mut omitted: Value = self.omit(account.clone(), Value::List(vec![Value::Str("positions".to_string())]), &[]);
let mut positions: Value = self.safe_value_k(account.clone(), "positions", &[]);
let mut position: Value = Value::Null;
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("inverse".to_string())), &Value::Bool(true)))) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_783: bool = true;
while { if !__for_first_783 { i = add(&i, &Value::Int(1)); } __for_first_783 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut entry: Value = get_value(&positions, &i);
let mut entry: Value = get_value(&positions, &i);
if is_equal(&get_value(&entry, &Value::Str("contract_code".to_string())), &get_value(&market, &Value::Str("id".to_string()))) {
position = entry.clone();
break;
}
}
}
} else {
position = self.safe_value(positions.clone(), Value::Int(0), &[]);
}
let mut timestamp: Value = self.safe_integer_k(response.clone(), "ts", &[]);
let __ws_arg_140 = self.extend(position.clone(), &[omitted.clone()]);
let mut parsed: Value = self.parse_position(__ws_arg_140, &[market.clone()]);
add_element_to_object(&mut parsed, &Value::Str("timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut parsed, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
return parsed;
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade".to_string(), Value::Str("trade".to_string()));
m.insert("etf".to_string(), Value::Str("trade".to_string()));
m.insert("transact-fee".to_string(), Value::Str("fee".to_string()));
m.insert("fee-deduction".to_string(), Value::Str("fee".to_string()));
m.insert("transfer".to_string(), Value::Str("transfer".to_string()));
m.insert("credit".to_string(), Value::Str("credit".to_string()));
m.insert("liquidation".to_string(), Value::Str("trade".to_string()));
m.insert("interest".to_string(), Value::Str("credit".to_string()));
m.insert("deposit".to_string(), Value::Str("deposit".to_string()));
m.insert("withdraw".to_string(), Value::Str("withdrawal".to_string()));
m.insert("withdraw-fee".to_string(), Value::Str("fee".to_string()));
m.insert("exchange".to_string(), Value::Str("exchange".to_string()));
m.insert("other-types".to_string(), Value::Str("transfer".to_string()));
m.insert("rebate".to_string(), Value::Str("rebate".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.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);
//
// {
// "accountId": 10000001,
// "currency": "usdt",
// "transactAmt": 10.000000000000000000,
// "transactType": "transfer",
// "transferType": "margin-transfer-out",
// "transactId": 0,
// "transactTime": 1629882331066,
// "transferer": 28483123,
// "transferee": 13496526
// }
//
let mut currencyId: Value = self.safe_string_k(item.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut id: Value = self.safe_string_k(item.clone(), "transactId", &[]);
let mut transferType: Value = self.safe_string_k(item.clone(), "transferType", &[]);
let mut timestamp: Value = self.safe_integer_k(item.clone(), "transactTime", &[]);
let mut account: Value = self.safe_string_k(item.clone(), "accountId", &[]);
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(), id.clone());
m.insert("direction".to_string(), self.safe_string_k(item.clone(), "direction", &[]));
m.insert("account".to_string(), account.clone());
m.insert("referenceId".to_string(), id.clone());
m.insert("referenceAccount".to_string(), account.clone());
m.insert("type".to_string(), self.parse_ledger_entry_type(transferType.clone()));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.safe_number_k(item.clone(), "transactAmt", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-account-history
* @param {string} [code] unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @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(), Value::Int(500)]).await;
}
let mut accountId: Value = self.fetch_account_id_by_type(Value::Str("spot".to_string()), &[Value::Null, Value::Null, params.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountId".to_string(), accountId.clone());
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())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // max 500
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_141 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_private_get_v2_account_ledger(&[__ws_arg_141]).await;
//
// {
// "code": 200,
// "message": "success",
// "data": [
// {
// "accountId": 10000001,
// "currency": "usdt",
// "transactAmt": 10.000000000000000000,
// "transactType": "transfer",
// "transferType": "margin-transfer-out",
// "transactId": 0,
// "transactTime": 1629882331066,
// "transferer": 28483123,
// "transferee": 13496526
// },
// {
// "accountId": 10000001,
// "currency": "usdt",
// "transactAmt": -10.000000000000000000,
// "transactType": "transfer",
// "transferType": "margin-transfer-in",
// "transactId": 0,
// "transactTime": 1629882096562,
// "transferer": 13496526,
// "transferee": 28483123
// }
// ],
// "nextId": 1624316679,
// "ok": true
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_ledger(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
* @param {string[]|undefined} 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 response: Value = self.contract_public_get_linear_swap_api_v1_swap_adjustfactor(&[params.clone()]).await;
//
// {
// "status": "ok",
// "data": [
// {
// "symbol": "MANA",
// "contract_code": "MANA-USDT",
// "margin_mode": "isolated",
// "trade_partition": "USDT",
// "list": [
// {
// "lever_rate": 75,
// "ladders": [
// {
// "ladder": 0,
// "min_size": 0,
// "max_size": 999,
// "adjust_factor": 0.7
// },
// ...
// ]
// }
// ...
// ]
// },
// ...
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_leverage_tiers(data.clone(), &[symbols.clone(), Value::Str("contract_code".to_string())]);
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);
let mut currencyId: Value = self.safe_string_k(info.clone(), "trade_partition", &[]);
let mut marketId: Value = self.safe_string_k(info.clone(), "contract_code", &[]);
let mut tiers: Value = Value::List(vec![]);
let mut brackets: Value = self.safe_list_k(info.clone(), "list", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_785: bool = true;
while { if !__for_first_785 { i = add(&i, &Value::Int(1)); } __for_first_785 = false; is_less_than(&i, &get_array_length(&brackets)) } {
let mut item: Value = get_value(&brackets, &i);
let mut item: Value = get_value(&brackets, &i);
let mut leverage: Value = self.safe_string_k(item.clone(), "lever_rate", &[]);
let mut ladders: Value = self.safe_list_k(item.clone(), "ladders", &[Value::List(vec![])]);
{
let mut k: Value = Value::Int(0);
let mut __for_first_784: bool = true;
while { if !__for_first_784 { k = add(&k, &Value::Int(1)); } __for_first_784 = false; is_less_than(&k, &get_array_length(&ladders)) } {
let mut bracket: Value = get_value(&ladders, &k);
let mut bracket: Value = get_value(&ladders, &k);
let mut adjustFactor: Value = self.safe_string_k(bracket.clone(), "adjust_factor", &[]);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_integer_k(bracket.clone(), "ladder", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[]));
m.insert("minNotional".to_string(), self.safe_number_k(bracket.clone(), "min_size", &[]));
m.insert("maxNotional".to_string(), self.safe_number_k(bracket.clone(), "max_size", &[]));
m.insert("maintenanceMarginRate".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&adjustFactor, &leverage), &[]));
m.insert("maxLeverage".to_string(), self.parse_number(leverage.clone(), &[]));
m.insert("info".to_string(), bracket.clone());
m
}));
}
}
}
}
return tiers;
Value::Null
}
/*
* @method
* @name htx#fetchOpenInterestHistory
* @description Retrieves the open interest history of a currency
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-information-on-open-interest
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-information-on-open-interest
* @see https://huobiapi.github.io/docs/usdt_swap/v1/en/#general-query-information-on-open-interest
* @param {string} symbol Unified CCXT market symbol
* @param {string} timeframe '1h', '4h', '12h', or '1d'
* @param {int} [since] Not used by huobi api, but response parsed by CCXT
* @param {int} [limit] Default:48,Data Range [1,200]
* @param {object} [params] Exchange specific parameters
* @param {int} [params.amount_type] *required* Open interest unit. 1-cont,2-cryptocurrency
* @param {int} [params.pair] eg BTC-USDT *Only for USDT-M*
* @returns {object} an array of [open interest structures]{@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("1h".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(&timeframe, &Value::Str("1h".to_string())) && !is_equal(&timeframe, &Value::Str("4h".to_string())) && !is_equal(&timeframe, &Value::Str("12h".to_string())) && !is_equal(&timeframe, &Value::Str("1d".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOpenInterestHistory cannot only use the 1h, 4h, 12h and 1d timeframe".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut timeframes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1h".to_string(), Value::Str("60min".to_string()));
m.insert("4h".to_string(), Value::Str("4hour".to_string()));
m.insert("12h".to_string(), Value::Str("12hour".to_string()));
m.insert("1d".to_string(), Value::Str("1day".to_string()));
m
});
let mut market: Value = self.market(symbol.clone());
let mut amountType: Value = self.safe_integer2(params.clone(), Value::Str("amount_type".to_string()), Value::Str("amountType".to_string()), &[Value::Int(2)]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("period".to_string(), get_value(&timeframes, &timeframe));
m.insert("amount_type".to_string(), amountType.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_type".to_string()), self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("contract_type".to_string()), &[]));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("baseId".to_string()))); // currency code on coin-m futures
// coin-m futures
let __ws_arg_142 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_api_v1_contract_his_open_interest(&[__ws_arg_142]).await;
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_type".to_string()), Value::Str("swap".to_string()));
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
// USDT-M
let __ws_arg_143 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_linear_swap_api_v1_swap_his_open_interest(&[__ws_arg_143]).await;
} else {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
// coin-m swaps
let __ws_arg_144 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_his_open_interest(&[__ws_arg_144]).await;
}
//
// contractPublicGetlinearSwapApiV1SwapHisOpenInterest
// {
// "status": "ok",
// "data": {
// "symbol": "BTC",
// "tick": [
// {
// "volume": "4385.4350000000000000",
// "amount_type": "2",
// "ts": "1648220400000",
// "value": "194059884.1850000000000000"
// },
// ...
// ],
// "contract_code": "BTC-USDT",
// "business_type": "swap",
// "pair": "BTC-USDT",
// "contract_type": "swap",
// "trade_partition": "USDT"
// },
// "ts": "1648223733007"
// }
//
// contractPublicGetSwapApiV1SwapHisOpenInterest
// {
// "status": "ok",
// "data": {
// "symbol": "CRV",
// "tick": [
// {
// "volume": 19174.0000000000000000,
// "amount_type": 1,
// "ts": 1648224000000
// },
// ...
// ],
// "contract_code": "CRV-USD"
// },
// "ts": 1648226554260
// }
//
// contractPublicGetApiV1ContractHisOpenInterest
// {
// "status": "ok",
// "data": {
// "symbol": "BTC",
// "contract_type": "this_week",
// "tick": [
// {
// "volume": "48419.0000000000000000",
// "amount_type": 1,
// "ts": 1648224000000
// },
// ...
// ]
// },
// "ts": 1648227062944
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
let mut tick: Value = self.safe_list_k(data.clone(), "tick", &[]);
return self.parse_open_interests_history(tick.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchOpenInterests
* @description Retrieves the open interest for a list of symbols
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-contract-open-interest-information
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-swap-open-interest-information
* @param {string[]} [symbols] a list of unified CCXT market symbols
* @param {object} [params] exchange specific parameters
* @returns {object[]} a list of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interests(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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 symbolsLength: Value = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(0)) {
let mut first: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
market = self.market(first.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOpenInterests".to_string()), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenInterests".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("future".to_string())) {
let __ws_arg_145 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_api_v1_contract_open_interest(&[__ws_arg_145]).await;
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_146 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_open_interest(&[__ws_arg_146]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOpenInterests() does not currently support linear markets".to_string()))));
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_open_interests(data.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name htx#fetchOpenInterest
* @description Retrieves the open interest of a currency
* @see https://huobiapi.github.io/docs/dm/v1/en/#get-contract-open-interest-information
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#get-swap-open-interest-information
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b97fb53f2
* @param {string} symbol Unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @returns {object} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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(" fetchOpenInterest() supports contract markets only".to_string()))));
}
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(" fetchOpenInterest() does not currently support option markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract_code".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_type".to_string()), self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("contract_type".to_string()), &[]));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
// COIN-M futures
let __ws_arg_147 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_api_v1_contract_open_interest(&[__ws_arg_147]).await;
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
// USDT-M swaps
let __ws_arg_148 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_v5_market_open_interest(&[__ws_arg_148]).await;
} else {
// COIN-M swaps
let __ws_arg_149 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_open_interest(&[__ws_arg_149]).await;
}
//
// USDT-M linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": {
// "amount": "32476.092",
// "volume": "32476092",
// "value": "2063137924.9668",
// "contract_code": "BTC-USDT",
// "trade_amount": "11371.362",
// "trade_volume": "11371362",
// "trade_turnover": "723600792.7222"
// },
// "ts": 1781327941440
// }
//
// COIN-M Swap contractPublicGetSwapApiV1SwapOpenInterest
//
// {
// "status": "ok",
// "data": [
// {
// "volume": 518018.000000000000000000,
// "amount": 2769.675777407074725180,
// "symbol": "BTC",
// "contract_code": "BTC-USD",
// "trade_amount": 9544.4032080046491323463688602729806842458,
// "trade_volume": 1848448,
// "trade_turnover": 184844800.000000000000000000
// }
// ],
// "ts": 1664337226028
// }
//
// COIN-M Futures contractPublicGetApiV1ContractOpenInterest
//
// {
// "status": "ok",
// "data": [
// {
// "volume": 118850.000000000000000000,
// "amount": 635.502025211544374189,
// "symbol": "BTC",
// "contract_type": "this_week",
// "contract_code": "BTC220930",
// "trade_amount": 1470.9400749347598691119206024033947897351,
// "trade_volume": 286286,
// "trade_turnover": 28628600.000000000000000000
// }
// ],
// "ts": 1664337928805
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "ts", &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut result: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let __ws_arg_150 = self.parse_open_interest(result.clone(), &[market.clone()]);
let __ws_arg_151 = self.iso8601(timestamp.clone());
return self.extend(__ws_arg_150, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), __ws_arg_151);
m
})]);
}
let mut data: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
let mut openInterest: Value = self.parse_open_interest(get_value(&data, &Value::Int(0)), &[market.clone()]);
add_element_to_object(&mut openInterest, &Value::Str("timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut openInterest, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
return openInterest;
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);
//
// fetchOpenInterestHistory
//
// {
// "volume": "4385.4350000000000000",
// "amount_type": "2",
// "ts": "1648220400000",
// "value": "194059884.1850000000000000"
// }
//
// fetchOpenInterest: USDT-M
//
// {
// "amount": "32476.092",
// "volume": "32476092",
// "value": "2063137924.9668",
// "contract_code": "BTC-USDT",
// "trade_amount": "11371.362",
// "trade_volume": "11371362",
// "trade_turnover": "723600792.7222"
// }
//
// fetchOpenInterest: COIN-M Swap
//
// {
// "volume": 518018.000000000000000000,
// "amount": 2769.675777407074725180,
// "symbol": "BTC",
// "contract_code": "BTC-USD",
// "trade_amount": 9544.4032080046491323463688602729806842458,
// "trade_volume": 1848448,
// "trade_turnover": 184844800.000000000000000000
// }
//
// fetchOpenInterest: COIN-M Futures
//
// {
// "volume": 118850.000000000000000000,
// "amount": 635.502025211544374189,
// "symbol": "BTC",
// "contract_type": "this_week",
// "contract_code": "BTC220930",
// "trade_amount": 1470.9400749347598691119206024033947897351,
// "trade_volume": 286286,
// "trade_turnover": 28628600.000000000000000000
// }
//
let mut timestamp: Value = self.safe_integer_k(interest.clone(), "ts", &[]);
let mut amount: Value = self.safe_number_k(interest.clone(), "volume", &[]);
let mut value: Value = self.safe_number_k(interest.clone(), "value", &[]);
let mut marketId: Value = self.safe_string_k(interest.clone(), "contract_code", &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("baseVolume".to_string(), amount.clone());
m.insert("quoteVolume".to_string(), value.clone());
m.insert("openInterestAmount".to_string(), amount.clone());
m.insert("openInterestValue".to_string(), value.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#borrowIsolatedMargin
* @description create a loan to borrow margin
* @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
* @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-cross
* @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
* @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 market: Value = self.market(symbol.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(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_152 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_margin_orders(&[__ws_arg_152]).await;
//
// Isolated
//
// {
// "data": 1000
// }
//
let mut transaction: Value = self.parse_margin_loan(response.clone(), &[currency.clone()]);
return self.extend(transaction.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m.insert("symbol".to_string(), symbol.clone());
m
})]);
Value::Null
}
/*
* @method
* @name htx#borrowCrossMargin
* @description create a loan to borrow margin
* @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
* @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-cross
* @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
* @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;
}
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("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let __ws_arg_153 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_cross_margin_orders(&[__ws_arg_153]).await;
//
// Cross
//
// {
// "status": "ok",
// "data": null
// }
//
let mut transaction: Value = self.parse_margin_loan(response.clone(), &[currency.clone()]);
return self.extend(transaction.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m
})]);
Value::Null
}
/*
* @method
* @name htx#repayIsolatedMargin
* @description repay borrowed margin and interest
* @see https://huobiapi.github.io/docs/spot/v1/en/#repay-margin-loan-cross-isolated
* @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
* @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 accountId: Value = self.fetch_account_id_by_type(Value::Str("spot".to_string()), &[Value::Str("isolated".to_string()), symbol.clone(), params.clone()]).await;
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(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("accountId".to_string(), accountId.clone());
m
});
let __ws_arg_154 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v2_private_post_account_repayment(&[__ws_arg_154]).await;
//
// {
// "code":200,
// "data": [
// {
// "repayId":1174424,
// "repayTime":1600747722018
// }
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "Data", &[Value::List(vec![])]);
let mut loan: Value = self.safe_value(data.clone(), Value::Int(0), &[]);
let mut transaction: Value = self.parse_margin_loan(loan.clone(), &[currency.clone()]);
return self.extend(transaction.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m.insert("symbol".to_string(), symbol.clone());
m
})]);
Value::Null
}
/*
* @method
* @name htx#repayCrossMargin
* @description repay borrowed margin and interest
* @see https://huobiapi.github.io/docs/spot/v1/en/#repay-margin-loan-cross-isolated
* @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
* @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;
}
let mut currency: Value = self.currency(code.clone());
let mut accountId: Value = self.fetch_account_id_by_type(Value::Str("spot".to_string()), &[Value::Str("cross".to_string()), Value::Null, params.clone()]).await;
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(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("accountId".to_string(), accountId.clone());
m
});
let __ws_arg_155 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.v2_private_post_account_repayment(&[__ws_arg_155]).await;
//
// {
// "code":200,
// "data": [
// {
// "repayId":1174424,
// "repayTime":1600747722018
// }
// ]
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "Data", &[Value::List(vec![])]);
let mut loan: Value = self.safe_value(data.clone(), Value::Int(0), &[]);
let mut transaction: Value = self.parse_margin_loan(loan.clone(), &[currency.clone()]);
return self.extend(transaction.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m
})]);
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);
//
// borrowMargin cross
//
// {
// "status": "ok",
// "data": null
// }
//
// borrowMargin isolated
//
// {
// "data": 1000
// }
//
// repayMargin
//
// {
// "repayId":1174424,
// "repayTime":1600747722018
// }
//
let mut timestamp: Value = self.safe_integer_k(info.clone(), "repayTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string2(info.clone(), Value::Str("repayId".to_string()), Value::Str("data".to_string()), &[]));
m.insert("currency".to_string(), self.safe_currency_code(Value::Null, &[currency.clone()]));
m.insert("amount".to_string(), Value::Null);
m.insert("symbol".to_string(), Value::Null);
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 htx#fetchSettlementHistory
* @description Fetches historical settlement records
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-historical-settlement-records-of-the-platform-interface
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-historical-settlement-records-of-the-platform-interface
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b931869f0
* @param {string} symbol unified symbol of the market to fetch the settlement history for
* @param {int} [since] timestamp in ms, value range = current time - 90 days,default = current time - 90 days
* @param {int} [limit] page items, default 20, shall not exceed 50
* @param {object} [params] exchange specific params
* @param {int} [params.until] timestamp in ms, value range = start_time -> current time,default = current time
* @param {int} [params.page_index] page index, default page 1 if not filled
* @param {int} [params.code] unified currency code, can be used when symbol is undefined
* @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()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
if is_true(&(is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))) && is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("page_size".to_string()), limit.clone());
}
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_156 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_v5_market_settlement_history(&[__ws_arg_156]).await;
} else {
let __ws_arg_157 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v1_swap_settlement_records(&[__ws_arg_157]).await;
}
} else {
let __ws_arg_158 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_api_v1_contract_settlement_records(&[__ws_arg_158]).await;
}
//
// coin-m swap
//
// {
// "status": "ok",
// "data": {
// "total_page": 14,
// "current_page": 1,
// "total_size": 270,
// "settlement_record": [
// {
// "symbol": "ADA",
// "contract_code": "ADA-USDT",
// "settlement_time": 1652313600000,
// "clawback_ratio": 0E-18,
// "settlement_price": 0.512303000000000000,
// "settlement_type": "settlement",
// "business_type": "swap",
// "pair": "ADA-USDT",
// "trade_partition": "USDT"
// },
// ...
// ],
// "ts": 1652338693256
// }
//
// coin-m future
//
// {
// "status": "ok",
// "data": {
// "total_page": 5,
// "current_page": 1,
// "total_size": 90,
// "settlement_record": [
// {
// "symbol": "FIL",
// "settlement_time": 1652342400000,
// "clawback_ratio": 0E-18,
// "list": [
// {
// "contract_code": "FIL220513",
// "settlement_price": 7.016000000000000000,
// "settlement_type": "settlement"
// },
// ...
// ]
// },
// ]
// }
// }
//
// linear swap
//
// {
// "code": 200,
// "message": "Success",
// "data": [
// {
// "id": "14900",
// "contract_code": "BTC-USDT",
// "settlement_time": "1781827200000",
// "clawback_ratio": "0",
// "settlement_price": "62933.747161774209291325"
// },
// ],
// "ts": 1781853150623
// }
//
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut dataLinear: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut settlementsLinear: Value = self.parse_settlements(dataLinear.clone(), market.clone());
return self.sort_by(settlementsLinear.clone(), Value::Str("timestamp".to_string()), &[]);
}
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
let mut settlementRecord: Value = self.safe_value_k(data.clone(), "settlement_record", &[]);
let mut settlements: Value = self.parse_settlements(settlementRecord.clone(), market.clone());
return self.sort_by(settlements.clone(), Value::Str("timestamp".to_string()), &[]);
Value::Null
}
/*
* @method
* @name htx#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees
* @see https://huobiapi.github.io/docs/spot/v1/en/#get-all-supported-currencies-v2
* @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 [fees 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.spot_public_get_v2_reference_currencies(&[params.clone()]).await;
//
// {
// "code": 200,
// "data": [
// {
// "currency": "sxp",
// "assetType": "1",
// "chains": [
// {
// "chain": "sxp",
// "displayName": "ERC20",
// "baseChain": "ETH",
// "baseChainProtocol": "ERC20",
// "isDynamic": true,
// "numOfConfirmations": "12",
// "numOfFastConfirmations": "12",
// "depositStatus": "allowed",
// "minDepositAmt": "0.23",
// "withdrawStatus": "allowed",
// "minWithdrawAmt": "0.23",
// "withdrawPrecision": "8",
// "maxWithdrawAmt": "227000.000000000000000000",
// "withdrawQuotaPerDay": "227000.000000000000000000",
// "withdrawQuotaPerYear": null,
// "withdrawQuotaTotal": null,
// "withdrawFeeType": "fixed",
// "transactFeeWithdraw": "11.1653",
// "addrWithTag": false,
// "addrDepositTag": false
// }
// ],
// "instStatus": "normal"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_deposit_withdraw_fees(data.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": "sxp",
// "assetType": "1",
// "chains": [
// {
// "chain": "sxp",
// "displayName": "ERC20",
// "baseChain": "ETH",
// "baseChainProtocol": "ERC20",
// "isDynamic": true,
// "numOfConfirmations": "12",
// "numOfFastConfirmations": "12",
// "depositStatus": "allowed",
// "minDepositAmt": "0.23",
// "withdrawStatus": "allowed",
// "minWithdrawAmt": "0.23",
// "withdrawPrecision": "8",
// "maxWithdrawAmt": "227000.000000000000000000",
// "withdrawQuotaPerDay": "227000.000000000000000000",
// "withdrawQuotaPerYear": null,
// "withdrawQuotaTotal": null,
// "withdrawFeeType": "fixed",
// "transactFeeWithdraw": "11.1653",
// "addrWithTag": false,
// "addrDepositTag": false
// }
// ],
// "instStatus": "normal"
// }
//
let mut chains: Value = self.safe_value_k(fee.clone(), "chains", &[Value::List(vec![])]);
let mut code: Value = self.safe_string_k(currency.clone(), "code", &[]);
let mut result: Value = self.deposit_withdraw_fee(fee.clone());
{
let mut j: Value = Value::Int(0);
let mut __for_first_786: bool = true;
while { if !__for_first_786 { j = add(&j, &Value::Int(1)); } __for_first_786 = false; is_less_than(&j, &get_array_length(&chains)) } {
let mut chainEntry: Value = get_value(&chains, &j);
let mut chainEntry: Value = get_value(&chains, &j);
let mut networkId: Value = self.safe_string_k(chainEntry.clone(), "chain", &[]);
let mut withdrawFeeType: Value = self.safe_string_k(chainEntry.clone(), "withdrawFeeType", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
let mut withdrawFee: Value = Value::Null;
let mut withdrawResult: Value = Value::Null;
if is_equal(&withdrawFeeType, &Value::Str("fixed".to_string())) {
withdrawFee = self.safe_number_k(chainEntry.clone(), "transactFeeWithdraw", &[]);
withdrawResult = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee.clone());
m.insert("percentage".to_string(), Value::Bool(false));
m
});
} else {
withdrawFee = self.safe_number_k(chainEntry.clone(), "transactFeeRateWithdraw", &[]);
withdrawResult = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee.clone());
m.insert("percentage".to_string(), Value::Bool(true));
m
});
}
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(), withdrawResult.clone());
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
}));
}
result = self.assign_default_deposit_withdraw_fees(result.clone(), &[currency.clone()]);
}
}
return result;
Value::Null
}
pub fn parse_settlements(&self, mut settlements: Value, mut market: Value) -> Value {
//
// coin-m swap, fetchSettlementHistory
//
// [
// {
// "symbol": "ADA",
// "contract_code": "ADA-USDT",
// "settlement_time": 1652313600000,
// "clawback_ratio": 0E-18,
// "settlement_price": 0.512303000000000000,
// "settlement_type": "settlement",
// "business_type": "swap",
// "pair": "ADA-USDT",
// "trade_partition": "USDT"
// },
// ...
// ]
//
// coin-m future, fetchSettlementHistory
//
// [
// {
// "symbol": "FIL",
// "settlement_time": 1652342400000,
// "clawback_ratio": 0E-18,
// "list": [
// {
// "contract_code": "FIL220513",
// "settlement_price": 7.016000000000000000,
// "settlement_type": "settlement"
// },
// ...
// ]
// },
// ]
//
// linear swap fetchSettlementHistory
//
// [
// {
// "id": "14900",
// "contract_code": "BTC-USDT",
// "settlement_time": "1781827200000",
// "clawback_ratio": "0",
// "settlement_price": "62933.747161774209291325"
// }
// ]
//
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_788: bool = true;
while { if !__for_first_788 { i = add(&i, &Value::Int(1)); } __for_first_788 = false; is_less_than(&i, &get_array_length(&settlements)) } {
let mut settlement: Value = get_value(&settlements, &i);
let mut settlement: Value = get_value(&settlements, &i);
let mut list: Value = self.safe_value_k(settlement.clone(), "list", &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut parsedSettlement: Value = self.parse_settlement(settlement.clone(), market.clone());
append_to_array(&mut result, parsedSettlement.clone());
} else if !is_equal(&list, &Value::Null) {
let mut timestamp: Value = self.safe_integer_k(settlement.clone(), "settlement_time", &[]);
let mut timestampDetails: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_787: bool = true;
while { if !__for_first_787 { j = add(&j, &Value::Int(1)); } __for_first_787 = false; is_less_than(&j, &get_array_length(&list)) } {
let mut item: Value = get_value(&list, &j);
let mut item: Value = get_value(&list, &j);
let mut parsedSettlement: Value = self.parse_settlement(item.clone(), market.clone());
append_to_array(&mut result, self.extend(parsedSettlement.clone(), &[timestampDetails.clone()]));
}
}
} else {
append_to_array(&mut result, self.parse_settlement(get_value(&settlements, &i), market.clone()));
}
}
}
return result;
Value::Null
}
pub fn parse_settlement(&self, mut settlement: Value, mut market: Value) -> Value {
//
// coin-m swap, fetchSettlementHistory
//
// {
// "symbol": "ADA",
// "contract_code": "ADA-USDT",
// "settlement_time": 1652313600000,
// "clawback_ratio": 0E-18,
// "settlement_price": 0.512303000000000000,
// "settlement_type": "settlement",
// "business_type": "swap",
// "pair": "ADA-USDT",
// "trade_partition": "USDT"
// }
//
// coin-m future, fetchSettlementHistory
//
// {
// "contract_code": "FIL220513",
// "settlement_price": 7.016000000000000000,
// "settlement_type": "settlement"
// }
//
// linear swap fetchSettlementHistory
//
// {
// "id": "14900",
// "contract_code": "BTC-USDT",
// "settlement_time": "1781827200000",
// "clawback_ratio": "0",
// "settlement_price": "62933.747161774209291325"
// }
//
let mut timestamp: Value = self.safe_integer_k(settlement.clone(), "settlement_time", &[]);
let mut marketId: Value = self.safe_string_k(settlement.clone(), "contract_code", &[]);
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(), "settlement_price", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name htx#fetchLiquidations
* @description retrieves the public liquidations of a trading pair
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19b975edf5a
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#query-liquidation-orders-new
* @see https://huobiapi.github.io/docs/dm/v1/en/#query-liquidation-order-information-new
* @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 huobi api endpoint
* @param {int} [params.until] timestamp in ms of the latest liquidation
* @param {int} [params.tradeType] *not supported for linear swap* default 0: filled liquidated orders, 5: liquidated close orders, 6: liquidated open orders
* @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());
let mut tradeType: Value = self.safe_integer2(params.clone(), Value::Str("trade_type".to_string()), Value::Str("tradeType".to_string()), &[Value::Int(0)]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("trade_type".to_string()), tradeType.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("trade_type".to_string()), Value::Str("tradeType".to_string())]), &[]);
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_time".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end_time".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("contract_code".to_string()), get_value(&market, &Value::Str("id".to_string())));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_159 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_v5_market_liquidation_orders(&[__ws_arg_159]).await;
} else {
add_element_to_object(&mut request, &Value::Str("contract".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_160 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_swap_api_v3_swap_liquidation_orders(&[__ws_arg_160]).await;
}
} else if is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_161 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_public_get_api_v3_contract_liquidation_orders(&[__ws_arg_161]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchLiquidations() does not support ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" orders".to_string()))));
}
//
// {
// "code": 200,
// "msg": "",
// "data": [
// {
// "query_id": 452057,
// "contract_code": "BTC-USDT-211210",
// "symbol": "USDT",
// "direction": "sell",
// "offset": "close",
// "volume": 479.000000000000000000,
// "price": 51441.700000000000000000,
// "created_at": 1638593647864,
// "amount": 0.479000000000000000,
// "trade_turnover": 24640.574300000000000000,
// "business_type": "futures",
// "pair": "BTC-USDT"
// }
// ],
// "ts": 1604312615051
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_liquidations(data.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);
//
// {
// "query_id": 452057,
// "contract_code": "BTC-USDT-211210",
// "symbol": "USDT",
// "direction": "sell",
// "offset": "close",
// "volume": 479.000000000000000000,
// "price": 51441.700000000000000000,
// "created_at": 1638593647864,
// "amount": 0.479000000000000000,
// "trade_turnover": 24640.574300000000000000,
// "business_type": "futures",
// "pair": "BTC-USDT"
// }
//
// linear swap
//
// {
// "id": "150153038758",
// "contract_code": "BTC-USDT",
// "liquidation_time": "1781849094165",
// "side": "buy",
// "position_side": "short",
// "volume": "2",
// "amount": "2",
// "bankrupt_price": "62978.5",
// "trade_turnover": "125.957"
// }
//
let mut marketId: Value = self.safe_string_k(liquidation.clone(), "contract_code", &[]);
let mut timestamp: Value = self.safe_integer2(liquidation.clone(), Value::Str("created_at".to_string()), Value::Str("liquidation_time".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.safe_number_k(liquidation.clone(), "volume", &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("price".to_string(), self.safe_number2(liquidation.clone(), Value::Str("price".to_string()), Value::Str("bankrupt_price".to_string()), &[]));
m.insert("side".to_string(), self.safe_string_lower2(liquidation.clone(), Value::Str("direction".to_string()), Value::Str("side".to_string()), &[]));
m.insert("baseValue".to_string(), self.safe_number_k(liquidation.clone(), "amount", &[]));
m.insert("quoteValue".to_string(), self.safe_number_k(liquidation.clone(), "trade_turnover", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}), &[]);
Value::Null
}
/*
* @method
* @name htx#closePosition
* @description closes open positions for a contract market
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1958953a715 // USDT-M
* @see https://huobiapi.github.io/docs/coin_margined_swap/v1/en/#place-lightning-close-order // Coin-M swap
* @see https://huobiapi.github.io/docs/dm/v1/en/#place-flash-close-order // Coin-M futures
* @param {string} symbol unified CCXT market symbol
* @param {string} side 'buy' or 'sell', the side of the closing order, opposite side as position side
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client needs to provide unique API and have to maintain the API themselves afterwards. [1, 9223372036854775807]
* @param {object} [params.marginMode] 'cross' or 'isolated', required for linear markets
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {number} [params.amount] order quantity
* @param {string} [params.order_price_type] 'lightning' by default, 'lightning_fok': lightning fok type, 'lightning_ioc': lightning ioc type 'market' by default, 'market': market order type, 'lightning_fok': lightning
* @param {string} [params.position_side] linear swap supports 'long', 'short' and 'both', 'both' is the default
* @returns {object} [an order structure]{@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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
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(" closePosition() symbol supports contract markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract_code".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("client_order_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("closePosition".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)); }
add_element_to_object(&mut request, &Value::Str("margin_mode".to_string()), marginMode.clone());
let __ws_arg_162 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_v5_trade_position(&[__ws_arg_162]).await;
} else {
self.check_required_argument(Value::Str("closePosition".to_string()), side.clone(), Value::Str("side".to_string()), &[]);
let mut amount: Value = self.safe_string2(params.clone(), Value::Str("volume".to_string()), Value::Str("amount".to_string()), &[]);
if is_equal(&amount, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" closePosition () requires an extra argument params[\"amount\"] for inverse markets".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("volume".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
add_element_to_object(&mut request, &Value::Str("direction".to_string()), side.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("volume".to_string()), Value::Str("amount".to_string())]), &[]);
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_163 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_swap_api_v1_swap_lightning_close_position(&[__ws_arg_163]).await;
} else {
let __ws_arg_164 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_post_api_v1_lightning_close_position(&[__ws_arg_164]).await;
}
}
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
}
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseOrder() returned empty response".to_string()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name htx#setPositionMode
* @description set hedged to true or false
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-1959443cae3
* @param {bool} hedged set to true to for hedged mode, must be set separately for each market in isolated margin mode, only valid for linear markets
* @param {string} [symbol] unified market symbol, required for isolated margin mode
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] "cross" (default) or "isolated"
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut posMode: Value = ternary(is_true(&hedged), Value::Str("dual_side".to_string()), Value::Str("single_side".to_string()));
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("position_mode".to_string(), posMode.clone());
m
});
if is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setPositionMode can only be used for linear markets".to_string()))));
}
let __ws_arg_165 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_post_v5_position_mode(&[__ws_arg_165]).await;
return response;
Value::Null
}
/*
* @method
* @name htx#fetchPositionsADLRank
* @description fetches the auto deleveraging rank and risk percentage for a list of symbols
* @see https://www.htx.com/en-us/opend/newApiPages/?id=8cb89359-77b5-11ed-9966-19594266bd8
* @see https://www.htx.com/en-us/opend/newApiPages/?id=28c2f164-77ae-11ed-9966-0242ac110003
* @see https://www.htx.com/en-us/opend/newApiPages/?id=5d518648-77b6-11ed-9966-0242ac110003
* @param {string[]} [symbols] a list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of [auto de leverage structures]{@link https://docs.ccxt.com/?id=auto-de-leverage-structure}
*/
pub async fn fetch_positions_adl_rank(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(0)) {
let mut first: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
market = self.market(first.clone());
}
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPositionsADLRank".to_string()), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchPositionsADLRank".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
marketType = Value::Str("future".to_string());
}
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("linear".to_string())) {
response = self.contract_private_get_v5_trade_position_opens(&[params.clone()]).await;
} else {
if is_equal(&marketType, &Value::Str("future".to_string())) {
response = self.contract_private_post_api_v1_contract_position_info(&[params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.contract_private_post_swap_api_v1_swap_position_info(&[params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchPositionsADLRank() not support this market type".to_string()))));
}
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_adl_ranks(data.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_adl_rank(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchPositionADLRank linear
//
// {
// "contract_code": "BTC-USDT",
// "position_side": "long",
// "direction": "buy",
// "margin_mode": "cross",
// "open_avg_price": "63204.5",
// "volume": "1",
// "available": "1",
// "lever_rate": 20,
// "adl_risk_percent": 3,
// "liquidation_price": "-110163.844268282697306843",
// "margin": "3.158275",
// "initial_margin": "3.158275",
// "maintenance_margin": "0.2147627",
// "profit_unreal": "-0.039",
// "profit_rate": "-0.0123",
// "margin_rate": "0.0012",
// "mark_price": "63165.5",
// "last_price": "63163.3",
// "margin_currency": "USDT",
// "contract_type": "swap",
// "created_time": "1780903703234",
// "updated_time": "1780903703234"
// }
//
// fetchPositionADLRank inverse
//
// {
// "symbol": "THETA"
// "contract_code": "THETA-USD"
// "volume": 20
// "available": 20
// "frozen": 0
// "cost_open": 0.6048347107438017
// "cost_hold": 0.65931
// "profit_unreal": -10.5257562398811
// "profit_rate": 1.0158596753357925
// "lever_rate": 20
// "position_margin": 15.693659761456372
// "direction": "buy"
// "profit": 16.795657677889032
// "last_price": 0.6372
// "adl_risk_percent": "3"
// "liq_px": "112"
// "new_risk_rate": ""
// "trade_partition": ""
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "contract_code", &[]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "created_time", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("rank".to_string(), self.safe_integer_k(info.clone(), "adl_risk_percent", &[]));
m.insert("rating".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
}