// 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 HashkeyCore {
pub exchange: crate::exchange::Exchange,
}
impl HashkeyCore {
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 = HashkeyCore::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 HashkeyCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::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 HashkeyCore.
HashkeyCore::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 HashkeyCore.
HashkeyCore::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 HashkeyCore.
HashkeyCore::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 HashkeyCore.
HashkeyCore::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 HashkeyCore.
HashkeyCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_currency(self, currency)
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_account(self, account)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_leverage(self, leverage, &[market.clone()])
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::parse_market_leverage_tiers(self, info, &[market.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on HashkeyCore.
HashkeyCore::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 HashkeyCore.
HashkeyCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for HashkeyCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_spot_order" => self.create_spot_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_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()[..]),
"create_swap_order" => self.create_swap_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_swap_order_request" => self.create_swap_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()[..]),
"custom_urlencode" => self.custom_urlencode(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"encode_account_type" => self.encode_account_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"encode_flow_type" => self.encode_flow_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_canceled_and_closed_orders" => self.fetch_canceled_and_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&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_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" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_spot_orders" => self.fetch_open_spot_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_swap_orders" => self.fetch_open_swap_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_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_for_symbol" => self.fetch_positions_for_symbol(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_fees" => self.fetch_trading_fees(&args.get(0..).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)),
"handle_trigger_option_and_params" => self.handle_trigger_option_and_params(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()[..]),
"modify_margin_helper" => self.modify_margin_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"parse_account" => self.parse_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_account_type" => self.parse_account_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_side_and_reduce_only" => self.parse_order_side_and_reduce_only(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type" => self.parse_order_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type_time_in_force_and_post_only" => self.parse_order_type_time_in_force_and_post_only(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).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_swap_balance" => self.parse_swap_balance(args.get(0).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_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()[..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_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,
"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 HashkeyCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for HashkeyCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl HashkeyCore {
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("hashkey".to_string()));
m.insert("name".to_string(), Value::Str("HashKey Global".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("BM".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("certified".to_string(), Value::Bool(true));
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(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("cancelWithdraw".to_string(), Value::Bool(false));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createConvertTrade".to_string(), Value::Bool(false));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(false));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(false));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(false));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrder".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(false));
m.insert("fetchConvertQuote".to_string(), Value::Bool(false));
m.insert("fetchConvertTrade".to_string(), Value::Bool(false));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchLastPrices".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarginModes".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(false));
m.insert("fetchMarkPrice".to_string(), Value::Bool(false));
m.insert("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".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(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrder".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsForSymbol".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(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
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(true));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(false));
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("1m".to_string()));
m.insert("3m".to_string(), Value::Str("3m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("8h".to_string(), Value::Str("8h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/3dd65db2-5da9-4ecc-93ac-6d420f36261c".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api-glb.hashkey.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api-glb.hashkey.com".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api-glb.sim.hashkeydev.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api-glb.sim.hashkeydev.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://global.hashkey.com/".to_string()));
m.insert("doc".to_string(), Value::Str("https://hashkeyglobal-apidoc.readme.io/".to_string()));
m.insert("fees".to_string(), Value::Str("https://support.global.hashkey.com/hc/en-us/articles/13199900083612-HashKey-Global-Fee-Structure".to_string()));
m.insert("referral".to_string(), Value::Str("https://global.hashkey.com/en-US/register/invite?invite_code=82FQUN".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/exchangeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("quote/v1/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/depth/merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/markPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/v1/index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/fundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/historyFundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/time".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("api/v1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/tradeOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/historyOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/liquidationAssignStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/riskLimit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/getBestOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/coinInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/vipInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/chainType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/checkApiKey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/balanceFlow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/spot/subAccount/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/subAccount/tradeOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/subAccount/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/subAccount/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/subAccount/historyOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/subAccount/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/depositOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/withdrawOrders".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("api/v1/userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/orderTest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1.1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/positionMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/position/trading-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("api/v1/futures/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/account/assetTransfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/authAddress".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/account/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v1/spot/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/spot/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/spot/cancelOrderByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v1/futures/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/futures/cancelOrderByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v1/userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".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("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("feeSide".to_string(), Value::Str("get".to_string()));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0012".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0012".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.0012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.00080".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.00070".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.00060".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.00040".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200000000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("400000000".to_string()), &[]), self.parse_number(Value::Str("0.00010".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("800000000".to_string()), &[]), self.parse_number(Value::Str("0.00".to_string()), &[])])]));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.0012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.00090".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.00085".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.00075".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.00065".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200000000".to_string()), &[]), self.parse_number(Value::Str("0.00045".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("400000000".to_string()), &[]), self.parse_number(Value::Str("0.00040".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("800000000".to_string()), &[]), self.parse_number(Value::Str("0.00035".to_string()), &[])])]));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("feeSide".to_string(), Value::Str("get".to_string()));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.00025".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.00060".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.00025".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.00016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.00014".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.00012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.000080".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200000000".to_string()), &[]), self.parse_number(Value::Str("0.000060".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("400000000".to_string()), &[]), self.parse_number(Value::Str("0.000020".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("800000000".to_string()), &[]), self.parse_number(Value::Str("0.00".to_string()), &[])])]));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.00060".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.00050".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.00045".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.00040".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.00035".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200000000".to_string()), &[]), self.parse_number(Value::Str("0.00030".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("400000000".to_string()), &[]), self.parse_number(Value::Str("0.00025".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("800000000".to_string()), &[]), self.parse_number(Value::Str("0.00020".to_string()), &[])])]));
m
}));
m
}));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("broker".to_string(), Value::Str("10000700011".to_string()));
m.insert("recvWindow".to_string(), Value::Null);
m.insert("sandboxMode".to_string(), Value::Bool(false));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("AVAX".to_string(), Value::Str("AvalancheC".to_string()));
m.insert("SOL".to_string(), Value::Str("Solana".to_string()));
m.insert("MATIC".to_string(), Value::Str("Polygon".to_string()));
m.insert("ATOM".to_string(), Value::Str("Cosmos".to_string()));
m.insert("DOT".to_string(), Value::Str("Polkadot".to_string()));
m.insert("LTC".to_string(), Value::Str("LTC".to_string()));
m.insert("OPTIMISM".to_string(), Value::Str("Optimism".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("Arbitrum".to_string()));
m.insert("DOGE".to_string(), Value::Str("Dogecoin".to_string()));
m.insert("TRC20".to_string(), Value::Str("Tron".to_string()));
m.insert("ZKSYNC".to_string(), Value::Str("zkSync".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("KLAYTN".to_string(), Value::Str("Klaytn".to_string()));
m.insert("MERLINCHAIN".to_string(), Value::Str("Merlin Chain".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("Bitcoin".to_string(), Value::Str("BTC".to_string()));
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
m.insert("AvalancheC".to_string(), Value::Str("AVAX".to_string()));
m.insert("AVAX C-Chain".to_string(), Value::Str("AVAX".to_string()));
m.insert("Solana".to_string(), Value::Str("SOL".to_string()));
m.insert("Cosmos".to_string(), Value::Str("ATOM".to_string()));
m.insert("Arbitrum".to_string(), Value::Str("ARBITRUM".to_string()));
m.insert("Polygon".to_string(), Value::Str("MATIC".to_string()));
m.insert("Optimism".to_string(), Value::Str("OPTIMISM".to_string()));
m.insert("Polkadot".to_string(), Value::Str("DOT".to_string()));
m.insert("LTC".to_string(), Value::Str("LTC".to_string()));
m.insert("Litecoin".to_string(), Value::Str("LTC".to_string()));
m.insert("Dogecoin".to_string(), Value::Str("DOGE".to_string()));
m.insert("Merlin Chain".to_string(), Value::Str("MERLINCHAIN".to_string()));
m.insert("zkSync".to_string(), Value::Str("ZKSYNC".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRC20".to_string()));
m.insert("Tron".to_string(), Value::Str("TRC20".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("BSC(BEP20)".to_string(), Value::Str("BSC".to_string()));
m.insert("Klaytn".to_string(), Value::Str("KLAYTN".to_string()));
m
}));
m.insert("defaultNetwork".to_string(), Value::Str("ERC20".to_string()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(false));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
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("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(20));
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(1000));
m.insert("daysBack".to_string(), Value::Int(30));
m.insert("untilDays".to_string(), Value::Int(30));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(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("limit".to_string(), Value::Int(1000));
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("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m.insert("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(500));
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::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("0002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("0003".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("0102".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("0103".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("0104".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("0201".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("0202".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("0206".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("0207".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("0209".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("0210".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("0211".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("0401".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("0402".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-100010".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-100012".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-1002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1005".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1006".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1007".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("-1014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1015".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1020".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1021".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("-1024".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1101".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("-1115".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1117".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1123".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1124".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1126".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1129".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1130".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1132".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1133".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1135".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1136".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1138".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1137".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1139".to_string(), Value::Str("OrderImmediatelyFillable".to_string()).clone());
m.insert("-1140".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1141".to_string(), Value::Str("DuplicateOrderId".to_string()).clone());
m.insert("-1142".to_string(), Value::Str("OrderNotFillable".to_string()).clone());
m.insert("-1143".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("-1144".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1145".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-1146".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("-1147".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("-1148".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1149".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1150".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1151".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1152".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-1153".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1154".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1155".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1156".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1157".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1158".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1159".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-1160".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-1161".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1162".to_string(), Value::Str("ContractUnavailable".to_string()).clone());
m.insert("-1163".to_string(), Value::Str("InvalidAddress".to_string()).clone());
m.insert("-1164".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-1165".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("-1166".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1167".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1168".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1169".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1170".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1171".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1172".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1173".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1174".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1175".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1176".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1177".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1178".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-1179".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("-1181".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1193".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1194".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-1195".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1196".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1200".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1201".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1202".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1203".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1204".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1205".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-1206".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1207".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1208".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1209".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2001".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("-2002".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-2003".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-2004".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-2005".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("-2010".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2011".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2016".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2017".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2018".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2019".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-2020".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-2021".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-2022".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2023".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-2024".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-2025".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-2026".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2027".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2028".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2029".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2030".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-2031".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-2032".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2033".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("-2034".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-2035".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2036".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-2037".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-2038".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-2039".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-2040".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("-2041".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2042".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2043".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2044".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2045".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2046".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2048".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2049".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2050".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2051".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2052".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2053".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("-2054".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2055".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2056".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-2057".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-3117".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-3143".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-3144".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-3145".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("-4001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4003".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("-4004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-4006".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-4007".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("-4008".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("-4009".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-4010".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-4011".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-4012".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-4013".to_string(), Value::Str("OperationFailed".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m
})]);
Value::Null
}
/*
* @method
* @name hashkey#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://hashkeyglobal-apidoc.readme.io/reference/check-server-time
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_api_v1_time(&[params.clone()]).await;
return self.safe_integer_k(response.clone(), "serverTime", &[]);
Value::Null
}
/*
* @method
* @name hashkey#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://hashkeyglobal-apidoc.readme.io/reference/test-connectivity
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_api_v1_ping(&[params.clone()]).await;
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("ok".to_string()));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
m
});
Value::Null
}
/*
* @method
* @name hashkey#fetchMarkets
* @description retrieves data on all markets for the exchange
* @see https://hashkeyglobal-apidoc.readme.io/reference/exchangeinfo
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.symbol] the id of the market to fetch
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_api_v1_exchange_info(&[__ws_arg_0]).await;
//
// {
// "timezone": "UTC",
// "serverTime": "1721661653952",
// "brokerFilters": [],
// "symbols": [
// {
// "symbol": "BTCUSDT",
// "symbolName": "BTCUSDT",
// "status": "TRADING",
// "baseAsset": "BTC",
// "baseAssetName": "BTC",
// "baseAssetPrecision": "0.00001",
// "quoteAsset": "USDT",
// "quoteAssetName": "USDT",
// "quotePrecision": "0.0000001",
// "retailAllowed": true,
// "piAllowed": true,
// "corporateAllowed": true,
// "omnibusAllowed": true,
// "icebergAllowed": false,
// "isAggregate": false,
// "allowMargin": false,
// "filters": [
// {
// "minPrice": "0.01",
// "maxPrice": "100000.00000000",
// "tickSize": "0.01",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.00001",
// "maxQty": "8",
// "stepSize": "0.00001",
// "marketOrderMinQty": "0.00001",
// "marketOrderMaxQty": "4",
// "filterType": "LOT_SIZE"
// },
// {
// "minNotional": "1",
// "filterType": "MIN_NOTIONAL"
// },
// {
// "minAmount": "1",
// "maxAmount": "400000",
// "minBuyPrice": "0",
// "marketOrderMinAmount": "1",
// "marketOrderMaxAmount": "200000",
// "filterType": "TRADE_AMOUNT"
// },
// {
// "maxSellPrice": "0",
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "LIMIT_TRADING"
// },
// {
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "MARKET_TRADING"
// },
// {
// "noAllowMarketStartTime": "1710485700000",
// "noAllowMarketEndTime": "1710486000000",
// "limitOrderStartTime": "0",
// "limitOrderEndTime": "0",
// "limitMinPrice": "0",
// "limitMaxPrice": "0",
// "filterType": "OPEN_QUOTE"
// }
// ]
// }
// ],
// "options": [ ],
// "contracts": [
// {
// "filters": [
// {
// "minPrice": "0.1",
// "maxPrice": "100000.00000000",
// "tickSize": "0.1",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.001",
// "maxQty": "10",
// "stepSize": "0.001",
// "marketOrderMinQty": "0",
// "marketOrderMaxQty": "0",
// "filterType": "LOT_SIZE"
// },
// {
// "minNotional": "0",
// "filterType": "MIN_NOTIONAL"
// },
// {
// "maxSellPrice": "999999",
// "buyPriceUpRate": "0.05",
// "sellPriceDownRate": "0.05",
// "maxEntrustNum": 200,
// "maxConditionNum": 200,
// "filterType": "LIMIT_TRADING"
// },
// {
// "buyPriceUpRate": "0.05",
// "sellPriceDownRate": "0.05",
// "filterType": "MARKET_TRADING"
// },
// {
// "noAllowMarketStartTime": "0",
// "noAllowMarketEndTime": "0",
// "limitOrderStartTime": "0",
// "limitOrderEndTime": "0",
// "limitMinPrice": "0",
// "limitMaxPrice": "0",
// "filterType": "OPEN_QUOTE"
// }
// ],
// "exchangeId": "301",
// "symbol": "BTCUSDT-PERPETUAL",
// "symbolName": "BTCUSDT-PERPETUAL",
// "status": "TRADING",
// "baseAsset": "BTCUSDT-PERPETUAL",
// "baseAssetPrecision": "0.001",
// "quoteAsset": "USDT",
// "quoteAssetPrecision": "0.1",
// "icebergAllowed": false,
// "inverse": false,
// "index": "USDT",
// "marginToken": "USDT",
// "marginPrecision": "0.0001",
// "contractMultiplier": "0.001",
// "underlying": "BTC",
// "riskLimits": [
// {
// "riskLimitId": "200000722",
// "quantity": "1000.00",
// "initialMargin": "0.10",
// "maintMargin": "0.005",
// "isWhite": false
// },
// {
// "riskLimitId": "200000723",
// "quantity": "2000.00",
// "initialMargin": "0.10",
// "maintMargin": "0.01",
// "isWhite": false
// }
// ]
// }
// ],
// "coins": [
// {
// "orgId": "9001",
// "coinId": "BTC",
// "coinName": "BTC",
// "coinFullName": "Bitcoin",
// "allowWithdraw": true,
// "allowDeposit": true,
// "tokenType": "CHAIN_TOKEN",
// "chainTypes": [
// {
// "chainType": "Bitcoin",
// "withdrawFee": "0",
// "minWithdrawQuantity": "0.002",
// "maxWithdrawQuantity": "0",
// "minDepositQuantity": "0.0005",
// "allowDeposit": true,
// "allowWithdraw": true
// }
// ]
// }
// ]
// }
//
let mut spotMarkets: Value = self.safe_list_k(response.clone(), "symbols", &[Value::List(vec![])]);
let mut swapMarkets: Value = self.safe_list_k(response.clone(), "contracts", &[Value::List(vec![])]);
let mut markets: Value = self.array_concat(spotMarkets.clone(), swapMarkets.clone());
if is_true(&self.is_empty(markets.clone())) {
markets = Value::List(vec![response.clone()]); // if user provides params.symbol the exchange returns a single object instead of list of objects
}
return self.parse_markets(markets.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
// spot
// {
// "symbol": "BTCUSDT",
// "symbolName": "BTCUSDT",
// "status": "TRADING",
// "baseAsset": "BTC",
// "baseAssetName": "BTC",
// "baseAssetPrecision": "0.00001",
// "quoteAsset": "USDT",
// "quoteAssetName": "USDT",
// "quotePrecision": "0.0000001",
// "retailAllowed": true,
// "piAllowed": true,
// "corporateAllowed": true,
// "omnibusAllowed": true,
// "icebergAllowed": false,
// "isAggregate": false,
// "allowMargin": false,
// "filters": [
// {
// "minPrice": "0.01",
// "maxPrice": "100000.00000000",
// "tickSize": "0.01",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.00001",
// "maxQty": "8",
// "stepSize": "0.00001",
// "marketOrderMinQty": "0.00001",
// "marketOrderMaxQty": "4",
// "filterType": "LOT_SIZE"
// },
// {
// "minNotional": "1",
// "filterType": "MIN_NOTIONAL"
// },
// {
// "minAmount": "1",
// "maxAmount": "400000",
// "minBuyPrice": "0",
// "marketOrderMinAmount": "1",
// "marketOrderMaxAmount": "200000",
// "filterType": "TRADE_AMOUNT"
// },
// {
// "maxSellPrice": "0",
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "LIMIT_TRADING"
// },
// {
// "buyPriceUpRate": "0.1",
// "sellPriceDownRate": "0.1",
// "filterType": "MARKET_TRADING"
// },
// {
// "noAllowMarketStartTime": "1710485700000",
// "noAllowMarketEndTime": "1710486000000",
// "limitOrderStartTime": "0",
// "limitOrderEndTime": "0",
// "limitMinPrice": "0",
// "limitMaxPrice": "0",
// "filterType": "OPEN_QUOTE"
// }
// ]
// }
//
// swap
// {
// "filters": [
// {
// "minPrice": "0.1",
// "maxPrice": "100000.00000000",
// "tickSize": "0.1",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.001",
// "maxQty": "10",
// "stepSize": "0.001",
// "marketOrderMinQty": "0",
// "marketOrderMaxQty": "0",
// "filterType": "LOT_SIZE"
// },
// {
// "minNotional": "0",
// "filterType": "MIN_NOTIONAL"
// },
// {
// "maxSellPrice": "999999",
// "buyPriceUpRate": "0.05",
// "sellPriceDownRate": "0.05",
// "maxEntrustNum": 200,
// "maxConditionNum": 200,
// "filterType": "LIMIT_TRADING"
// },
// {
// "buyPriceUpRate": "0.05",
// "sellPriceDownRate": "0.05",
// "filterType": "MARKET_TRADING"
// },
// {
// "noAllowMarketStartTime": "0",
// "noAllowMarketEndTime": "0",
// "limitOrderStartTime": "0",
// "limitOrderEndTime": "0",
// "limitMinPrice": "0",
// "limitMaxPrice": "0",
// "filterType": "OPEN_QUOTE"
// }
// ],
// "exchangeId": "301",
// "symbol": "BTCUSDT-PERPETUAL",
// "symbolName": "BTCUSDT-PERPETUAL",
// "status": "TRADING",
// "baseAsset": "BTCUSDT-PERPETUAL",
// "baseAssetPrecision": "0.001",
// "quoteAsset": "USDT",
// "quoteAssetPrecision": "0.1",
// "icebergAllowed": false,
// "inverse": false,
// "index": "USDT",
// "marginToken": "USDT",
// "marginPrecision": "0.0001",
// "contractMultiplier": "0.001",
// "underlying": "BTC",
// "riskLimits": [
// {
// "riskLimitId": "200000722",
// "quantity": "1000.00",
// "initialMargin": "0.10",
// "maintMargin": "0.005",
// "isWhite": false
// },
// {
// "riskLimitId": "200000723",
// "quantity": "2000.00",
// "initialMargin": "0.10",
// "maintMargin": "0.01",
// "isWhite": false
// }
// ]
// }
//
let mut marketId: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteAsset", &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "marginToken", &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseAsset", &[]);
let mut marketType: Value = Value::Str("spot".to_string());
let mut isSpot: Value = Value::Bool(true);
let mut isSwap: Value = Value::Bool(false);
let mut suffix: Value = Value::Str("".to_string());
let mut parts: Value = split(&marketId, &Value::Str("-".to_string()));
let mut secondPart: Value = self.safe_string(parts.clone(), Value::Int(1), &[]);
if is_equal(&secondPart, &Value::Str("PERPETUAL".to_string())) {
marketType = Value::Str("swap".to_string());
isSpot = Value::Bool(false);
isSwap = Value::Bool(true);
baseId = self.safe_string_k(market.clone(), "underlying", &[]);
suffix = add(&suffix, &add(&Value::Str(":".to_string()), &settleId));
}
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut symbol: Value = add(&add(&add(&base, &Value::Str("/".to_string())), "e), &suffix);
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut active: Value = Value::Bool(is_equal(&status, &Value::Str("TRADING".to_string())));
let mut isLinear: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut isInverse: Value = self.safe_bool_k(market.clone(), "inverse", &[]);
if !is_equal(&isInverse, &Value::Null) {
if is_true(&isInverse) {
isLinear = Value::Bool(false);
subType = Value::Str("inverse".to_string());
} else {
isLinear = Value::Bool(true);
subType = Value::Str("linear".to_string());
}
}
let mut filtersList: Value = self.safe_list_k(market.clone(), "filters", &[Value::List(vec![])]);
let mut filters: Value = self.index_by(filtersList.clone(), Value::Str("filterType".to_string()));
let mut priceFilter: Value = self.safe_dict_k(filters.clone(), "PRICE_FILTER", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amountFilter: Value = self.safe_dict_k(filters.clone(), "LOT_SIZE", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut costFilter: Value = self.safe_dict_k(filters.clone(), "MIN_NOTIONAL", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut minCostString: Value = self.omit_zero(self.safe_string_k(costFilter.clone(), "min_notional", &[]));
let mut contractSizeString: Value = self.safe_string_k(market.clone(), "contractMultiplier", &[]);
let mut amountPrecisionString: Value = self.safe_string_k(amountFilter.clone(), "stepSize", &[]);
let mut amountMinLimitString: Value = self.safe_string_k(amountFilter.clone(), "minQty", &[]);
let mut amountMaxLimitString: Value = self.safe_string_k(amountFilter.clone(), "maxQty", &[]);
let mut minLeverage: Value = Value::Null;
let mut maxLeverage: Value = Value::Null;
if is_true(&isSwap) {
amountPrecisionString = crate::precise::Precise::stringDiv(&amountPrecisionString, &contractSizeString);
amountMinLimitString = crate::precise::Precise::stringDiv(&amountMinLimitString, &contractSizeString);
amountMaxLimitString = crate::precise::Precise::stringDiv(&amountMaxLimitString, &contractSizeString);
let mut riskLimits: Value = self.safe_list_k(market.clone(), "riskLimits", &[]);
if !is_equal(&riskLimits, &Value::Null) {
let mut first: Value = self.safe_dict(riskLimits.clone(), Value::Int(0), &[]);
let mut arrayLength: Value = get_array_length(&riskLimits);
let mut last: Value = self.safe_dict(riskLimits.clone(), subtract(&arrayLength, &Value::Int(1)), &[]);
let mut minInitialMargin: Value = self.safe_string_k(first.clone(), "initialMargin", &[]);
let mut maxInitialMargin: Value = self.safe_string_k(last.clone(), "initialMargin", &[]);
if is_true(&crate::precise::Precise::stringGt(&minInitialMargin, &maxInitialMargin)) {
{ let __destr_tmp = Value::List(vec![maxInitialMargin.clone(), minInitialMargin.clone()]); minInitialMargin = get_value(&__destr_tmp, &Value::Int(0)); maxInitialMargin = get_value(&__destr_tmp, &Value::Int(1)); }
}
minLeverage = self.parse_to_int(crate::precise::Precise::stringDiv(&Value::Str("1".to_string()), &maxInitialMargin));
maxLeverage = self.parse_to_int(crate::precise::Precise::stringDiv(&Value::Str("1".to_string()), &minInitialMargin));
}
}
let mut tradingFees: Value = self.safe_dict_k(self.fees.clone(), "trading", &[]);
let mut fees: Value = ternary(is_true(&isSpot), self.safe_dict_k(tradingFees.clone(), "spot", &[]), self.safe_dict_k(tradingFees.clone(), "swap", &[]));
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("active".to_string(), active.clone());
m.insert("type".to_string(), marketType.clone());
m.insert("subType".to_string(), subType.clone());
m.insert("spot".to_string(), isSpot.clone());
m.insert("margin".to_string(), self.safe_bool_k(market.clone(), "allowMargin", &[]));
m.insert("swap".to_string(), isSwap.clone());
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("contract".to_string(), isSwap.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("contractSize".to_string(), self.parse_number(contractSizeString.clone(), &[]));
m.insert("linear".to_string(), isLinear.clone());
m.insert("inverse".to_string(), isInverse.clone());
m.insert("taker".to_string(), self.safe_number_k(fees.clone(), "taker", &[]));
m.insert("maker".to_string(), self.safe_number_k(fees.clone(), "maker", &[]));
m.insert("percentage".to_string(), self.safe_bool_k(fees.clone(), "percentage", &[]));
m.insert("tierBased".to_string(), self.safe_bool_k(fees.clone(), "tierBased", &[]));
m.insert("feeSide".to_string(), self.safe_string_k(fees.clone(), "feeSide", &[]));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(amountPrecisionString.clone(), &[]));
m.insert("price".to_string(), self.safe_number_k(priceFilter.clone(), "tickSize", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(amountMinLimitString.clone(), &[]));
m.insert("max".to_string(), self.parse_number(amountMaxLimitString.clone(), &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(priceFilter.clone(), "minPrice", &[]));
m.insert("max".to_string(), self.safe_number_k(priceFilter.clone(), "maxPrice", &[]));
m
}));
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minLeverage.clone());
m.insert("max".to_string(), maxLeverage.clone());
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minCostString.clone(), &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name hashkey#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://hashkeyglobal-apidoc.readme.io/reference/exchangeinfo
* @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.public_get_api_v1_exchange_info(&[params.clone()]).await;
let mut coins: Value = self.safe_list_k(response.clone(), "coins", &[]);
return self.parse_currencies(coins.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut currencyId: Value = self.safe_string_k(rawCurrency.clone(), "coinId", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut networks: Value = self.safe_list_k(rawCurrency.clone(), "chainTypes", &[]);
let mut parsedNetworks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_720: bool = true;
while { if !__for_first_720 { j = add(&j, &Value::Int(1)); } __for_first_720 = false; is_less_than(&j, &get_array_length(&networks)) } {
let mut network: Value = get_value(&networks, &j);
let mut network: Value = get_value(&networks, &j);
let mut networkId: Value = self.safe_string_k(network.clone(), "chainType", &[]);
let mut networkCode: Value = self.network_code_to_id(networkId.clone(), &[code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut parsedNetworks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(network.clone(), "minWithdrawQuantity", &[]));
m.insert("max".to_string(), self.parse_number(self.omit_zero(self.safe_string_k(network.clone(), "maxWithdrawQuantity", &[])), &[]));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(network.clone(), "minDepositQuantity", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(network.clone(), "allowDeposit", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(network.clone(), "allowWithdraw", &[]));
m.insert("fee".to_string(), self.safe_number_k(network.clone(), "withdrawFee", &[]));
m.insert("precision".to_string(), Value::Null);
m.insert("info".to_string(), network.clone());
m
}));
}
}
}
let mut rawType: Value = self.safe_string_k(rawCurrency.clone(), "tokenType", &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&rawType, &Value::Str("REAL_MONEY".to_string())))), Value::Str("fiat".to_string()), Value::Str("crypto".to_string()));
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId.clone());
m.insert("code".to_string(), code.clone());
m.insert("precision".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("name".to_string(), self.safe_string_k(rawCurrency.clone(), "coinFullName", &[]));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(rawCurrency.clone(), "allowDeposit", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(rawCurrency.clone(), "allowWithdraw", &[]));
m.insert("fee".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), parsedNetworks.clone());
m.insert("info".to_string(), rawCurrency.clone());
m
}));
Value::Null
}
/*
* @method
* @name hashkey#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-order-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return (maximum value is 200)
* @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("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_quote_v1_depth(&[__ws_arg_1]).await;
//
// {
// "t": 1721681436393,
// "b": [
// ["67902.49", "0.00112"],
// ["67901.08", "0.01014"]
// ...
// ],
// "a": [
// ["67905.99", "0.87134"],
// ["67906", "0.57361"]
// ...
// ]
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "t", &[]);
return self.parse_order_book(response.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("b".to_string()), Value::Str("a".to_string())]);
Value::Null
}
/*
* @method
* @name hashkey#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-recent-trade-list
* @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 (maximum value is 100)
* @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::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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_quote_v1_trades(&[__ws_arg_2]).await;
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchMyTrades
* @description fetch all trades made by the user
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-account-trade-list
* @see https://hashkeyglobal-apidoc.readme.io/reference/query-futures-trades
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-sub-account-user
* @param {string} symbol *is mandatory for swap markets* unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum amount of trades to fetch (default 200, max 500)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap' - the type of the market to fetch trades for (default 'spot')
* @param {int} [params.until] the latest time in ms to fetch trades for, only supports the last 30 days timeframe
* @param {string} [params.fromId] srarting trade id
* @param {string} [params.toId] ending trade id
* @param {string} [params.clientOrderId] *spot markets only* filter trades by orderId
* @param {string} [params.accountId] account id to fetch the orders from
* @returns {Trade[]} a list of [trade structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#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
}));
let mut methodName: Value = Value::Str("fetchMyTrades".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 = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let mut accountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("accountId".to_string()), &[]); accountId = 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("spot".to_string())) {
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&accountId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("accountId".to_string()), accountId.clone());
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_account_trades(&[__ws_arg_3]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a symbol argument for swap markets".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
if !is_equal(&accountId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("subAccountId".to_string()), accountId.clone());
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_sub_account_user_trades(&[__ws_arg_4]).await;
} else {
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_user_trades(&[__ws_arg_5]).await;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &marketType), &Value::Str(" type of markets".to_string()))));
}
return self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades
//
// {
// "t": 1721682745779,
// "p": "67835.99",
// "q": "0.00017",
// "ibm": true
// }
//
// fetchMyTrades spot
//
// {
// "id": "1739352552862964736",
// "clientOrderId": "1722082982086472",
// "ticketId": "1739352552795029504",
// "symbol": "ETHUSDT",
// "symbolName": "ETHUSDT",
// "orderId": "1739352552762301440",
// "matchOrderId": "0",
// "price": "3289.96",
// "qty": "0.001",
// "commission": "0.0000012",
// "commissionAsset": "ETH",
// "time": "1722082982097",
// "isBuyer": true,
// "isMaker": false,
// "fee": {
// "feeCoinId": "ETH",
// "feeCoinName": "ETH",
// "fee": "0.0000012"
// },
// "feeCoinId": "ETH",
// "feeAmount": "0.0000012",
// "makerRebate": "0"
// }
//
// fetchMyTrades swap
// {
// "time": "1722429951648",
// "tradeId": "1742263144691139328",
// "orderId": "1742263144028363776",
// "symbol": "ETHUSDT-PERPETUAL",
// "price": "3327.54",
// "quantity": "4",
// "commissionAsset": "USDT",
// "commission": "0.00798609",
// "makerRebate": "0",
// "type": "LIMIT",
// "side": "BUY_OPEN",
// "realizedPnl": "0",
// "isMarker": false
// }
let mut timestamp: Value = self.safe_integer2(trade.clone(), Value::Str("t".to_string()), Value::Str("time".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut side: Value = self.safe_string_lower(trade.clone(), Value::Str("side".to_string()), &[]); // swap trades have side param
if !is_equal(&side, &Value::Null) {
side = self.safe_string(split(&side, &Value::Str("_".to_string())), Value::Int(0), &[]);
}
let mut isBuyer: Value = self.safe_bool_k(trade.clone(), "isBuyer", &[]);
if !is_equal(&isBuyer, &Value::Null) {
side = ternary(is_true(&isBuyer), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
}
let mut takerOrMaker: Value = Value::Null;
let mut isMaker: Value = self.safe_bool2(trade.clone(), Value::Str("isMaker".to_string()), Value::Str("isMarker".to_string()), &[]);
if !is_equal(&isMaker, &Value::Null) {
takerOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
let mut isBuyerMaker: Value = self.safe_bool_k(trade.clone(), "ibm", &[]);
// if public trade
if !is_equal(&isBuyerMaker, &Value::Null) {
takerOrMaker = Value::Str("taker".to_string());
side = ternary(is_true(&isBuyerMaker), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
}
let mut feeCost: Value = self.safe_string_k(trade.clone(), "commission", &[]);
let mut feeCurrncyId: Value = self.safe_string_k(trade.clone(), "commissionAsset", &[]);
let mut feeInfo: Value = self.safe_dict_k(trade.clone(), "fee", &[]);
let mut fee: Value = Value::Null;
if !is_equal(&feeInfo, &Value::Null) {
feeCost = self.safe_string_k(feeInfo.clone(), "fee", &[]);
feeCurrncyId = self.safe_string_k(feeInfo.clone(), "feeCoinId", &[]);
}
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeCost.clone(), &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCurrncyId.clone(), &[]));
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("id".to_string()), Value::Str("tradeId".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.safe_string2(trade.clone(), Value::Str("p".to_string()), Value::Str("price".to_string()), &[]));
m.insert("amount".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("q".to_string()), Value::Str("qty".to_string()), Value::Str("quantity".to_string())]), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("type".to_string(), Value::Null);
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("fee".to_string(), fee.clone());
m.insert("info".to_string(), trade.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchOHLCV
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-kline
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
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
}));
let mut methodName: Value = Value::Str("fetchOHLCV".to_string());
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), 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());
timeframe = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), timeframe.clone());
m
});
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());
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_quote_v1_klines(&[__ws_arg_6]).await;
//
// [
// [
// 1721684280000,
// "67832.49",
// "67862.5",
// "67832.49",
// "67861.44",
// "0.01122",0,
// "761.2763533",68,
// "0.00561",
// "380.640643"
// ],
// ...
// ]
//
let mut ohlcvs: Value = self.to_array(response.clone());
return self.parse_ohlc_vs(ohlcvs.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_integer(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name hashkey#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-24hr-ticker-price-change
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_quote_v1_ticker24hr(&[__ws_arg_7]).await;
//
// [
// {
// "t": 1721685896846,
// "s": "BTCUSDT-PERPETUAL",
// "c": "67756.7",
// "h": "68479.9",
// "l": "66594.3",
// "o": "68279.7",
// "b": "67756.6",
// "a": "67756.7",
// "v": "1604722",
// "qv": "108827258.7761"
// }
// ]
//
let mut ticker: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(ticker.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-24hr-ticker-price-change
* @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 response: Value = self.public_get_quote_v1_ticker24hr(&[params.clone()]).await;
return self.parse_tickers(response.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "t": 1721685896846,
// "s": "BTCUSDT-PERPETUAL",
// "c": "67756.7",
// "h": "68479.9",
// "l": "66594.3",
// "o": "68279.7",
// "b": "67756.6",
// "a": "67756.7",
// "v": "1604722",
// "qv": "108827258.7761"
// }
//
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "t", &[]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "s", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut last: Value = self.safe_string_k(ticker.clone(), "c", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "v", &[]);
if is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))) && is_true(&(!is_equal(&get_value(&market, &Value::Str("contractSize".to_string())), &Value::Null))) {
// 'v' counts contracts, and a ticker reports base volume
baseVolume = crate::precise::Precise::stringMul(&baseVolume, &self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string()))));
}
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(), "h", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "l", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "b", &[]));
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "a", &[]));
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "o", &[]));
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "qv", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchLastPrices
* @description fetches the last price for multiple markets
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-symbol-price-ticker
* @param {string[]} [symbols] unified symbols of the markets to fetch the last prices
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.symbol] the id of the market to fetch last price for
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_quote_v1_ticker_price(&[__ws_arg_8]).await;
return self.parse_last_prices(response.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);
let mut marketId: Value = self.safe_string_k(entry.clone(), "s", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
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(), self.safe_number_omit_zero(entry.clone(), Value::Str("p".to_string()), &[]));
m.insert("side".to_string(), Value::Null);
m.insert("info".to_string(), entry.clone());
m
});
Value::Null
}
/*
* @method
* @name hashkey#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-account-information
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountId] account ID, for Master Key only
* @param {string} [params.type] 'spot' or 'swap' - the type of the market to fetch balance for (default 'spot')
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut methodName: Value = Value::Str("fetchBalance".to_string());
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(methodName.clone(), &[Value::Null, params.clone(), marketType.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("swap".to_string())) {
let mut response: Value = self.private_get_api_v1_futures_balance(&[params.clone()]).await;
//
// [
// {
// "balance": "30.63364672",
// "availableBalance": "28.85635534",
// "positionMargin": "4.3421",
// "orderMargin": "0",
// "asset": "USDT",
// "crossUnRealizedPnl": "2.5649"
// }
// ]
//
let mut balance: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_swap_balance(balance.clone());
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_account(&[__ws_arg_9]).await;
return self.parse_balance(response.clone());
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &marketType), &Value::Str(" type of markets".to_string()))));
}
Value::Null
}
pub fn parse_balance(&self, mut balance: Value) -> Value {
//
// {
// "balances": [
// {
// "asset":"USDT",
// "assetId":"USDT",
// "assetName":"USDT",
// "total":"40",
// "free":"40",
// "locked":"0"
// },
// ...
// ],
// "userId": "1732885739572845312"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), balance.clone());
m
});
let mut balances: Value = self.safe_list_k(balance.clone(), "balances", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_721: bool = true;
while { if !__for_first_721 { i = add(&i, &Value::Int(1)); } __for_first_721 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut balanceEntry: Value = get_value(&balances, &i);
let mut balanceEntry: Value = get_value(&balances, &i);
let mut currencyId: Value = self.safe_string_k(balanceEntry.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balanceEntry.clone(), "total", &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balanceEntry.clone(), "free", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balanceEntry.clone(), "locked", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
pub fn parse_swap_balance(&self, mut balance: Value) -> Value {
//
// {
// "balance": "30.63364672",
// "availableBalance": "28.85635534",
// "positionMargin": "4.3421",
// "orderMargin": "0",
// "asset": "USDT",
// "crossUnRealizedPnl": "2.5649"
// }
//
let mut currencyId: Value = self.safe_string_k(balance.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "balance", &[]));
let mut positionMargin: Value = self.safe_string_k(balance.clone(), "positionMargin", &[]);
let mut orderMargin: Value = self.safe_string_k(balance.clone(), "orderMargin", &[]);
add_element_to_object(&mut account, &Value::Str("used".to_string()), crate::precise::Precise::stringAdd(&positionMargin, &orderMargin));
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), balance.clone());
m
});
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name hashkey#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-deposit-address
* @param {string} code unified currency code (default is 'USDT')
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] network for fetch deposit address (default is 'ETH')
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
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) {
networkCode = self.default_network_code(code.clone());
}
add_element_to_object(&mut request, &Value::Str("chainType".to_string()), self.network_code_to_id(networkCode.clone(), &[code.clone()]));
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_account_deposit_address(&[__ws_arg_10]).await;
//
// {
// "canDeposit": true,
// "address": "0x61AAd7F763e2C7fF1CC996918740F67f9dC8BF4e",
// "addressExt": "",
// "minQuantity": "1",
// "needAddressTag": false,
// "requiredConfirmTimes": 64,
// "canWithdrawConfirmTimes": 64,
// "coinType": "ERC20_TOKEN"
// }
//
let mut depositAddress: Value = self.parse_deposit_address(response.clone(), &[currency.clone()]);
add_element_to_object(&mut depositAddress, &Value::Str("network".to_string()), networkCode.clone());
return depositAddress;
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);
//
// {
// "canDeposit": true,
// "address": "0x61AAd7F763e2C7fF1CC996918740F67f9dC8BF4e",
// "addressExt": "",
// "minQuantity": "1",
// "needAddressTag": false,
// "requiredConfirmTimes": 64,
// "canWithdrawConfirmTimes": 64,
// "coinType": "ERC20_TOKEN"
// }
//
let mut address: Value = self.safe_string_k(depositAddress.clone(), "address", &[]);
self.check_address(&[address.clone()]);
let mut tag: Value = self.safe_string_k(depositAddress.clone(), "addressExt", &[]);
if is_equal(&tag, &Value::Str("".to_string())) {
tag = Value::Null;
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), self.safe_string_k(currency.clone(), "code", &[]));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m
});
Value::Null
}
/*
* @method
* @name hashkey#fetchDeposits
* @description fetch all deposits made to an account
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-deposit-history
* @param {string} code unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for (default 24 hours ago)
* @param {int} [limit] the maximum number of transfer structures to retrieve (default 50, max 200)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch transfers for (default time now)
* @param {int} [params.fromId] starting ID (To be released)
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/?id=transfer-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
}));
let mut methodName: Value = Value::Str("fetchDeposits".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 currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("coin".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());
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_account_deposit_orders(&[__ws_arg_11]).await;
return self.parse_transactions(response.clone(), &[currency.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("deposit".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name hashkey#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://hashkeyglobal-apidoc.readme.io/reference/withdrawal-records
* @param {string} code unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for (default 24 hours ago)
* @param {int} [limit] the maximum number of transfer structures to retrieve (default 50, max 200)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch transfers for (default time now)
* @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
}));
let mut methodName: Value = Value::Str("fetchWithdrawals".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 currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("coin".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());
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_account_withdraw_orders(&[__ws_arg_12]).await;
return self.parse_transactions(response.clone(), &[currency.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("withdrawal".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name hashkey#withdraw
* @description make a withdrawal
* @see https://hashkeyglobal-apidoc.readme.io/reference/withdraw
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] network for withdraw
* @param {string} [params.clientOrderId] client order id
* @param {string} [params.platform] the platform to withdraw to (hashkey, HashKey HK)
* @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;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("address".to_string(), address.clone());
m.insert("quantity".to_string(), amount.clone());
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("addressExt".to_string()), tag.clone());
}
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chainType".to_string()), self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))]));
}
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_account_withdraw(&[__ws_arg_13]).await;
return self.parse_transaction(response.clone(), &[currency.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
// {
// "time": "1721641082163",
// "coin": "TRXUSDT", // todo how to parse it?
// "coinName": "TRXUSDT",
// "address": "TBA6CypYJizwA9XdC7Ubgc5F1bxrQ7SqPt",
// "quantity": "86.00000000000000000000",
// "status": 4,
// "statusCode": "4",
// "txId": "0970c14da4d7412295fa7b21c03a08da319e746a0d59ef14462a74183d118da4"
// }
//
// fetchWithdrawals
// {
// "time": "1723545505366",
// "id": "W611267400947572736",
// "coin": "USDT",
// "coinId": "USDT",
// "coinName": "USDT",
// "address": "TQbkBMnWnJNGTAUpFS4kvv4NRLzUAnGAes",
// "quantity": "2.00000000",
// "arriveQuantity": "2.00000000",
// "txId": "f83f94e7d2e81fbec98c66c25d6615872cc2d426145629b6cf22e5e0a0753715",
// "addressUrl": "TQbkBMnWnJNGTAUpFS4kvv4NRLzUAnGAes",
// "feeCoinId": "USDT",
// "feeCoinName": "USDT",
// "fee": "1.00000000",
// "remark": "",
// "platform": ""
// }
//
// withdraw
// {
// "success": true,
// "id": "0",
// "orderId": "W611267400947572736",
// "accountId": "1732885739589466115"
// }
//
let mut id: Value = self.safe_string2(transaction.clone(), Value::Str("id".to_string()), Value::Str("orderId".to_string()), &[]);
let mut address: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut status: Value = self.safe_string_k(transaction.clone(), "status", &[]); // for fetchDeposits
if is_equal(&status, &Value::Null) {
let mut success: Value = self.safe_bool_k(transaction.clone(), "success", &[Value::Bool(false)]); // for withdraw
if is_equal(&success, &Value::Bool(true)) {
status = Value::Str("ok".to_string());
} else {
let mut addressUrl: Value = self.safe_string_k(transaction.clone(), "addressUrl", &[]); // for fetchWithdrawals
if !is_equal(&addressUrl, &Value::Null) {
status = Value::Str("ok".to_string());
}
}
}
let mut txid: Value = self.safe_string_k(transaction.clone(), "txId", &[]);
let mut coin: Value = self.safe_string_k(transaction.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(coin.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "time", &[]);
let mut amount: Value = self.safe_number_k(transaction.clone(), "quantity", &[]);
let mut feeCost: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
let mut fee: Value = Value::Null;
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), code.clone());
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.clone());
m.insert("txid".to_string(), txid.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("amount".to_string(), amount.clone());
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), self.parse_transaction_status(status.clone()));
m.insert("updated".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
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("1".to_string(), Value::Str("pending".to_string()));
m.insert("2".to_string(), Value::Str("pending".to_string()));
m.insert("3".to_string(), Value::Str("failed".to_string()));
m.insert("4".to_string(), Value::Str("ok".to_string()));
m.insert("5".to_string(), Value::Str("pending".to_string()));
m.insert("6".to_string(), Value::Str("ok".to_string()));
m.insert("7".to_string(), Value::Str("failed".to_string()));
m.insert("8".to_string(), Value::Str("cancelled".to_string()));
m.insert("9".to_string(), Value::Str("failed".to_string()));
m.insert("10".to_string(), Value::Str("failed".to_string()));
m.insert("successful".to_string(), Value::Str("ok".to_string()));
m.insert("success".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#transfer
* @description transfer currency internally between wallets on the same account
* @see https://hashkeyglobal-apidoc.readme.io/reference/new-account-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account id to transfer from
* @param {string} toAccount account id to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the transfer
* @param {string} [params.remark] a note for the transfer
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("quantity".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("fromAccountId".to_string(), fromAccount.clone());
m.insert("toAccountId".to_string(), toAccount.clone());
m
});
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_account_asset_transfer(&[__ws_arg_14]).await;
return self.parse_transfer(response.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "timestamp", &[]);
let mut currencyId: Value = self.safe_string_k(currency.clone(), "id", &[]);
let mut status: Value = Value::Null;
let mut success: Value = self.safe_bool_k(transfer.clone(), "success", &[Value::Bool(false)]);
if is_equal(&success, &Value::Bool(true)) {
status = Value::Str("ok".to_string());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "orderId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("info".to_string(), transfer.clone());
m
});
Value::Null
}
/*
* @method
* @name hashkey#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://hashkeyglobal-apidoc.readme.io/reference/query-sub-account
* @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.private_get_api_v1_account_type(&[params.clone()]).await;
return self.parse_accounts(response.clone(), &[params.clone()]);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
let mut accountLabel: Value = self.safe_string_k(account.clone(), "accountLabel", &[]);
let mut label: Value = Value::Str("".to_string());
if is_equal(&accountLabel, &Value::Str("Main Trading Account".to_string())) || is_equal(&accountLabel, &Value::Str("Main Future Account".to_string())) {
label = Value::Str("main".to_string());
} else if is_equal(&accountLabel, &Value::Str("Sub Main Trading Account".to_string())) || is_equal(&accountLabel, &Value::Str("Sub Main Future Account".to_string())) {
label = Value::Str("sub".to_string());
}
let mut accountType: Value = self.parse_account_type(self.safe_string_k(account.clone(), "accountType", &[]));
let mut type_var: Value = add(&add(&label, &Value::Str(" ".to_string())), &accountType);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(account.clone(), "accountId", &[]));
m.insert("type".to_string(), type_var.clone());
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), account.clone());
m
});
Value::Null
}
pub fn parse_account_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1".to_string(), Value::Str("spot account".to_string()));
m.insert("3".to_string(), Value::Str("swap account".to_string()));
m.insert("5".to_string(), Value::Str("custody account".to_string()));
m.insert("6".to_string(), Value::Str("fiat account".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn encode_account_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("1".to_string()));
m.insert("swap".to_string(), Value::Str("3".to_string()));
m.insert("custody".to_string(), Value::Str("5".to_string()));
m
});
return self.safe_integer(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn encode_flow_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("1".to_string()));
m.insert("fee".to_string(), Value::Str("3".to_string()));
m.insert("transfer".to_string(), Value::Str("51".to_string()));
m.insert("deposit".to_string(), Value::Str("900".to_string()));
m.insert("withdraw".to_string(), Value::Str("904".to_string()));
m
});
return self.safe_integer(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-account-transaction-list
* @param {string} [code] unified currency code, default is undefined (not used)
* @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 {int} [params.flowType] trade, fee, transfer, deposit, withdrawal
* @param {int} [params.accountType] spot, swap, custody
* @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
}));
let mut methodName: Value = Value::Str("fetchLedger".to_string());
if is_equal(&since, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a since argument".to_string()))));
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&until, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires an until argument".to_string()))));
}
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
});
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());
}
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
let mut flowType: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("flowType".to_string()), &[]); flowType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&flowType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("flowType".to_string()), self.encode_flow_type(flowType.clone()));
}
let mut accountType: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("accountType".to_string()), &[]); accountType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&accountType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("accountType".to_string()), self.encode_account_type(accountType.clone()));
}
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_account_balance_flow(&[__ws_arg_15]).await;
return self.parse_ledger(response.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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("1".to_string(), Value::Str("trade".to_string()));
m.insert("2".to_string(), Value::Str("fee".to_string()));
m.insert("51".to_string(), Value::Str("transfer".to_string()));
m.insert("900".to_string(), Value::Str("deposit".to_string()));
m.insert("904".to_string(), Value::Str("withdraw".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);
//
// {
// "id": "1740844413612065537",
// "accountId": "1732885739589466112",
// "coin": "USDT",
// "coinId": "USDT",
// "coinName": "USDT",
// "flowTypeValue": 51,
// "flowType": "USER_ACCOUNT_TRANSFER",
// "flowName": "",
// "change": "-1",
// "total": "8.015680088",
// "created": "1722260825765"
// }
//
let mut id: Value = self.safe_string_k(item.clone(), "id", &[]);
let mut account: Value = self.safe_string_k(item.clone(), "accountId", &[]);
let mut timestamp: Value = self.safe_integer_k(item.clone(), "created", &[]);
let mut type_var: Value = self.parse_ledger_entry_type(self.safe_string_k(item.clone(), "flowTypeValue", &[]));
let mut currencyId: Value = self.safe_string_k(item.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut amountString: Value = self.safe_string_k(item.clone(), "change", &[]);
let mut amount: Value = self.parse_number(amountString.clone(), &[]);
let mut direction: Value = Value::Str("in".to_string());
if is_greater_than_or_equal(&get_index_of(&amountString, &Value::Str("-".to_string())), &Value::Int(0)) {
direction = Value::Str("out".to_string());
}
let mut afterString: Value = self.safe_string_k(item.clone(), "total", &[]);
let mut after: Value = self.parse_number(afterString.clone(), &[]);
let mut status: Value = Value::Str("ok".to_string());
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("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("account".to_string(), account.clone());
m.insert("direction".to_string(), direction.clone());
m.insert("referenceId".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), code.clone());
m.insert("symbol".to_string(), Value::Null);
m.insert("amount".to_string(), amount.clone());
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), after.clone());
m.insert("status".to_string(), status.clone());
m.insert("fee".to_string(), Value::Null);
m
}), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#createOrder
* @description create a trade order
* @see https://hashkeyglobal-apidoc.readme.io/reference/test-new-order
* @see https://hashkeyglobal-apidoc.readme.io/reference/create-order
* @see https://hashkeyglobal-apidoc.readme.io/reference/create-new-futures-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit' or 'LIMIT_MAKER' for spot, 'market' or 'limit' or 'STOP' for swap
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that 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.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
* @param {boolean} [params.test] *spot markets only* whether to use the test endpoint or not, default is false
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
* @param {string} [params.timeInForce] "GTC" or "IOC" or "PO" for spot, 'GTC' or 'FOK' or 'IOC' or 'LIMIT_MAKER' or 'PO' for swap
* @param {string} [params.clientOrderId] a unique id for the order - is mandatory for swap
* @param {float} [params.triggerPrice] *swap markets only* The price at which a trigger order is triggered at
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
return self.create_spot_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
return self.create_swap_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" createOrder() is not supported for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" type of markets".to_string()))));
}
Value::Null
}
/*
* @method
* @name hashkey#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @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() is supported for spot markets only".to_string()))));
}
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), cost.clone());
m
});
let __ws_arg_16 = self.extend(req.clone(), &[params.clone()]);
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), cost.clone(), &[Value::Null, __ws_arg_16]).await;
Value::Null
}
/*
* @method
* @name hashkey#createSpotOrder
* @description create a trade order on spot market
* @see https://hashkeyglobal-apidoc.readme.io/reference/test-new-order
* @see https://hashkeyglobal-apidoc.readme.io/reference/create-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit' or 'LIMIT_MAKER'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that 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.cost] *market buy only* the quote quantity that can be used as an alternative for the amount
* @param {bool} [params.test] whether to use the test endpoint or not, default is false
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
* @param {string} [params.timeInForce] 'GTC', 'IOC', or 'PO'
* @param {string} [params.clientOrderId] a unique id for the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_spot_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
}));
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
if !is_equal(&triggerPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" trigger orders are not supported for spot markets".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut isMarketBuy: bool = is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_equal(&side, &Value::Str("buy".to_string()))));
let mut cost: Value = self.safe_string_k(params.clone(), "cost", &[]);
if is_true(&(!is_true(&isMarketBuy))) && is_true(&(!is_equal(&cost, &Value::Null))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() supports cost parameter for spot market buy orders only".to_string()))));
}
let mut request: Value = self.create_spot_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut test: Value = self.safe_bool_k(params.clone(), "test", &[]);
if is_equal(&test, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("test".to_string()), &[]);
response = self.private_post_api_v1_spot_order_test(&[request.clone()]).await;
} else if is_true(&isMarketBuy) && is_true(&(is_equal(&cost, &Value::Null))) {
response = self.private_post_api_v11_spot_order(&[request.clone()]).await; // the endpoint for market buy orders by amount
} else {
response = self.private_post_api_v1_spot_order(&[request.clone()]).await; // the endpoint for market buy orders by cost and other orders
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
return self.create_spot_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
return self.create_swap_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &Value::Str("createOrderRequest() is not supported for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" type of markets".to_string()))));
}
Value::Null
}
pub fn create_spot_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 hashkey#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' or 'LIMIT_MAKER'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that 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.cost] *market buy only* the quote quantity that can be used as an alternative for the amount
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
* @param {string} [params.timeInForce] "GTC", "IOC", or "PO"
* @param {string} [params.clientOrderId] a unique id for the order
* @returns {object} request to be sent to the exchange
*/
let mut market: Value = self.market(symbol.clone());
type_var = to_upper(&type_var);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), to_upper(&side));
m.insert("type".to_string(), type_var.clone());
m
});
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
let mut cost: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("cost".to_string()), &[]); cost = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&cost, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.cost_to_precision(symbol.clone(), cost.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("MARKET".to_string())));
let mut postOnly: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_post_only(isMarketOrder.clone(), Value::Bool(is_equal(&type_var, &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_true(&postOnly) && is_true(&(is_equal(&type_var, &Value::Str("LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("LIMIT_MAKER".to_string()));
}
let mut clientOrderId: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("clientOrderId".to_string()), &[]); clientOrderId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("newClientOrderId".to_string()), clientOrderId.clone());
}
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
pub fn create_swap_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
}));
/*
* @method
* @ignore
* @name hashkey#createSwapOrderRequest
* @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' or 'STOP'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
* @param {bool} [params.reduceOnly] true or false whether the order is reduce only
* @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
* @param {string} [params.timeInForce] 'GTC', 'FOK', 'IOC', 'LIMIT_MAKER' or 'PO'
* @param {string} [params.clientOrderId] a unique id for the order
* @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("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("type".to_string(), Value::Str("LIMIT".to_string()));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("market".to_string())));
if is_true(&isMarketOrder) {
add_element_to_object(&mut request, &Value::Str("priceType".to_string()), Value::Str("MARKET".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()));
add_element_to_object(&mut request, &Value::Str("priceType".to_string()), Value::Str("INPUT".to_string()));
}
let mut reduceOnly: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_param_bool(params.clone(), Value::Str("reduceOnly".to_string()), &[reduceOnly.clone()]); reduceOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut suffix: Value = Value::Str("_OPEN".to_string());
if is_equal(&reduceOnly, &Value::Bool(true)) {
suffix = Value::Str("_CLOSE".to_string());
}
add_element_to_object(&mut request, &Value::Str("side".to_string()), add(&to_upper(&side), &suffix));
let mut timeInForce: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("timeInForce".to_string()), &[]); timeInForce = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut postOnly: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_post_only(isMarketOrder.clone(), Value::Bool(is_equal(&timeInForce, &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_true(&postOnly) {
timeInForce = Value::Str("LIMIT_MAKER".to_string());
}
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), timeInForce.clone());
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOrderId".to_string()), self.uuid(&[]));
}
let mut triggerPrice: Value = self.safe_string_k(params.clone(), "triggerPrice", &[]);
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP".to_string()));
params = self.omit(params.clone(), Value::Str("triggerPrice".to_string()), &[]);
}
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#createSwapOrder
* @description create a trade order on swap market
* @see https://hashkeyglobal-apidoc.readme.io/reference/create-new-futures-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit' or 'STOP'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
* @param {bool} [params.reduceOnly] true or false whether the order is reduce only
* @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
* @param {string} [params.timeInForce] 'GTC', 'FOK', 'IOC', 'LIMIT_MAKER' or 'PO'
* @param {string} [params.clientOrderId] a unique id for the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_swap_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 request: Value = self.create_swap_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_futures_order(&[__ws_arg_17]).await;
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#createOrders
* @description create a list of trade orders (all orders should be of the same symbol)
* @see https://hashkeyglobal-apidoc.readme.io/reference/create-multiple-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/batch-create-new-futures-order
* @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 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 i: Value = Value::Int(0);
let mut __for_first_722: bool = true;
while { if !__for_first_722 { i = add(&i, &Value::Int(1)); } __for_first_722 = 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 symbol: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
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_number_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_number_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
let mut clientOrderId: Value = self.safe_string_k(orderRequest.clone(), "clientOrderId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut orderRequest, &Value::Str("clientOrderId".to_string()), self.uuid(&[])); // both spot and swap endpoints require clientOrderId
}
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut firstOrder: Value = get_value(&ordersRequests, &Value::Int(0));
let mut firstSymbol: Value = self.safe_string_k(firstOrder.clone(), "symbol", &[]);
let mut market: Value = self.market(firstSymbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), ordersRequests.clone());
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_api_v1_spot_batch_orders(&[__ws_arg_18]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_api_v1_futures_batch_orders(&[__ws_arg_19]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &Value::Str("createOrderRequest() is not supported for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" type of markets".to_string()))));
}
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
let mut responseOrders: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_723: bool = true;
while { if !__for_first_723 { i = add(&i, &Value::Int(1)); } __for_first_723 = false; is_less_than(&i, &get_array_length(&result)) } {
let mut responseEntry: Value = self.safe_dict(result.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut responseOrder: Value = self.safe_dict_k(responseEntry.clone(), "order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
append_to_array(&mut responseOrders, responseOrder.clone());
}
}
return self.parse_orders(responseOrders.clone(), &[]);
Value::Null
}
/*
* @method
* @name hashkey#cancelOrder
* @description cancels an open order
* @see https://hashkeyglobal-apidoc.readme.io/reference/cancel-order
* @see https://hashkeyglobal-apidoc.readme.io/reference/cancel-futures-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 {string} [params.type] 'spot' or 'swap' - the type of the market to fetch entry for (default 'spot')
* @param {string} [params.clientOrderId] a unique id for the order that can be used as an alternative for the id
* @param {bool} [params.trigger] *swap markets only* true for canceling a trigger order (default false)
* @param {bool} [params.stop] *swap markets only* an alternative for trigger param
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut methodName: Value = Value::Str("cancelOrder".to_string());
self.check_type_param(methodName.clone(), params.clone());
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 clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params.clone(), marketType.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("spot".to_string())) {
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_spot_order(&[__ws_arg_20]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
let mut isTrigger: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_trigger_option_and_params(params.clone(), methodName.clone(), &[isTrigger.clone()]); isTrigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("LIMIT".to_string()));
}
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_futures_order(&[__ws_arg_21]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &marketType), &Value::Str(" type of markets".to_string()))));
}
return self.parse_order(response.clone(), &[]);
Value::Null
}
/*
* @method
* @name hashkey#cancelAllOrders
* @description cancel all open orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/cancel-all-open-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/batch-cancel-futures-order
* @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 {string} [params.side] 'buy' or 'sell'
* @returns {object} response from exchange
*/
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
}));
// Does not cancel trigger orders. For canceling trigger order use cancelOrder() or cancelOrders()
let mut methodName: Value = Value::Str("cancelAllOrders".to_string());
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut side: Value = self.safe_string_k(params.clone(), "side", &[]);
if !is_equal(&side, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("side".to_string()), side.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_spot_open_orders(&[__ws_arg_22]).await;
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v1_futures_batch_orders(&[__ws_arg_23]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" type of markets".to_string()))));
}
let mut order: Value = self.safe_order(response.clone(), &[]);
add_element_to_object(&mut order, &Value::Str("info".to_string()), response.clone());
return Value::List(vec![order.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#cancelOrders
* @description cancel multiple orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/cancel-multiple-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/batch-cancel-futures-order-by-order-id
* @param {string[]} ids order ids
* @param {string} [symbol] unified market symbol (not used by hashkey)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap' - the type of the market to fetch entry for (default 'spot')
* @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
}));
let mut methodName: Value = Value::Str("cancelOrders".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 orderIds: Value = join(&ids, &Value::Str(",".to_string()));
add_element_to_object(&mut request, &Value::Str("ids".to_string()), orderIds.clone());
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params.clone(), marketType.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("spot".to_string())) {
response = self.private_delete_api_v1_spot_cancel_order_by_ids(&[request.clone()]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
response = self.private_delete_api_v1_futures_cancel_order_by_ids(&[request.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &marketType), &Value::Str(" type of markets".to_string()))));
}
let mut order: Value = self.safe_order(response.clone(), &[]);
add_element_to_object(&mut order, &Value::Str("info".to_string()), response.clone());
return Value::List(vec![order.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchOrder
* @description fetches information on an order made by the user
* @see https://hashkeyglobal-apidoc.readme.io/reference/query-order
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-futures-order
* @param {string} id the order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap' - the type of the market to fetch entry for (default 'spot')
* @param {string} [params.clientOrderId] a unique id for the order that can be used as an alternative for the id
* @param {string} [params.accountId] *spot markets only* account id to fetch the order from
* @param {bool} [params.trigger] *swap markets only* true for fetching a trigger order (default false)
* @param {bool} [params.stop] *swap markets only* an alternative for trigger param
* @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
}));
let mut methodName: Value = Value::Str("fetchOrder".to_string());
self.check_type_param(methodName.clone(), params.clone());
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 clientOrderId: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("clientOrderId".to_string()), &[]); clientOrderId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params.clone(), marketType.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("spot".to_string())) {
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("origClientOrderId".to_string()), clientOrderId.clone());
}
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_spot_order(&[__ws_arg_24]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
let mut isTrigger: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_trigger_option_and_params(params.clone(), methodName.clone(), &[isTrigger.clone()]); isTrigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP".to_string()));
}
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_order(&[__ws_arg_25]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &marketType), &Value::Str(" type of markets".to_string()))));
}
return self.parse_order(response.clone(), &[]);
Value::Null
}
/*
* @method
* @name hashkey#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-current-open-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-sub-account-open-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/sub
* @see https://hashkeyglobal-apidoc.readme.io/reference/query-open-futures-orders
* @param {string} [symbol] unified market symbol of the market orders were made in - is mandatory for swap markets
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve - default 500, maximum 1000
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap' - the type of the market to fetch entries for (default 'spot')
* @param {string} [params.orderId] *spot markets only* the id of the order to fetch
* @param {string} [params.side] *spot markets only* 'buy' or 'sell' - the side of the orders to fetch
* @param {string} [params.fromOrderId] *swap markets only* the id of the order to start from
* @param {bool} [params.trigger] *swap markets only* true for fetching trigger orders (default false)
* @param {bool} [params.stop] *swap markets only* an alternative for trigger param
* @param {string} [params.accountId] account id to fetch the orders from
* @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
}));
let mut methodName: Value = Value::Str("fetchOpenOrders".to_string());
self.check_type_param(methodName.clone(), params.clone());
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::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params.clone(), marketType.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
params = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("methodName".to_string(), methodName.clone());
m
}), &[params.clone()]);
if is_equal(&marketType, &Value::Str("spot".to_string())) {
return self.fetch_open_spot_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
return self.fetch_open_swap_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &marketType), &Value::Str(" type of markets".to_string()))));
}
Value::Null
}
/*
* @method
* @ignore
* @name hashkey#fetchOpenSpotOrders
* @description fetch all unfilled currently open orders for spot markets
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-current-open-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/sub
* @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 - default 500, maximum 1000
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.orderId] the id of the order to fetch
* @param {string} [params.side] 'buy' or 'sell' - the side of the orders to fetch
* @param {string} [params.accountId] account id to fetch the orders from
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut methodName: Value = Value::Str("fetchOpenSpotOrders".to_string());
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("methodName".to_string()), &[methodName.clone()]); methodName = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut accountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("accountId".to_string()), &[]); accountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&accountId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("subAccountId".to_string()), accountId.clone());
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_spot_sub_account_open_orders(&[__ws_arg_26]).await;
} else {
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("limit".to_string()), limit.clone());
}
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_spot_open_orders(&[__ws_arg_27]).await;
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @ignore
* @name hashkey#fetchOpenSwapOrders
* @description fetch all unfilled currently open orders for swap markets
* @see https://hashkeyglobal-apidoc.readme.io/reference/query-open-futures-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-sub-account-open-orders
* @param {string} symbol *is mandatory* 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 - maximum 500
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.fromOrderId] the id of the order to start from
* @param {bool} [params.trigger] true for fetching trigger orders (default false)
* @param {bool} [params.stop] an alternative for trigger param
* @param {string} [params.accountId] account id to fetch the orders from
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_swap_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut methodName: Value = Value::Str("fetchOpenSwapOrders".to_string());
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("methodName".to_string()), &[methodName.clone()]); methodName = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a symbol argument for swap market orders".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut isTrigger: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_trigger_option_and_params(params.clone(), methodName.clone(), &[isTrigger.clone()]); isTrigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("LIMIT".to_string()));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut response: Value = Value::Null;
let mut accountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("accountId".to_string()), &[]); accountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&accountId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("subAccountId".to_string()), accountId.clone());
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_sub_account_open_orders(&[__ws_arg_28]).await;
} else {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_open_orders(&[__ws_arg_29]).await;
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchCanceledAndClosedOrders
* @description fetches information on multiple canceled and closed orders made by the user
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-all-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/query-futures-history-orders
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-sub-account-history-orders
* @param {string} symbol *is mandatory for swap markets* 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 - default 500, maximum 1000
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for - only supports the last 90 days timeframe
* @param {string} [params.type] 'spot' or 'swap' - the type of the market to fetch entries for (default 'spot')
* @param {string} [params.orderId] *spot markets only* the id of the order to fetch
* @param {string} [params.side] *spot markets only* 'buy' or 'sell' - the side of the orders to fetch
* @param {string} [params.fromOrderId] *swap markets only* the id of the order to start from
* @param {bool} [params.trigger] *swap markets only* the id of the order to start from true for fetching trigger orders (default false)
* @param {bool} [params.stop] *swap markets only* the id of the order to start from an alternative for trigger param
* @param {string} [params.accountId] account id to fetch the orders from
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_and_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut methodName: Value = Value::Str("fetchCanceledAndClosedOrders".to_string());
self.check_type_param(methodName.clone(), params.clone());
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
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("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let mut accountId: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("accountId".to_string()), &[]); accountId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params.clone(), marketType.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("spot".to_string())) {
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&accountId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("accountId".to_string()), accountId.clone());
}
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_spot_trade_orders(&[__ws_arg_30]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a symbol argument for swap markets".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
let mut isTrigger: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_trigger_option_and_params(params.clone(), methodName.clone(), &[isTrigger.clone()]); isTrigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("LIMIT".to_string()));
}
if !is_equal(&accountId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("subAccountId".to_string()), accountId.clone());
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_sub_account_history_orders(&[__ws_arg_31]).await;
} else {
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v1_futures_history_orders(&[__ws_arg_32]).await;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &marketType), &Value::Str(" type of markets".to_string()))));
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn check_type_param(&self, mut methodName: Value, mut params: Value) {
// some hashkey endpoints have a type param for swap markets that defines the type of an order
// type param is reserved in ccxt for defining the type of the market
// current method warns user if he provides the exchange specific value in type parameter
let mut paramsType: Value = self.safe_string_k(params.clone(), "type", &[]);
if is_true(&(!is_equal(¶msType, &Value::Null))) && is_true(&(!is_equal(¶msType, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(¶msType, &Value::Str("swap".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str(" () type parameter can not be \"".to_string())), ¶msType), &Value::Str("\". It should define the type of the market (\"spot\" or \"swap\"). To define the type of an order use the trigger parameter (true for trigger orders)".to_string()))));
}
}
pub fn handle_trigger_option_and_params(&self, mut params: Value, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut defaultValue = get_arg(optional_args, 0, Value::Null);
let mut isTrigger: Value = defaultValue.clone();
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), methodName.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[isTrigger.clone()]); isTrigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
return Value::List(vec![isTrigger.clone(), params.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);
//
// createOrder spot
// {
// "accountId": "1732885739589466112",
// "symbol": "ETHUSDT",
// "symbolName": "ETHUSDT",
// "clientOrderId": "1722004623170558",
// "orderId": "1738695230608169984",
// "transactTime": "1722004623186",
// "price": "0",
// "origQty": "0",
// "executedQty": "0.0061",
// "status": "FILLED",
// "timeInForce": "IOC",
// "type": "MARKET",
// "side": "BUY",
// "reqAmount": "20",
// "concentration": ""
// }
//
// fetchOrder spot
// {
// "accountId": "1732885739589466112",
// "exchangeId": "301",
// "symbol": "ETHUSDT",
// "symbolName": "ETHUSDT",
// "clientOrderId": "1722004623170558",
// "orderId": "1738695230608169984",
// "price": "0",
// "origQty": "0",
// "executedQty": "0.0061",
// "cummulativeQuoteQty": "19.736489",
// "cumulativeQuoteQty": "19.736489",
// "avgPrice": "3235.49",
// "status": "FILLED",
// "timeInForce": "IOC",
// "type": "MARKET",
// "side": "BUY",
// "stopPrice": "0.0",
// "icebergQty": "0.0",
// "time": "1722004623186",
// "updateTime": "1722004623406",
// "isWorking": true,
// "reqAmount": "20",
// "feeCoin": "",
// "feeAmount": "0",
// "sumFeeAmount": "0"
// }
//
// cancelOrder
// {
// "accountId": "1732885739589466112",
// "symbol": "ETHUSDT",
// "clientOrderId": "1722006209978370",
// "orderId": "1738708541676585728",
// "transactTime": "1722006209989",
// "price": "5000",
// "origQty": "0.005",
// "executedQty": "0",
// "status": "NEW",
// "timeInForce": "GTC",
// "type": "LIMIT_MAKER",
// "side": "SELL"
// }
//
// createOrder swap
// {
// "time": "1722429951611",
// "updateTime": "1722429951648",
// "orderId": "1742263144028363776",
// "clientOrderId": "1722429950315",
// "symbol": "ETHUSDT-PERPETUAL",
// "price": "3460.62",
// "leverage": "5",
// "origQty": "10",
// "executedQty": "10",
// "avgPrice": "0",
// "marginLocked": "6.9212",
// "type": "LIMIT",
// "side": "BUY_OPEN",
// "timeInForce": "IOC",
// "status": "FILLED",
// "priceType": "MARKET",
// "contractMultiplier": "0.00100000"
// }
//
// fetchOrder swap
// {
// "time": "1722429951611",
// "updateTime": "1722429951700",
// "orderId": "1742263144028363776",
// "clientOrderId": "1722429950315",
// "symbol": "ETHUSDT-PERPETUAL",
// "price": "3460.62",
// "leverage": "5",
// "origQty": "10",
// "executedQty": "10",
// "avgPrice": "3327.52",
// "marginLocked": "0",
// "type": "LIMIT",
// "side": "BUY_OPEN",
// "timeInForce": "IOC",
// "status": "FILLED",
// "priceType": "MARKET",
// "isLiquidationOrder": false,
// "indexPrice": "0",
// "liquidationType": ""
// }
//
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("transactTime".to_string()), Value::Str("time".to_string()), &[]);
let mut status: Value = self.safe_string_k(order.clone(), "status", &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut priceType: Value = self.safe_string_k(order.clone(), "priceType", &[]);
if is_equal(&priceType, &Value::Str("MARKET".to_string())) {
type_var = Value::Str("market".to_string());
}
let mut price: Value = self.omit_zero(self.safe_string_k(order.clone(), "price", &[]));
if is_equal(&type_var, &Value::Str("STOP".to_string())) {
if is_equal(&price, &Value::Null) {
type_var = Value::Str("market".to_string());
} else {
type_var = Value::Str("limit".to_string());
}
}
let mut timeInForce: Value = self.safe_string_k(order.clone(), "timeInForce", &[]);
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.parse_order_type_time_in_force_and_post_only(type_var.clone(), timeInForce.clone()); type_var = get_value(&__destr_tmp, &Value::Int(0)); timeInForce = get_value(&__destr_tmp, &Value::Int(1)); postOnly = get_value(&__destr_tmp, &Value::Int(2)); }
let mut average: Value = self.omit_zero(self.safe_string_k(order.clone(), "avgPrice", &[]));
if is_equal(&price, &Value::Null) {
price = average.clone();
}
let mut side: Value = self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]);
let mut reduceOnly: Value = Value::Null;
{ let __destr_tmp = self.parse_order_side_and_reduce_only(side.clone()); side = get_value(&__destr_tmp, &Value::Int(0)); reduceOnly = get_value(&__destr_tmp, &Value::Int(1)); }
let mut feeCurrncyId: Value = self.safe_string_k(order.clone(), "feeCoin", &[]);
if is_equal(&feeCurrncyId, &Value::Str("".to_string())) {
feeCurrncyId = Value::Null;
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(order.clone(), "orderId", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "clientOrderId", &[]));
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(order.clone(), "updateTime", &[]));
m.insert("status".to_string(), self.parse_order_status(status.clone()));
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(), timeInForce.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("average".to_string(), average.clone());
m.insert("amount".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "origQty", &[])));
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "executedQty", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("triggerPrice".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "stopPrice", &[])));
m.insert("takeProfitPrice".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("cost".to_string(), self.omit_zero(self.safe_string2(order.clone(), Value::Str("cumulativeQuoteQty".to_string()), Value::Str("cummulativeQuoteQty".to_string()), &[])));
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(feeCurrncyId.clone(), &[]));
m.insert("amount".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "feeAmount", &[])));
m
}));
m.insert("reduceOnly".to_string(), reduceOnly.clone());
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_order_side_and_reduce_only(&self, mut unparsed: Value) -> Value {
let mut parts: Value = split(&unparsed, &Value::Str("_".to_string()));
let mut side: Value = get_value(&parts, &Value::Int(0));
let mut reduceOnly: Value = Value::Null;
let mut secondPart: Value = self.safe_string(parts.clone(), Value::Int(1), &[]);
if !is_equal(&secondPart, &Value::Null) {
if is_equal(&secondPart, &Value::Str("open".to_string())) {
reduceOnly = Value::Bool(false);
} else if is_true(&(is_equal(&secondPart, &Value::Str("close".to_string())))) {
reduceOnly = Value::Bool(true);
}
}
return Value::List(vec![side.clone(), reduceOnly.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("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.insert("FILLED".to_string(), Value::Str("closed".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("ORDER_CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("PENDING_CANCEL".to_string(), Value::Str("canceled".to_string()));
m.insert("REJECTED".to_string(), Value::Str("rejected".to_string()));
m.insert("ORDER_NEW".to_string(), Value::Str("open".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order_type_time_in_force_and_post_only(&self, mut type_var: Value, mut timeInForce: Value) -> Value {
let mut postOnly: Value = Value::Null;
if is_equal(&type_var, &Value::Str("LIMIT_MAKER".to_string())) {
postOnly = Value::Bool(true);
} else if is_true(&(is_equal(&timeInForce, &Value::Str("LIMIT_MAKER".to_string())))) || is_true(&(is_equal(&timeInForce, &Value::Str("MAKER".to_string())))) {
postOnly = Value::Bool(true);
timeInForce = Value::Str("PO".to_string());
}
type_var = self.parse_order_type(type_var.clone());
return Value::List(vec![type_var.clone(), timeInForce.clone(), postOnly.clone()]);
Value::Null
}
pub fn parse_order_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".to_string()));
m.insert("LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("LIMIT_MAKER".to_string(), Value::Str("limit".to_string()));
m.insert("MARKET_OF_BASE".to_string(), Value::Str("market".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchFundingRate
* @description fetch the current funding rate
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-futures-funding-rate
* @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("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("timestamp".to_string(), self.milliseconds());
m
});
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_api_v1_futures_funding_rate(&[__ws_arg_33]).await;
//
// [
// { "symbol": "ETHUSDT-PERPETUAL", "rate": "0.0001", "nextSettleTime": "1722297600000" }
// ]
//
let mut rate: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(rate.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#fetchFundingRates
* @description fetch the funding rate for multiple markets
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-futures-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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), self.milliseconds());
m
});
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_api_v1_futures_funding_rate(&[__ws_arg_34]).await;
return self.parse_funding_rates(response.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETHUSDT-PERPETUAL",
// "rate": "0.0001",
// "nextSettleTime": "1722297600000"
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut fundingRate: Value = self.safe_number_k(contract.clone(), "rate", &[]);
let mut fundingTimestamp: Value = self.safe_integer_k(contract.clone(), "nextSettleTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("markPrice".to_string(), 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(), fundingRate.clone());
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), fundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(fundingTimestamp.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(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name hashkey#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-futures-history-funding-rate
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.fromId] the id of the entry to start from
* @param {int} [params.endId] the id of the entry to end with
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
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 market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_api_v1_futures_history_funding_rate(&[__ws_arg_35]).await;
//
// [
// {
// "id": "10698",
// "symbol": "ETHUSDT-PERPETUAL",
// "settleTime": "1722268800000",
// "settleRate": "0.0001"
// },
// ...
// ]
//
let mut rates: Value = Value::List(vec![]);
let mut rows: Value = self.to_array(response.clone());
{
let mut i: Value = Value::Int(0);
let mut __for_first_724: bool = true;
while { if !__for_first_724 { i = add(&i, &Value::Int(1)); } __for_first_724 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut entry: Value = get_value(&rows, &i);
let mut entry: Value = get_value(&rows, &i);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "settleTime", &[]);
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(), self.safe_symbol(self.safe_string_k(entry.clone(), "symbol", &[]), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "settleRate", &[]));
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_since_limit(sorted.clone(), &[since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @description fetch open positions for a market
* @name hashkey#fetchPositions
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-futures-positions
* @description fetch all open positions
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.side] 'LONG' or 'SHORT' - the direction of the position (if not provided, positions for both sides will be returned)
* @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
}));
let mut methodName: Value = Value::Str("fetchPositions".to_string());
if is_true(&(is_equal(&symbols, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a symbol argument with one single market symbol".to_string()))));
} else {
let mut symbolsLength: Value = get_array_length(&symbols);
if !is_equal(&symbolsLength, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is supported for a symbol argument with one single market symbol only".to_string()))));
}
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let __ws_arg_36 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("methodName".to_string(), Value::Str("fetchPositions".to_string()));
m
}), &[params.clone()]);
return self.fetch_positions_for_symbol(get_value(&symbols, &Value::Int(0)), &[__ws_arg_36]).await;
Value::Null
}
/*
* @method
* @description fetch open positions for a single market
* @name hashkey#fetchPositionsForSymbol
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-futures-positions
* @description fetch all open positions for specific symbol
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.side] 'LONG' or 'SHORT' - the direction of the position (if not provided, positions for both sides will be returned)
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions_for_symbol(&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 methodName: Value = Value::Str("fetchPosition".to_string());
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("methodName".to_string()), &[methodName.clone()]); methodName = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() supports swap markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_futures_positions(&[__ws_arg_37]).await;
return self.parse_positions(response.clone(), &[Value::List(vec![symbol.clone()])]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("id".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "position", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_lower(position.clone(), Value::Str("side".to_string()), &[]));
m.insert("notional".to_string(), self.safe_number_k(position.clone(), "positionValue", &[]));
m.insert("leverage".to_string(), self.safe_integer_k(position.clone(), "leverage", &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealizedPnL", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "realizedPnL", &[]));
m.insert("collateral".to_string(), Value::Null);
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "avgPrice", &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liquidationPrice", &[]));
m.insert("marginMode".to_string(), Value::Str("cross".to_string()));
m.insert("hedged".to_string(), Value::Bool(true));
m.insert("maintenanceMargin".to_string(), self.safe_number_k(position.clone(), "minMargin", &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "margin", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "lastPrice", &[]));
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("info".to_string(), position.clone());
m
}));
Value::Null
}
/*
* @method
* @name hashkey#fetchLeverage
* @description fetch the set leverage for a market
* @see https://hashkeyglobal-apidoc.readme.io/reference/query-futures-leverage-trade
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage structure]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverage(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v1_futures_leverage(&[__ws_arg_38]).await;
//
// [
// {
// "symbolId": "ETHUSDT-PERPETUAL",
// "leverage": "5",
// "marginType": "CROSS"
// }
// ]
//
let mut leverage: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(leverage.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marginMode: Value = self.safe_string_lower(leverage.clone(), Value::Str("marginType".to_string()), &[]);
let mut leverageValue: Value = self.safe_number_k(leverage.clone(), "leverage", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue.clone());
m
});
Value::Null
}
/*
* @method
* @name hashkey#setLeverage
* @description set the level of leverage for a market
* @see https://hashkeyglobal-apidoc.readme.io/reference/change-futures-leverage-trade
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
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("leverage".to_string(), leverage.clone());
m
});
let mut market: Value = 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_39 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_futures_leverage(&[__ws_arg_39]).await;
return self.parse_leverage(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name hashkey#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://hashkeyglobal-apidoc.readme.io/reference/change-margin-type
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_margin_mode(&mut self, mut marginMode: 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(" setMarginMode() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
marginMode = to_upper(&marginMode);
if is_equal(&marginMode, &Value::Str("CROSSED".to_string())) {
marginMode = Value::Str("CROSS".to_string());
}
if is_true(&(!is_equal(&marginMode, &Value::Str("CROSS".to_string())))) && is_true(&(!is_equal(&marginMode, &Value::Str("ISOLATED".to_string())))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() marginMode must be either cross or isolated".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" setMarginMode() supports swap markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("marginType".to_string(), marginMode.clone());
m
});
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
return self.private_post_api_v1_futures_margin_type(&[__ws_arg_40]).await;
Value::Null
}
/*
* @method
* @name hashkey#addMargin
* @description add margin
* @see https://hashkeyglobal-apidoc.readme.io/reference/modify-isolated-position-margin
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.side position side, either 'long' or 'short'
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Str("add".to_string()), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name hashkey#reduceMargin
* @description remove margin from a position
* @see https://hashkeyglobal-apidoc.readme.io/reference/modify-isolated-position-margin
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.side position side, either 'long' or 'short'
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Str("reduce".to_string()), &[params.clone()]).await;
Value::Null
}
pub async fn modify_margin_helper(&mut self, mut symbol: Value, mut amount: Value, mut type_var: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" modifyMarginHelper() supports swap markets only".to_string()))));
}
let mut side: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("side".to_string()), &[]); side = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &type_var), &Value::Str("Margin() requires a params[\"side\"] argument, either \"long\" or \"short\"".to_string()))));
}
side = to_upper(&side);
if is_true(&(!is_equal(&side, &Value::Str("LONG".to_string())))) && is_true(&(!is_equal(&side, &Value::Str("SHORT".to_string())))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &type_var), &Value::Str("Margin() params[\"side\"] must be either long or short".to_string()))));
}
let mut amountString: Value = self.number_to_string(amount.clone());
if is_equal(&type_var, &Value::Str("reduce".to_string())) {
amountString = crate::precise::Precise::stringMul(&amountString, &Value::Str("-1".to_string()));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), side.clone());
m.insert("amount".to_string(), amountString.clone());
m
});
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_api_v1_futures_position_margin(&[__ws_arg_41]).await;
let __ws_arg_42 = self.parse_margin_modification(response.clone(), &[market.clone()]);
return self.extend(__ws_arg_42, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), amount.clone());
m
})]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(data.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "timestamp", &[]);
let mut errorCode: Value = self.safe_string_k(data.clone(), "code", &[]);
let mut success: Value = Value::Bool(is_equal(&errorCode, &Value::Str("0000".to_string())));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), self.safe_number_k(data.clone(), "margin", &[]));
m.insert("code".to_string(), get_value(&market, &Value::Str("settle".to_string())));
m.insert("status".to_string(), ternary(is_true(&(success)), Value::Str("ok".to_string()), Value::Str("failed".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name hashkey#fetchLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
* @see https://hashkeyglobal-apidoc.readme.io/reference/exchangeinfo
* @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.public_get_api_v1_exchange_info(&[params.clone()]).await;
// response is the same as in fetchMarkets()
let mut data: Value = self.safe_list_k(response.clone(), "contracts", &[Value::List(vec![])]);
symbols = self.market_symbols(&[symbols.clone()]);
return self.parse_leverage_tiers(data.clone(), &[symbols.clone(), Value::Str("symbol".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);
//
// {
// "filters": [
// {
// "minPrice": "0.1",
// "maxPrice": "100000.00000000",
// "tickSize": "0.1",
// "filterType": "PRICE_FILTER"
// },
// {
// "minQty": "0.001",
// "maxQty": "10",
// "stepSize": "0.001",
// "marketOrderMinQty": "0",
// "marketOrderMaxQty": "0",
// "filterType": "LOT_SIZE"
// },
// {
// "minNotional": "0",
// "filterType": "MIN_NOTIONAL"
// },
// {
// "maxSellPrice": "999999",
// "buyPriceUpRate": "0.05",
// "sellPriceDownRate": "0.05",
// "maxEntrustNum": 200,
// "maxConditionNum": 200,
// "filterType": "LIMIT_TRADING"
// },
// {
// "buyPriceUpRate": "0.05",
// "sellPriceDownRate": "0.05",
// "filterType": "MARKET_TRADING"
// },
// {
// "noAllowMarketStartTime": "0",
// "noAllowMarketEndTime": "0",
// "limitOrderStartTime": "0",
// "limitOrderEndTime": "0",
// "limitMinPrice": "0",
// "limitMaxPrice": "0",
// "filterType": "OPEN_QUOTE"
// }
// ],
// "exchangeId": "301",
// "symbol": "BTCUSDT-PERPETUAL",
// "symbolName": "BTCUSDT-PERPETUAL",
// "status": "TRADING",
// "baseAsset": "BTCUSDT-PERPETUAL",
// "baseAssetPrecision": "0.001",
// "quoteAsset": "USDT",
// "quoteAssetPrecision": "0.1",
// "icebergAllowed": false,
// "inverse": false,
// "index": "USDT",
// "marginToken": "USDT",
// "marginPrecision": "0.0001",
// "contractMultiplier": "0.001",
// "underlying": "BTC",
// "riskLimits": [
// {
// "riskLimitId": "200000722",
// "quantity": "1000.00",
// "initialMargin": "0.10",
// "maintMargin": "0.005",
// "isWhite": false
// },
// {
// "riskLimitId": "200000723",
// "quantity": "2000.00",
// "initialMargin": "0.10",
// "maintMargin": "0.01",
// "isWhite": false
// }
// ]
// }
//
let mut riskLimits: Value = self.safe_list_k(info.clone(), "riskLimits", &[Value::List(vec![])]);
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut tiers: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_725: bool = true;
while { if !__for_first_725 { i = add(&i, &Value::Int(1)); } __for_first_725 = false; is_less_than(&i, &get_array_length(&riskLimits)) } {
let mut tier: Value = get_value(&riskLimits, &i);
let mut tier: Value = get_value(&riskLimits, &i);
let mut initialMarginRate: Value = self.safe_string_k(tier.clone(), "initialMargin", &[]);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.sum(&[i.clone(), Value::Int(1)]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("currency".to_string(), get_value(&market, &Value::Str("settle".to_string())));
m.insert("minNotional".to_string(), Value::Null);
m.insert("maxNotional".to_string(), self.safe_number_k(tier.clone(), "quantity", &[]));
m.insert("maintenanceMarginRate".to_string(), self.safe_number_k(tier.clone(), "maintMargin", &[]));
m.insert("maxLeverage".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&Value::Str("1".to_string()), &initialMarginRate), &[]));
m.insert("info".to_string(), tier.clone());
m
}));
}
}
return tiers;
Value::Null
}
/*
* @method
* @name hashkey#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-vip-information // spot
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-futures-commission-rate-request-weight // swap
* @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 methodName: Value = Value::Str("fetchTradingFee".to_string());
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
response = self.fetch_trading_fees(&[params.clone()]).await;
return self.safe_dict(response.clone(), symbol.clone(), &[]);
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
let __ws_arg_43 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
}), &[params.clone()]);
response = self.private_get_api_v1_futures_commission_rate(&[__ws_arg_43]).await;
return self.parse_trading_fee(response.clone(), &[market.clone()]);
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() is not supported for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" type of markets".to_string()))));
}
Value::Null
}
/*
* @method
* @name hashkey#fetchTradingFees
* @description *for spot markets only* fetch the trading fees for multiple markets
* @see https://hashkeyglobal-apidoc.readme.io/reference/get-vip-information
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_api_v1_account_vip_info(&[params.clone()]).await;
//
// {
// "code": 0,
// "vipLevel": "0",
// "tradeVol30Day": "67",
// "totalAssetBal": "0",
// "data": [
// {
// "symbol": "UXLINKUSDT",
// "productType": "Token-Token",
// "buyMakerFeeCurrency": "UXLINK",
// "buyTakerFeeCurrency": "UXLINK",
// "sellMakerFeeCurrency": "USDT",
// "sellTakerFeeCurrency": "USDT",
// "actualMakerRate": "0.0012",
// "actualTakerRate": "0.0012"
// },
// ...
// ],
// "updateTimestamp": "1722320137809"
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_726: bool = true;
while { if !__for_first_726 { i = add(&i, &Value::Int(1)); } __for_first_726 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut fee: Value = self.safe_dict(data.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut parsedFee: Value = self.parse_trading_fee(fee.clone(), &[]);
add_element_to_object(&mut result, &get_value(&parsedFee, &Value::Str("symbol".to_string())), parsedFee.clone());
}
}
return result;
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);
//
// spot
// {
// "symbol": "UXLINKUSDT",
// "productType": "Token-Token",
// "buyMakerFeeCurrency": "UXLINK",
// "buyTakerFeeCurrency": "UXLINK",
// "sellMakerFeeCurrency": "USDT",
// "sellTakerFeeCurrency": "USDT",
// "actualMakerRate": "0.0012",
// "actualTakerRate": "0.0012"
// }
//
// swap
// {
// "openMakerFee": "0.00025",
// "openTakerFee": "0.0006",
// "closeMakerFee": "0.00025",
// "closeTakerFee": "0.0006"
// }
//
let mut marketId: Value = self.safe_string_k(fee.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("maker".to_string(), self.safe_number2(fee.clone(), Value::Str("openMakerFee".to_string()), Value::Str("actualMakerRate".to_string()), &[]));
m.insert("taker".to_string(), self.safe_number2(fee.clone(), Value::Str("openTakerFee".to_string()), Value::Str("actualTakerRate".to_string()), &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &path);
let mut query: Value = Value::Null;
if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut timestamp: Value = self.milliseconds();
let mut additionalParams: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m
});
let mut recvWindow: Value = self.safe_integer_k(self.options.clone(), "recvWindow", &[]);
if !is_equal(&recvWindow, &Value::Null) {
add_element_to_object(&mut additionalParams, &Value::Str("recvWindow".to_string()), recvWindow.clone());
}
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-HK-APIKEY".to_string(), self.apiKey.clone());
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".to_string()));
m
});
let mut signature: Value = Value::Null;
if is_true(&(is_equal(&method, &Value::Str("POST".to_string())))) && is_true(&(is_true(&(is_equal(&path, &Value::Str("api/v1/spot/batchOrders".to_string())))) || is_true(&(is_equal(&path, &Value::Str("api/v1/futures/batchOrders".to_string())))))) {
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
body = self.json(self.safe_list_k(params.clone(), "orders", &[]));
signature = self.hmac(self.encode(self.custom_urlencode(&[additionalParams.clone()])), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[]);
let __ws_arg_44 = self.extend(additionalParams.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("signature".to_string(), signature.clone());
m
})]);
query = self.custom_urlencode(&[__ws_arg_44]);
url = add(&url, &add(&Value::Str("?".to_string()), &query));
} else {
let mut totalParams: Value = self.extend(additionalParams.clone(), &[params.clone()]);
signature = self.hmac(self.encode(self.custom_urlencode(&[totalParams.clone()])), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[]);
add_element_to_object(&mut totalParams, &Value::Str("signature".to_string()), signature.clone());
query = self.custom_urlencode(&[totalParams.clone()]);
if is_equal(&method, &Value::Str("GET".to_string())) {
url = add(&url, &add(&Value::Str("?".to_string()), &query));
} else {
body = query.clone();
}
}
add_element_to_object(&mut headers, &Value::Str("INPUT-SOURCE".to_string()), self.safe_string_k(self.options.clone(), "broker", &[Value::Str("10000700011".to_string())]));
add_element_to_object(&mut headers, &Value::Str("broker_sign".to_string()), signature.clone());
} else {
query = self.urlencode(params.clone(), &[]);
if !is_equal(&get_array_length(&query), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &query));
}
}
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 custom_urlencode(&self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut result: Value = self.urlencode(params.clone(), &[]);
result = replace_str(&result, &Value::Str("%2C".to_string()), &Value::Str(",".to_string()));
return result;
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
let mut errorInArray: bool = false;
let mut responseCodeString: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut responseCodeInteger: Value = self.safe_integer_k(response.clone(), "code", &[]); // some codes in response are returned as '0000' others as 0
if is_equal(&responseCodeInteger, &Value::Int(0)) {
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]); // for batch methods
{
let mut i: Value = Value::Int(0);
let mut __for_first_727: bool = true;
while { if !__for_first_727 { i = add(&i, &Value::Int(1)); } __for_first_727 = false; is_less_than(&i, &get_array_length(&result)) } {
let mut entry: Value = self.safe_dict(result.clone(), i.clone(), &[]);
let mut entryCodeInteger: Value = self.safe_integer_k(entry.clone(), "code", &[]);
if !is_equal(&entryCodeInteger, &Value::Int(0)) {
errorInArray = true;
responseCodeString = self.safe_string_k(entry.clone(), "code", &[]);
}
}
}
}
if is_true(&(!is_equal(&code, &Value::Int(200)))) || is_true(&errorInArray) {
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())), responseCodeString.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), responseCodeString.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}