// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct 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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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])
}
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, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on 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[2.min(args.len())..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_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[4.min(args.len())..]).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[4.min(args.len())..]),
"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[4.min(args.len())..]).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[4.min(args.len())..]),
"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[..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_canceled_and_closed_orders" => self.fetch_canceled_and_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args[..]).await,
"fetch_last_prices" => self.fetch_last_prices(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_open_spot_orders" => self.fetch_open_spot_orders(&args[..]).await,
"fetch_open_swap_orders" => self.fetch_open_swap_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_positions_for_symbol" => self.fetch_positions_for_symbol(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_status" => self.fetch_status(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).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[2.min(args.len())..]),
"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[3.min(args.len())..]).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[1.min(args.len())..]),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_last_price" => self.parse_last_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"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[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_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_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[1.min(args.len())..]),
"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[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for 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".into()));
m.insert("name".to_string(), Value::Str("HashKey Global".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("BM".into())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v1".into()));
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".into()));
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".into()));
m.insert("3m".to_string(), Value::Str("3m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15m".to_string(), Value::Str("15m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("2h".to_string(), Value::Str("2h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("8h".to_string(), Value::Str("8h".into()));
m.insert("12h".to_string(), Value::Str("12h".into()));
m.insert("1d".to_string(), Value::Str("1d".into()));
m.insert("1w".to_string(), Value::Str("1w".into()));
m.insert("1M".to_string(), Value::Str("1M".into()));
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".into()));
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".into()));
m.insert("private".to_string(), Value::Str("https://api-glb.hashkey.com".into()));
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".into()));
m.insert("private".to_string(), Value::Str("https://api-glb.sim.hashkeydev.com".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://global.hashkey.com/".into()));
m.insert("doc".to_string(), Value::Str("https://hashkeyglobal-apidoc.readme.io/".into()));
m.insert("fees".to_string(), Value::Str("https://support.global.hashkey.com/hc/en-us/articles/13199900083612-HashKey-Global-Fee-Structure".into()));
m.insert("referral".to_string(), Value::Str("https://global.hashkey.com/en-US/register/invite?invite_code=82FQUN".into()));
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.insert("api/v1/affiliate/inviteeInfo".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/spot/cancelAllOpenOrders".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/futures/cancelAllOpenOrders".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".into()));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0012".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0012".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.0012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.00080".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.00070".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.00060".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000000".into()), &[]), self.parse_number(Value::Str("0.00040".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200000000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("400000000".into()), &[]), self.parse_number(Value::Str("0.00010".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("800000000".into()), &[]), self.parse_number(Value::Str("0.00".into()), &[])])]));
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.0012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.00090".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.00085".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.00075".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000000".into()), &[]), self.parse_number(Value::Str("0.00065".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200000000".into()), &[]), self.parse_number(Value::Str("0.00045".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("400000000".into()), &[]), self.parse_number(Value::Str("0.00040".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("800000000".into()), &[]), self.parse_number(Value::Str("0.00035".into()), &[])])]));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("feeSide".to_string(), Value::Str("get".into()));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.00025".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.00060".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.00025".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.00016".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.00014".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.00012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000000".into()), &[]), self.parse_number(Value::Str("0.000080".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200000000".into()), &[]), self.parse_number(Value::Str("0.000060".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("400000000".into()), &[]), self.parse_number(Value::Str("0.000020".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("800000000".into()), &[]), self.parse_number(Value::Str("0.00".into()), &[])])]));
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.00060".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.00050".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.00045".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.00040".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("50000000".into()), &[]), self.parse_number(Value::Str("0.00035".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("200000000".into()), &[]), self.parse_number(Value::Str("0.00030".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("400000000".into()), &[]), self.parse_number(Value::Str("0.00025".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("800000000".into()), &[]), self.parse_number(Value::Str("0.00020".into()), &[])])]));
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".into()));
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".into()));
m.insert("ERC20".to_string(), Value::Str("ETH".into()));
m.insert("AVAX".to_string(), Value::Str("AvalancheC".into()));
m.insert("SOL".to_string(), Value::Str("Solana".into()));
m.insert("MATIC".to_string(), Value::Str("Polygon".into()));
m.insert("ATOM".to_string(), Value::Str("Cosmos".into()));
m.insert("DOT".to_string(), Value::Str("Polkadot".into()));
m.insert("LTC".to_string(), Value::Str("LTC".into()));
m.insert("OPTIMISM".to_string(), Value::Str("Optimism".into()));
m.insert("ARBITRUM".to_string(), Value::Str("Arbitrum".into()));
m.insert("DOGE".to_string(), Value::Str("Dogecoin".into()));
m.insert("TRC20".to_string(), Value::Str("Tron".into()));
m.insert("ZKSYNC".to_string(), Value::Str("zkSync".into()));
m.insert("TON".to_string(), Value::Str("TON".into()));
m.insert("KLAYTN".to_string(), Value::Str("Klaytn".into()));
m.insert("MERLINCHAIN".to_string(), Value::Str("Merlin Chain".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".into()));
m.insert("Bitcoin".to_string(), Value::Str("BTC".into()));
m.insert("ETH".to_string(), Value::Str("ERC20".into()));
m.insert("ERC20".to_string(), Value::Str("ERC20".into()));
m.insert("AvalancheC".to_string(), Value::Str("AVAX".into()));
m.insert("AVAX C-Chain".to_string(), Value::Str("AVAX".into()));
m.insert("Solana".to_string(), Value::Str("SOL".into()));
m.insert("Cosmos".to_string(), Value::Str("ATOM".into()));
m.insert("Arbitrum".to_string(), Value::Str("ARBITRUM".into()));
m.insert("Polygon".to_string(), Value::Str("MATIC".into()));
m.insert("Optimism".to_string(), Value::Str("OPTIMISM".into()));
m.insert("Polkadot".to_string(), Value::Str("DOT".into()));
m.insert("LTC".to_string(), Value::Str("LTC".into()));
m.insert("Litecoin".to_string(), Value::Str("LTC".into()));
m.insert("Dogecoin".to_string(), Value::Str("DOGE".into()));
m.insert("Merlin Chain".to_string(), Value::Str("MERLINCHAIN".into()));
m.insert("zkSync".to_string(), Value::Str("ZKSYNC".into()));
m.insert("TRC20".to_string(), Value::Str("TRC20".into()));
m.insert("Tron".to_string(), Value::Str("TRC20".into()));
m.insert("TON".to_string(), Value::Str("TON".into()));
m.insert("BSC(BEP20)".to_string(), Value::Str("BSC".into()));
m.insert("Klaytn".to_string(), Value::Str("KLAYTN".into()));
m
}));
m.insert("defaultNetwork".to_string(), Value::Str("ERC20".into()));
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".into()));
m
}));
m.insert("forDerivatives".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
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".into()));
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".into()).clone());
m.insert("0002".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("0003".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("0102".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("0103".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("0104".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("0201".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("0202".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("0206".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("0207".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("0209".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("0210".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("0211".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("0401".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("0402".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1000".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-1001".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-100010".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("-100012".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("-1002".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("-1004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1005".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1006".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-1007".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("-1014".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1015".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1020".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1021".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("-1024".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1101".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("-1115".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1117".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1123".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1124".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1126".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1129".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1130".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1132".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1133".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1135".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1136".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1138".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1137".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1139".to_string(), Value::Str("OrderImmediatelyFillable".into()).clone());
m.insert("-1140".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1141".to_string(), Value::Str("DuplicateOrderId".into()).clone());
m.insert("-1142".to_string(), Value::Str("OrderNotFillable".into()).clone());
m.insert("-1143".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("-1144".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1145".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-1146".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("-1147".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("-1148".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1149".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1150".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1151".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1152".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-1153".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1154".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1155".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1156".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1157".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1158".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1159".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-1160".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-1161".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1162".to_string(), Value::Str("ContractUnavailable".into()).clone());
m.insert("-1163".to_string(), Value::Str("InvalidAddress".into()).clone());
m.insert("-1164".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-1165".to_string(), Value::Str("ArgumentsRequired".into()).clone());
m.insert("-1166".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1167".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1168".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1169".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1170".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1171".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1172".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1173".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1174".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-1175".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1176".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1177".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("-1178".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-1179".to_string(), Value::Str("AccountSuspended".into()).clone());
m.insert("-1181".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-1193".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1194".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-1195".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1196".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1200".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1201".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1202".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1203".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1204".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1205".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-1206".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1207".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1208".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-1209".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2001".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("-2002".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-2003".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-2004".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-2005".to_string(), Value::Str("RequestTimeout".into()).clone());
m.insert("-2010".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2011".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2016".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2017".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2018".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2019".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-2020".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-2021".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-2022".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2023".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("-2024".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-2025".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-2026".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2027".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2028".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2029".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2030".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-2031".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-2032".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2033".to_string(), Value::Str("OperationFailed".into()).clone());
m.insert("-2034".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-2035".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2036".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-2037".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-2038".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-2039".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-2040".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m.insert("-2041".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2042".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2043".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2044".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2045".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2046".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2048".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2049".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2050".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2051".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2052".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2053".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("-2054".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2055".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2056".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-2057".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-3117".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-3143".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-3144".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-3145".to_string(), Value::Str("DDoSProtection".into()).clone());
m.insert("-4001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-4002".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-4003".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("-4004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-4005".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("-4006".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-4007".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("-4008".to_string(), Value::Str("AccountNotEnabled".into()).clone());
m.insert("-4009".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-4010".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("-4011".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-4012".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("-4013".to_string(), Value::Str("OperationFailed".into()).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]).await;
return self.safe_integer_k(response, "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]).await;
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("ok".into()));
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);
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, &[params]);
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::from(vec![])]);
let mut swapMarkets: Value = self.safe_list_k(response.clone(), "contracts", &[Value::from(vec![])]);
let mut markets: Value = self.array_concat(spotMarkets, swapMarkets);
if self.is_empty(markets.clone()).as_bool() == Some(true) {
markets = Value::from(vec![response]); // if user provides params.symbol the exchange returns a single object instead of list of objects
}
return self.parse_markets(markets);
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".into());
let mut isSpot: Value = Value::Bool(true);
let mut isSwap: Value = Value::Bool(false);
let mut suffix: Value = Value::Str("".into());
let mut parts: Value = split(&marketId, &Value::Str("-".into()));
let mut secondPart: Option<String> = self.safe_string(parts, Value::Int(1), &[]).as_str().map(str::to_owned);
if (secondPart.as_deref() == Some("PERPETUAL")) {
marketType = Value::Str("swap".into());
isSpot = Value::Bool(false);
isSwap = Value::Bool(true);
baseId = self.safe_string_k(market.clone(), "underlying", &[]);
suffix = Value::Str(format!("{}{}", suffix, Value::Str(format!("{}{}", Value::Str(":".into()), settleId).into())).into());
}
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()), suffix).into());
let mut status: Option<String> = self.safe_string_k(market.clone(), "status", &[]).as_str().map(str::to_owned);
let mut active: Value = Value::Bool(status.as_deref() == Some("TRADING"));
let mut isLinear: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut isInverse: Value = self.safe_bool_k(market.clone(), "inverse", &[]);
if (isInverse != Value::Null) {
if isInverse.as_bool() == Some(true) {
isLinear = Value::Bool(false);
subType = Value::Str("inverse".into());
} else {
isLinear = Value::Bool(true);
subType = Value::Str("linear".into());
}
}
let mut filtersList: Value = self.safe_list_k(market.clone(), "filters", &[Value::from(vec![])]);
let mut filters: Value = self.index_by(filtersList, Value::Str("filterType".into()));
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, "MIN_NOTIONAL", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut minCostString: Value = self.omit_zero(self.safe_string_k(costFilter, "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, "maxQty", &[]);
let mut minLeverage: Value = Value::Null;
let mut maxLeverage: Value = Value::Null;
if isSwap.as_bool() == Some(true) {
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 (riskLimits != Value::Null) {
let mut first: Value = self.safe_dict(riskLimits.clone(), Value::Int(0), &[]);
let mut arrayLength: Value = Value::Int(riskLimits.len() as i64);
let mut last: Value = self.safe_dict(riskLimits, (match (&(arrayLength), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null }), &[]);
let mut minInitialMargin: Value = self.safe_string_k(first, "initialMargin", &[]);
let mut maxInitialMargin: Value = self.safe_string_k(last, "initialMargin", &[]);
if is_true(&crate::precise::Precise::stringGt(&minInitialMargin, &maxInitialMargin)) {
{ let __destr_tmp = Value::from(vec![maxInitialMargin.clone(), minInitialMargin.clone()]); minInitialMargin = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); maxInitialMargin = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
}
minLeverage = self.parse_to_int(crate::precise::Precise::stringDiv(&Value::Str("1".into()), &maxInitialMargin));
maxLeverage = self.parse_to_int(crate::precise::Precise::stringDiv(&Value::Str("1".into()), &minInitialMargin));
}
}
let mut tradingFees: Value = self.safe_dict_k(self.fees.clone(), "trading", &[]);
let mut fees: Value = Value::Null;
if isSpot.as_bool() == Some(true) {
fees = self.safe_dict_k(tradingFees.clone(), "spot", &[]);
} else {
fees = self.safe_dict_k(tradingFees, "swap", &[]);
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId);
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("active".to_string(), active);
m.insert("type".to_string(), marketType);
m.insert("subType".to_string(), subType);
m.insert("spot".to_string(), isSpot);
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);
m.insert("settle".to_string(), settle);
m.insert("settleId".to_string(), settleId);
m.insert("contractSize".to_string(), self.parse_number(contractSizeString, &[]));
m.insert("linear".to_string(), isLinear);
m.insert("inverse".to_string(), isInverse);
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, "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, &[]));
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, &[]));
m.insert("max".to_string(), self.parse_number(amountMaxLimitString, &[]));
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, "maxPrice", &[]));
m
}));
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minLeverage);
m.insert("max".to_string(), maxLeverage);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minCostString, &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
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]).await;
let mut coins: Value = self.safe_list_k(response, "coins", &[]);
return self.parse_currencies(coins);
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_704: bool = true;
while { if !__for_first_704 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_704 = false; j.as_f64().unwrap_or(f64::NAN) < ((networks.len() as i64) as f64) } {
let mut network: Value = networks.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.safe_string_k(network.clone(), "chainType", &[]);
let mut networkCode: Value = self.network_code_to_id(networkId.clone(), &[code.clone()]);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut parsedNetworks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId);
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);
m
})); }
}
}
}
let mut rawType: Option<String> = self.safe_string_k(rawCurrency.clone(), "tokenType", &[]).as_str().map(str::to_owned);
let mut type_var: Value = Value::Str("crypto".into());
if (rawType.as_deref() == Some("REAL_MONEY")) {
type_var = Value::Str("fiat".into());
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId);
m.insert("code".to_string(), code);
m.insert("precision".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
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);
m.insert("info".to_string(), rawCurrency);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit); }
}
let __ws_arg_1 = self.extend(request, &[params]);
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, symbol, &[timestamp, Value::Str("b".into()), Value::Str("a".into())]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_2 = self.extend(request, &[params]);
let mut response: Value = self.public_get_quote_v1_trades(&[__ws_arg_2]).await;
return self.parse_trades(response, &[market, since, limit]);
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".into());
if (self.markets.clone() == 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 (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut untilparamsUntilVariable = self.handle_option_and_params(paramsMarketType, methodName.clone(), Value::Str("until".into()), &[]);
let mut until: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("endTime".into(), until); }
}
let mut accountIdparamsAccountIdVariable = self.handle_option_string_and_params(paramsUntil, methodName.clone(), Value::Str("accountId".into()), &[]);
let mut accountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsAccountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
if (market != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (accountId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("accountId".into(), accountId.clone()); }
}
let __ws_arg_3 = self.extend(request.clone(), &[paramsAccountId.clone()]);
response = self.private_get_api_v1_account_trades(&[__ws_arg_3]).await;
} else if (marketType.as_str() == Some("swap")) {
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a symbol argument for swap markets".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[])); }
if (accountId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("subAccountId".into(), accountId); }
let __ws_arg_4 = self.extend(request.clone(), &[paramsAccountId.clone()]);
response = self.private_get_api_v1_futures_sub_account_user_trades(&[__ws_arg_4]).await;
} else {
let __ws_arg_5 = self.extend(request, &[paramsAccountId]);
response = self.private_get_api_v1_futures_user_trades(&[__ws_arg_5]).await;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), marketType).into()), Value::Str(" type of markets".into()))));
}
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// 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".into()), Value::Str("time".into()), &[]);
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut side: Value = self.safe_string_lower_k(trade.clone(), "side", &[]); // swap trades have side param
if (side != Value::Null) {
side = self.safe_string(split(&side, &Value::Str("_".into())), Value::Int(0), &[]);
}
let mut isBuyer: Value = self.safe_bool_k(trade.clone(), "isBuyer", &[]);
if (isBuyer != Value::Null) {
side = (if isBuyer.as_bool() == Some(true) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
}
let mut takerOrMaker: Value = Value::Null;
let mut isMaker: Value = self.safe_bool2(trade.clone(), Value::Str("isMaker".into()), Value::Str("isMarker".into()), &[]);
if (isMaker != Value::Null) {
takerOrMaker = (if isMaker.as_bool() == Some(true) { Value::Str("maker".into()) } else { Value::Str("taker".into()) });
}
let mut isBuyerMaker: Value = self.safe_bool_k(trade.clone(), "ibm", &[]);
// if public trade
if (isBuyerMaker != Value::Null) {
takerOrMaker = Value::Str("taker".into());
side = (if isBuyerMaker.as_bool() == Some(true) { Value::Str("sell".into()) } else { Value::Str("buy".into()) });
}
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 (feeInfo != Value::Null) {
feeCost = self.safe_string_k(feeInfo.clone(), "fee", &[]);
feeCurrncyId = self.safe_string_k(feeInfo, "feeCoinId", &[]);
}
if (feeCost != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeCost, &[]));
m.insert("currency".to_string(), self.safe_currency_code(feeCurrncyId, &[]));
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".into()), Value::Str("tradeId".into()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), side);
m.insert("price".to_string(), self.safe_string2(trade.clone(), Value::Str("p".into()), Value::Str("price".into()), &[]));
m.insert("amount".to_string(), self.safe_string_n(trade.clone(), Value::from(vec![Value::Str("q".into()), Value::Str("qty".into()), Value::Str("quantity".into())]), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker);
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);
m.insert("info".to_string(), trade);
m
}), &[marketResolved]);
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".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut methodName: Value = Value::Str("fetchOHLCV".into());
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, methodName.clone(), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), Value::Int(1000)]).await;
}
let mut market: Value = self.market(symbol);
let mut timeframeValue: Value = 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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("interval".to_string(), timeframeValue.clone());
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut untilparamsUntilVariable = self.handle_option_and_params(paramsPaginate, methodName, Value::Str("until".into()), &[]);
let mut until: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("endTime".into(), until); }
}
let __ws_arg_6 = self.extend(request, &[paramsUntil]);
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);
return self.parse_ohlc_vs(ohlcvs, &[market, timeframeValue, since, limit]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(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, 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_7 = self.extend(request, &[params]);
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, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(ticker, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.public_get_quote_v1_ticker24hr(&[params]).await;
return self.parse_tickers(response, &[symbolsNormalized]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut symbol: Value = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut last: Value = self.safe_string_k(ticker.clone(), "c", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "v", &[]);
if (marketResolved.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) && (marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null) != Value::Null) {
// 'v' counts contracts, and a ticker reports base volume
baseVolume = crate::precise::Precise::stringMul(&baseVolume, &self.number_to_string(marketResolved.as_map().and_then(|__m| __m.get("contractSize")).cloned().unwrap_or(Value::Null)));
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), 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);
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);
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "qv", &[]));
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_8 = self.extend(request, &[params]);
let mut response: Value = self.public_get_quote_v1_ticker_price(&[__ws_arg_8]).await;
return self.parse_last_prices(response, &[symbolsNormalized]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
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".into()), &[]));
m.insert("side".to_string(), Value::Null);
m.insert("info".to_string(), entry);
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 (self.markets.clone() == 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".into());
let mut marketType: Value = Value::Str("spot".into());
let mut marketTypeOptionparamsMarketTypeVariable = self.handle_market_type_and_params(methodName.clone(), &[Value::Null, params, marketType]);
let mut marketTypeOption: Value = marketTypeOptionparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeOptionparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (marketTypeOption.as_str() == Some("swap")) {
let mut response: Value = self.private_get_api_v1_futures_balance(&[paramsMarketType.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);
} else if (marketTypeOption.as_str() == Some("spot")) {
let __ws_arg_9 = self.extend(request, &[paramsMarketType]);
let mut response: Value = self.private_get_api_v1_account(&[__ws_arg_9]).await;
return self.parse_balance(response);
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), marketTypeOption).into()), Value::Str(" type of markets".into()))));
}
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, "balances", &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_705: bool = true;
while { if !__for_first_705 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_705 = false; i.as_f64().unwrap_or(f64::NAN) < ((balances.len() as i64) as f64) } {
let mut balanceEntry: Value = self.safe_dict(balances.clone(), i.clone(), &[]);
let mut currencyId: Value = self.safe_string_k(balanceEntry.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string_k(balanceEntry.clone(), "total", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(balanceEntry.clone(), "free", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(balanceEntry, "locked", &[])); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
return self.safe_balance(result);
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, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), 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", &[]);
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), crate::precise::Precise::stringAdd(&positionMargin, &orderMargin)); }
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), balance);
m
});
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
return self.safe_balance(result);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut networkCodeInParamsparamsNetworkCodeVariable = self.handle_network_code_and_params(params);
let mut networkCodeInParams: Value = networkCodeInParamsparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeInParamsparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut networkCode: Value = (if (networkCodeInParams == Value::Null) { self.default_network_code(code.clone()) } else { networkCodeInParams });
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("chainType".into(), self.network_code_to_id(networkCode.clone(), &[code])); }
let __ws_arg_10 = self.extend(request, &[paramsNetworkCode]);
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, &[currency]);
add_element_to_object(&mut depositAddress, &Value::Str("network".into()), networkCode);
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);
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
//
// {
// "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 (tag.as_str() == Some("")) {
tag = Value::Null;
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress);
m.insert("currency".to_string(), (match currency.get("code") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null }));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address);
m.insert("tag".to_string(), tag);
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".into());
if (self.markets.clone() == 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 (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("coin".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut untilparamsUntilVariable = self.handle_option_and_params(params, methodName, Value::Str("until".into()), &[]);
let mut until: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("endTime".into(), until); }
}
let __ws_arg_11 = self.extend(request, &[paramsUntil]);
let mut response: Value = self.private_get_api_v1_account_deposit_orders(&[__ws_arg_11]).await;
return self.parse_transactions(response, &[currency, since, limit, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("deposit".into()));
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".into());
if (self.markets.clone() == 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 (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("coin".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut untilparamsUntilVariable = self.handle_option_and_params(params, methodName, Value::Str("until".into()), &[]);
let mut until: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("endTime".into(), until); }
}
let __ws_arg_12 = self.extend(request, &[paramsUntil]);
let mut response: Value = self.private_get_api_v1_account_withdraw_orders(&[__ws_arg_12]).await;
return self.parse_transactions(response, &[currency, since, limit, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("withdrawal".into()));
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 {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tag] memo / destination tag, required for currencies in options['withdrawTagRequiredCurrencies']
* @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 params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut tagWithdrawTagparamsWithdrawTagVariable = self.handle_param_string(params, Value::Str("tag".into()), &[]);
let mut tagWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone(), code.clone(), tagWithdrawTag.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("address".to_string(), address);
m.insert("quantity".to_string(), amount);
m
});
if (tagWithdrawTag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("addressExt".into(), tagWithdrawTag); }
}
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(paramsWithdrawTag);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("chainType".into(), self.network_code_to_id(networkCode, &[self.safe_string_k(currency.clone(), "code", &[])])); }
}
let __ws_arg_13 = self.extend(request, &[paramsNetworkCode]);
let mut response: Value = self.private_post_api_v1_account_withdraw(&[__ws_arg_13]).await;
return self.parse_transaction(response, &[currency]);
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".into()), Value::Str("orderId".into()), &[]);
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 (status == Value::Null) {
let mut success: Value = self.safe_bool_k(transaction.clone(), "success", &[Value::Bool(false)]); // for withdraw
if (success.as_bool() == Some(true)) {
status = Value::Str("ok".into());
} else {
let mut addressUrl: Option<String> = self.safe_string_k(transaction.clone(), "addressUrl", &[]).as_str().map(str::to_owned); // for fetchWithdrawals
if (addressUrl.is_some()) {
status = Value::Str("ok".into());
}
}
}
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, &[currency]);
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 (feeCost != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost);
m.insert("currency".to_string(), code.clone());
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction);
m.insert("id".to_string(), id);
m.insert("txid".to_string(), txid);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address);
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), 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);
m.insert("currency".to_string(), code);
m.insert("status".to_string(), self.parse_transaction_status(status));
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);
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".into()));
m.insert("2".to_string(), Value::Str("pending".into()));
m.insert("3".to_string(), Value::Str("failed".into()));
m.insert("4".to_string(), Value::Str("ok".into()));
m.insert("5".to_string(), Value::Str("pending".into()));
m.insert("6".to_string(), Value::Str("ok".into()));
m.insert("7".to_string(), Value::Str("failed".into()));
m.insert("8".to_string(), Value::Str("cancelled".into()));
m.insert("9".to_string(), Value::Str("failed".into()));
m.insert("10".to_string(), Value::Str("failed".into()));
m.insert("successful".to_string(), Value::Str("ok".into()));
m.insert("success".to_string(), Value::Str("ok".into()));
m
});
return self.safe_string(statuses, 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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.currency_to_precision(code, amount, &[]));
m.insert("fromAccountId".to_string(), fromAccount);
m.insert("toAccountId".to_string(), toAccount);
m
});
let __ws_arg_14 = self.extend(request, &[params]);
let mut response: Value = self.private_post_api_v1_account_asset_transfer(&[__ws_arg_14]).await;
return self.parse_transfer(response, &[currency]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
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 (success.as_bool() == Some(true)) {
status = Value::Str("ok".into());
}
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));
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), status);
m.insert("info".to_string(), transfer);
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 (self.markets.clone() == 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, &[params]);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
let mut accountLabel: Option<String> = self.safe_string_k(account.clone(), "accountLabel", &[]).as_str().map(str::to_owned);
let mut label: Value = Value::Str("".into());
if (accountLabel.as_deref() == Some("Main Trading Account")) || (accountLabel.as_deref() == Some("Main Future Account")) {
label = Value::Str("main".into());
} else if (accountLabel.as_deref() == Some("Sub Main Trading Account")) || (accountLabel.as_deref() == Some("Sub Main Future Account")) {
label = Value::Str("sub".into());
}
let mut accountType: Value = self.parse_account_type(self.safe_string_k(account.clone(), "accountType", &[]));
let mut type_var: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", label, Value::Str(" ".into())).into()), accountType).into());
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);
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), account);
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".into()));
m.insert("3".to_string(), Value::Str("swap account".into()));
m.insert("5".to_string(), Value::Str("custody account".into()));
m.insert("6".to_string(), Value::Str("fiat account".into()));
m
});
return self.safe_string(types, 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".into()));
m.insert("swap".to_string(), Value::Str("3".into()));
m.insert("custody".to_string(), Value::Str("5".into()));
m
});
return self.safe_integer(types, 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".into()));
m.insert("fee".to_string(), Value::Str("3".into()));
m.insert("transfer".to_string(), Value::Str("51".into()));
m.insert("deposit".to_string(), Value::Str("900".into()));
m.insert("withdraw".to_string(), Value::Str("904".into()));
m
});
return self.safe_integer(types, 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".into());
if (since == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a since argument".into()))));
}
let mut untilparamsUntilVariable = self.handle_option_and_params(params, methodName.clone(), Value::Str("until".into()), &[]);
let mut until: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (until == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires an until argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("endTime".into(), until); }
let mut flowTypeparamsFlowTypeVariable = self.handle_option_string_and_params(paramsUntil, methodName.clone(), Value::Str("flowType".into()), &[]);
let mut flowType: Value = flowTypeparamsFlowTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsFlowType: Value = flowTypeparamsFlowTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (flowType != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("flowType".into(), self.encode_flow_type(flowType)); }
}
let mut accountTypeparamsAccountTypeVariable = self.handle_option_string_and_params(paramsFlowType, methodName, Value::Str("accountType".into()), &[]);
let mut accountType: Value = accountTypeparamsAccountTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsAccountType: Value = accountTypeparamsAccountTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (accountType != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("accountType".into(), self.encode_account_type(accountType)); }
}
let __ws_arg_15 = self.extend(request, &[paramsAccountType]);
let mut response: Value = self.private_get_api_v1_account_balance_flow(&[__ws_arg_15]).await;
return self.parse_ledger(response, &[currency, since, limit]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1".to_string(), Value::Str("trade".into()));
m.insert("2".to_string(), Value::Str("fee".into()));
m.insert("51".to_string(), Value::Str("transfer".into()));
m.insert("900".to_string(), Value::Str("deposit".into()));
m.insert("904".to_string(), Value::Str("withdraw".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
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", &[])).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut currencyId: Value = self.safe_string_k(item.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut currencyResolved: Value = self.safe_currency(currencyId, &[currency]);
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".into());
if Value::Int(amountString.as_str().and_then(|__s| __s.find("-")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
direction = Value::Str("out".into());
}
let mut afterString: Value = self.safe_string_k(item.clone(), "total", &[]);
let mut after: Value = self.parse_number(afterString, &[]);
let mut status: Value = Value::Str("ok".into());
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item);
m.insert("id".to_string(), id);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("account".to_string(), account);
m.insert("direction".to_string(), direction);
m.insert("referenceId".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code);
m.insert("symbol".to_string(), Value::Null);
m.insert("amount".to_string(), amount);
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), after);
m.insert("status".to_string(), status);
m.insert("fee".to_string(), Value::Null);
m
}), &[currencyResolved]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
return self.create_spot_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
return self.create_swap_order(symbol, type_var, side, amount, &[price, params]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createOrder() is not supported for ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" type of markets".into()))));
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createMarketBuyOrderWithCost() is supported for spot markets only".into()))));
}
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, &[params]);
return self.create_order(symbol, Value::Str("market".into()), Value::Str("buy".into()), cost, &[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: Option<String> = self.safe_string2(params.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]).as_str().map(str::to_owned);
if (triggerPrice.is_some()) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" trigger orders are not supported for spot markets".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut isMarketBuy: bool = (type_var.as_str() == Some("market")) && (side.as_str() == Some("buy"));
let mut cost: Option<String> = self.safe_string_k(params.clone(), "cost", &[]).as_str().map(str::to_owned);
if (!isMarketBuy) && (cost.is_some()) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() supports cost parameter for spot market buy orders only".into()))));
}
let mut request: Value = self.create_spot_order_request(symbol, type_var, side, amount, &[price, params.clone()]);
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut test: Value = self.safe_bool_k(params, "test", &[]);
if (test.as_bool() == Some(true)) {
response = self.private_post_api_v1_spot_order_test(&[request.clone()]).await;
} else if isMarketBuy && (cost.is_none()) {
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]).await; // the endpoint for market buy orders by cost and other orders
}
return self.parse_order(response, &[market]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
return self.create_spot_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
return self.create_swap_order_request(symbol, type_var, side, amount, &[price, params]);
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), Value::Str("createOrderRequest() is not supported for ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" type of markets".into()))));
}
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 (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
/*
* @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());
let mut typeValue: Value = to_upper(&type_var);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), to_upper(&side));
m.insert("type".to_string(), typeValue.clone());
m
});
if (amount != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.amount_to_precision(symbol.clone(), amount)); }
}
let mut costparamsCostVariable = self.handle_param_string(params, Value::Str("cost".into()), &[]);
let mut cost: Value = costparamsCostVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsCost: Value = costparamsCostVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (cost != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.cost_to_precision(symbol.clone(), cost)); }
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol, price)); }
}
let mut isMarketOrder: Value = Value::Bool(typeValue.as_str() == Some("MARKET"));
let mut postOnlyparamsPostOnlyVariable = self.handle_post_only(isMarketOrder, Value::Bool(typeValue.as_str() == Some("LIMIT_MAKER")), &[paramsCost]);
let mut postOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&postOnly) && (typeValue.as_str() == Some("LIMIT")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("LIMIT_MAKER".into())); }
}
let mut clientOrderId: Value = Value::Null;
let mut paramsClientOrderId: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{ let __destr_tmp = self.handle_param_string(paramsPostOnly, Value::Str("clientOrderId".into()), &[]); clientOrderId = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); paramsClientOrderId = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut paramsClientOrderId { std::sync::Arc::make_mut(__d).insert("newClientOrderId".into(), clientOrderId); }
}
return self.extend(request, &[paramsClientOrderId]);
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(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), Value::Str("LIMIT".into()));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount));
m
});
let mut isMarketOrder: Value = Value::Bool(type_var.as_str() == Some("market"));
if matches!(&isMarketOrder, Value::Bool(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("priceType".into(), Value::Str("MARKET".into())); }
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("priceType".into(), Value::Str("INPUT".into())); }
}
let mut reduceOnlyparamsReduceOnlyVariable = self.handle_param_bool(params, Value::Str("reduceOnly".into()), &[Value::Bool(false)]);
let mut reduceOnly: Value = reduceOnlyparamsReduceOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsReduceOnly: Value = reduceOnlyparamsReduceOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut suffix: Value = Value::Str("_OPEN".into());
if (reduceOnly.as_bool() == Some(true)) {
suffix = Value::Str("_CLOSE".into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("side".into(), Value::Str(format!("{}{}", to_upper(&side), suffix).into())); }
let mut timeInForceParamparamsTimeInForceVariable = self.handle_param_string(paramsReduceOnly, Value::Str("timeInForce".into()), &[]);
let mut timeInForceParam: Value = timeInForceParamparamsTimeInForceVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTimeInForce: Value = timeInForceParamparamsTimeInForceVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut postOnlyparamsPostOnlyVariable = self.handle_post_only(isMarketOrder, Value::Bool(timeInForceParam.as_str() == Some("LIMIT_MAKER")), &[paramsTimeInForce]);
let mut postOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut timeInForce: Value = timeInForceParam;
if is_true(&postOnly) {
timeInForce = Value::Str("LIMIT_MAKER".into());
}
if (timeInForce != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("timeInForce".into(), timeInForce); }
}
let mut clientOrderId: Option<String> = self.safe_string_k(paramsPostOnly.clone(), "clientOrderId", &[]).as_str().map(str::to_owned);
if (clientOrderId.is_none()) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("clientOrderId".into(), self.uuid(&[])); }
}
let mut triggerPrice: Value = self.safe_string_k(paramsPostOnly.clone(), "triggerPrice", &[]);
let mut paramsOmitted: Value = (if (triggerPrice != Value::Null) { self.omit(paramsPostOnly.clone(), Value::Str("triggerPrice".into()), &[]) } else { paramsPostOnly });
if (triggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stopPrice".into(), self.price_to_precision(symbol, triggerPrice)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP".into())); }
}
return self.extend(request, &[paramsOmitted]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_swap_order_request(symbol, type_var, side, amount, &[price, params.clone()]);
let __ws_arg_17 = self.extend(request, &[params]);
let mut response: Value = self.private_post_api_v1_futures_order(&[__ws_arg_17]).await;
return self.parse_order(response, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_706: bool = true;
while { if !__for_first_706 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_706 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut rawOrder: Value = self.safe_dict(orders.clone(), i.clone(), &[]);
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, "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_order_request(symbol, type_var, side, amount, &[price, orderParams]);
let mut clientOrderId: Option<String> = self.safe_string_k(orderRequest.clone(), "clientOrderId", &[]).as_str().map(str::to_owned);
if (clientOrderId.is_none()) {
add_element_to_object(&mut orderRequest, &Value::Str("clientOrderId".into()), self.uuid(&[])); // both spot and swap endpoints require clientOrderId
}
append_to_array(&mut ordersRequests, orderRequest);
}
}
let mut firstOrder: Value = self.safe_dict(ordersRequests.clone(), Value::Int(0), &[]);
let mut firstSymbol: Value = self.safe_string_k(firstOrder, "symbol", &[]);
let mut market: Value = self.market(firstSymbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), ordersRequests);
m
});
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
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 (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_19 = self.extend(request, &[params]);
response = self.private_post_api_v1_futures_batch_orders(&[__ws_arg_19]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), Value::Str("createOrderRequest() is not supported for ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" type of markets".into()))));
}
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]);
let mut responseOrders: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_707: bool = true;
while { if !__for_first_707 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_707 = false; i.as_f64().unwrap_or(f64::NAN) < ((result.len() as i64) as f64) } {
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, "order", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
append_to_array(&mut responseOrders, responseOrder);
}
}
return self.parse_orders(responseOrders, &[]);
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".into());
self.check_type_param(methodName.clone(), params.clone());
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Option<String> = self.safe_string_k(params.clone(), "clientOrderId", &[]).as_str().map(str::to_owned);
if (clientOrderId.is_none()) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderId".into(), id.clone()); }
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), params, Value::Str("spot".into())]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
let __ws_arg_20 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_delete_api_v1_spot_order(&[__ws_arg_20]).await;
} else if (marketType.as_str() == Some("swap")) {
let mut isTriggerparamsTriggerVariable = self.handle_trigger_option_and_params(paramsMarketType, methodName.clone(), &[Value::Bool(false)]);
let mut isTrigger: Value = isTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTrigger: Value = isTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (isTrigger.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("LIMIT".into())); }
}
if (market != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let __ws_arg_21 = self.extend(request, &[paramsTrigger]);
response = self.private_delete_api_v1_futures_order(&[__ws_arg_21]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), marketType).into()), Value::Str(" type of markets".into()))));
}
return self.parse_order(response, &[]);
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".into());
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut side: Value = self.safe_string_k(params.clone(), "side", &[]);
if (side != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("side".into(), side); }
}
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
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 (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_23 = self.extend(request, &[params]);
response = self.private_delete_api_v1_futures_batch_orders(&[__ws_arg_23]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" type of markets".into()))));
}
let mut order: Value = self.safe_order(response.clone(), &[]);
add_element_to_object(&mut order, &Value::Str("info".into()), response);
return Value::from(vec![order]);
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".into());
if (self.markets.clone() == 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(",".into()));
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("ids".into(), orderIds); }
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut marketType: Value = Value::Str("spot".into());
let mut marketTypeOption: Value = self.handle_market_type_and_params(methodName.clone(), &[market, params, marketType]).as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketTypeOption.as_str() == Some("spot")) {
response = self.private_delete_api_v1_spot_cancel_order_by_ids(&[request.clone()]).await;
} else if (marketTypeOption.as_str() == Some("swap")) {
response = self.private_delete_api_v1_futures_cancel_order_by_ids(&[request]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), marketTypeOption).into()), Value::Str(" type of markets".into()))));
}
let mut order: Value = self.safe_order(response.clone(), &[]);
add_element_to_object(&mut order, &Value::Str("info".into()), response);
return Value::from(vec![order]);
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".into());
self.check_type_param(methodName.clone(), params.clone());
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderIdparamsClientOrderIdVariable = self.handle_param_string(params, Value::Str("clientOrderId".into()), &[]);
let mut clientOrderId: Value = clientOrderIdparamsClientOrderIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsClientOrderId: Value = clientOrderIdparamsClientOrderIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (clientOrderId == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderId".into(), id.clone()); }
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(methodName.clone(), &[market, paramsClientOrderId, Value::Str("spot".into())]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("origClientOrderId".into(), clientOrderId); }
}
let __ws_arg_24 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_get_api_v1_spot_order(&[__ws_arg_24]).await;
} else if (marketType.as_str() == Some("swap")) {
let mut isTriggerparamsTriggerVariable = self.handle_trigger_option_and_params(paramsMarketType, methodName.clone(), &[Value::Bool(false)]);
let mut isTrigger: Value = isTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTrigger: Value = isTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (isTrigger.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP".into())); }
}
let __ws_arg_25 = self.extend(request, &[paramsTrigger]);
response = self.private_get_api_v1_futures_order(&[__ws_arg_25]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), marketType).into()), Value::Str(" type of markets".into()))));
}
return self.parse_order(response, &[]);
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".into());
self.check_type_param(methodName.clone(), params.clone());
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".into());
let mut marketTypeOptionparamsMarketTypeVariable = self.handle_market_type_and_params(methodName.clone(), &[market, params, marketType]);
let mut marketTypeOption: Value = marketTypeOptionparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeOptionparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut paramsExtended: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("methodName".to_string(), methodName.clone());
m
}), &[paramsMarketType]);
if (marketTypeOption.as_str() == Some("spot")) {
return self.fetch_open_spot_orders(&[symbol.clone(), since.clone(), limit.clone(), paramsExtended.clone()]).await;
} else if (marketTypeOption.as_str() == Some("swap")) {
return self.fetch_open_swap_orders(&[symbol, since, limit, paramsExtended]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), marketTypeOption).into()), Value::Str(" type of markets".into()))));
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut methodName: Value = Value::Str("fetchOpenSpotOrders".into());
let mut methodNameOptionparamsMethodNameVariable = self.handle_param_string(params, Value::Str("methodName".into()), &[methodName]);
let mut methodNameOption: Value = methodNameOptionparamsMethodNameVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMethodName: Value = methodNameOptionparamsMethodNameVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
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 accountIdparamsAccountIdVariable = self.handle_option_string_and_params(paramsMethodName, methodNameOption, Value::Str("accountId".into()), &[]);
let mut accountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsAccountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (accountId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("subAccountId".into(), accountId); }
let __ws_arg_26 = self.extend(request.clone(), &[paramsAccountId.clone()]);
response = self.private_get_api_v1_spot_sub_account_open_orders(&[__ws_arg_26]).await;
} else {
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_27 = self.extend(request, &[paramsAccountId]);
response = self.private_get_api_v1_spot_open_orders(&[__ws_arg_27]).await;
}
return self.parse_orders(response, &[market, since, limit]);
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".into());
let mut methodNameOptionparamsMethodNameVariable = self.handle_param_string(params, Value::Str("methodName".into()), &[methodName]);
let mut methodNameOption: Value = methodNameOptionparamsMethodNameVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMethodName: Value = methodNameOptionparamsMethodNameVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodNameOption).into()), Value::Str("() requires a symbol argument for swap market orders".into()))));
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut isTrigger: Value = Value::Bool(false);
let mut isTriggerTriggerparamsTriggerVariable = self.handle_trigger_option_and_params(paramsMethodName, methodNameOption.clone(), &[isTrigger]);
let mut isTriggerTrigger: Value = isTriggerTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTrigger: Value = isTriggerTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (isTriggerTrigger.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("LIMIT".into())); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut response: Value = Value::Null;
let mut accountIdparamsAccountIdVariable = self.handle_option_string_and_params(paramsTrigger, methodNameOption, Value::Str("accountId".into()), &[]);
let mut accountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsAccountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (accountId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("subAccountId".into(), accountId); }
let __ws_arg_28 = self.extend(request.clone(), &[paramsAccountId.clone()]);
response = self.private_get_api_v1_futures_sub_account_open_orders(&[__ws_arg_28]).await;
} else {
let __ws_arg_29 = self.extend(request, &[paramsAccountId]);
response = self.private_get_api_v1_futures_open_orders(&[__ws_arg_29]).await;
}
return self.parse_orders(response, &[market, since, limit]);
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".into());
self.check_type_param(methodName.clone(), params.clone());
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("startTime".into(), since.clone()); }
}
let mut untilparamsUntilVariable = self.handle_option_and_params(params, methodName.clone(), Value::Str("until".into()), &[]);
let mut until: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = untilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("endTime".into(), until); }
}
let mut accountIdparamsAccountIdVariable = self.handle_option_string_and_params(paramsUntil, methodName.clone(), Value::Str("accountId".into()), &[]);
let mut accountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsAccountId: Value = accountIdparamsAccountIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
}
let mut marketTypeparamsMarketTypeVariable = self.handle_market_type_and_params(methodName.clone(), &[market.clone(), paramsAccountId, Value::Str("spot".into())]);
let mut marketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarketType: Value = marketTypeparamsMarketTypeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (marketType.as_str() == Some("spot")) {
if (market != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (accountId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("accountId".into(), accountId.clone()); }
}
let __ws_arg_30 = self.extend(request.clone(), &[paramsMarketType.clone()]);
response = self.private_get_api_v1_spot_trade_orders(&[__ws_arg_30]).await;
} else if (marketType.as_str() == Some("swap")) {
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a symbol argument for swap markets".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), self.safe_string_k(market.clone(), "id", &[])); }
let mut isTriggerparamsTriggerVariable = self.handle_trigger_option_and_params(paramsMarketType, methodName.clone(), &[Value::Bool(false)]);
let mut isTrigger: Value = isTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTrigger: Value = isTriggerparamsTriggerVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (isTrigger.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("STOP".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("LIMIT".into())); }
}
if (accountId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("subAccountId".into(), accountId); }
let __ws_arg_31 = self.extend(request.clone(), &[paramsTrigger.clone()]);
response = self.private_get_api_v1_futures_sub_account_history_orders(&[__ws_arg_31]).await;
} else {
let __ws_arg_32 = self.extend(request, &[paramsTrigger]);
response = self.private_get_api_v1_futures_history_orders(&[__ws_arg_32]).await;
}
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), marketType).into()), Value::Str(" type of markets".into()))));
}
return self.parse_orders(response, &[market, since, limit]);
Value::Null
}
pub fn check_type_param(&self, mut methodName: Value, mut params: Value) {
let __params_empty = indexmap::IndexMap::new();
let params = params.as_map().unwrap_or(&__params_empty);
// 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 = (match params.get("type") { Some(Value::Str(__s)) if !__s.is_empty() => Value::Str(__s.clone()), Some(Value::Int(__n)) => Value::Str(__n.to_string().into()), Some(Value::Float(__f)) => Value::Str(__f.to_string().into()), _ => Value::Null });
if (paramsType != Value::Null) && (paramsType.as_str() != Some("spot")) && (paramsType.as_str() != Some("swap")) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str(" () type parameter can not be \"".into())).into()), paramsType).into()), 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)".into()))));
}
}
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;
let mut isTriggerStopparamsStopVariable = self.handle_option_bool_and_params2(params, methodName, Value::Str("stop".into()), Value::Str("trigger".into()), &[isTrigger]);
let mut isTriggerStop: Value = isTriggerStopparamsStopVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsStop: Value = isTriggerStopparamsStopVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
return Value::from(vec![isTriggerStop, paramsStop]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("transactTime".into()), Value::Str("time".into()), &[]);
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: Option<String> = self.safe_string_k(order.clone(), "priceType", &[]).as_str().map(str::to_owned);
if (priceType.as_deref() == Some("MARKET")) {
type_var = Value::Str("market".into());
}
let mut price: Value = self.omit_zero(self.safe_string_k(order.clone(), "price", &[]));
if (type_var.as_str() == Some("STOP")) {
if (price == Value::Null) {
type_var = Value::Str("market".into());
} else {
type_var = Value::Str("limit".into());
}
}
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 = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); timeInForce = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); postOnly = __destr_tmp.as_array().and_then(|__arr| __arr.get(2)).cloned().unwrap_or(Value::Null); }
let mut average: Value = self.omit_zero(self.safe_string_k(order.clone(), "avgPrice", &[]));
if (price == Value::Null) {
price = average.clone();
}
let mut side: Value = self.safe_string_lower_k(order.clone(), "side", &[]);
let mut reduceOnly: Value = Value::Null;
{ let __destr_tmp = self.parse_order_side_and_reduce_only(side.clone()); side = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); reduceOnly = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut feeCurrncyId: Value = self.safe_string_k(order.clone(), "feeCoin", &[]);
if (feeCurrncyId.as_str() == Some("")) {
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);
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));
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), type_var);
m.insert("timeInForce".to_string(), timeInForce);
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("average".to_string(), average);
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".into()), Value::Str("cummulativeQuoteQty".into()), &[])));
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, &[]));
m.insert("cost".to_string(), self.omit_zero(self.safe_string_k(order.clone(), "feeAmount", &[])));
m
}));
m.insert("reduceOnly".to_string(), reduceOnly);
m.insert("postOnly".to_string(), postOnly);
m.insert("info".to_string(), order);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_order_side_and_reduce_only(&self, mut unparsed: Value) -> Value {
let mut parts: Value = split(&unparsed, &Value::Str("_".into()));
let mut side: Value = get_value(&parts, &Value::Int(0));
let mut reduceOnly: Value = Value::Null;
let mut secondPart: Option<String> = self.safe_string(parts, Value::Int(1), &[]).as_str().map(str::to_owned);
if (secondPart.is_some()) {
if (secondPart.as_deref() == Some("open")) {
reduceOnly = Value::Bool(false);
} else if (secondPart.as_deref() == Some("close")) {
reduceOnly = Value::Bool(true);
}
}
return Value::from(vec![side, reduceOnly]);
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".into()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".into()));
m.insert("PARTIALLY_CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("FILLED".to_string(), Value::Str("closed".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("ORDER_CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("PENDING_CANCEL".to_string(), Value::Str("canceled".into()));
m.insert("REJECTED".to_string(), Value::Str("rejected".into()));
m.insert("ORDER_NEW".to_string(), Value::Str("open".into()));
m
});
return self.safe_string(statuses, 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;
let mut isMakerTimeInForce: bool = (timeInForce.as_str() == Some("LIMIT_MAKER")) || (timeInForce.as_str() == Some("MAKER"));
if (type_var.as_str() == Some("LIMIT_MAKER")) || isMakerTimeInForce {
postOnly = Value::Bool(true);
}
let mut timeInForceParsed: Value = timeInForce;
if (type_var.as_str() != Some("LIMIT_MAKER")) && isMakerTimeInForce {
timeInForceParsed = Value::Str("PO".into());
}
let mut typeValue: Value = self.parse_order_type(type_var).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
return Value::from(vec![typeValue, timeInForceParsed, postOnly]);
Value::Null
}
pub fn parse_order_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".into()));
m.insert("LIMIT".to_string(), Value::Str("limit".into()));
m.insert("LIMIT_MAKER".to_string(), Value::Str("limit".into()));
m.insert("MARKET_OF_BASE".to_string(), Value::Str("market".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
/*
* @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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("timestamp".to_string(), self.milliseconds());
m
});
let __ws_arg_33 = self.extend(request, &[params]);
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, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(rate, &[market]);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
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, &[params]);
let mut response: Value = self.public_get_api_v1_futures_funding_rate(&[__ws_arg_34]).await;
return self.parse_funding_rates(response, &[symbolsNormalized]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETHUSDT-PERPETUAL",
// "rate": "0.0001",
// "nextSettleTime": "1722297600000"
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Null, Value::Str("swap".into())]);
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);
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
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);
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));
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let __ws_arg_35 = self.extend(request, &[params]);
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::from(vec![]);
let mut rows: Value = self.to_array(response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_708: bool = true;
while { if !__for_first_708 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_708 = false; i.as_f64().unwrap_or(f64::NAN) < ((rows.len() as i64) as f64) } {
let mut entry: Value = rows.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut 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".into())]));
m.insert("fundingRate".to_string(), self.safe_number_k(entry, "settleRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates, Value::Str("timestamp".into()), &[]);
return self.filter_by_since_limit(sorted, &[since, limit]);
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".into());
if (symbols == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() requires a symbol argument with one single market symbol".into()))));
} else {
let mut symbolsLength: f64 = ((symbols.len() as i64) as f64);
if (symbolsLength != 1.0) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is supported for a symbol argument with one single market symbol only".into()))));
}
}
if (self.markets.clone() == 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".into()));
m
}), &[params]);
return self.fetch_positions_for_symbol(symbols.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null), &[__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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut methodName: Value = Value::Str("fetchPosition".into());
let mut methodNameOptionparamsMethodNameVariable = self.handle_param_string(params, Value::Str("methodName".into()), &[methodName]);
let mut methodNameOption: Value = methodNameOptionparamsMethodNameVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMethodName: Value = methodNameOptionparamsMethodNameVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodNameOption).into()), Value::Str("() supports swap markets only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_37 = self.extend(request, &[paramsMethodName]);
let mut response: Value = self.private_get_api_v1_futures_positions(&[__ws_arg_37]).await;
return self.parse_positions(response, &[Value::from(vec![symbol])]);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut symbol: Value = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
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_k(position.clone(), "side", &[]));
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".into()));
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);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_38 = self.extend(request, &[params]);
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, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(leverage, &[market]);
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_k(leverage.clone(), "marginType", &[]);
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);
m.insert("symbol".to_string(), self.safe_string_k(market, "symbol", &[]));
m.insert("marginMode".to_string(), marginMode);
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue);
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setLeverage() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), leverage);
m
});
let mut market: Value = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_39 = self.extend(request, &[params]);
let mut response: Value = self.private_post_api_v1_futures_leverage(&[__ws_arg_39]).await;
return self.parse_leverage(response, &[market]);
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut marginModeUpper: Value = to_upper(&marginMode);
let mut marginModeValue: Value = (if (marginModeUpper.as_str() == Some("CROSSED")) { Value::Str("CROSS".into()) } else { marginModeUpper });
if (marginModeValue.as_str() != Some("CROSS")) && (marginModeValue.as_str() != Some("ISOLATED")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() marginMode must be either cross or isolated".into()))));
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" setMarginMode() supports swap markets only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("marginType".to_string(), marginModeValue);
m
});
let __ws_arg_40 = self.extend(request, &[params]);
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, amount, Value::Str("add".into()), &[params]).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, amount, Value::Str("reduce".into()), &[params]).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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_symbol(format!("{}{}", self.id.clone(), Value::Str(" modifyMarginHelper() supports swap markets only".into()))));
}
let mut sideParamparamsSideVariable = self.handle_param_string(params, Value::Str("side".into()), &[]);
let mut sideParam: Value = sideParamparamsSideVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsSide: Value = sideParamparamsSideVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (sideParam == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), type_var).into()), Value::Str("Margin() requires a params[\"side\"] argument, either \"long\" or \"short\"".into()))));
}
let mut side: Value = to_upper(&sideParam);
if (side.as_str() != Some("LONG")) && (side.as_str() != Some("SHORT")) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), type_var).into()), Value::Str("Margin() params[\"side\"] must be either long or short".into()))));
}
let mut amountString: Value = self.number_to_string(amount.clone());
if (type_var.as_str() == Some("reduce")) {
amountString = crate::precise::Precise::stringMul(&amountString, &Value::Str("-1".into()));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), side);
m.insert("amount".to_string(), amountString);
m
});
let __ws_arg_41 = self.extend(request, &[paramsSide]);
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, &[market]);
return self.extend(__ws_arg_42, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var);
m.insert("amount".to_string(), amount);
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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market, Value::Null, Value::Str("swap".into())]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "timestamp", &[]);
let mut errorCode: Option<String> = self.safe_string_k(data.clone(), "code", &[]).as_str().map(str::to_owned);
let mut success: bool = errorCode.as_deref() == Some("0000");
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), self.safe_number_k(data, "margin", &[]));
m.insert("code".to_string(), marketResolved.as_map().and_then(|__m| __m.get("settle")).cloned().unwrap_or(Value::Null));
m.insert("status".to_string(), (if (success) { Value::Str("ok".into()) } else { Value::Str("failed".into()) }));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.public_get_api_v1_exchange_info(&[params]).await;
// response is the same as in fetchMarkets()
let mut data: Value = self.safe_list_k(response, "contracts", &[Value::from(vec![])]);
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
return self.parse_leverage_tiers(data, &[symbolsNormalized, Value::Str("symbol".into())]);
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::from(vec![])]);
let mut marketId: Value = self.safe_string_k(info, "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId.clone(), market]);
let mut tiers: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_709: bool = true;
while { if !__for_first_709 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_709 = false; i.as_f64().unwrap_or(f64::NAN) < ((riskLimits.len() as i64) as f64) } {
let mut tier: Value = riskLimits.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut 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(), &[marketResolved.clone()]));
m.insert("currency".to_string(), marketResolved.as_map().and_then(|__m| __m.get("settle")).cloned().unwrap_or(Value::Null));
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".into()), &initialMarginRate), &[]));
m.insert("info".to_string(), tier);
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut methodName: Value = Value::Str("fetchTradingFee".into());
let mut response: Value = Value::Null;
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
response = self.fetch_trading_fees(&[params.clone()]).await;
let mut fee: Value = self.safe_dict(response.clone(), symbol, &[]);
return fee;
} else if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
let __ws_arg_43 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
}), &[params]);
response = self.private_get_api_v1_futures_commission_rate(&[__ws_arg_43]).await;
return self.parse_trading_fee(response, &[market.clone()]);
} else {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), methodName).into()), Value::Str("() is not supported for ".into())).into()), market.as_map().and_then(|__m| __m.get("type")).cloned().unwrap_or(Value::Null)).into()), Value::Str(" type of markets".into()))));
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_api_v1_account_vip_info(&[params]).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, "data", &[Value::from(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_710: bool = true;
while { if !__for_first_710 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_710 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
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, &[]);
add_element_to_object(&mut result, &parsedFee.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null), 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", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("maker".to_string(), self.safe_number2(fee.clone(), Value::Str("openMakerFee".into()), Value::Str("actualMakerRate".into()), &[]));
m.insert("taker".to_string(), self.safe_number2(fee, Value::Str("openTakerFee".into()), Value::Str("actualTakerRate".into()), &[]));
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".into()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut apiUrl: Value = self.safe_string(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), api.clone(), &[]);
if (apiUrl == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", apiUrl, Value::Str("/".into())).into()), path).into());
let mut query: Value = Value::Null;
if (api.as_str() == Some("private")) {
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);
m
});
let mut recvWindow: Value = self.safe_integer_k(self.options.clone(), "recvWindow", &[]);
if (recvWindow != Value::Null) {
if let Value::Dict(__d) = &mut additionalParams { std::sync::Arc::make_mut(__d).insert("recvWindow".into(), recvWindow); }
}
let mut headersSigned: Value = 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".into()));
m
});
let mut signature: Value = Value::Null;
let mut bodySigned: Value = Value::Null;
if (method.as_str() == Some("POST")) && ((path.as_str() == Some("api/v1/spot/batchOrders")) || (path.as_str() == Some("api/v1/futures/batchOrders"))) {
if let Value::Dict(__d) = &mut headersSigned { std::sync::Arc::make_mut(__d).insert("Content-Type".into(), Value::Str("application/json".into())); }
bodySigned = self.json(self.safe_list_k(params.clone(), "orders", &[]));
signature = self.hmac(self.encode(self.custom_urlencode(&[additionalParams.clone()]).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null)), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[]);
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]).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), query).into())).into());
} else {
let mut totalParams: Value = self.extend(additionalParams, &[params.clone()]);
signature = self.hmac(self.encode(self.custom_urlencode(&[totalParams.clone()]).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null)), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[]);
add_element_to_object(&mut totalParams, &Value::Str("signature".into()), signature.clone());
query = self.custom_urlencode(&[totalParams]).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
if (method.as_str() == Some("GET")) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), query).into())).into());
} else {
bodySigned = query.clone();
}
}
if let Value::Dict(__d) = &mut headersSigned { std::sync::Arc::make_mut(__d).insert("INPUT-SOURCE".into(), self.safe_string_k(self.options.clone(), "broker", &[Value::Str("10000700011".into())])); }
if let Value::Dict(__d) = &mut headersSigned { std::sync::Arc::make_mut(__d).insert("broker_sign".into(), signature); }
let mut bodyResolved: Value = (if (method.as_str() == Some("GET")) { body.clone() } else { bodySigned });
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(), bodyResolved);
m.insert("headers".to_string(), headersSigned);
m
});
} else {
query = self.urlencode(params, &[]);
if (Value::Int(query.len() as i64).as_f64() != Some(0.0)) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), query).into())).into());
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), body);
m.insert("headers".to_string(), headers);
m
});
Value::Null
}
pub fn custom_urlencode(&self, optional_args: &[Value]) -> Option<String> {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut result: Value = self.urlencode(params, &[]);
result = replace_str(&result, &Value::Str("%2C".into()), &Value::Str(",".into()));
return result.as_str().map(str::to_owned);
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
let mut errorInArray: bool = false;
let mut responseCodeString: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut responseCodeInteger: Option<i64> = self.safe_integer_k(response.clone(), "code", &[]).as_i64(); // some codes in response are returned as '0000' others as 0
if (responseCodeInteger == Some(0)) {
let mut result: Value = self.safe_list_k(response, "result", &[Value::from(vec![])]); // for batch methods
{
let mut i: Value = Value::Int(0);
let mut __for_first_711: bool = true;
while { if !__for_first_711 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_711 = false; i.as_f64().unwrap_or(f64::NAN) < ((result.len() as i64) as f64) } {
let mut entry: Value = self.safe_dict(result.clone(), i.clone(), &[]);
let mut entryCodeInteger: Option<i64> = self.safe_integer_k(entry.clone(), "code", &[]).as_i64();
if (entryCodeInteger != Some(0)) {
errorInArray = true;
responseCodeString = self.safe_string_k(entry, "code", &[]);
}
}
}
}
if (code.as_f64() != Some(200.0)) || errorInArray {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), responseCodeString.clone(), feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), responseCodeString, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}