// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
pub struct KucoinCore {
pub exchange: crate::exchange::Exchange,
}
impl KucoinCore {
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 = KucoinCore::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 KucoinCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_order(self, order, &[market.clone()])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_position(self, position, &[market.clone()])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_deposit_address(self, depositAddress, &[currency.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_ledger_entry(self, entry, &[currency.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_funding_rate_history(self, entry, &[market.clone()])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_borrow_interest(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_borrow_interest(self, info, &[market.clone()])
}
fn parse_adl_rank(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_adl_rank(self, info, &[market.clone()])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_margin_mode(self, margin_mode, &[market.clone()])
}
fn parse_borrow_rate(&self, info: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_borrow_rate(self, info, &[currency.clone()])
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_market_leverage_tiers(self, info, &[market.clone()])
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::parse_deposit_withdraw_fee(self, fee, &[currency.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::sign(self, path, &[api.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on KucoinCore.
KucoinCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for KucoinCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"borrow_cross_margin" => self.borrow_cross_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"borrow_isolated_margin" => self.borrow_isolated_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"calculate_rate_limiter_cost" => self.calculate_rate_limiter_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"cancel_all_contract_orders" => self.cancel_all_contract_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_spot_orders" => self.cancel_all_spot_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_uta_orders" => self.cancel_all_uta_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_contract_order" => self.cancel_contract_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_spot_order" => self.cancel_spot_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_uta_order" => self.cancel_uta_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_contract_order" => self.create_contract_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_contract_order_request" => self.create_contract_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_contract_orders" => self.create_contract_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_deposit_address" => self.create_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"create_market_order_with_cost" => self.create_market_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"create_market_sell_order_with_cost" => self.create_market_sell_order_with_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_spot_order" => self.create_spot_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_spot_order_request" => self.create_spot_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_spot_orders" => self.create_spot_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_uta_order" => self.create_uta_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_uta_order_request" => self.create_uta_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_accounts" => self.fetch_accounts(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_interest" => self.fetch_borrow_interest(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_rate_histories" => self.fetch_borrow_rate_histories(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_rate_history" => self.fetch_borrow_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_balance" => self.fetch_contract_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_deposit_address" => self.fetch_contract_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_deposits" => self.fetch_contract_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_markets" => self.fetch_contract_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_ohlcv" => self.fetch_contract_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_order" => self.fetch_contract_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_orders_by_status" => self.fetch_contract_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_tickers" => self.fetch_contract_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_withdrawals" => self.fetch_contract_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_cross_borrow_rate" => self.fetch_cross_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fee" => self.fetch_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_interval" => self.fetch_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_mode" => self.fetch_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_mark_price" => self.fetch_mark_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_mark_prices" => self.fetch_mark_prices(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_market_leverage_tiers" => self.fetch_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_contract_trades" => self.fetch_my_contract_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_spot_trades" => self.fetch_my_spot_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_uta_trades" => self.fetch_my_uta_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interests" => self.fetch_open_interests(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position_mode" => self.fetch_position_mode(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_adl_rank" => self.fetch_positions_adl_rank(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_ohlcv" => self.fetch_spot_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_order" => self.fetch_spot_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_orders_by_status" => self.fetch_spot_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_status" => self.fetch_status(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transaction_fee" => self.fetch_transaction_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transfers" => self.fetch_transfers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_uta_balance" => self.fetch_uta_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_uta_markets" => self.fetch_uta_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_uta_order" => self.fetch_uta_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_uta_orders_by_status" => self.fetch_uta_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_utaohlcv" => self.fetch_utaohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"handle_hf_and_params" => self.handle_hf_and_params(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"handle_trade_type" => self.handle_trade_type(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"handle_trigger_prices" => self.handle_trigger_prices(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"is_futures_method" => self.is_futures_method(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"is_hf_or_mining" => self.is_hf_or_mining(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"is_uta_enabled" => self.is_uta_enabled(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"load_migration_status" => self.load_migration_status(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"market_order_amount_to_precision" => self.market_order_amount_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"parse_adl_rank" => self.parse_adl_rank(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_balance_helper" => self.parse_balance_helper(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_borrow_interest" => self.parse_borrow_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_borrow_rate" => self.parse_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_borrow_rate_histories" => self.parse_borrow_rate_histories(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null)),
"parse_contract_order" => self.parse_contract_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_contract_ticker" => self.parse_contract_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_contract_trade" => self.parse_contract_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_interval" => self.parse_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_direction" => self.parse_ledger_direction(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ledger_status" => self.parse_ledger_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_margin_loan" => self.parse_margin_loan(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_mode" => self.parse_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_my_uta_trade" => self.parse_my_uta_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_time_in_force" => self.parse_order_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_spot_or_uta_ticker" => self.parse_spot_or_uta_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_spot_or_uta_trade" => self.parse_spot_or_uta_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_spot_order" => self.parse_spot_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer_status" => self.parse_transfer_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_uta_order" => self.parse_uta_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"repay_cross_margin" => self.repay_cross_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"repay_isolated_margin" => self.repay_isolated_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"set_contract_leverage" => self.set_contract_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"transfer_classic" => self.transfer_classic(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"transfer_uta" => self.transfer_uta(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"type_to_trade_type" => self.type_to_trade_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for KucoinCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for KucoinCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl KucoinCore {
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("kucoin".to_string()));
m.insert("name".to_string(), Value::Str("KuCoin".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("SC".to_string())]));
m.insert("rateLimit".to_string(), Value::Float(7.5));
m.insert("version".to_string(), Value::Str("v2".to_string()));
m.insert("certified".to_string(), Value::Bool(true));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("comment".to_string(), Value::Str("Platform 2.0".to_string()));
m.insert("quoteJsonNumbers".to_string(), Value::Bool(false));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(true));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(true));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(true));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingInterval".to_string(), Value::Bool(true));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchL3OrderBook".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(true));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
m.insert("fetchMarkPrice".to_string(), Value::Bool(true));
m.insert("fetchMarkPrices".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(true));
m.insert("fetchOpenInterests".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionADLRank".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Bool(true));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsADLRank".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTransactionFee".to_string(), Value::Bool(true));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(true));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpg".to_string()));
m.insert("referral".to_string(), Value::Str("https://www.kucoin.com/ucenter/signup?rcode=E5wkqe".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.kucoin.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api.kucoin.com".to_string()));
m.insert("futuresPrivate".to_string(), Value::Str("https://api-futures.kucoin.com".to_string()));
m.insert("futuresPublic".to_string(), Value::Str("https://api-futures.kucoin.com".to_string()));
m.insert("webExchange".to_string(), Value::Str("https://kucoin.com/_api".to_string()));
m.insert("broker".to_string(), Value::Str("https://api-broker.kucoin.com".to_string()));
m.insert("earn".to_string(), Value::Str("https://api.kucoin.com".to_string()));
m.insert("uta".to_string(), Value::Str("https://api.kucoin.com".to_string()));
m.insert("utaPrivate".to_string(), Value::Str("https://api.kucoin.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.kucoin.com".to_string()));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://docs.kucoin.com".to_string())]));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m.insert("password".to_string(), Value::Bool(true));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("market/orderbook/level1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("market/allTickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("market/stats".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("market/orderbook/level{level}_{limit}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("market/orderbook/level2_20".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("market/orderbook/level2_100".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("market/histories".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("market/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("prices".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("timestamp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("mark-price/{symbol}/current".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("mark-price/all-symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("margin/config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("announcements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("margin/collateralRatio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("convert/symbol".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("convert/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bullet-public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
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("user-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("user/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("accounts/{accountId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("accounts/ledgers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/accounts/ledgers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/account/ledgers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("transaction-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("sub/user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("sub-accounts/{subUserId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("sub-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("sub/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("margin/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("margin/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("isolated/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("deposit-addresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("hist-deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("hist-withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("withdrawals/quotas".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("accounts/transferable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("transfer-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("base-fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("trade-fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("market/orderbook/level{level}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("market/orderbook/level2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("market/orderbook/level3".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/accounts/opened".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/orders/active".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/orders/active/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/order/active/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/orders/done".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/orders/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/orders/dead-cancel-all/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("limit/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("order/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("limit/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("stop-order/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("stop-order/queryOrderByClientOid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("oco/order/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("oco/order/details/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("oco/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("oco/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/orders/active".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("hf/margin/orders/done".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("hf/margin/orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("hf/margin/orders/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("hf/margin/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("hf/margin/stop-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("hf/margin/stop-order/orderId".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/margin/stop-order/clientOid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/margin/oco-order/orderId".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/oco-order/clientOid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/oco-order/detail/orderId".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/oco-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("etf/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("margin/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("risk/limit/strategy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("isolated/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("margin/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("isolated/account/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("margin/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("margin/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("margin/interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("project/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("project/marketInterestRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("redeem/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("purchase/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("broker/api/rebase/download".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("broker/queryMyCommission".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("broker/queryUser".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("broker/queryDetailByUid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("migrate/user/account/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("convert/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("convert/order/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("convert/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("convert/limit/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("convert/limit/order/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("convert/limit/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("affiliate/inviter/statistics".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub/user/created".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("sub/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("sub/api-key/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("deposit-addresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("accounts/universal-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("accounts/sub-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("accounts/inner-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("transfer-in".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("hf/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/sync".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/multi".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/multi/sync".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/alter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/dead-cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders/multi".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("oco/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/order/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/stop-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("margin/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("margin/order/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("hf/margin/oco-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("margin/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("margin/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("purchase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("lend/purchase/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("convert/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("convert/limit/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("bullet-private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("position/update-user-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("deposit-address/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("withdrawals/{withdrawalId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("hf/orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/sync/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/sync/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders/cancel/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("hf/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/orders/cancelAll".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("order/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("stop-order/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("stop-order/cancelOrderByClientOid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("stop-order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("oco/order/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("oco/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("oco/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/margin/orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/orders/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("hf/margin/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("hf/margin/stop-order/cancel-by-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/margin/stop-order/cancel-by-clientOid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("hf/margin/stop-order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/margin/oco-order/cancel-by-id".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/margin/oco-order/cancel-by-clientOid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("hf/margin/oco-order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("convert/limit/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
m.insert("futuresPublic".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("contracts/active".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("contracts/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("allTickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("level2/snapshot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("level2/depth20".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("level2/depth100".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("kline/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("interest/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("index/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("mark-price/{symbol}/current".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("premium/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("trade-statistics".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("funding-rate/{symbol}/current".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("contract/funding-rates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("timestamp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("level2/message/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.3953));
m
}));
m.insert("contracts/risk-limit/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("level3/message/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("level3/snapshot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bullet-public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m
}));
m.insert("futuresPrivate".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("transaction-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account-overview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account-overview-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("transfer-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("stopOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("recentDoneOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("orders/byClientOid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("recentFills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("trade-fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("openOrderStatistics".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("margin/maxWithdrawMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("contracts/risk-limit/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("funding-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("copy-trade/futures/get-max-open-size".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("copy-trade/futures/position/margin/max-withdraw-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("history-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("position/getMarginMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("position/getPositionMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("deposit-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("withdrawals/quotas".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("withdrawal-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("sub/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("trade-statistics".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("getMaxOpenSize".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("getCrossUserLeverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("transfer-in".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("st-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("orders/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("orders/multi".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("position/margin/auto-deposit-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("margin/withdrawMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("position/margin/deposit-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("position/risk-limit-level/change".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("copy-trade/futures/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copy-trade/futures/orders/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copy-trade/futures/st-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copy-trade/futures/position/margin/deposit-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("copy-trade/futures/position/margin/withdraw-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("copy-trade/futures/position/risk-limit-level/change".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copy-trade/futures/position/margin/auto-deposit-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("copy-trade/futures/position/changeMarginMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copy-trade/futures/position/changeCrossUserLeverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copy-trade/getCrossModeMarginRequirement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("copy-trade/position/switchPositionMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("changeCrossUserLeverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("sub/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("sub/api-key/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("position/changeMarginMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("position/switchPositionMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("bullet-private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders/client-order/{clientOid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("stopOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("copy-trade/futures/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.5));
m
}));
m.insert("copy-trade/futures/orders/client-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.5));
m
}));
m.insert("orders/multi-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("withdrawals/{withdrawalId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("cancel/transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("sub/api-key".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m
}));
m.insert("webExchange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency/currency/chain-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/{symbol}/funding-rates".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m.insert("broker".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("broker/nd/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/nd/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/nd/account/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/nd/rebase/download".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("asset/ndbroker/deposit/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("broker/nd/transfer/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("broker/nd/deposit/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("broker/nd/withdraw/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("broker/nd/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("broker/nd/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("broker/nd/account/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("broker/nd/account/update-apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("broker/nd/account/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m
}));
m
}));
m.insert("earn".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("otc-loan/discount-rate-configs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("otc-loan/loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("otc-loan/accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("earn/redeem-preview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("earn/saving/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("earn/hold-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("earn/promotion/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("earn/kcs-staking/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("earn/staking/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("earn/eth-staking/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("struct-earn/dual/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("struct-earn/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("earn/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("struct-earn/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("earn/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m
}));
m.insert("uta".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("market/announcement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("market/currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("asset/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("market/instrument".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("market/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("market/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("market/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("market/funding-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("market/funding-rate-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("market/cross-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("market/collateral-discount-ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("market/index-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("market/position-tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("market/open-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("server/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("market/borrowable-currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("user/my-ip".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("market/fiat-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m
}));
m
}));
m.insert("utaPrivate".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("market/orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/transfer-quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("account/mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(60));
m
}));
m.insert("account/ledger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/interest-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("asset/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("{accountMode}/account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("{accountMode}/account/overview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("{accountMode}/order/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("{accountMode}/order/open-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("{accountMode}/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("{accountMode}/order/execution".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("{accountMode}/position/open-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("{accountMode}/position/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("position/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("{accountMode}/position/tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub-account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("dcp/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("unified/account/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("position/funding-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("account/interest-limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("account/mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(60));
m
}));
m.insert("{accountMode}/account/modify-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("{accountMode}/order/place".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("{accountMode}/order/place-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("{accountMode}/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("{accountMode}/order/cancel-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("{accountMode}/order/cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("sub-account/canTransferOut".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("dcp/set".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("{accountMode}/account/modify-leverage-margin-cross".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m
}));
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1min".to_string()));
m.insert("3m".to_string(), Value::Str("3min".to_string()));
m.insert("5m".to_string(), Value::Str("5min".to_string()));
m.insert("15m".to_string(), Value::Str("15min".to_string()));
m.insert("30m".to_string(), Value::Str("30min".to_string()));
m.insert("1h".to_string(), Value::Str("1hour".to_string()));
m.insert("2h".to_string(), Value::Str("2hour".to_string()));
m.insert("4h".to_string(), Value::Str("4hour".to_string()));
m.insert("6h".to_string(), Value::Str("6hour".to_string()));
m.insert("8h".to_string(), Value::Str("8hour".to_string()));
m.insert("12h".to_string(), Value::Str("12hour".to_string()));
m.insert("1d".to_string(), Value::Str("1day".to_string()));
m.insert("1w".to_string(), Value::Str("1week".to_string()));
m.insert("1M".to_string(), Value::Str("1month".to_string()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
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("Order not exist or not allow to be cancelled".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("The order does not exist.".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("order not exist".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("order not exist.".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("order_not_exist".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("order_not_exist_or_not_allow_to_cancel".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("Order size below the minimum requirement.".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("Order size increment invalid.".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("The withdrawal amount is below the minimum requirement.".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("Unsuccessful! Exceeded the max. funds out-transfer limit".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("The amount increment is invalid.".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("The quantity is below the minimum requirement.".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("not in the given range!".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("recAccountType not in the given range".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("Unsupported trading pair.".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("400".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("401".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("403".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("404".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("405".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("415".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("429".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("500".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("503".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("101030".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("103000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("112010".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("130101".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("130102".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("130103".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("130104".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("130105".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("130106".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("130107".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("130108".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("130201".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("130202".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("130203".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("130204".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("130301".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("130302".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("130303".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("130304".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("130305".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("130306".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("130307".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("130308".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130309".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130310".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("130311".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130312".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130313".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130314".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130315".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("126000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126001".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("126002".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126004".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126005".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("126006".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126007".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126009".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126010".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126011".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126013".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("126015".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126021".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("126022".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126027".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126028".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126029".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126030".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126033".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126034".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126036".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126037".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126038".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126039".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126041".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126042".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("126043".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("126044".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("126045".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("126046".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("126047".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("126048".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("135005".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("135018".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("200004".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("210014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("210021".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("230003".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("260000".to_string(), Value::Str("InvalidAddress".to_string()).clone());
m.insert("260100".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("300000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("400000".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("400001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("400002".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("400003".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("400004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("400005".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("400006".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("400007".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("400008".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("400100".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("400200".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("400330".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("400350".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("400370".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("400400".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("400401".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("400500".to_string(), Value::Str("RestrictedLocation".to_string()).clone());
m.insert("400600".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("400760".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("401000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("408000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("411100".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("415000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("400303".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("500000".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("260220".to_string(), Value::Str("InvalidAddress".to_string()).clone());
m.insert("600100".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("600101".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("900014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("330012".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("330005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("100001".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("100004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("300003".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("300012".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("404000".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("300009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("330008".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pageSize should not greater than 500".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("Exceeded the access frequency".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("require more permission".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("Position does not exist".to_string(), Value::Str("OrderNotFound".to_string()).clone());
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("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.001".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.001".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.0009".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.0008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("4000".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("8000".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000".to_string()), &[]), self.parse_number(Value::Str("0.00045".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("0.00035".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("60000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("80000".to_string()), &[]), self.parse_number(Value::Str("0.00025".to_string()), &[])])]));
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50".to_string()), &[]), self.parse_number(Value::Str("0.0009".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("4000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("8000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("60000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("80000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])])]));
m
}));
m
}));
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("taker".to_string(), self.parse_number(Value::Str("0.001".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.001".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.0009".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.0008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("4000".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("8000".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000".to_string()), &[]), self.parse_number(Value::Str("0.00045".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("0.00035".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("60000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("80000".to_string()), &[]), self.parse_number(Value::Str("0.00025".to_string()), &[])])]));
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50".to_string()), &[]), self.parse_number(Value::Str("0.0009".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.0007".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("4000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("8000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("60000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("80000".to_string()), &[]), self.parse_number(Value::Str("-0.00005".to_string()), &[])])]));
m
}));
m
}));
m.insert("contract".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("taker".to_string(), self.parse_number(Value::Str("0.0006".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.0005".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("4000".to_string()), &[]), self.parse_number(Value::Str("0.00038".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("8000".to_string()), &[]), self.parse_number(Value::Str("0.00035".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000".to_string()), &[]), self.parse_number(Value::Str("0.00032".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("60000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("80000".to_string()), &[]), self.parse_number(Value::Str("0.0003".to_string()), &[])])]));
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50".to_string()), &[]), self.parse_number(Value::Str("0.015".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("200".to_string()), &[]), self.parse_number(Value::Str("0.01".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.01".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000".to_string()), &[]), self.parse_number(Value::Str("0.01".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("4000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("8000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000".to_string()), &[]), self.parse_number(Value::Str("-0.003".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000".to_string()), &[]), self.parse_number(Value::Str("-0.006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("40000".to_string()), &[]), self.parse_number(Value::Str("-0.009".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("60000".to_string()), &[]), self.parse_number(Value::Str("-0.012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("80000".to_string()), &[]), self.parse_number(Value::Str("-0.015".to_string()), &[])])]));
m
}));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(false));
m.insert("percentage".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BIFI".to_string(), Value::Str("BIFIF".to_string()));
m.insert("VAI".to_string(), Value::Str("VAIOT".to_string()));
m.insert("WAX".to_string(), Value::Str("WAXP".to_string()));
m.insert("ALT".to_string(), Value::Str("APTOSLAUNCHTOKEN".to_string()));
m.insert("KALT".to_string(), Value::Str("ALT".to_string()));
m.insert("FUD".to_string(), Value::Str("FTX Users' Debt".to_string()));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("hf".to_string(), Value::Null);
m.insert("uta".to_string(), Value::Null);
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("symbolSeparator".to_string(), Value::Str("-".to_string()));
m.insert("fetchMyTradesMethod".to_string(), Value::Str("private_get_fills".to_string()));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("brokenCurrencies".to_string(), Value::List(vec![Value::Str("00".to_string()), Value::Str("OPEN_ERROR".to_string()), Value::Str("HUF".to_string()), Value::Str("BDT".to_string())]));
m
}));
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("types".to_string(), Value::List(vec![Value::Str("spot".to_string()), Value::Str("swap".to_string()), Value::Str("future".to_string()), Value::Str("contract".to_string())]));
m.insert("fetchTickersFees".to_string(), Value::Bool(true));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("includeFee".to_string(), Value::Bool(false));
m
}));
m.insert("transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fillResponseFromRequest".to_string(), Value::Bool(true));
m
}));
m.insert("fetchBalance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("code".to_string(), Value::Str("USDT".to_string()));
m
}));
m.insert("setLeverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("code".to_string(), Value::Str("USDT".to_string()));
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Str("IOC".to_string()));
m.insert("FOK".to_string(), Value::Str("FOK".to_string()));
m.insert("PO".to_string(), Value::Str("PO".to_string()));
m.insert("GTD".to_string(), Value::Str("GTT".to_string()));
m.insert("RPI".to_string(), Value::Str("RPI".to_string()));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Int(1));
m.insert("3m".to_string(), Value::Null);
m.insert("5m".to_string(), Value::Int(5));
m.insert("15m".to_string(), Value::Int(15));
m.insert("30m".to_string(), Value::Int(30));
m.insert("1h".to_string(), Value::Int(60));
m.insert("2h".to_string(), Value::Int(120));
m.insert("4h".to_string(), Value::Int(240));
m.insert("6h".to_string(), Value::Null);
m.insert("8h".to_string(), Value::Int(480));
m.insert("12h".to_string(), Value::Int(720));
m.insert("1d".to_string(), Value::Int(1440));
m.insert("1w".to_string(), Value::Int(10080));
m
}));
m
}));
m.insert("versions".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("currencies".to_string(), Value::Str("v3".to_string()));
m.insert("currencies/{currency}".to_string(), Value::Str("v3".to_string()));
m.insert("symbols".to_string(), Value::Str("v2".to_string()));
m.insert("mark-price/all-symbols".to_string(), Value::Str("v3".to_string()));
m.insert("announcements".to_string(), Value::Str("v3".to_string()));
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("user-info".to_string(), Value::Str("v2".to_string()));
m.insert("hf/margin/account/ledgers".to_string(), Value::Str("v3".to_string()));
m.insert("sub/user".to_string(), Value::Str("v2".to_string()));
m.insert("sub-accounts".to_string(), Value::Str("v2".to_string()));
m.insert("margin/accounts".to_string(), Value::Str("v3".to_string()));
m.insert("isolated/accounts".to_string(), Value::Str("v3".to_string()));
m.insert("deposit-addresses".to_string(), Value::Str("v1".to_string()));
m.insert("market/orderbook/level2".to_string(), Value::Str("v3".to_string()));
m.insert("market/orderbook/level3".to_string(), Value::Str("v3".to_string()));
m.insert("market/orderbook/level{level}".to_string(), Value::Str("v3".to_string()));
m.insert("oco/order/{orderId}".to_string(), Value::Str("v3".to_string()));
m.insert("oco/order/details/{orderId}".to_string(), Value::Str("v3".to_string()));
m.insert("oco/client-order/{clientOid}".to_string(), Value::Str("v3".to_string()));
m.insert("oco/orders".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/orders/active".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/order/active/symbols".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/orders/done".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/orders/{orderId}".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/orders/client-order/{clientOid}".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/fills".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/stop-orders".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/stop-order/orderId".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/stop-order/clientOid".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-order/orderId".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-order/clientOid".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-order/detail/orderId".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-orders".to_string(), Value::Str("v3".to_string()));
m.insert("etf/info".to_string(), Value::Str("v3".to_string()));
m.insert("margin/currencies".to_string(), Value::Str("v3".to_string()));
m.insert("margin/borrow".to_string(), Value::Str("v3".to_string()));
m.insert("margin/repay".to_string(), Value::Str("v3".to_string()));
m.insert("margin/interest".to_string(), Value::Str("v3".to_string()));
m.insert("project/list".to_string(), Value::Str("v3".to_string()));
m.insert("project/marketInterestRate".to_string(), Value::Str("v3".to_string()));
m.insert("redeem/orders".to_string(), Value::Str("v3".to_string()));
m.insert("purchase/orders".to_string(), Value::Str("v3".to_string()));
m.insert("migrate/user/account/status".to_string(), Value::Str("v3".to_string()));
m.insert("margin/symbols".to_string(), Value::Str("v3".to_string()));
m.insert("affiliate/inviter/statistics".to_string(), Value::Str("v2".to_string()));
m.insert("asset/ndbroker/deposit/list".to_string(), Value::Str("v1".to_string()));
m
}));
m.insert("POST".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sub/user/created".to_string(), Value::Str("v2".to_string()));
m.insert("accounts/universal-transfer".to_string(), Value::Str("v3".to_string()));
m.insert("accounts/sub-transfer".to_string(), Value::Str("v2".to_string()));
m.insert("accounts/inner-transfer".to_string(), Value::Str("v2".to_string()));
m.insert("transfer-out".to_string(), Value::Str("v3".to_string()));
m.insert("deposit-address/create".to_string(), Value::Str("v3".to_string()));
m.insert("oco/order".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/order".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/order/test".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/stop-order".to_string(), Value::Str("v3".to_string()));
m.insert("margin/borrow".to_string(), Value::Str("v3".to_string()));
m.insert("margin/repay".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-order".to_string(), Value::Str("v3".to_string()));
m.insert("purchase".to_string(), Value::Str("v3".to_string()));
m.insert("redeem".to_string(), Value::Str("v3".to_string()));
m.insert("lend/purchase/update".to_string(), Value::Str("v3".to_string()));
m.insert("position/update-user-leverage".to_string(), Value::Str("v3".to_string()));
m.insert("withdrawals".to_string(), Value::Str("v3".to_string()));
m
}));
m.insert("DELETE".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("hf/margin/orders/{orderId}".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/orders/client-order/{clientOid}".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/orders".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/stop-order/cancel-by-id".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/stop-order/cancel-by-clientOid".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/stop-order/cancel".to_string(), Value::Str("v3".to_string()));
m.insert("oco/order/{orderId}".to_string(), Value::Str("v3".to_string()));
m.insert("oco/client-order/{clientOid}".to_string(), Value::Str("v3".to_string()));
m.insert("oco/orders".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-order/cancel-by-id".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-order/cancel-by-clientOid".to_string(), Value::Str("v3".to_string()));
m.insert("hf/margin/oco-order/cancel".to_string(), Value::Str("v3".to_string()));
m
}));
m
}));
m.insert("futuresPrivate".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("getMaxOpenSize".to_string(), Value::Str("v2".to_string()));
m.insert("getCrossUserLeverage".to_string(), Value::Str("v2".to_string()));
m.insert("position/getMarginMode".to_string(), Value::Str("v2".to_string()));
m.insert("position/getPositionMode".to_string(), Value::Str("v2".to_string()));
m
}));
m.insert("POST".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("transfer-out".to_string(), Value::Str("v2".to_string()));
m.insert("changeCrossUserLeverage".to_string(), Value::Str("v2".to_string()));
m.insert("position/changeMarginMode".to_string(), Value::Str("v2".to_string()));
m.insert("position/switchPositionMode".to_string(), Value::Str("v2".to_string()));
m
}));
m
}));
m.insert("futuresPublic".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("level3/snapshot".to_string(), Value::Str("v2".to_string()));
m
}));
m
}));
m
}));
m.insert("partner".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("id".to_string(), Value::Str("ccxt".to_string()));
m.insert("key".to_string(), Value::Str("9e58cc35-5b5e-4133-92ec-166e3f077cb8".to_string()));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("ccxtfutures".to_string()));
m.insert("key".to_string(), Value::Str("1b327198-f30c-4f14-a0ac-918871282f15".to_string()));
m
}));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("trade".to_string()));
m.insert("margin".to_string(), Value::Str("margin".to_string()));
m.insert("cross".to_string(), Value::Str("margin".to_string()));
m.insert("marginV2".to_string(), Value::Str("margin".to_string()));
m.insert("isolated".to_string(), Value::Str("isolated".to_string()));
m.insert("main".to_string(), Value::Str("main".to_string()));
m.insert("funding".to_string(), Value::Str("main".to_string()));
m.insert("future".to_string(), Value::Str("contract".to_string()));
m.insert("swap".to_string(), Value::Str("contract".to_string()));
m.insert("mining".to_string(), Value::Str("pool".to_string()));
m.insert("hf".to_string(), Value::Str("trade_hf".to_string()));
m.insert("contract".to_string(), Value::Str("contract".to_string()));
m.insert("uta".to_string(), Value::Str("unified".to_string()));
m.insert("unified".to_string(), Value::Str("unified".to_string()));
m
}));
m.insert("utaAccountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade".to_string(), Value::Str("SPOT".to_string()));
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("margin".to_string(), Value::Str("CROSS".to_string()));
m.insert("cross".to_string(), Value::Str("CROSS".to_string()));
m.insert("isolated".to_string(), Value::Str("ISOLATED".to_string()));
m.insert("main".to_string(), Value::Str("FUNDING".to_string()));
m.insert("funding".to_string(), Value::Str("FUNDING".to_string()));
m.insert("future".to_string(), Value::Str("FUTURES".to_string()));
m.insert("swap".to_string(), Value::Str("FUTURES".to_string()));
m.insert("contract".to_string(), Value::Str("FUTURES".to_string()));
m.insert("uta".to_string(), Value::Str("unified".to_string()));
m.insert("unified".to_string(), Value::Str("unified".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("btc".to_string()));
m.insert("BRC20".to_string(), Value::Str("btc".to_string()));
m.insert("BTCNATIVESEGWIT".to_string(), Value::Str("bech32".to_string()));
m.insert("ETH".to_string(), Value::Str("eth".to_string()));
m.insert("ERC20".to_string(), Value::Str("eth".to_string()));
m.insert("TRX".to_string(), Value::Str("trx".to_string()));
m.insert("TRC20".to_string(), Value::Str("trx".to_string()));
m.insert("HECO".to_string(), Value::Str("heco".to_string()));
m.insert("HRC20".to_string(), Value::Str("heco".to_string()));
m.insert("MATIC".to_string(), Value::Str("matic".to_string()));
m.insert("KCC".to_string(), Value::Str("kcc".to_string()));
m.insert("SOL".to_string(), Value::Str("sol".to_string()));
m.insert("ALGO".to_string(), Value::Str("algo".to_string()));
m.insert("EOS".to_string(), Value::Str("eos".to_string()));
m.insert("BEP20".to_string(), Value::Str("bsc".to_string()));
m.insert("BEP2".to_string(), Value::Str("bnb".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("arbitrum".to_string()));
m.insert("AVAXX".to_string(), Value::Str("avax".to_string()));
m.insert("AVAXC".to_string(), Value::Str("avaxc".to_string()));
m.insert("TLOS".to_string(), Value::Str("tlos".to_string()));
m.insert("CFX".to_string(), Value::Str("cfx".to_string()));
m.insert("ACA".to_string(), Value::Str("aca".to_string()));
m.insert("OP".to_string(), Value::Str("optimism".to_string()));
m.insert("OPTIMISM".to_string(), Value::Str("optimism".to_string()));
m.insert("ONT".to_string(), Value::Str("ont".to_string()));
m.insert("GLMR".to_string(), Value::Str("glmr".to_string()));
m.insert("CSPR".to_string(), Value::Str("cspr".to_string()));
m.insert("KLAY".to_string(), Value::Str("klay".to_string()));
m.insert("XRD".to_string(), Value::Str("xrd".to_string()));
m.insert("RVN".to_string(), Value::Str("rvn".to_string()));
m.insert("NEAR".to_string(), Value::Str("near".to_string()));
m.insert("APT".to_string(), Value::Str("aptos".to_string()));
m.insert("ETHW".to_string(), Value::Str("ethw".to_string()));
m.insert("TON".to_string(), Value::Str("ton".to_string()));
m.insert("BCH".to_string(), Value::Str("bch".to_string()));
m.insert("BSV".to_string(), Value::Str("bchsv".to_string()));
m.insert("BCHA".to_string(), Value::Str("bchabc".to_string()));
m.insert("OSMO".to_string(), Value::Str("osmo".to_string()));
m.insert("NANO".to_string(), Value::Str("nano".to_string()));
m.insert("XLM".to_string(), Value::Str("xlm".to_string()));
m.insert("VET".to_string(), Value::Str("vet".to_string()));
m.insert("IOST".to_string(), Value::Str("iost".to_string()));
m.insert("ZIL".to_string(), Value::Str("zil".to_string()));
m.insert("XRP".to_string(), Value::Str("xrp".to_string()));
m.insert("TOMO".to_string(), Value::Str("tomo".to_string()));
m.insert("XMR".to_string(), Value::Str("xmr".to_string()));
m.insert("COTI".to_string(), Value::Str("coti".to_string()));
m.insert("XTZ".to_string(), Value::Str("xtz".to_string()));
m.insert("ADA".to_string(), Value::Str("ada".to_string()));
m.insert("WAX".to_string(), Value::Str("waxp".to_string()));
m.insert("THETA".to_string(), Value::Str("theta".to_string()));
m.insert("ONE".to_string(), Value::Str("one".to_string()));
m.insert("IOTEX".to_string(), Value::Str("iotx".to_string()));
m.insert("NULS".to_string(), Value::Str("nuls".to_string()));
m.insert("KSM".to_string(), Value::Str("ksm".to_string()));
m.insert("LTC".to_string(), Value::Str("ltc".to_string()));
m.insert("WAVES".to_string(), Value::Str("waves".to_string()));
m.insert("DOT".to_string(), Value::Str("dot".to_string()));
m.insert("STEEM".to_string(), Value::Str("steem".to_string()));
m.insert("QTUM".to_string(), Value::Str("qtum".to_string()));
m.insert("DOGE".to_string(), Value::Str("doge".to_string()));
m.insert("FIL".to_string(), Value::Str("fil".to_string()));
m.insert("XYM".to_string(), Value::Str("xym".to_string()));
m.insert("FLUX".to_string(), Value::Str("flux".to_string()));
m.insert("ATOM".to_string(), Value::Str("atom".to_string()));
m.insert("XDC".to_string(), Value::Str("xdc".to_string()));
m.insert("KDA".to_string(), Value::Str("kda".to_string()));
m.insert("ICP".to_string(), Value::Str("icp".to_string()));
m.insert("CELO".to_string(), Value::Str("celo".to_string()));
m.insert("LSK".to_string(), Value::Str("lsk".to_string()));
m.insert("VSYS".to_string(), Value::Str("vsys".to_string()));
m.insert("KAR".to_string(), Value::Str("kar".to_string()));
m.insert("XCH".to_string(), Value::Str("xch".to_string()));
m.insert("FLOW".to_string(), Value::Str("flow".to_string()));
m.insert("BAND".to_string(), Value::Str("band".to_string()));
m.insert("EGLD".to_string(), Value::Str("egld".to_string()));
m.insert("HBAR".to_string(), Value::Str("hbar".to_string()));
m.insert("XPR".to_string(), Value::Str("xpr".to_string()));
m.insert("AR".to_string(), Value::Str("ar".to_string()));
m.insert("FTM".to_string(), Value::Str("ftm".to_string()));
m.insert("KAVA".to_string(), Value::Str("kava".to_string()));
m.insert("KMA".to_string(), Value::Str("kma".to_string()));
m.insert("XEC".to_string(), Value::Str("xec".to_string()));
m.insert("IOTA".to_string(), Value::Str("iota".to_string()));
m.insert("HNT".to_string(), Value::Str("hnt".to_string()));
m.insert("ASTR".to_string(), Value::Str("astr".to_string()));
m.insert("PDEX".to_string(), Value::Str("pdex".to_string()));
m.insert("METIS".to_string(), Value::Str("metis".to_string()));
m.insert("ZEC".to_string(), Value::Str("zec".to_string()));
m.insert("POKT".to_string(), Value::Str("pokt".to_string()));
m.insert("OASYS".to_string(), Value::Str("oas".to_string()));
m.insert("OASIS".to_string(), Value::Str("oasis".to_string()));
m.insert("ETC".to_string(), Value::Str("etc".to_string()));
m.insert("AKT".to_string(), Value::Str("akt".to_string()));
m.insert("FSN".to_string(), Value::Str("fsn".to_string()));
m.insert("SCRT".to_string(), Value::Str("scrt".to_string()));
m.insert("CFG".to_string(), Value::Str("cfg".to_string()));
m.insert("ICX".to_string(), Value::Str("icx".to_string()));
m.insert("KMD".to_string(), Value::Str("kmd".to_string()));
m.insert("NEM".to_string(), Value::Str("NEM".to_string()));
m.insert("STX".to_string(), Value::Str("stx".to_string()));
m.insert("DGB".to_string(), Value::Str("dgb".to_string()));
m.insert("DCR".to_string(), Value::Str("dcr".to_string()));
m.insert("CKB".to_string(), Value::Str("ckb".to_string()));
m.insert("ELA".to_string(), Value::Str("ela".to_string()));
m.insert("HYDRA".to_string(), Value::Str("hydra".to_string()));
m.insert("BTM".to_string(), Value::Str("btm".to_string()));
m.insert("KARDIA".to_string(), Value::Str("kai".to_string()));
m.insert("SXP".to_string(), Value::Str("sxp".to_string()));
m.insert("NEBL".to_string(), Value::Str("nebl".to_string()));
m.insert("ZEN".to_string(), Value::Str("zen".to_string()));
m.insert("SDN".to_string(), Value::Str("sdn".to_string()));
m.insert("LTO".to_string(), Value::Str("lto".to_string()));
m.insert("WEMIX".to_string(), Value::Str("wemix".to_string()));
m.insert("EVER".to_string(), Value::Str("ever".to_string()));
m.insert("BNC".to_string(), Value::Str("bnc".to_string()));
m.insert("BNCDOT".to_string(), Value::Str("bncdot".to_string()));
m.insert("AION".to_string(), Value::Str("aion".to_string()));
m.insert("GRIN".to_string(), Value::Str("grin".to_string()));
m.insert("LOKI".to_string(), Value::Str("loki".to_string()));
m.insert("QKC".to_string(), Value::Str("qkc".to_string()));
m.insert("TT".to_string(), Value::Str("TT".to_string()));
m.insert("PIVX".to_string(), Value::Str("pivx".to_string()));
m.insert("SERO".to_string(), Value::Str("sero".to_string()));
m.insert("METER".to_string(), Value::Str("meter".to_string()));
m.insert("STATEMINE".to_string(), Value::Str("statemine".to_string()));
m.insert("DVPN".to_string(), Value::Str("dvpn".to_string()));
m.insert("XPRT".to_string(), Value::Str("xprt".to_string()));
m.insert("MOVR".to_string(), Value::Str("movr".to_string()));
m.insert("ERGO".to_string(), Value::Str("ergo".to_string()));
m.insert("ABBC".to_string(), Value::Str("abbc".to_string()));
m.insert("DIVI".to_string(), Value::Str("divi".to_string()));
m.insert("PURA".to_string(), Value::Str("pura".to_string()));
m.insert("DFI".to_string(), Value::Str("dfi".to_string()));
m.insert("NEON3".to_string(), Value::Str("neon3".to_string()));
m.insert("DOCK".to_string(), Value::Str("dock".to_string()));
m.insert("TRUE".to_string(), Value::Str("true".to_string()));
m.insert("CS".to_string(), Value::Str("cs".to_string()));
m.insert("ORAI".to_string(), Value::Str("orai".to_string()));
m.insert("BASE".to_string(), Value::Str("base".to_string()));
m.insert("TARA".to_string(), Value::Str("tara".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("btc".to_string(), Value::Str("BTC".to_string()));
m.insert("trx".to_string(), Value::Str("TRC20".to_string()));
m.insert("eth".to_string(), Value::Str("ERC20".to_string()));
m.insert("heco".to_string(), Value::Str("HRC20".to_string()));
m.insert("optimism".to_string(), Value::Str("OP".to_string()));
m.insert("op".to_string(), Value::Str("OP".to_string()));
m
}));
m.insert("marginModes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cross".to_string(), Value::Str("MARGIN_TRADE".to_string()));
m.insert("isolated".to_string(), Value::Str("MARGIN_ISOLATED_TRADE".to_string()));
m.insert("spot".to_string(), Value::Str("TRADE".to_string()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(true));
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(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(true));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(5));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Null);
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(500));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(500));
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1500));
m
}));
m
}));
m.insert("forDerivs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("triggerDirection".to_string(), Value::Bool(true));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("price".to_string(), Value::Bool(true));
m
}));
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(false));
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(true));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(true));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(20));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
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(true));
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::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::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(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("forDerivs".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivs".to_string()));
m
}));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivs".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forDerivs".to_string()));
m
}));
m
}));
m
}));
m.insert("rollingWindowSize".to_string(), Value::Int(30000));
m
})]);
Value::Null
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
/*
* @method
* @name kucoin#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-server-time
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-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 type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTime".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&(!is_equal(&type_var, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(&type_var, &Value::Str("margin".to_string())))) {
//
// {
// "code": "200000",
// "data": 1637385119302,
// }
//
response = self.futures_public_get_timestamp(&[params.clone()]).await;
} else {
//
// {
// "code":"200000",
// "msg":"success",
// "data":1546837113087
// }
//
response = self.public_get_timestamp(&[params.clone()]).await;
}
return self.safe_integer_k(response.clone(), "data", &[]);
Value::Null
}
/*
* @method
* @name kucoin#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-service-status
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-service-status
* @see https://www.kucoin.com/docs-new/rest/ua/get-service-status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] spot or swap
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @param {string} [params.tradeType] *uta only* set to SPOT or FUTURES
* @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 uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchStatus".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchStatus".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&uta) {
let mut defaultType: Value = self.safe_string_k(self.options.clone(), "defaultType", &[Value::Str("spot".to_string())]);
let mut defaultTradeType: Value = ternary(is_true(&(is_equal(&defaultType, &Value::Str("spot".to_string())))), Value::Str("SPOT".to_string()), Value::Str("FUTURES".to_string()));
let mut tradeType: Value = self.safe_string_upper(params.clone(), Value::Str("tradeType".to_string()), &[defaultTradeType.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradeType".to_string(), tradeType.clone());
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_get_server_status(&[__ws_arg_0]).await;
} else if is_true(&(!is_equal(&type_var, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(&type_var, &Value::Str("margin".to_string())))) {
response = self.futures_public_get_status(&[params.clone()]).await;
} else {
response = self.public_get_status(&[params.clone()]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut status: Value = self.safe_string2(data.clone(), Value::Str("status".to_string()), Value::Str("serverStatus".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), ternary(is_true(&(is_equal(&status, &Value::Str("open".to_string())))), Value::Str("ok".to_string()), Value::Str("maintenance".to_string())));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchMarkets
* @description retrieves data on all markets for kucoin
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-symbols
* @see https://www.kucoin.com/docs-new/rest/ua/get-symbol
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-all-symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @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 fetchTickersFees: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMarkets".to_string()), Value::Str("fetchTickersFees".to_string()), &[Value::Bool(true)]); fetchTickersFees = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMarkets".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
return self.fetch_uta_markets(&[params.clone()]).await;
}
let mut defaultTypes: Value = Value::List(vec![Value::Str("spot".to_string()), Value::Str("swap".to_string()), Value::Str("future".to_string()), Value::Str("contract".to_string())]);
let mut fetchMarketsOptions: Value = self.safe_dict_k(self.options.clone(), "fetchMarkets", &[]);
let mut types: Value = self.safe_list_k(fetchMarketsOptions.clone(), "types", &[defaultTypes.clone()]);
let mut credentialsSet: Value = self.check_required_credentials(&[Value::Bool(false)]);
let mut requestMarginables: Value = Value::Bool(is_true(&credentialsSet) && is_true(&self.safe_bool_k(params.clone(), "marginables", &[Value::Bool(true)])));
params = self.omit(params.clone(), Value::Str("marginables".to_string()), &[]);
let mut fetchContractMarkets: bool = false;
if is_true(&self.in_array(Value::Str("swap".to_string()), types.clone())) || is_true(&self.in_array(Value::Str("future".to_string()), types.clone())) || is_true(&self.in_array(Value::Str("contract".to_string()), types.clone())) {
fetchContractMarkets = true;
}
let mut fetchSpotMarkets: Value = self.in_array(Value::Str("spot".to_string()), types.clone());
fetchTickersFees = Value::Bool(is_true(&fetchTickersFees) && is_true(&fetchSpotMarkets)); // tickers and fees are only fetched for spot markets
let mut promises: Value = Value::List(vec![]);
if is_true(&fetchSpotMarkets) {
append_to_array(&mut promises, self.public_get_symbols(&[params.clone()]).await);
}
if is_equal(&requestMarginables, &Value::Bool(true)) {
append_to_array(&mut promises, self.private_get_margin_symbols(&[params.clone()]).await); // cross margin symbols
//
// {
// "code": "200000",
// "data": {
// "timestamp": 1719393213421,
// "items": [
// {
// // same object as in market, with one additional field:
// "minFunds": "0.1"
// },
//
append_to_array(&mut promises, self.private_get_isolated_symbols(&[params.clone()]).await); // isolated margin symbols
}
if is_true(&fetchTickersFees) {
//
// {
// "code": "200000",
// "data": {
// "time":1602832092060,
// "ticker":[
// {
// "symbol": "BTC-USDT", // symbol
// "symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
// "buy": "11328.9", // bestAsk
// "sell": "11329", // bestBid
// "changeRate": "-0.0055", // 24h change rate
// "changePrice": "-63.6", // 24h change price
// "high": "11610", // 24h highest price
// "low": "11200", // 24h lowest price
// "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
// "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
// "last": "11328.9", // last price
// "averagePrice": "11360.66065903", // 24h average transaction price yesterday
// "takerFeeRate": "0.001", // Basic Taker Fee
// "makerFeeRate": "0.001", // Basic Maker Fee
// "takerCoefficient": "1", // Taker Fee Coefficient
// "makerCoefficient": "1" // Maker Fee Coefficient
// }
//
append_to_array(&mut promises, self.public_get_market_all_tickers(&[params.clone()]).await);
}
if is_true(&fetchContractMarkets) {
append_to_array(&mut promises, self.fetch_contract_markets(&[params.clone()]).await);
}
if is_true(&credentialsSet) {
// load migration status for account
append_to_array(&mut promises, self.load_migration_status(&[]).await);
}
let mut responses: Value = promise_all(&promises).await;
let mut symbolsData: Value = ternary(is_true(&fetchSpotMarkets), self.safe_list(get_value(&responses, &Value::Int(0)), Value::Str("data".to_string()), &[Value::List(vec![])]), Value::List(vec![]));
let mut crossIndex: Value = Value::Int(0);
let mut isolatedIndex: Value = Value::Int(0);
let mut tickersIndex: Value = Value::Int(0);
let mut contractIndex: Value = Value::Int(0);
let mut nextIndex: Value = Value::Int(0);
if is_true(&fetchSpotMarkets) {
nextIndex = Value::Int(1);
}
if is_equal(&requestMarginables, &Value::Bool(true)) {
crossIndex = nextIndex.clone();
nextIndex = self.sum(&[nextIndex.clone(), Value::Int(2)]);
isolatedIndex = self.sum(&[crossIndex.clone(), Value::Int(1)]);
}
if is_true(&fetchTickersFees) {
tickersIndex = nextIndex.clone();
nextIndex = self.sum(&[nextIndex.clone(), Value::Int(1)]);
}
if is_true(&fetchContractMarkets) {
contractIndex = nextIndex.clone();
}
let mut crossData: Value = ternary(is_true(&(is_equal(&requestMarginables, &Value::Bool(true)))), self.safe_dict_k(get_value(&responses, &crossIndex), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut crossItems: Value = self.safe_list_k(crossData.clone(), "items", &[Value::List(vec![])]);
let mut crossById: Value = self.index_by(crossItems.clone(), Value::Str("symbol".to_string()));
let mut isolatedData: Value = ternary(is_true(&(is_equal(&requestMarginables, &Value::Bool(true)))), get_value(&responses, &isolatedIndex), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut isolatedItems: Value = self.safe_list_k(isolatedData.clone(), "data", &[Value::List(vec![])]);
let mut isolatedById: Value = self.index_by(isolatedItems.clone(), Value::Str("symbol".to_string()));
let mut tickersResponse: Value = ternary(is_true(&fetchTickersFees), self.safe_dict(responses.clone(), tickersIndex.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut tickerItems: Value = self.safe_list(self.safe_dict_k(tickersResponse.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), Value::Str("ticker".to_string()), &[Value::List(vec![])]);
let mut tickersById: Value = self.index_by(tickerItems.clone(), Value::Str("symbol".to_string()));
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_877: bool = true;
while { if !__for_first_877 { i = add(&i, &Value::Int(1)); } __for_first_877 = false; is_less_than(&i, &get_array_length(&symbolsData)) } {
let mut market: Value = get_value(&symbolsData, &i);
let mut market: Value = get_value(&symbolsData, &i);
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
if is_equal(&id, &Value::Null) {
continue;
}
let mut baseIdquoteIdVariable = split(&id, &Value::Str("-".to_string()));
let mut baseId: Value = get_value(&baseIdquoteIdVariable, &Value::Int(0));
let mut quoteId: Value = get_value(&baseIdquoteIdVariable, &Value::Int(1));
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
// const quoteIncrement = this.safeNumber (market, 'quoteIncrement');
let mut ticker: Value = self.safe_dict(tickersById.clone(), id.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut makerFeeRate: Value = self.safe_string_k(ticker.clone(), "makerFeeRate", &[]);
let mut takerFeeRate: Value = self.safe_string_k(ticker.clone(), "takerFeeRate", &[]);
let mut makerCoefficient: Value = self.safe_string_k(ticker.clone(), "makerCoefficient", &[]);
let mut takerCoefficient: Value = self.safe_string_k(ticker.clone(), "takerCoefficient", &[]);
let mut hasCrossMargin: Value = (Value::Bool(in_op(&crossById, &id)));
let mut hasIsolatedMargin: Value = (Value::Bool(in_op(&isolatedById, &id)));
let mut isMarginable: Value = Value::Bool(is_true(&self.safe_bool_k(market.clone(), "isMarginEnabled", &[Value::Bool(false)])) || is_true(&hasCrossMargin) || is_true(&hasIsolatedMargin));
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), add(&add(&base, &Value::Str("/".to_string())), "e));
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".to_string()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), isMarginable.clone());
m.insert("marginModes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cross".to_string(), hasCrossMargin.clone());
m.insert("isolated".to_string(), hasIsolatedMargin.clone());
m
}));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), self.safe_bool_k(market.clone(), "enableTrading", &[]));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringMul(&takerFeeRate, &takerCoefficient), &[]));
m.insert("maker".to_string(), self.parse_number(crate::precise::Precise::stringMul(&makerFeeRate, &makerCoefficient), &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(market.clone(), "baseIncrement", &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "priceIncrement", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "baseMinSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "baseMaxSize", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "quoteMinSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "quoteMaxSize", &[]));
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
}));
}
}
if is_true(&fetchContractMarkets) {
let mut contractMarkets: Value = self.safe_list(responses.clone(), contractIndex.clone(), &[Value::List(vec![])]);
result = self.array_concat(result.clone(), contractMarkets.clone());
}
if is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
return result;
Value::Null
}
pub async fn fetch_contract_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 response: Value = self.futures_public_get_contracts_active(&[params.clone()]).await;
//
// {
// "code": "200000",
// "data": {
// "symbol": "ETHUSDTM",
// "rootSymbol": "USDT",
// "type": "FFWCSX",
// "firstOpenDate": 1591086000000,
// "expireDate": null,
// "settleDate": null,
// "baseCurrency": "ETH",
// "quoteCurrency": "USDT",
// "settleCurrency": "USDT",
// "maxOrderQty": 1000000,
// "maxPrice": 1000000.0000000000,
// "lotSize": 1,
// "tickSize": 0.05,
// "indexPriceTickSize": 0.01,
// "multiplier": 0.01,
// "initialMargin": 0.01,
// "maintainMargin": 0.005,
// "maxRiskLimit": 1000000,
// "minRiskLimit": 1000000,
// "riskStep": 500000,
// "makerFeeRate": 0.00020,
// "takerFeeRate": 0.00060,
// "takerFixFee": 0.0000000000,
// "makerFixFee": 0.0000000000,
// "settlementFee": null,
// "isDeleverage": true,
// "isQuanto": true,
// "isInverse": false,
// "markMethod": "FairPrice",
// "fairMethod": "FundingRate",
// "fundingBaseSymbol": ".ETHINT8H",
// "fundingQuoteSymbol": ".USDTINT8H",
// "fundingRateSymbol": ".ETHUSDTMFPI8H",
// "indexSymbol": ".KETHUSDT",
// "settlementSymbol": "",
// "status": "Open",
// "fundingFeeRate": 0.000535,
// "predictedFundingFeeRate": 0.002197,
// "openInterest": "8724443",
// "turnoverOf24h": 341156641.03354263,
// "volumeOf24h": 74833.54000000,
// "markPrice": 4534.07,
// "indexPrice":4531.92,
// "lastTradePrice": 4545.4500000000,
// "nextFundingRateTime": 25481884,
// "maxLeverage": 100,
// "sourceExchanges": [ "huobi", "Okex", "Binance", "Kucoin", "Poloniex", "Hitbtc" ],
// "premiumsSymbol1M": ".ETHUSDTMPI",
// "premiumsSymbol8H": ".ETHUSDTMPI8H",
// "fundingBaseSymbol1M": ".ETHINT",
// "fundingQuoteSymbol1M": ".USDTINT",
// "lowPrice": 4456.90,
// "highPrice": 4674.25,
// "priceChgPct": 0.0046,
// "priceChg": 21.15
// }
// }
//
let mut result: Value = Value::List(vec![]);
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_878: bool = true;
while { if !__for_first_878 { i = add(&i, &Value::Int(1)); } __for_first_878 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut market: Value = get_value(&data, &i);
let mut market: Value = get_value(&data, &i);
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut expiry: Value = self.safe_integer_k(market.clone(), "expireDate", &[]);
let mut future: Value = Value::Bool(is_equal(&self.safe_string_k(market.clone(), "nextFundingRateTime", &[]), &Value::Null));
let mut swap: Value = Value::Bool(!is_true(&future));
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCurrency", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCurrency", &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "settleCurrency", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut symbol: Value = add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle);
let mut type_var: Value = Value::Str("swap".to_string());
if is_true(&future) {
symbol = add(&add(&symbol, &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[Value::Str("".to_string())]));
type_var = Value::Str("future".to_string());
}
let mut inverse: Value = self.safe_value_k(market.clone(), "isInverse", &[]);
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut multiplier: Value = self.safe_string_k(market.clone(), "multiplier", &[]);
let mut tickSize: Value = self.safe_number_k(market.clone(), "tickSize", &[]);
let mut lotSize: Value = self.safe_number_k(market.clone(), "lotSize", &[]);
let mut limitAmountMin: Value = lotSize.clone();
if is_equal(&limitAmountMin, &Value::Null) {
limitAmountMin = self.safe_number_k(market.clone(), "baseMinSize", &[]);
}
let mut limitAmountMax: Value = self.safe_number_k(market.clone(), "maxOrderQty", &[]);
if is_equal(&limitAmountMax, &Value::Null) {
limitAmountMax = self.safe_number_k(market.clone(), "baseMaxSize", &[]);
}
let mut limitPriceMax: Value = self.safe_number_k(market.clone(), "maxPrice", &[]);
if is_equal(&limitPriceMax, &Value::Null) {
let mut baseMinSizeString: Value = self.safe_string_k(market.clone(), "baseMinSize", &[]);
let mut quoteMaxSizeString: Value = self.safe_string_k(market.clone(), "quoteMaxSize", &[]);
limitPriceMax = self.parse_number(crate::precise::Precise::stringDiv("eMaxSizeString, &baseMinSizeString), &[]);
}
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), future.clone());
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool((is_equal(&status, &Value::Str("Open".to_string())))));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), Value::Bool((!is_equal(&inverse, &Value::Bool(true)))));
m.insert("inverse".to_string(), inverse.clone());
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "takerFeeRate", &[]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "makerFeeRate", &[]));
m.insert("contractSize".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&multiplier), &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), lotSize.clone());
m.insert("price".to_string(), tickSize.clone());
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxLeverage", &[]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), limitAmountMin.clone());
m.insert("max".to_string(), limitAmountMax.clone());
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), tickSize.clone());
m.insert("max".to_string(), limitPriceMax.clone());
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "quoteMinSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "quoteMaxSize", &[]));
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer_k(market.clone(), "firstOpenDate", &[]));
m.insert("info".to_string(), market.clone());
m
}));
}
}
return result;
Value::Null
}
pub async fn fetch_uta_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 promises: Value = Value::List(vec![]);
let __ws_arg_1 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradeType".to_string(), Value::Str("SPOT".to_string()));
m
})]);
append_to_array(&mut promises, self.uta_get_market_instrument(&[__ws_arg_1]).await);
//
// {
// "code": "200000",
// "data": {
// "tradeType": "SPOT",
// "list": [
// {
// "symbol": "AVA-USDT",
// "name": "AVA-USDT",
// "baseCurrency": "AVA",
// "quoteCurrency": "USDT",
// "market": "USDS",
// "minBaseOrderSize": "0.1",
// "minQuoteOrderSize": "0.1",
// "maxBaseOrderSize": "10000000000",
// "maxQuoteOrderSize": "99999999",
// "baseOrderStep": "0.01",
// "quoteOrderStep": "0.0001",
// "tickSize": "0.0001",
// "feeCurrency": "USDT",
// "tradingStatus": "1",
// "marginMode": "2",
// "priceLimitRatio": "0.05",
// "feeCategory": 1,
// "makerFeeCoefficient": "1.00",
// "takerFeeCoefficient": "1.00",
// "st": false
// },
// ]
// }
// }
//
let __ws_arg_2 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradeType".to_string(), Value::Str("FUTURES".to_string()));
m
})]);
append_to_array(&mut promises, self.uta_get_market_instrument(&[__ws_arg_2]).await);
//
// {
// "code": "200000",
// "data": {
// "tradeType": "FUTURES",
// "list": [
// {
// "symbol": "XBTUSDTM",
// "baseCurrency": "XBT",
// "quoteCurrency": "USDT",
// "maxBaseOrderSize": "1000000",
// "tickSize": "0.1",
// "tradingStatus": "1",
// "settlementCurrency": "USDT",
// "contractType": "0",
// "isInverse": false,
// "launchTime": 1585555200000,
// "expiryTime": null,
// "settlementTime": null,
// "maxPrice": "1000000.0",
// "lotSize": "1",
// "unitSize": "0.001",
// "makerFeeRate": "0.00020",
// "takerFeeRate": "0.00060",
// "settlementFeeRate": null,
// "maxLeverage": 125,
// "indexSourceExchanges": ["okex","binance","kucoin","bybit","bitmart","gateio"],
// "k": "490.0",
// "m": "300.0",
// "f": "1.3",
// "mmrLimit": "0.3",
// "mmrLevConstant": "125.0"
// },
// ]
// }
// }
//
let mut responses: Value = promise_all(&promises).await;
let mut data: Value = self.safe_dict(get_value(&responses, &Value::Int(0)), Value::Str("data".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractData: Value = self.safe_dict(get_value(&responses, &Value::Int(1)), Value::Str("data".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotData: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
let mut contractSymbolsData: Value = self.safe_list_k(contractData.clone(), "list", &[Value::List(vec![])]);
let mut symbolsData: Value = self.array_concat(spotData.clone(), contractSymbolsData.clone());
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_879: bool = true;
while { if !__for_first_879 { i = add(&i, &Value::Int(1)); } __for_first_879 = false; is_less_than(&i, &get_array_length(&symbolsData)) } {
let mut market: Value = get_value(&symbolsData, &i);
let mut market: Value = get_value(&symbolsData, &i);
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCurrency", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCurrency", &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "settlementCurrency", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut hasMargin: Value = self.safe_string_k(market.clone(), "marginMode", &[]);
let mut isMarginable: Value = ternary(is_true(&(is_equal(&hasMargin, &Value::Str("1".to_string())))), Value::Bool(true), Value::Bool(false));
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
if !is_equal(&settle, &Value::Null) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &settle));
}
let mut contractType: Value = self.safe_string_k(market.clone(), "contractType", &[]);
let mut expiry: Value = self.safe_integer_k(market.clone(), "expiryTime", &[]);
let mut active: Value = self.safe_string_k(market.clone(), "tradingStatus", &[]);
let mut type_var: Value = Value::Null;
let mut spot: Value = Value::Bool(false);
let mut swap: Value = Value::Bool(false);
let mut future: Value = Value::Bool(false);
let mut contract: Value = Value::Bool(false);
let mut linear: Value = Value::Bool(false);
let mut inverse: Value = Value::Bool(false);
if !is_equal(&contractType, &Value::Null) {
contract = Value::Bool(true);
if is_equal("e, &settle) {
linear = Value::Bool(true);
} else {
inverse = Value::Bool(true);
}
if is_equal(&contractType, &Value::Str("0".to_string())) {
type_var = Value::Str("swap".to_string());
swap = Value::Bool(true);
} else {
type_var = Value::Str("future".to_string());
future = Value::Bool(true);
}
} else {
type_var = Value::Str("spot".to_string());
spot = Value::Bool(true);
}
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), isMarginable.clone());
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), future.clone());
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool((is_equal(&active, &Value::Str("1".to_string())))));
m.insert("contract".to_string(), contract.clone());
m.insert("linear".to_string(), linear.clone());
m.insert("inverse".to_string(), inverse.clone());
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "makerFeeRate", &[]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "takerFeeRate", &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "unitSize", &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number2(market.clone(), Value::Str("lotSize".to_string()), Value::Str("baseOrderStep".to_string()), &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "tickSize", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), self.safe_integer_k(market.clone(), "maxLeverage", &[]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minBaseOrderSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxBaseOrderSize", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxPrice", &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minQuoteOrderSize", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxQuoteOrderSize", &[]));
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer_k(market.clone(), "launchTime", &[]));
m.insert("info".to_string(), market.clone());
m
}));
}
}
if is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
return result;
Value::Null
}
/*
* @method
* @name kucoin#loadMigrationStatus
* @param {boolean} force load account state for non hf
* @description loads the migration status for the account (hf or not)
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-type-spot
* @returns {any} ignore
*/
pub async fn load_migration_status(&mut self, optional_args: &[Value]) -> Value {
let mut force = get_arg(optional_args, 0, Value::Bool(false));
if !is_true(&(Value::Bool(in_op(&self.options, &Value::Str("hf".to_string()))))) || is_true(&(is_equal(&get_value(&self.options, &Value::Str("hf".to_string())), &Value::Null))) || is_true(&force) {
let mut result: Value = self.private_get_hf_accounts_opened(&[]).await;
{ let __be_tmp = self.safe_bool_k(result.clone(), "data", &[]); add_element_to_object(&mut self.options, &Value::Str("hf".to_string()), __be_tmp); };
}
return Value::Bool(true);
Value::Null
}
pub fn handle_hf_and_params(&self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut migrated: Value = self.safe_bool_k(self.options.clone(), "hf", &[Value::Bool(false)]);
let mut loadedHf: Value = Value::Null;
if !is_equal(&migrated, &Value::Null) {
if is_true(&migrated) {
loadedHf = Value::Bool(true);
} else {
loadedHf = Value::Bool(false);
}
}
let mut hf: Value = self.safe_bool_k(params.clone(), "hf", &[loadedHf.clone()]);
params = self.omit(params.clone(), Value::Str("hf".to_string()), &[]);
return Value::List(vec![hf.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-currencies
* @see https://www.kucoin.com/docs-new/rest/ua/get-currencies
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @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 uta: Value = Value::Bool(false);
if is_true(&self.check_required_credentials(&[Value::Bool(false)])) {
uta = self.is_uta_enabled(&[]).await;
}
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchCurrencies".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&uta) {
response = self.uta_get_asset_currencies(&[params.clone()]).await;
} else {
//
// {
// "code":"200000",
// "data":[
// {
// "currency":"CSP",
// "name":"CSP",
// "fullName":"Caspian",
// "precision":8,
// "confirms":null,
// "contractAddress":null,
// "isMarginEnabled":false,
// "isDebitEnabled":false,
// "chains":[
// {
// "chainName":"ERC20",
// "chainId": "eth"
// "withdrawalMinSize":"2999",
// "depositMinSize":null,
// "withdrawFeeRate":"0",
// "withdrawalMinFee":"2999",
// "isWithdrawEnabled":false,
// "isDepositEnabled":false,
// "confirms":12,
// "preConfirms":12,
// "withdrawPrecision": 8,
// "maxWithdraw": null,
// "maxDeposit": null,
// "needTag": false,
// "contractAddress":"0xa6446d655a0c34bc4f05042ee88170d056cbaf45",
// "depositFeeRate": "0.001", // present for some currencies/networks
// }
// ]
// },
// ]
// }
//
response = self.public_get_currencies(&[params.clone()]).await;
}
let mut currenciesData: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut brokenCurrencies: Value = self.handle_option(Value::Str("fetchCurrencies".to_string()), Value::Str("brokenCurrencies".to_string()), &[Value::List(vec![])]);
let mut filteredCurrencies: Value = self.filter_out_by_array(currenciesData.clone(), Value::Str("currency".to_string()), &[brokenCurrencies.clone()]); // remove broken entries
return self.parse_currencies(filteredCurrencies.clone());
Value::Null
}
pub fn parse_currency(&self, mut currency: Value) -> Value {
let mut entry: Value = currency.clone();
let mut id: Value = self.safe_string_k(entry.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut chains: Value = self.safe_list2(entry.clone(), Value::Str("chains".to_string()), Value::Str("items".to_string()), &[Value::List(vec![])]);
let mut chainsLength: Value = get_array_length(&chains);
{
let mut j: Value = Value::Int(0);
let mut __for_first_880: bool = true;
while { if !__for_first_880 { j = add(&j, &Value::Int(1)); } __for_first_880 = false; is_less_than(&j, &chainsLength) } {
let mut chain: Value = get_value(&chains, &j);
let mut chain: Value = get_value(&chains, &j);
let mut chainId: Value = self.safe_string_k(chain.clone(), "chainId", &[]);
let mut networkCode: Value = self.network_id_to_code(&[chainId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), chainId.clone());
m.insert("name".to_string(), self.safe_string_k(chain.clone(), "chainName", &[]));
m.insert("code".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), self.safe_number2(chain.clone(), Value::Str("withdrawalMinFee".to_string()), Value::Str("minWithdrawFee".to_string()), &[]));
m.insert("deposit".to_string(), self.safe_bool_k(chain.clone(), "isDepositEnabled", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(chain.clone(), "isWithdrawEnabled", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(chain.clone(), "withdrawPrecision", &[])]), &[]));
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_number2(chain.clone(), Value::Str("withdrawalMinSize".to_string()), Value::Str("minWithdrawSize".to_string()), &[]));
m.insert("max".to_string(), self.safe_number2(chain.clone(), Value::Str("maxWithdraw".to_string()), Value::Str("maxWithdrawSize".to_string()), &[]));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number2(chain.clone(), Value::Str("depositMinSize".to_string()), Value::Str("minDepositSize".to_string()), &[]));
m.insert("max".to_string(), self.safe_number2(chain.clone(), Value::Str("maxDeposit".to_string()), Value::Str("maxDepositSize".to_string()), &[]));
m
}));
m
}));
m
}));
}
}
}
// kucoin has determined 'fiat' currencies with below logic
let mut rawPrecision: Value = self.safe_string_k(entry.clone(), "precision", &[]);
let mut precision: Value = self.parse_number(self.parse_precision(&[rawPrecision.clone()]), &[]);
let mut isFiat: bool = is_equal(&chainsLength, &Value::Int(0));
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("name".to_string(), self.safe_string_k(entry.clone(), "fullName", &[]));
m.insert("code".to_string(), code.clone());
m.insert("type".to_string(), ternary(is_true(&isFiat), Value::Str("fiat".to_string()), Value::Str("crypto".to_string())));
m.insert("precision".to_string(), precision.clone());
m.insert("info".to_string(), entry.clone());
m.insert("networks".to_string(), networks.clone());
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name kucoin#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-list-spot
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @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
}));
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchAccounts".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut data: Value = Value::List(vec![]);
if is_true(&uta) {
let __ws_arg_3 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountMode".to_string(), Value::Str("unified".to_string()));
m
})]);
response = self.uta_private_get_account_mode_account_overview(&[__ws_arg_3]).await;
//
// {
// "code": "200000",
// "data": {
// "accountType": "UNIFIED",
// "riskRatio": "0.0000000000",
// "equity": "30.0000000000",
// "liability": "0.0000000000",
// "availableMargin": "30.0000000000",
// "adjustedEquity": "30.0000000000",
// "im": "0.0000000000",
// "mm": "0.0000000000"
// }
// }
//
let mut dataDict: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
data = Value::List(vec![dataDict.clone()]);
} else {
//
// {
// "code": "200000",
// "data": [
// {
// "balance": "0.00009788",
// "available": "0.00009788",
// "holds": "0",
// "currency": "BTC",
// "id": "5c6a4fd399a1d81c4f9cc4d0",
// "type": "trade"
// },
// {
// "balance": "0.00000001",
// "available": "0.00000001",
// "holds": "0",
// "currency": "ETH",
// "id": "5c6a49ec99a1d819392e8e9f",
// "type": "trade"
// }
// ]
// }
//
response = self.private_get_accounts(&[params.clone()]).await;
data = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
}
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_881: bool = true;
while { if !__for_first_881 { i = add(&i, &Value::Int(1)); } __for_first_881 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut account: Value = get_value(&data, &i);
let mut account: Value = get_value(&data, &i);
let mut accountId: Value = self.safe_string_k(account.clone(), "id", &[]);
let mut currencyId: Value = self.safe_string_k(account.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut type_var: Value = self.safe_string_lower2(account.clone(), Value::Str("type".to_string()), Value::Str("accountType".to_string()), &[]); // main or trade or unified
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), accountId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), code.clone());
m.insert("code".to_string(), code.clone());
m.insert("info".to_string(), account.clone());
m
}));
}
}
return result;
Value::Null
}
/*
* @method
* @name kucoin#fetchTransactionFee
* @description *DEPRECATED* please use fetchDepositWithdrawFee instead
* @see https://www.kucoin.com/docs-new/rest/account-info/withdrawals/get-withdrawal-quotas
* @param {string} code unified currency code
* @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_transaction_fee(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
let mut _netIdTmp: Value = self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))]);
if !is_equal(&_netIdTmp, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), to_lower(&_netIdTmp));
}
}
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_withdrawals_quotas(&[__ws_arg_4]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut withdrawFees: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut withdrawFees, &code, self.safe_number_k(data.clone(), "withdrawMinFee", &[]));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("withdraw".to_string(), withdrawFees.clone());
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchDepositWithdrawFee
* @description fetch the fee for deposits and withdrawals
* @see https://www.kucoin.com/docs-new/rest/account-info/withdrawals/get-withdrawal-quotas
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] The chain of currency. This only apply for multi-chain currency, and there is no need for single chain currency; you can query the chain through the response of the GET /api/v2/currencies/{currency} interface
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_deposit_withdraw_fee(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
let mut _netIdTmp: Value = self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))]);
if !is_equal(&_netIdTmp, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), to_lower(&_netIdTmp));
}
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_withdrawals_quotas(&[__ws_arg_5]).await;
//
// {
// "code": "200000",
// "data": {
// "currency": "USDT",
// "limitBTCAmount": "1.00000000",
// "usedBTCAmount": "0.00000000",
// "remainAmount": "16548.072149",
// "availableAmount": "0",
// "withdrawMinFee": "25",
// "innerWithdrawMinFee": "0",
// "withdrawMinSize": "50",
// "isWithdrawEnabled": true,
// "precision": 6,
// "chain": "ERC20"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
return self.parse_deposit_withdraw_fee(data.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_deposit_withdraw_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "currency": "USDT",
// "limitBTCAmount": "1.00000000",
// "usedBTCAmount": "0.00000000",
// "remainAmount": "16548.072149",
// "availableAmount": "0",
// "withdrawMinFee": "25",
// "innerWithdrawMinFee": "0",
// "withdrawMinSize": "50",
// "isWithdrawEnabled": true,
// "precision": 6,
// "chain": "ERC20"
// }
//
if is_true(&Value::Bool(in_op(&fee, &Value::Str("chains".to_string())))) {
// if data obtained through `currencies` endpoint
let mut resultNew: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
let mut chains: Value = self.safe_list_k(fee.clone(), "chains", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_882: bool = true;
while { if !__for_first_882 { i = add(&i, &Value::Int(1)); } __for_first_882 = false; is_less_than(&i, &get_array_length(&chains)) } {
let mut chain: Value = get_value(&chains, &i);
let mut chain: Value = get_value(&chains, &i);
let mut chainId: Value = self.safe_string_k(chain.clone(), "chainId", &[]);
let mut networkCodeNew: Value = self.network_id_to_code(&[chainId.clone(), self.safe_string_k(currency.clone(), "code", &[])]);
if !is_equal(&networkCodeNew, &Value::Null) {
add_element_to_object(get_value_mut(&mut resultNew, &Value::Str("networks".to_string())), &networkCodeNew, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), self.safe_number2(chain.clone(), Value::Str("withdrawalMinFee".to_string()), Value::Str("withdrawMinFee".to_string()), &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
}));
}
}
}
return resultNew;
}
let mut minWithdrawFee: Value = self.safe_number_k(fee.clone(), "withdrawMinFee", &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), minWithdrawFee.clone());
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
let mut networkId: Value = self.safe_string_k(fee.clone(), "chain", &[]);
let mut currencyId: Value = self.safe_string_k(fee.clone(), "currency", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), get_value(¤cy, &Value::Str("code".to_string()))]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("networks".to_string())), &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), minWithdrawFee.clone());
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
}));
}
return result;
Value::Null
}
pub fn is_futures_method(&self, mut methodName: Value, mut params: Value) -> Value {
//
// Helper
// @methodName (string): The name of the method
// @params (dict): The parameters passed into {methodName}
// @return: true if the method used is meant for futures trading, false otherwise
//
let mut defaultType: Value = self.safe_string2(self.options.clone(), methodName.clone(), Value::Str("defaultType".to_string()), &[Value::Str("trade".to_string())]);
let mut requestedType: Value = self.safe_string_k(params.clone(), "type", &[defaultType.clone()]);
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut type_var: Value = self.safe_string(accountsByType.clone(), requestedType.clone(), &[]);
if is_equal(&type_var, &Value::Null) {
let mut keys: Value = object_keys(&accountsByType);
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" isFuturesMethod() type must be one of ".to_string())), &join(&keys, &Value::Str(", ".to_string())))));
}
params = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
return Value::Bool(is_true(&(is_equal(&type_var, &Value::Str("contract".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("futures".to_string())))));
Value::Null
}
pub fn parse_spot_or_uta_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTC-USDT", // symbol
// "symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
// "buy": "11328.9", // bestAsk
// "sell": "11329", // bestBid
// "changeRate": "-0.0055", // 24h change rate
// "changePrice": "-63.6", // 24h change price
// "high": "11610", // 24h highest price
// "low": "11200", // 24h lowest price
// "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
// "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
// "last": "11328.9", // last price
// "averagePrice": "11360.66065903", // 24h average transaction price yesterday
// "takerFeeRate": "0.001", // Basic Taker Fee
// "makerFeeRate": "0.001", // Basic Maker Fee
// "takerCoefficient": "1", // Taker Fee Coefficient
// "makerCoefficient": "1" // Maker Fee Coefficient
// }
//
// {
// "trading": true,
// "symbol": "KCS-BTC",
// "buy": 0.00011,
// "sell": 0.00012,
// "sort": 100,
// "volValue": 3.13851792584, //total
// "baseCurrency": "KCS",
// "market": "BTC",
// "quoteCurrency": "BTC",
// "symbolCode": "KCS-BTC",
// "datetime": 1548388122031,
// "high": 0.00013,
// "vol": 27514.34842,
// "low": 0.0001,
// "changePrice": -1.0e-5,
// "changeRate": -0.0769,
// "lastTradedPrice": 0.00012,
// "board": 0,
// "mark": 0
// }
//
// market/ticker ws subscription
//
// {
// "bestAsk": "62258.9",
// "bestAskSize": "0.38579986",
// "bestBid": "62258.8",
// "bestBidSize": "0.0078381",
// "price": "62260.7",
// "sequence": "1621383297064",
// "size": "0.00002841",
// "time": 1634641777363
// }
//
// uta spot
// {
// "symbol": "ETH-USDT",
// "name": "ETH-USDT",
// "bestBidSize": "2.8893176",
// "bestBidPrice": "1566.24",
// "bestAskSize": "2.4373857",
// "bestAskPrice": "1566.25",
// "lastPrice": "1565.87",
// "size": "0.0384399",
// "open": "1572.96",
// "high": "1637.4",
// "low": "1550.41",
// "baseVolume": "101560.01156957747448132256",
// "quoteVolume": "161467045.65271628672329459176",
// "priceChange": "-7.09",
// "priceChangePercent": "-0.0045"
// }
//
// uta swap
//
// {
// "symbol": "ETHUSDTM",
// "bestBidSize": "4",
// "bestBidPrice": "1573.45",
// "bestAskSize": "43",
// "bestAskPrice": "1573.46",
// "lastPrice": "1573.63",
// "size": "1",
// "open": "1570.09",
// "high": "1637.08",
// "low": "1549.63",
// "baseVolume": "282920.90",
// "quoteVolume": "449940743.674",
// "priceChange": "3.54",
// "priceChangePercent": "0.2255",
// "indexPrice": "1572.67",
// "markPrice": "1572.68"
// }
//
let mut percentage: Value = self.safe_string_k(ticker.clone(), "changeRate", &[]);
if !is_equal(&percentage, &Value::Null) {
percentage = crate::precise::Precise::stringMul(&percentage, &Value::Str("100".to_string()));
} else {
percentage = self.safe_string_k(ticker.clone(), "priceChangePercent", &[]);
}
let mut last: Value = self.safe_string_n(ticker.clone(), Value::List(vec![Value::Str("last".to_string()), Value::Str("lastTradedPrice".to_string()), Value::Str("lastPrice".to_string())]), &[]);
last = self.safe_string_k(ticker.clone(), "price", &[last.clone()]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("-".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut baseVolume: Value = self.safe_string2(ticker.clone(), Value::Str("vol".to_string()), Value::Str("baseVolume".to_string()), &[]);
let mut quoteVolume: Value = self.safe_string2(ticker.clone(), Value::Str("volValue".to_string()), Value::Str("quoteVolume".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_n(ticker.clone(), Value::List(vec![Value::Str("time".to_string()), Value::Str("datetime".to_string()), Value::Str("timePoint".to_string())]), &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "low", &[]));
m.insert("bid".to_string(), self.safe_string_n(ticker.clone(), Value::List(vec![Value::Str("buy".to_string()), Value::Str("bestBid".to_string()), Value::Str("bestBidPrice".to_string())]), &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bestBidSize", &[]));
m.insert("ask".to_string(), self.safe_string_n(ticker.clone(), Value::List(vec![Value::Str("sell".to_string()), Value::Str("bestAsk".to_string()), Value::Str("bestAskPrice".to_string())]), &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "bestAskSize", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "open", &[]));
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_string2(ticker.clone(), Value::Str("changePrice".to_string()), Value::Str("priceChange".to_string()), &[]));
m.insert("percentage".to_string(), percentage.clone());
m.insert("average".to_string(), self.safe_string_k(ticker.clone(), "averagePrice", &[]));
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
m.insert("markPrice".to_string(), self.safe_string2(ticker.clone(), Value::Str("markPrice".to_string()), Value::Str("value".to_string()), &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "indexPrice", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return self.parse_contract_ticker(ticker.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_contract_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "LTCUSDTM",
// "granularity": 1000,
// "timePoint": 1727967339000,
// "value": 62.37, mark price
// "indexPrice": 62.37
// }
//
// {
// "code": "200000",
// "data": {
// "sequence": 1629930362547,
// "symbol": "ETHUSDTM",
// "side": "buy",
// "size": 130,
// "price": "4724.7",
// "bestBidSize": 5,
// "bestBidPrice": "4724.6",
// "bestAskPrice": "4724.65",
// "tradeId": "618d2a5a77a0c4431d2335f4",
// "ts": 1636641371963227600,
// "bestAskSize": 1789
// }
// }
//
// from fetchTickers
//
// {
// symbol: "XBTUSDTM",
// rootSymbol: "USDT",
// type: "FFWCSX",
// firstOpenDate: 1585555200000,
// expireDate: null,
// settleDate: null,
// baseCurrency: "XBT",
// quoteCurrency: "USDT",
// settleCurrency: "USDT",
// maxOrderQty: 1000000,
// maxPrice: 1000000,
// lotSize: 1,
// tickSize: 0.1,
// indexPriceTickSize: 0.01,
// multiplier: 0.001,
// initialMargin: 0.008,
// maintainMargin: 0.004,
// maxRiskLimit: 100000,
// minRiskLimit: 100000,
// riskStep: 50000,
// makerFeeRate: 0.0002,
// takerFeeRate: 0.0006,
// takerFixFee: 0,
// makerFixFee: 0,
// settlementFee: null,
// isDeleverage: true,
// isQuanto: true,
// isInverse: false,
// markMethod: "FairPrice",
// fairMethod: "FundingRate",
// fundingBaseSymbol: ".XBTINT8H",
// fundingQuoteSymbol: ".USDTINT8H",
// fundingRateSymbol: ".XBTUSDTMFPI8H",
// indexSymbol: ".KXBTUSDT",
// settlementSymbol: "",
// status: "Open",
// fundingFeeRate: 0.000297,
// predictedFundingFeeRate: 0.000327,
// fundingRateGranularity: 28800000,
// openInterest: "8033200",
// turnoverOf24h: 659795309.2524643,
// volumeOf24h: 9998.54,
// markPrice: 67193.51,
// indexPrice: 67184.81,
// lastTradePrice: 67191.8,
// nextFundingRateTime: 20022985,
// maxLeverage: 125,
// premiumsSymbol1M: ".XBTUSDTMPI",
// premiumsSymbol8H: ".XBTUSDTMPI8H",
// fundingBaseSymbol1M: ".XBTINT",
// fundingQuoteSymbol1M: ".USDTINT",
// lowPrice: 64041.6,
// highPrice: 67737.3,
// priceChgPct: 0.0447,
// priceChg: 2878.7
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("-".to_string())]);
let mut last: Value = self.safe_string2(ticker.clone(), Value::Str("price".to_string()), Value::Str("lastTradePrice".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_product(ticker.clone(), Value::Str("ts".to_string()), Value::Float(0.000001), &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "highPrice", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "lowPrice", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "bestBidPrice", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bestBidSize", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "bestAskPrice", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "bestAskSize", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "priceChg", &[]));
m.insert("percentage".to_string(), crate::precise::Precise::stringMul(&self.safe_string_k(ticker.clone(), "priceChgPct", &[]), &Value::Str("100".to_string())));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "volumeOf24h", &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "turnoverOf24h", &[]));
m.insert("markPrice".to_string(), self.safe_string2(ticker.clone(), Value::Str("markPrice".to_string()), Value::Str("value".to_string()), &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "indexPrice", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn type_to_trade_type(&self, mut type_var: Value) -> Value {
let mut tradeTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("margin".to_string(), Value::Str("MARGIN".to_string()));
m.insert("swap".to_string(), Value::Str("FUTURES".to_string()));
m
});
if is_equal(&type_var, &Value::Null) {
return Value::Null;
}
return self.safe_string(tradeTypes.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-tickers
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-all-tickers
* @see https://www.kucoin.com/docs-new/rest/ua/get-ticker
* @param {string[]|undefined} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @param {string} [params.type] spot or swap (default is spot)
* @param {string} [params.method] *swap only* the method to use, futuresPublicGetContractsActive or futuresPublicGetAllTickers (default is futuresPublicGetContractsActive)
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTickers".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut tradeType: Value = self.safe_string_k(params.clone(), "tradeType", &[]);
let mut firstMarket: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
if !is_equal(&firstSymbol, &Value::Null) {
firstMarket = self.market(firstSymbol.clone());
}
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[firstMarket.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&(!is_equal(&tradeType, &Value::Null))) || is_true(&uta) {
if is_equal(&tradeType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), self.type_to_trade_type(type_var.clone()));
}
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_get_market_ticker(&[__ws_arg_6]).await;
} else if is_true(&(!is_equal(&type_var, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(&type_var, &Value::Str("margin".to_string())))) {
return self.fetch_contract_tickers(&[symbols.clone(), params.clone()]).await;
} else {
response = self.public_get_market_all_tickers(&[params.clone()]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut tickers: Value = self.safe_list2(data.clone(), Value::Str("ticker".to_string()), Value::Str("list".to_string()), &[Value::List(vec![])]);
let mut time: Value = self.safe_integer2(data.clone(), Value::Str("time".to_string()), Value::Str("ts".to_string()), &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_883: bool = true;
while { if !__for_first_883 { i = add(&i, &Value::Int(1)); } __for_first_883 = false; is_less_than(&i, &get_array_length(&tickers)) } {
add_element_to_object(get_value_mut(&mut tickers, &i), &Value::Str("time".to_string()), time.clone());
let mut ticker: Value = self.parse_spot_or_uta_ticker(get_value(&tickers, &i), &[]);
let mut symbol: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut result, &symbol, ticker.clone());
}
}
}
return self.filter_by_array_tickers(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
pub async fn fetch_contract_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
}));
let mut method: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTickers".to_string()), Value::Str("method".to_string()), &[Value::Str("futuresPublicGetContractsActive".to_string())]); method = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("futuresPublicGetAllTickers".to_string())) {
response = self.futures_public_get_all_tickers(&[params.clone()]).await;
} else {
response = self.futures_public_get_contracts_active(&[params.clone()]).await;
}
//
// {
// "code": "200000",
// "data": {
// "symbol": "ETHUSDTM",
// "rootSymbol": "USDT",
// "type": "FFWCSX",
// "firstOpenDate": 1591086000000,
// "expireDate": null,
// "settleDate": null,
// "baseCurrency": "ETH",
// "quoteCurrency": "USDT",
// "settleCurrency": "USDT",
// "maxOrderQty": 1000000,
// "maxPrice": 1000000.0000000000,
// "lotSize": 1,
// "tickSize": 0.05,
// "indexPriceTickSize": 0.01,
// "multiplier": 0.01,
// "initialMargin": 0.01,
// "maintainMargin": 0.005,
// "maxRiskLimit": 1000000,
// "minRiskLimit": 1000000,
// "riskStep": 500000,
// "makerFeeRate": 0.00020,
// "takerFeeRate": 0.00060,
// "takerFixFee": 0.0000000000,
// "makerFixFee": 0.0000000000,
// "settlementFee": null,
// "isDeleverage": true,
// "isQuanto": true,
// "isInverse": false,
// "markMethod": "FairPrice",
// "fairMethod": "FundingRate",
// "fundingBaseSymbol": ".ETHINT8H",
// "fundingQuoteSymbol": ".USDTINT8H",
// "fundingRateSymbol": ".ETHUSDTMFPI8H",
// "indexSymbol": ".KETHUSDT",
// "settlementSymbol": "",
// "status": "Open",
// "fundingFeeRate": 0.000535,
// "predictedFundingFeeRate": 0.002197,
// "openInterest": "8724443",
// "turnoverOf24h": 341156641.03354263,
// "volumeOf24h": 74833.54000000,
// "markPrice": 4534.07,
// "indexPrice":4531.92,
// "lastTradePrice": 4545.4500000000,
// "nextFundingRateTime": 25481884,
// "maxLeverage": 100,
// "sourceExchanges": [ "huobi", "Okex", "Binance", "Kucoin", "Poloniex", "Hitbtc" ],
// "premiumsSymbol1M": ".ETHUSDTMPI",
// "premiumsSymbol8H": ".ETHUSDTMPI8H",
// "fundingBaseSymbol1M": ".ETHINT",
// "fundingQuoteSymbol1M": ".USDTINT",
// "lowPrice": 4456.90,
// "highPrice": 4674.25,
// "priceChgPct": 0.0046,
// "priceChg": 21.15
// }
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
let mut tickers: Value = self.parse_tickers(data.clone(), &[symbols.clone()]);
return self.filter_by_array_tickers(tickers.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchMarkPrices
* @description fetches the mark price for multiple markets
* @see https://www.kucoin.com/docs-new/rest/margin-trading/market-data/get-mark-price-list
* @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_mark_prices(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.public_get_mark_price_all_symbols(&[params.clone()]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_tickers(data.clone(), &[]);
Value::Null
}
/*
* @method
* @name kucoin#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-24hr-stats
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-ticker
* @see https://www.kucoin.com/docs-new/rest/ua/get-ticker
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTicker".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut result: Value = Value::Null;
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTicker".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), self.type_to_trade_type(type_var.clone()));
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_get_market_ticker(&[__ws_arg_7]).await;
//
// {
// "code": "200000",
// "data": {
// "tradeType": "FUTURES",
// "ts": 1782828116206000000,
// "list": [
// {
// "symbol": "ETHUSDTM",
// "bestBidSize": "4",
// "bestBidPrice": "1573.45",
// "bestAskSize": "43",
// "bestAskPrice": "1573.46",
// "lastPrice": "1573.63",
// "size": "1",
// "open": "1570.09",
// "high": "1637.08",
// "low": "1549.63",
// "baseVolume": "282920.90",
// "quoteVolume": "449940743.674",
// "priceChange": "3.54",
// "priceChangePercent": "0.2255",
// "indexPrice": "1572.67",
// "markPrice": "1572.68"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut resultList: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
result = self.safe_dict(resultList.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_ticker(&[__ws_arg_8]).await;
//
// {
// "code": "200000",
// "data": {
// "sequence": 1638444978558,
// "symbol": "ETHUSDTM",
// "side": "sell",
// "size": 4,
// "price": "4229.35",
// "bestBidSize": 2160,
// "bestBidPrice": "4229.0",
// "bestAskPrice": "4229.05",
// "tradeId": "61aaa8b777a0c43055fe4851",
// "ts": 1638574296209786785,
// "bestAskSize": 36,
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(data.clone(), &[market.clone()]);
} else {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_stats(&[__ws_arg_9]).await;
//
// {
// "code": "200000",
// "data": {
// "time": 1602832092060, // time
// "symbol": "BTC-USDT", // symbol
// "buy": "11328.9", // bestAsk
// "sell": "11329", // bestBid
// "changeRate": "-0.0055", // 24h change rate
// "changePrice": "-63.6", // 24h change price
// "high": "11610", // 24h highest price
// "low": "11200", // 24h lowest price
// "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
// "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
// "last": "11328.9", // last price
// "averagePrice": "11360.66065903", // 24h average transaction price yesterday
// "takerFeeRate": "0.001", // Basic Taker Fee
// "makerFeeRate": "0.001", // Basic Maker Fee
// "takerCoefficient": "1", // Taker Fee Coefficient
// "makerCoefficient": "1" // Maker Fee Coefficient
// }
// }
//
result = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_spot_or_uta_ticker(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchMarkPrice
* @description fetches the mark price for a specific market
* @see https://www.kucoin.com/docs-new/rest/margin-trading/market-data/get-mark-price-detail
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-mark-price
* @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_mark_price(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_mark_price_symbol_current(&[__ws_arg_10]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(data.clone(), &[market.clone()]);
} else {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_mark_price_symbol_current(&[__ws_arg_11]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_spot_or_uta_ticker(data.clone(), &[market.clone()]);
}
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// "1545904980", // Start time of the candle cycle
// "0.058", // opening price
// "0.049", // closing price
// "0.058", // highest price
// "0.049", // lowest price
// "0.018", // base volume
// "0.000945", // quote volume
// ]
//
let mut timestampString: Value = self.safe_string(ohlcv.clone(), Value::Int(0), &[]);
if !is_equal(×tampString, &Value::Null) && is_less_than_or_equal(&get_array_length(×tampString), &Value::Int(10)) {
return Value::List(vec![self.safe_timestamp(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
} else {
return Value::List(vec![self.safe_integer(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
}
Value::Null
}
/*
* @method
* @name kucoin#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-klines
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-klines
* @see https://www.kucoin.com/docs-new/rest/ua/get-klines
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut priceType: Value = self.safe_string_k(params.clone(), "price", &[]);
if is_true(&(!is_equal(&priceType, &Value::Null))) && is_true(&(!is_true(&uta))) {
uta = Value::Bool(true); // mark, index, premiumIndex price types are only available for UTA
}
if is_true(&uta) {
return self.fetch_utaohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
return self.fetch_contract_ohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
return self.fetch_spot_ohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @ignore
* @name kucoin#fetchUTAOHLCV
* @description helper method for fetchOHLCV
* @see https://www.kucoin.com/docs-new/rest/ua/get-klines
* @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
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_utaohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(1500);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchUTAOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut duration: Value = multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000));
let mut endAt: Value = self.milliseconds(); // required param
let mut denominator: Value = Value::Int(1000);
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), self.parse_to_int(math_floor(÷(&since, &denominator))));
if is_equal(&limit, &Value::Null) {
// For each query, the system would return at most 1500 pieces of data.
// To obtain more data, please page the data by time.
limit = self.safe_integer_k(self.options.clone(), "fetchOHLCVLimit", &[maxLimit.clone()]);
}
endAt = self.sum(&[since.clone(), multiply(&limit, &duration)]);
} else if !is_equal(&limit, &Value::Null) {
since = subtract(&endAt, &multiply(&limit, &duration));
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), self.parse_to_int(math_floor(÷(&since, &denominator))));
}
add_element_to_object(&mut request, &Value::Str("endAt".to_string()), self.parse_to_int(math_floor(÷(&endAt, &denominator))));
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOHLCV".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string())))) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("SPOT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("FUTURES".to_string()));
}
let mut priceType: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("price".to_string()), &[priceType.clone()]); priceType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&priceType, &Value::Null) {
let mut priceTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Str("mark-price".to_string()));
m.insert("index".to_string(), Value::Str("index-price".to_string()));
m.insert("premiumIndex".to_string(), Value::Str("premium-index".to_string()));
m
});
let mut suffix: Value = self.safe_string(priceTypes.clone(), priceType.clone(), &[]);
if is_equal(&suffix, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOHLCV() price parameter must be one of \"mark\", \"index\", or \"premiumIndex\"".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), add(&add(&get_value(&market, &Value::Str("id".to_string())), &Value::Str("-".to_string())), &suffix));
}
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_get_market_kline(&[__ws_arg_12]).await;
//
// {
// "code": "200000",
// "data": {
// "tradeType": "SPOT",
// "symbol": "BTC-USDT",
// "list": [
// ["1762240200","104581.4","104527.1","104620.1","104526.4","5.57665554","583263.661804122"],
// ["1762240140","104565.6","104581.3","104601.7","104511.3","6.48505114","677973.775916968"],
// ["1762240080","104621.5","104571.3","104704.7","104571.3","14.51713618","1519468.954060838"]
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut result: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
return self.parse_ohlc_vs(result.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @ignore
* @name kucoin#fetchSpotOHLCV
* @description helper method for fetchOHLCV
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-klines
* @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
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_spot_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(1500);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchSpotOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("type".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut duration: Value = multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000));
let mut endAt: Value = self.milliseconds(); // required param
let mut denominator: Value = Value::Int(1000);
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), self.parse_to_int(math_floor(÷(&since, &denominator))));
if is_equal(&limit, &Value::Null) {
// For each query, the system would return at most 1500 pieces of data.
// To obtain more data, please page the data by time.
limit = self.safe_integer_k(self.options.clone(), "fetchOHLCVLimit", &[maxLimit.clone()]);
}
endAt = self.sum(&[since.clone(), multiply(&limit, &duration)]);
} else if !is_equal(&limit, &Value::Null) {
since = subtract(&endAt, &multiply(&limit, &duration));
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), self.parse_to_int(math_floor(÷(&since, &denominator))));
}
add_element_to_object(&mut request, &Value::Str("endAt".to_string()), self.parse_to_int(math_floor(÷(&endAt, &denominator))));
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_market_candles(&[__ws_arg_13]).await;
//
// {
// "code":"200000",
// "data":[
// ["1591517700","0.025078","0.025069","0.025084","0.025064","18.9883256","0.4761861079404"],
// ["1591516800","0.025089","0.025079","0.025089","0.02506","99.4716622","2.494143499081"],
// ["1591515900","0.025079","0.02509","0.025091","0.025068","59.83701271","1.50060885172798"],
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @ignore
* @name kucoin#fetchContractOHLCV
* @description helper method for fetchOHLCV
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-klines
* @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
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_contract_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(200);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchContractOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut timeframeOptions: Value = self.safe_dict_k(self.options.clone(), "timeframes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut swapTimeframes: Value = self.safe_dict_k(timeframeOptions.clone(), "swap", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut parsedTimeframe: Value = self.safe_integer(swapTimeframes.clone(), timeframe.clone(), &[]);
if !is_equal(&parsedTimeframe, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("granularity".to_string()), parsedTimeframe.clone());
} else {
add_element_to_object(&mut request, &Value::Str("granularity".to_string()), timeframe.clone());
}
let mut duration: Value = multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000));
let mut endAt: Value = self.milliseconds(); // required param
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
if is_equal(&limit, &Value::Null) {
// For each query, the system would return at most 200 pieces of data.
// To obtain more data, please page the data by time.
limit = self.safe_integer_k(self.options.clone(), "fetchOHLCVLimit", &[maxLimit.clone()]);
}
endAt = self.sum(&[since.clone(), multiply(&limit, &duration)]);
} else if !is_equal(&limit, &Value::Null) {
since = subtract(&endAt, &multiply(&limit, &duration));
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
}
add_element_to_object(&mut request, &Value::Str("to".to_string()), endAt.clone());
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_public_get_kline_query(&[__ws_arg_14]).await;
//
// {
// "code": "200000",
// "data": [
// [1636459200000, 4779.3, 4792.1, 4768.7, 4770.3, 78051],
// [1636460100000, 4770.25, 4778.55, 4757.55, 4777.25, 80164],
// [1636461000000, 4777.25, 4791.45, 4774.5, 4791.3, 51555]
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#createDepositAddress
* @see https://www.kucoin.com/docs-new/rest/account-info/deposit/add-deposit-address-v3
* @description create a currency deposit address
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] the blockchain network name
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))])); // docs mention "chain-name", but seems "chain-id" is used, like in "fetchDepositAddress"
}
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_deposit_address_create(&[__ws_arg_15]).await;
// {"code":"260000","msg":"Deposit address already exists."}
//
// {
// "code": "200000",
// "data": {
// "address": "0x2336d1834faab10b2dac44e468f2627138417431",
// "memo": null,
// "chainId": "bsc",
// "to": "MAIN",
// "expirationDate": 0,
// "currency": "BNB",
// "chainName": "BEP20"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_deposit_address(data.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://www.kucoin.com/docs-new/rest/account-info/deposit/get-deposit-address-v3/en
* @see https://www.kucoin.com/docs-new/rest/ua/get-deposit-address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] the blockchain network name
* @param {string} [params.accountType] 'main', 'contract' or 'uta' (default is 'main')
* @param {boolean} [params.uta] set to true for the unified trading account (uta) endpoint, defaults to false
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountType: Value = Value::Str("main".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchDepositAddress".to_string()), Value::Str("accountType".to_string()), &[accountType.clone()]); accountType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
accountType = self.safe_string(accountsByType.clone(), accountType.clone(), &[accountType.clone()]);
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchDepositAddress".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&accountType, &Value::Str("contract".to_string())) {
return self.fetch_contract_deposit_address(code.clone(), &[params.clone()]).await;
} else if is_true(&uta) || is_true(&(is_equal(&accountType, &Value::Str("uta".to_string())))) || is_true(&(is_equal(&accountType, &Value::Str("unified".to_string())))) {
let __ws_arg_16 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uta".to_string(), Value::Bool(true));
m
})]);
return self.super_fetch_deposit_address(code.clone(), __ws_arg_16).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
let mut _netIdTmp: Value = self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))]);
if !is_equal(&_netIdTmp, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), to_lower(&_netIdTmp));
}
}
let mut version: Value = get_value(&get_value(&get_value(&get_value(&self.options, &Value::Str("versions".to_string())), &Value::Str("private".to_string())), &Value::Str("GET".to_string())), &Value::Str("deposit-addresses".to_string()));
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("versions".to_string())), &Value::Str("private".to_string())), &Value::Str("GET".to_string())), &Value::Str("deposit-addresses".to_string()), Value::Str("v1".to_string()));
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_deposit_addresses(&[__ws_arg_17]).await;
// BCH {"code":"200000","data":{"address":"bitcoincash:qza3m4nj9rx7l9r0cdadfqxts6f92shvhvr5ls4q7z","memo":""}}
// BTC {"code":"200000","data":{"address":"36SjucKqQpQSvsak9A7h6qzFjrVXpRNZhE","memo":""}}
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("versions".to_string())), &Value::Str("private".to_string())), &Value::Str("GET".to_string())), &Value::Str("deposit-addresses".to_string()), version.clone());
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
if is_equal(&data, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchDepositAddress() returned an empty response, you might try to run createDepositAddress() first and try again".to_string()))));
}
return self.parse_deposit_address(data.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchContractDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://www.kucoin.com/docs/rest/funding/deposit/get-deposit-address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_contract_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut currencyId: Value = get_value(¤cy, &Value::Str("id".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currencyId.clone());
m
});
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_deposit_address(&[__ws_arg_18]).await;
//
// {
// "code": "200000",
// "data": {
// "address": "0x78d3ad1c0aa1bf068e19c94a2d7b16c9c0fcd8b1",//Deposit address
// "memo": null//Address tag. If the returned value is null, it means that the requested token has no memo. If you are to transfer funds from another platform to KuCoin Futures and if the token to be //transferred has memo(tag), you need to fill in the memo to ensure the transferred funds will be sent //to the address you specified.
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut address: Value = self.safe_string_k(data.clone(), "address", &[]);
if !is_equal(¤cyId, &Value::Str("NIM".to_string())) {
// contains spaces
self.check_address(&[address.clone()]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("currency".to_string(), currencyId.clone());
m.insert("network".to_string(), self.safe_string_k(data.clone(), "chain", &[]));
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), self.safe_string_k(data.clone(), "memo", &[]));
m
});
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 mut address: Value = self.safe_string_k(depositAddress.clone(), "address", &[]);
// BCH/BSV is returned with a "bitcoincash:" prefix, which we cut off here and only keep the address
if !is_equal(&address, &Value::Null) {
address = replace_str(&address, &Value::Str("bitcoincash:".to_string()), &Value::Str("".to_string()));
}
let mut code: Value = Value::Null;
if !is_equal(¤cy, &Value::Null) {
code = self.safe_currency_code(get_value(¤cy, &Value::Str("id".to_string())), &[]);
if !is_equal(&code, &Value::Str("NIM".to_string())) {
// contains spaces
self.check_address(&[address.clone()]);
}
}
let mut chainId: Value = self.safe_string_k(depositAddress.clone(), "chainId", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), self.network_id_to_code(&[chainId.clone(), code.clone()]));
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), self.safe_string_k(depositAddress.clone(), "memo", &[]));
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchDepositAddressesByNetwork
* @see https://www.kucoin.com/docs-new/rest/account-info/deposit/get-deposit-address-v3/en
* @see https://www.kucoin.com/docs-new/rest/ua/get-deposit-address
* @description fetch the deposit address for a currency associated with this account
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta) endpoint, defaults to false
* @returns {object} a dictionary of [address structures]{@link https://docs.ccxt.com/?id=address-structure} indexed by the network
*/
pub async fn fetch_deposit_addresses_by_network(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchDepositAddressesByNetwork".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&uta) {
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
let mut _netIdTmp: Value = self.network_code_to_id(networkCode.clone(), &[code.clone()]);
if !is_equal(&_netIdTmp, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), to_lower(&_netIdTmp));
}
}
//
// {
// "code": "200000",
// "data": [
// {
// "address": "0xf30a9b6968183668dbce515bd6449438ab3252b3",
// "memo": "",
// "remark": "",
// "chainId": "eth",
// "to": "FUNDING",
// "expirationDate": 0,
// "currency": "USDT",
// "contractAddress": "0xdac17f958d2ee523a2206206994597c13d831ec7",
// "chainName": "ERC20"
// }
// ]
// }
//
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_asset_deposit_address(&[__ws_arg_19]).await;
} else {
let mut version: Value = get_value(&get_value(&get_value(&get_value(&self.options, &Value::Str("versions".to_string())), &Value::Str("private".to_string())), &Value::Str("GET".to_string())), &Value::Str("deposit-addresses".to_string()));
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("versions".to_string())), &Value::Str("private".to_string())), &Value::Str("GET".to_string())), &Value::Str("deposit-addresses".to_string()), Value::Str("v2".to_string()));
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_deposit_addresses(&[__ws_arg_20]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "address": "fr1qvus7d4d5fgxj5e7zvqe6yhxd7txm95h2and69r",
// "memo": "",
// "chain": "BTC-Segwit",
// "contractAddress": ""
// },
// {"address":"37icNMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn","memo":"","chain":"BTC","contractAddress":""},
// {"address":"Deposit temporarily blocked","memo":"","chain":"TRC20","contractAddress":""}
// ]
// }
//
add_element_to_object(get_value_mut(get_value_mut(get_value_mut(&mut self.options, &Value::Str("versions".to_string())), &Value::Str("private".to_string())), &Value::Str("GET".to_string())), &Value::Str("deposit-addresses".to_string()), version.clone());
}
let mut chains: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut parsed: Value = self.parse_deposit_addresses(chains.clone(), &[Value::List(vec![get_value(¤cy, &Value::Str("code".to_string()))]), Value::Bool(false), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("code".to_string())));
m
})]);
return self.index_by(parsed.clone(), Value::Str("network".to_string()));
Value::Null
}
/*
* @method
* @name kucoin#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-part-orderbook
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-full-orderbook
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-part-orderbook
* @see https://www.kucoin.com/docs-new/rest/ua/get-orderbook
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut level: Value = self.safe_integer_k(params.clone(), "level", &[Value::Int(2)]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut isAuthenticated: Value = self.check_required_credentials(&[Value::Bool(false)]);
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrderBook".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrderBook".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
let mut limitString: Value = Value::Str("20".to_string());
if is_true(&(is_equal(&limit, &Value::Null))) || is_true(&(is_greater_than_or_equal(&limit, &Value::Int(100)))) {
limitString = Value::Str("FULL".to_string());
} else if is_greater_than(&limit, &Value::Int(20)) {
limitString = Value::Str("100".to_string());
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limitString.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string())))) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("SPOT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("FUTURES".to_string()));
}
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_market_orderbook(&[__ws_arg_21]).await;
} else if is_true(&(!is_equal(&type_var, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(&type_var, &Value::Str("margin".to_string())))) {
if !is_equal(&level, &Value::Int(2)) && !is_equal(&level, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOrderBook() can only return level 2".to_string()))));
}
if is_equal(&limit, &Value::Null) {
// full L2 snapshot - required for correct ws diff-sync: the futures delta
// stream covers the whole book while depth20/depth100 truncate the snapshot,
// see https://github.com/ccxt/ccxt/issues/22063
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_level2_snapshot(&[__ws_arg_22]).await;
} else if is_equal(&limit, &Value::Int(20)) {
//
// {
// "code": "200000",
// "data": {
// "symbol": "XBTUSDM", //Symbol
// "sequence": 100, //Ticker sequence number
// "asks": [
// ["5000.0", 1000], //Price, quantity
// ["6000.0", 1983] //Price, quantity
// ],
// "bids": [
// ["3200.0", 800], //Price, quantity
// ["3100.0", 100] //Price, quantity
// ],
// "ts": 1604643655040584408 // timestamp
// }
// }
//
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_level2_depth20(&[__ws_arg_23]).await;
} else if is_equal(&limit, &Value::Int(100)) {
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_level2_depth100(&[__ws_arg_24]).await;
} else {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOrderBook() limit argument must be 20 or 100".to_string()))));
}
} else if !is_true(&isAuthenticated) || !is_equal(&limit, &Value::Null) {
if is_equal(&level, &Value::Int(2)) {
add_element_to_object(&mut request, &Value::Str("level".to_string()), level.clone());
if !is_equal(&limit, &Value::Null) {
if is_true(&(is_equal(&limit, &Value::Int(20)))) || is_true(&(is_equal(&limit, &Value::Int(100)))) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
} else {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchOrderBook() limit argument must be 20 or 100".to_string()))));
}
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), ternary(is_true(&(!is_equal(&limit, &Value::Null))), limit.clone(), Value::Int(100)));
}
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_orderbook_level_level_limit(&[__ws_arg_25]).await;
} else {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_market_orderbook_level2(&[__ws_arg_26]).await;
}
//
// public (v1) market/orderbook/level2_20 and market/orderbook/level2_100
//
// {
// "sequence": "3262786978",
// "time": 1550653727731,
// "bids": [
// ["6500.12", "0.45054140"],
// ["6500.11", "0.45054140"],
// ],
// "asks": [
// ["6500.16", "0.57753524"],
// ["6500.15", "0.57753524"],
// ]
// }
//
// private (v3) market/orderbook/level2
//
// {
// "sequence": "3262786978",
// "time": 1550653727731,
// "bids": [
// ["6500.12", "0.45054140"],
// ["6500.11", "0.45054140"],
// ],
// "asks": [
// ["6500.16", "0.57753524"],
// ["6500.15", "0.57753524"],
// ]
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "time", &[]);
if is_equal(×tamp, &Value::Null) {
let mut nanoseconds: Value = self.safe_integer_k(data.clone(), "ts", &[]);
if !is_equal(&nanoseconds, &Value::Null) {
timestamp = self.parse_to_int(divide(&nanoseconds, &Value::Int(1000000)));
}
}
let mut orderbook: Value = self.parse_order_book(data.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), subtract(&level, &Value::Int(2)), subtract(&level, &Value::Int(1))]);
add_element_to_object(&mut orderbook, &Value::Str("nonce".to_string()), self.safe_integer_k(data.clone(), "sequence", &[]));
return orderbook;
Value::Null
}
pub fn handle_trigger_prices(&self, mut params: Value) -> Value {
let mut triggerPrice: Value = self.safe_value2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossPrice: Value = self.safe_value_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_value_k(params.clone(), "takeProfitPrice", &[]);
let mut isStopLoss: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isTakeProfit: bool = !is_equal(&takeProfitPrice, &Value::Null);
if is_true(&(is_true(&isStopLoss) && is_true(&isTakeProfit))) || is_true(&(is_true(&(!is_equal(&triggerPrice, &Value::Null))) && is_true(&(!is_equal(&stopLossPrice, &Value::Null))))) || is_true(&(is_true(&(!is_equal(&triggerPrice, &Value::Null))) && is_true(&isTakeProfit))) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" createOrder() - you should use either triggerPrice or stopLossPrice or takeProfitPrice".to_string()))));
}
return Value::List(vec![triggerPrice.clone(), stopLossPrice.clone(), takeProfitPrice.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#createOrder
* @description Create an order on the exchange
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-sync
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-test
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-stop-order
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order-test
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-stop-order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order-test
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-take-profit-and-stop-loss-order
* @see https://www.kucoin.com/docs-new/rest/ua/place-order
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta) endpoint, defaults to false
* Check createSpotOrder(), createContractOrder() and createUtaOrder () for more details on the extra parameters that can be used in params
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
return self.create_uta_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
return self.create_spot_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
return self.create_contract_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&self.id, &Value::Str(" createOrder() does not support market ".to_string())), &get_value(&market, &Value::Str("type".to_string())))));
}
Value::Null
}
/*
* @method
* @name kucoin#createSpotOrder
* @description helper method for creating spot orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-sync
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order-test
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-stop-order
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-order-test
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/add-stop-order
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
* @param {string} [params.marginMode] 'cross', // cross (cross mode) and isolated (isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned
* @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
* @param {bool} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {string} [params.clientOid] client order id, defaults to uuid if not passed
* @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
* @param {string} [params.tradeType] 'TRADE', // TRADE, MARGIN_TRADE // not used with margin orders
* limit orders ---------------------------------------------------
* @param {float} [params.cancelAfter] long, // cancel after n seconds, requires timeInForce to be GTT
* @param {bool} [params.hidden] false, // Order will not be displayed in the order book
* @param {bool} [params.iceberg] false, // Only a portion of the order is displayed in the order book
* @param {string} [params.visibleSize] this.amountToPrecision (symbol, visibleSize), // The maximum visible size of an iceberg order
* market orders --------------------------------------------------
* @param {string} [params.funds] // Amount of quote currency to use
* stop orders ----------------------------------------------------
* @param {string} [params.stop] Either loss or entry, the default is loss. Requires triggerPrice to be defined
* margin orders --------------------------------------------------
* @param {float} [params.leverage] Leverage size of the order
* @param {string} [params.stp] '', // self trade prevention, CN, CO, CB or DC
* @param {bool} [params.autoBorrow] false, // The system will first borrow you funds at the optimal interest rate and then place an order for you
* @param {bool} [params.hf] false, // true for hf order
* @param {bool} [params.test] set to true to test an order, no order will be created but the request will be validated
* @param {bool} [params.sync] set to true to use the hf sync call
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut testOrder: Value = self.safe_bool_k(params.clone(), "test", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("test".to_string()), &[]);
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut useSync: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("sync".to_string()), &[Value::Bool(false)]); useSync = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut triggerPricestopLossPricetakeProfitPriceVariable = self.handle_trigger_prices(params.clone());
let mut triggerPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(0));
let mut stopLossPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(1));
let mut takeProfitPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(2));
let mut tradeType: Value = self.safe_string_k(params.clone(), "tradeType", &[]); // keep it for backward compatibility
let mut isTriggerOrder: bool = is_true(&(!is_equal(&triggerPrice, &Value::Null))) || is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null)));
let mut marginResult: Value = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone()]);
let mut marginMode: Value = self.safe_string(marginResult.clone(), Value::Int(0), &[]);
let mut isMarginOrder: bool = is_equal(&tradeType, &Value::Str("MARGIN_TRADE".to_string())) || !is_equal(&marginMode, &Value::Null);
// don't omit anything before calling createOrderRequest
let mut orderRequest: Value = self.create_spot_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&testOrder, &Value::Bool(true)) {
if is_true(&isMarginOrder) {
if is_equal(&hf, &Value::Bool(true)) {
response = self.private_post_hf_margin_order_test(&[orderRequest.clone()]).await;
} else {
response = self.private_post_margin_order_test(&[orderRequest.clone()]).await;
}
} else if is_equal(&hf, &Value::Bool(true)) {
response = self.private_post_hf_orders_test(&[orderRequest.clone()]).await;
} else {
response = self.private_post_orders_test(&[orderRequest.clone()]).await;
}
} else if is_true(&isTriggerOrder) {
if is_true(&isMarginOrder) {
response = self.private_post_hf_margin_stop_order(&[orderRequest.clone()]).await;
} else {
response = self.private_post_stop_order(&[orderRequest.clone()]).await;
}
} else if is_true(&isMarginOrder) {
if is_equal(&hf, &Value::Bool(true)) {
response = self.private_post_hf_margin_order(&[orderRequest.clone()]).await;
} else {
response = self.private_post_margin_order(&[orderRequest.clone()]).await;
}
} else if is_true(&useSync) {
response = self.private_post_hf_orders_sync(&[orderRequest.clone()]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
response = self.private_post_hf_orders(&[orderRequest.clone()]).await;
} else {
response = self.private_post_orders(&[orderRequest.clone()]).await;
}
//
// {
// "code": "200000",
// "data": {
// "orderId": "5bd6e9286d99522a52e458de"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
pub fn create_spot_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
// required param, cannot be used twice
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[self.uuid(&[])]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clientOid".to_string(), clientOrderId.clone());
m.insert("side".to_string(), side.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("type".to_string(), type_var.clone());
m
});
let mut quoteAmount: Value = self.safe_number2(params.clone(), Value::Str("cost".to_string()), Value::Str("funds".to_string()), &[]);
let mut amountString: Value = Value::Null;
let mut costString: Value = Value::Null;
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("market".to_string())) {
if !is_equal("eAmount, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("cost".to_string()), Value::Str("funds".to_string())]), &[]);
// kucoin uses base precision even for quote values
costString = self.market_order_amount_to_precision(symbol.clone(), quoteAmount.clone());
add_element_to_object(&mut request, &Value::Str("funds".to_string()), costString.clone());
} else {
amountString = self.amount_to_precision(symbol.clone(), amount.clone());
add_element_to_object(&mut request, &Value::Str("size".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
} else {
amountString = self.amount_to_precision(symbol.clone(), amount.clone());
add_element_to_object(&mut request, &Value::Str("size".to_string()), amountString.clone());
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut tradeType: Value = self.safe_string_k(params.clone(), "tradeType", &[]); // keep it for backward compatibility
let mut triggerPricestopLossPricetakeProfitPriceVariable = self.handle_trigger_prices(params.clone());
let mut triggerPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(0));
let mut stopLossPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(1));
let mut takeProfitPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(2));
let mut isTriggerOrder: bool = is_true(&(!is_equal(&triggerPrice, &Value::Null))) || is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null)));
let mut isMarginOrder: bool = is_equal(&tradeType, &Value::Str("MARGIN_TRADE".to_string())) || !is_equal(&marginMode, &Value::Null);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string())]), &[]);
if is_true(&isTriggerOrder) {
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
} else if is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) {
if !is_equal(&stopLossPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stop".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("entry".to_string()), Value::Str("loss".to_string())));
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("stop".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("loss".to_string()), Value::Str("entry".to_string())));
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
}
}
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder does not support isolated margin for stop orders".to_string()))));
} else if is_equal(&marginMode, &Value::Str("cross".to_string())) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), get_value(&get_value(&self.options, &Value::Str("marginModes".to_string())), &marginMode));
}
} else if is_true(&isMarginOrder) {
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
add_element_to_object(&mut request, &Value::Str("marginModel".to_string()), Value::Str("isolated".to_string()));
}
}
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(false), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&postOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("postOnly".to_string()), Value::Bool(true));
}
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
pub fn market_order_amount_to_precision(&self, mut symbol: Value, mut amount: Value) -> Value {
let mut market: Value = self.market(symbol.clone());
let mut result: Value = self.decimal_to_precision(amount.clone(), Value::Int(crate::runtime::TRUNCATE), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("quoteIncrement".to_string())), &[self.precisionMode.clone(), self.paddingMode.clone()]);
if is_equal(&result, &Value::Str("0".to_string())) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&add(&self.id, &Value::Str(" amount of ".to_string())), &get_value(&market, &Value::Str("symbol".to_string()))), &Value::Str(" must be greater than minimum amount precision of ".to_string())), &self.number_to_string(get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("amount".to_string()))))));
}
return result;
Value::Null
}
/*
* @method
* @name kucoin#createContractOrder
* @description helper method for creating contract orders
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order-test
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-take-profit-and-stop-loss-order
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered and the triggerPriceType
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered and the triggerPriceType
* @param {float} [params.triggerPrice] The price a trigger order is triggered at
* @param {float} [params.stopLossPrice] price to trigger stop-loss orders
* @param {float} [params.takeProfitPrice] price to trigger take-profit orders
* @param {bool} [params.reduceOnly] A mark to reduce the position size only. Set to false by default. Need to set the position size when reduceOnly is true.
* @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
* @param {bool} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
* @param {float} [params.cost] the cost of the order in units of USDT
* @param {string} [params.marginMode] 'cross' or 'isolated', default is 'isolated'
* @param {bool} [params.hedged] *swap and future only* true for hedged mode, false for one way mode, default is false
* ----------------- Exchange Specific Parameters -----------------
* @param {float} [params.leverage] Leverage size of the order (mandatory param in request, default is 1)
* @param {string} [params.clientOid] client order id, defaults to uuid if not passed
* @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
* @param {string} [params.stop] 'up' or 'down', the direction the triggerPrice is triggered from, requires triggerPrice. down: Triggers when the price reaches or goes below the triggerPrice. up: Triggers when the price reaches or goes above the triggerPrice.
* @param {string} [params.triggerPriceType] "last", "mark", "index" - defaults to "mark"
* @param {string} [params.stopPriceType] exchange-specific alternative for triggerPriceType: TP, IP or MP
* @param {bool} [params.closeOrder] set to true to close position
* @param {bool} [params.test] set to true to use the test order endpoint (does not submit order, use to validate params)
* @param {bool} [params.forceHold] A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default.\
* @param {string} [params.positionSide] *swap and future only* hedged two-way position side, LONG or SHORT
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_contract_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut testOrder: Value = self.safe_bool_k(params.clone(), "test", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("test".to_string()), &[]);
let mut hasTpOrSlOrder: bool = is_true(&(!is_equal(&self.safe_value_k(params.clone(), "stopLoss", &[]), &Value::Null))) || is_true(&(!is_equal(&self.safe_value_k(params.clone(), "takeProfit", &[]), &Value::Null)));
let mut orderRequest: Value = self.create_contract_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&testOrder, &Value::Bool(true)) {
response = self.futures_private_post_orders_test(&[orderRequest.clone()]).await;
} else {
if is_true(&hasTpOrSlOrder) {
response = self.futures_private_post_st_orders(&[orderRequest.clone()]).await;
} else {
response = self.futures_private_post_orders(&[orderRequest.clone()]).await;
}
}
//
// {
// "code": "200000",
// "data": {
// "orderId": "619717484f1d010001510cde",
// },
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
pub fn create_contract_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
// required param, cannot be used twice
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[self.uuid(&[])]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clientOid".to_string(), clientOrderId.clone());
m.insert("side".to_string(), side.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("leverage".to_string(), Value::Int(1));
m
});
let mut marginModeUpper: Value = self.safe_string_upper(params.clone(), Value::Str("marginMode".to_string()), &[]);
if !is_equal(&marginModeUpper, &Value::Null) {
params = self.omit(params.clone(), Value::Str("marginMode".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("marginMode".to_string()), marginModeUpper.clone());
}
let mut cost: Value = self.safe_string_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if !is_equal(&cost, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("valueQty".to_string()), self.cost_to_precision(symbol.clone(), cost.clone()));
} else {
if is_equal(&amount, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires an amount argument".to_string()))));
}
if is_less_than(&amount, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() minimum contract order amount is 1".to_string()))));
}
let mut sizeString: Value = self.amount_to_precision(symbol.clone(), amount.clone());
if !is_equal(&sizeString, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), crate::runtime::parse_int(&sizeString));
}
}
let mut triggerPricestopLossPricetakeProfitPriceVariable = self.handle_trigger_prices(params.clone());
let mut triggerPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(0));
let mut stopLossPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(1));
let mut takeProfitPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(2));
let mut stopLoss: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
// const isTpAndSl = stopLossPrice && takeProfitPrice;
let mut triggerPriceTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Str("MP".to_string()));
m.insert("last".to_string(), Value::Str("TP".to_string()));
m.insert("index".to_string(), Value::Str("IP".to_string()));
m
});
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
let mut triggerPriceTypeValue: Value = self.safe_string(triggerPriceTypes.clone(), triggerPriceType.clone(), &[triggerPriceType.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("takeProfit".to_string()), Value::Str("stopLoss".to_string())]), &[]);
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stop".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("up".to_string()), Value::Str("down".to_string())));
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("stopPriceType".to_string()), triggerPriceTypeValue.clone());
} else if is_true(&hasStopLoss) || is_true(&hasTakeProfit) {
let mut priceType: Value = triggerPriceTypeValue.clone();
if is_true(&hasStopLoss) {
let mut slPrice: Value = self.safe_string2(stopLoss.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("triggerStopDownPrice".to_string()), self.price_to_precision(symbol.clone(), slPrice.clone()));
priceType = self.safe_string_k(stopLoss.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
priceType = self.safe_string(triggerPriceTypes.clone(), priceType.clone(), &[priceType.clone()]);
}
if is_true(&hasTakeProfit) {
let mut tpPrice: Value = self.safe_string2(takeProfit.clone(), Value::Str("triggerPrice".to_string()), Value::Str("takeProfitPrice".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("triggerStopUpPrice".to_string()), self.price_to_precision(symbol.clone(), tpPrice.clone()));
priceType = self.safe_string_k(takeProfit.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
priceType = self.safe_string(triggerPriceTypes.clone(), priceType.clone(), &[priceType.clone()]);
}
add_element_to_object(&mut request, &Value::Str("stopPriceType".to_string()), priceType.clone());
} else if is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) {
if !is_equal(&stopLossPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stop".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("up".to_string()), Value::Str("down".to_string())));
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("stop".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("down".to_string()), Value::Str("up".to_string())));
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
}
add_element_to_object(&mut request, &Value::Str("reduceOnly".to_string()), Value::Bool(true));
add_element_to_object(&mut request, &Value::Str("stopPriceType".to_string()), triggerPriceTypeValue.clone());
}
let mut uppercaseType: Value = to_upper(&type_var);
let mut timeInForce: Value = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[]);
if is_equal(&uppercaseType, &Value::Str("LIMIT".to_string())) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a price argument for limit orders".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), timeInForce.clone());
}
}
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(Value::Bool(is_equal(&type_var, &Value::Str("market".to_string()))), Value::Bool(false), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&postOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("postOnly".to_string()), Value::Bool(true));
}
let mut hidden: Value = self.safe_value_k(params.clone(), "hidden", &[]);
if is_true(&(is_equal(&postOnly, &Value::Bool(true)))) && is_true(&(!is_equal(&hidden, &Value::Null))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() does not support the postOnly parameter together with a hidden parameter".to_string()))));
}
let mut iceberg: Value = self.safe_value_k(params.clone(), "iceberg", &[]);
if is_true(&(!is_equal(&iceberg, &Value::Null))) && is_true(&(!is_equal(&iceberg, &Value::Bool(false)))) {
let mut visibleSize: Value = self.safe_value_k(params.clone(), "visibleSize", &[]);
if is_equal(&visibleSize, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a visibleSize parameter for iceberg orders".to_string()))));
}
}
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut hedged: Value = Value::Null;
{ let __destr_tmp = self.handle_param_bool(params.clone(), Value::Str("hedged".to_string()), &[Value::Bool(false)]); hedged = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&reduceOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("reduceOnly".to_string()), reduceOnly.clone());
if is_equal(&hedged, &Value::Bool(true)) {
let mut reduceOnlyPosSide: Value = ternary(is_true(&(is_equal(&side, &Value::Str("sell".to_string())))), Value::Str("LONG".to_string()), Value::Str("SHORT".to_string()));
add_element_to_object(&mut request, &Value::Str("positionSide".to_string()), reduceOnlyPosSide.clone());
}
} else {
if is_equal(&hedged, &Value::Bool(true)) {
let mut posSide: Value = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("LONG".to_string()), Value::Str("SHORT".to_string()));
add_element_to_object(&mut request, &Value::Str("positionSide".to_string()), posSide.clone());
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("timeInForce".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("hedged".to_string())]), &[]); // Time in force only valid for limit orders, exchange error when gtc for market orders
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#createUtaOrder
* @description helper method for creating uta orders
* @see https://www.kucoin.com/docs-new/rest/ua/place-order
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client order id, defaults to uuid if not passed
* @param {float} [params.cost] the cost of the order in units of quote currency
* @param {string} [params.timeInForce] GTC, GTD, IOC, FOK or PO
* @param {bool} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK (default is false)
* @param {bool} [params.reduceOnly] *contract markets only* A mark to reduce the position size only. Set to false by default
* @param {float} [params.triggerPrice] The price a trigger order is triggered at
* @param {string} [params.triggerDirection] 'ascending' or 'descending', the direction the triggerPrice is triggered from, requires triggerPrice
* @param {string} [params.triggerPriceType] *contract markets only* "last", "mark", "index" - defaults to "mark"
* @param {float} [params.stopLossPrice] price to trigger stop-loss orders
* @param {float} [params.takeProfitPrice] price to trigger take-profit orders
* @param {string} [params.marginMode] 'cross' or 'isolated', (default is 'cross' for margin orders, default is 'isolated' for contract orders)
*
* Exchange-specific parameters -------------------------------------------------
* @param {string} [params.accountMode] 'unified' or 'classic', default is 'unified'
* @param {string} [params.stp] '', // self trade prevention, CN, CO, CB or DC
* @param {int} [params.cancelAfter] - Cancel After N Seconds (Calculated from the time of entering the matching engine), only effective when timeInForce is GTD
* @param {string} [params.sizeUnit] *contracts only* 'BASECCY' (amount of base currency) or 'UNIT' (number of contracts), default is 'UNIT'
*
* Classic account parameters
* @param {bool} [params.autoBorrow] *classic margin orders only*
* @param {bool} [params.autoRepay] *classic margin orders only*
* @param {string} [params.hedged] *classic contract orders only* true for hedged mode, false for one way mode, default is false
* @param {int} [params.leverage] *classic contract orders with isolated marginMode only* Leverage size of the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_uta_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_uta_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = self.uta_private_post_account_mode_order_place(&[request.clone()]).await;
//
// {
// "code": "200000",
// "data": {
// "orderId": "426319129738321920",
// "tradeType": "SPOT",
// "ts": 1774455603216000000,
// "clientOid": "b896c118-a674-4863-baf4-a9ea3cd696c5"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
pub fn create_uta_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a side argument".to_string()))));
}
let mut isSpot: Value = get_value(&market, &Value::Str("spot".to_string()));
let mut isContract: Value = get_value(&market, &Value::Str("contract".to_string()));
let mut accountMode: Value = Value::Str("unified".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("accountMode".to_string()), &[accountMode.clone()]); accountMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isUnified: Value = Value::Bool(is_equal(&accountMode, &Value::Str("unified".to_string())));
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut tradeType: Value = self.handle_trade_type(&[isContract.clone(), marginMode.clone(), isUnified.clone(), params.clone()]);
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[self.uuid(&[])]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountMode".to_string(), accountMode.clone());
m.insert("tradeType".to_string(), tradeType.clone());
m.insert("clientOid".to_string(), clientOrderId.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), to_upper(&side));
m.insert("orderType".to_string(), to_upper(&type_var));
m
});
if !is_equal(&tradeType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), tradeType.clone());
}
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("market".to_string())));
let mut cost: Value = self.safe_string_k(params.clone(), "cost", &[]);
if !is_equal(&cost, &Value::Null) {
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if is_true(&(is_equal(&isSpot, &Value::Bool(true)))) && is_true(&isMarketOrder) {
add_element_to_object(&mut request, &Value::Str("sizeUnit".to_string()), Value::Str("QUOTECCY".to_string()));
add_element_to_object(&mut request, &Value::Str("size".to_string()), self.market_order_amount_to_precision(symbol.clone(), cost.clone()));
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() with cost is supported for spot market orders only".to_string()))));
}
} else {
let mut sizeUnit: Value = Value::Str("BASECCY".to_string());
if is_equal(&isContract, &Value::Bool(true)) {
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("sizeUnit".to_string()), &[Value::Str("UNIT".to_string())]); sizeUnit = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
}
add_element_to_object(&mut request, &Value::Str("sizeUnit".to_string()), sizeUnit.clone());
add_element_to_object(&mut request, &Value::Str("size".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_true(&isMarketOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(isMarketOrder.clone(), Value::Bool(false), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut timeInForce: Value = self.handle_time_in_force(&[params.clone()]);
if is_true(&(!is_equal(&timeInForce, &Value::Null))) {
params = self.omit(params.clone(), Value::Str("timeInForce".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), timeInForce.clone());
}
if is_equal(&postOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("postOnly".to_string()), Value::Bool(true));
}
if is_equal(&isContract, &Value::Bool(true)) {
if !is_true(&isUnified) {
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("marginMode".to_string()), to_upper(&marginMode));
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
let mut leverage: Value = self.safe_integer_k(params.clone(), "leverage", &[]);
if is_equal(&leverage, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("leverage".to_string()), Value::Int(1));
}
}
}
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut hedged: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_param_bool(params.clone(), Value::Str("hedged".to_string()), &[hedged.clone()]); hedged = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&hedged, &Value::Bool(true)) {
let mut positionSide: Value = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("LONG".to_string()), Value::Str("SHORT".to_string()));
if is_equal(&reduceOnly, &Value::Bool(true)) {
positionSide = ternary(is_true(&(is_equal(&positionSide, &Value::Str("LONG".to_string())))), Value::Str("SHORT".to_string()), Value::Str("LONG".to_string()));
}
add_element_to_object(&mut request, &Value::Str("positionSide".to_string()), positionSide.clone());
}
}
}
// handling with conditional orders
let mut triggerPricestopLossPricetakeProfitPriceVariable = self.handle_trigger_prices(params.clone());
let mut triggerPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(0));
let mut stopLossPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(1));
let mut takeProfitPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPriceVariable, &Value::Int(2));
let mut stopLoss: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
let mut triggerPriceTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Str("MP".to_string()));
m.insert("last".to_string(), Value::Str("TP".to_string()));
m.insert("index".to_string(), Value::Str("IP".to_string()));
m
});
if !is_equal(&triggerPrice, &Value::Null) {
let mut triggerDirection: Value = self.safe_string_k(params.clone(), "triggerDirection", &[]);
if is_equal(&triggerDirection, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a triggerDirection parameter for trigger orders. Provide params.tringgerDirection or use params.stopLossPrice or params.takeProfitPrice instead of params.triggerPrice".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("triggerDirection".to_string()), ternary(is_true(&(is_equal(&triggerDirection, &Value::Str("ascending".to_string())))), Value::Str("UP".to_string()), Value::Str("DOWN".to_string())));
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
} else if is_true(&hasStopLoss) || is_true(&hasTakeProfit) {
if !is_equal(&isContract, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() stopLoss and takeProfit parameters are only supported for contract orders".to_string()))));
}
if is_true(&hasStopLoss) {
let mut slTriggerPrice: Value = self.safe_string2(stopLoss.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut slTriggerPriceType: Value = self.safe_string_k(stopLoss.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
add_element_to_object(&mut request, &Value::Str("slTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), slTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("slTriggerPriceType".to_string()), self.safe_string(triggerPriceTypes.clone(), slTriggerPriceType.clone(), &[slTriggerPriceType.clone()]));
}
if is_true(&hasTakeProfit) {
let mut tpTriggerPrice: Value = self.safe_string2(takeProfit.clone(), Value::Str("triggerPrice".to_string()), Value::Str("takeProfitPrice".to_string()), &[]);
let mut tpTriggerPriceType: Value = self.safe_string_k(takeProfit.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
add_element_to_object(&mut request, &Value::Str("tpTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), tpTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("tpTriggerPriceType".to_string()), self.safe_string(triggerPriceTypes.clone(), tpTriggerPriceType.clone(), &[tpTriggerPriceType.clone()]));
}
} else if is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) {
if !is_equal(&stopLossPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("triggerDirection".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("UP".to_string()), Value::Str("DOWN".to_string())));
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
if is_equal(&isContract, &Value::Bool(true)) {
let mut stopLossPriceType: Value = self.safe_string2(params.clone(), Value::Str("stopLossPriceType".to_string()), Value::Str("triggerPriceType".to_string()), &[Value::Str("mark".to_string())]);
add_element_to_object(&mut request, &Value::Str("triggerPriceType".to_string()), self.safe_string(triggerPriceTypes.clone(), stopLossPriceType.clone(), &[stopLossPriceType.clone()]));
}
} else {
add_element_to_object(&mut request, &Value::Str("triggerDirection".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("DOWN".to_string()), Value::Str("UP".to_string())));
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
if is_equal(&isContract, &Value::Bool(true)) {
let mut takeProfitPriceType: Value = self.safe_string2(params.clone(), Value::Str("takeProfitPriceType".to_string()), Value::Str("triggerPriceType".to_string()), &[Value::Str("mark".to_string())]);
add_element_to_object(&mut request, &Value::Str("triggerPriceType".to_string()), self.safe_string(triggerPriceTypes.clone(), takeProfitPriceType.clone(), &[takeProfitPriceType.clone()]));
}
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("stopPriceType".to_string()), Value::Str("stopLossPriceType".to_string()), Value::Str("takeProfitPriceType".to_string()), Value::Str("triggerPriceType".to_string()), Value::Str("triggerDirection".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string()), Value::Str("hedged".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#createMarketOrderWithCost
* @description create a market order by providing the symbol, side and cost
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} side 'buy' or 'sell'
* @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_order_with_cost(&mut self, mut symbol: Value, mut side: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), cost.clone());
m
});
let __ws_arg_27 = self.extend(req.clone(), &[params.clone()]);
return self.create_order(symbol.clone(), Value::Str("market".to_string()), side.clone(), cost.clone(), &[Value::Null, __ws_arg_27]).await;
Value::Null
}
/*
* @method
* @name kucoin#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_market_buy_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
return self.create_market_order_with_cost(symbol.clone(), Value::Str("buy".to_string()), cost.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name kucoin#createMarketSellOrderWithCost
* @description create a market sell order by providing the symbol and cost
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_market_sell_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
return self.create_market_order_with_cost(symbol.clone(), Value::Str("sell".to_string()), cost.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name kucoin#createOrders
* @description create a list of trade orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders-sync
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @param {object} [params] extra parameters specific to the exchange API endpoint
* Check createSpotOrders() and createContractOrders() for more details on the extra parameters that can be used in params
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut isSpot: bool = false;
let mut isContract: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_884: bool = true;
while { if !__for_first_884 { i = add(&i, &Value::Int(1)); } __for_first_884 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = self.safe_dict(orders.clone(), i.clone(), &[]);
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[]);
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrders() requires a symbol for each order".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
isSpot = true;
} else if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
isContract = true;
}
}
}
if is_true(&isSpot) && is_true(&isContract) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() requires all orders to be either spot or contract".to_string()))));
} else if is_true(&isSpot) {
return self.create_spot_orders(orders.clone(), &[params.clone()]).await;
} else if is_true(&isContract) {
return self.create_contract_orders(orders.clone(), &[params.clone()]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() does not support the markets of the orders provided".to_string()))));
}
Value::Null
}
/*
* @method
* @name kucoin#createSpotOrders
* @description helper method for creating spot orders in batch
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-add-orders-sync
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/batch-add-orders
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.hf] false, // true for hf orders
* @param {bool} [params.sync] false, // true to use the hf sync call
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_spot_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut symbol: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_885: bool = true;
while { if !__for_first_885 { i = add(&i, &Value::Int(1)); } __for_first_885 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
if is_equal(&marketId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrders() requires a symbol for each order".to_string()))));
}
if is_equal(&symbol, &Value::Null) {
symbol = marketId.clone();
} else {
if !is_equal(&symbol, &marketId) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() requires all orders to have the same symbol".to_string()))));
}
}
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
if !is_equal(&type_var, &Value::Str("limit".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() only supports limit orders".to_string()))));
}
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_value_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_spot_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrders() requires at least one order with a symbol".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("orderList".to_string(), ordersRequests.clone());
m
});
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut useSync: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrders".to_string()), Value::Str("sync".to_string()), &[Value::Bool(false)]); useSync = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&useSync) {
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_hf_orders_multi_sync(&[__ws_arg_28]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_hf_orders_multi(&[__ws_arg_29]).await;
} else {
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_orders_multi(&[__ws_arg_30]).await;
}
//
// {
// "code": "200000",
// "data": {
// "data": [
// {
// "symbol": "LTC-USDT",
// "type": "limit",
// "side": "sell",
// "price": "90",
// "size": "0.1",
// "funds": null,
// "stp": "",
// "stop": "",
// "stopPrice": null,
// "timeInForce": "GTC",
// "cancelAfter": 0,
// "postOnly": false,
// "hidden": false,
// "iceberge": false,
// "iceberg": false,
// "visibleSize": null,
// "channel": "API",
// "id": "6539148443fcf500079d15e5",
// "status": "success",
// "failMsg": null,
// "clientOid": "5c4c5398-8ab2-4b4e-af8a-e2d90ad2488f"
// },
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
data = self.safe_list_k(data.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[]);
Value::Null
}
/*
* @method
* @name kucoin#createContractOrders
* @description helper method for creating contract orders in batch
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/batch-add-orders
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_contract_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_886: bool = true;
while { if !__for_first_886 { i = add(&i, &Value::Int(1)); } __for_first_886 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut symbol: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrders() requires a symbol for each order".to_string()))));
}
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[Value::Str("".to_string())]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_value_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_contract_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut response: Value = self.futures_private_post_orders_multi(&[ordersRequests.clone()]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "orderId": "135241412609331200",
// "clientOid": "3d8fcc13-0b13-447f-ad30-4b3441e05213",
// "symbol": "LTCUSDTM",
// "code": "200000",
// "msg": "success"
// },
// {
// "orderId": "135241412747743234",
// "clientOid": "b878c7ee-ae3e-4d63-a20b-038acbb7306f",
// "symbol": "LTCUSDTM",
// "code": "200000",
// "msg": "success"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[]);
Value::Null
}
/*
* @method
* @name kucoin#editOrder
* @description edit an order, kucoin currently only supports the modification of HF orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/modify-order
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type not used
* @param {string} side not used
* @param {float} amount how much of the currency you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client order id, defaults to id if not passed
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("newSize".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("newPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_hf_orders_alter(&[__ws_arg_31]).await;
//
// {
// "code":"200000",
// "data":{
// "newOrderId":"6478d7a6c883280001e92d8b"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#cancelOrder
* @description cancels an open order
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld-sync
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid-sync
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/ua/cancel-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', used if symbol is not provided (default is 'spot')
* @param {string} [params.marginMode] *spot only* 'cross' or 'isolated'
* @param {boolean} [params.uta] true for cancelling order with unified account endpoint (default is false)
* Check cancelSpotOrder() and cancelContractOrder() for more details on the extra parameters that can be used in params
* @returns Response from the exchange
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelOrder".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
return self.cancel_uta_order(id.clone(), &[symbol.clone(), params.clone()]).await;
}
let mut marketType: Value = Value::Null;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("margin".to_string())))) {
return self.cancel_spot_order(id.clone(), &[symbol.clone(), params.clone()]).await;
} else {
return self.cancel_contract_order(id.clone(), &[symbol.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name kucoin#cancelSpotOrder
* @description helper method for cancelling spot orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-orderld-sync
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-order-by-clientoid-sync
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-stop-order-by-clientoid
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] True if cancelling a stop order
* @param {bool} [params.hf] false, // true for hf order
* @param {bool} [params.sync] false, // true to use the hf sync call
* @param {string} [params.marginMode] 'cross' or 'isolated'
* @returns Response from the exchange
*/
pub async fn cancel_spot_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut useSync: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelOrder".to_string()), Value::Str("sync".to_string()), &[Value::Bool(false)]); useSync = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("cancelOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut tradeType: Value = self.safe_string_k(params.clone(), "tradeType", &[]); // keep it for backward compatibility
let mut isMarginOrder: bool = is_equal(&tradeType, &Value::Str("MARGIN_TRADE".to_string())) || !is_equal(&marginMode, &Value::Null);
if is_true(&(is_equal(&hf, &Value::Bool(true)))) || is_true(&useSync) || is_true(&isMarginOrder) {
if !is_equal(&trigger, &Value::Bool(true)) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol parameter for hf orders".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let mut response: Value = Value::Null;
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), Value::Str("tradeType".to_string())]), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
if is_equal(&trigger, &Value::Bool(true)) {
if is_true(&isMarginOrder) {
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_margin_stop_order_cancel_by_client_oid(&[__ws_arg_32]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut orderIds: Value = self.safe_list_k(data.clone(), "cancelledOrderIds", &[Value::List(vec![])]);
let mut orderId: Value = self.safe_string(orderIds.clone(), Value::Int(0), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("id".to_string(), orderId.clone());
m
}), &[]);
} else {
//
// {
// code: '200000',
// data: {
// cancelledOrderId: 'vs8lgpiuao41iaft003khbbk',
// clientOid: '123456'
// }
// }
//
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_stop_order_cancel_order_by_client_oid(&[__ws_arg_33]).await;
}
} else if is_true(&isMarginOrder) {
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_margin_orders_client_order_client_oid(&[__ws_arg_34]).await;
} else if is_true(&useSync) {
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_orders_sync_client_order_client_oid(&[__ws_arg_35]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_orders_client_order_client_oid(&[__ws_arg_36]).await;
} else {
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_order_client_order_client_oid(&[__ws_arg_37]).await;
}
response = self.safe_dict_k(response.clone(), "data", &[]);
return self.parse_order(response.clone(), &[]);
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
if is_equal(&trigger, &Value::Bool(true)) {
if is_true(&isMarginOrder) {
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_margin_stop_order_cancel_by_id(&[__ws_arg_38]).await;
} else {
//
// {
// code: '200000',
// data: { cancelledOrderIds: [ 'vs8lgpiuaco91qk8003vebu9' ] }
// }
//
let __ws_arg_39 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_stop_order_order_id(&[__ws_arg_39]).await;
}
} else if is_true(&isMarginOrder) {
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_margin_orders_order_id(&[__ws_arg_40]).await;
} else if is_true(&useSync) {
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_orders_sync_order_id(&[__ws_arg_41]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_hf_orders_order_id(&[__ws_arg_42]).await;
//
// {
// "code": "200000",
// "data": {
// "orderId": "630625dbd9180300014c8d52"
// }
// }
//
response = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(response.clone(), &[]);
} else {
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_orders_order_id(&[__ws_arg_43]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut orderId: Value = self.safe_string_k(data.clone(), "orderId", &[]);
let mut orderIds: Value = self.safe_list_k(data.clone(), "cancelledOrderIds", &[Value::List(vec![])]);
orderId = self.safe_string(orderIds.clone(), Value::Int(0), &[orderId.clone()]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("id".to_string(), orderId.clone());
m
}), &[]);
}
Value::Null
}
/*
* @method
* @name kucoin#cancelContractOrder
* @description helper method for cancelling contract orders
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-order-by-clientoid
* @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.clientOrderId] cancel order by client order id
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_contract_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if !is_equal(&clientOrderId, &Value::Null) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument when cancelling by clientOrderId".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_delete_orders_client_order_client_oid(&[__ws_arg_44]).await;
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
let __ws_arg_45 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_delete_orders_order_id(&[__ws_arg_45]).await;
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[]);
Value::Null
}
/*
* @method
* @name kucoin#cancelUtaOrder
* @description helper method for cancelling uta orders
* @see https://www.kucoin.com/docs-new/rest/ua/cancel-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.accountMode] 'unified' or 'classic' (default is 'unified')
* @param {string} [params.clientOrderId] client order id, required if id is not provided
* @param {string} [params.marginMode] 'cross' or 'isolated', required if fetching a margin order (unified accountMode supports only cross margin)
* @returns Response from the exchange
*/
pub async fn cancel_uta_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument for uta endpoint".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
} else {
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires an id argument or clientOrderId parameter".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let mut accountMode: Value = Value::Str("unified".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelOrder".to_string()), Value::Str("accountMode".to_string()), &[accountMode.clone()]); accountMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), accountMode.clone());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("cancelOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isUnified: Value = Value::Bool(is_equal(&accountMode, &Value::Str("unified".to_string())));
let mut tradeType: Value = self.handle_trade_type(&[get_value(&market, &Value::Str("contract".to_string())), marginMode.clone(), isUnified.clone(), params.clone()]);
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), tradeType.clone());
let __ws_arg_46 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_private_post_account_mode_order_cancel(&[__ws_arg_46]).await;
//
// {
// "code": "200000",
// "data": {
// "orderId": "426319129738321920",
// "tradeType": "SPOT",
// "ts": 1774457628105000000,
// "clientOid": "b896c118-a674-4863-baf4-a9ea3cd696c5"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#cancelAllOrders
* @description cancel all open orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders-by-symbol
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-cancel-stop-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-all-orders-by-symbol
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/batch-cancel-stop-orders
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-orders
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-stop-orders
* @see https://www.kucoin.com/docs-new/rest/ua/batch-cancel-order-by-symbol
* @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.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @param {string} [params.marginMode] *spot only* 'cross' or 'isolated'
* @param {boolean} [params.uta] true for cancelling orders with unified account endpoint (default is false)
* Check cancelAllSpotOrders(), cancelAllContractOrders() and cancelAllUtaOrders() for more details on the extra parameters that can be used in params
* @returns Response from the 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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelAllOrders".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
return self.cancel_all_uta_orders(&[symbol.clone(), params.clone()]).await;
}
let mut marketType: Value = Value::Null;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("margin".to_string())))) {
return self.cancel_all_spot_orders(&[symbol.clone(), params.clone()]).await;
} else {
return self.cancel_all_contract_orders(&[symbol.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name kucoin#cancelAllSpotOrders
* @description helper method for cancelling all spot orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders-by-symbol
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/cancel-all-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/batch-cancel-stop-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/cancel-all-orders-by-symbol
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/batch-cancel-stop-orders
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] *invalid for isolated margin* true if cancelling all stop orders
* @param {string} [params.marginMode] 'cross' or 'isolated'
* @param {string} [params.orderIds] *stop orders only* Comma separated order IDs
* @param {bool} [params.hf] false, // true for hf order
* @returns Response from the exchange
*/
pub async fn cancel_all_spot_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut marginModequeryVariable = self.handle_margin_mode_and_params(Value::Str("cancelAllOrders".to_string()), &[params.clone()]);
let mut marginMode: Value = get_value(&marginModequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marginModequeryVariable, &Value::Int(1));
let mut isMarginOrders: bool = !is_equal(&marginMode, &Value::Null);
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.market_id(symbol.clone()));
} else if is_true(&(!is_equal(&trigger, &Value::Bool(true)))) && is_true(&isMarginOrders) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument for margin non-trigger orders".to_string()))));
}
if is_true(&isMarginOrders) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), get_value(&get_value(&self.options, &Value::Str("marginModes".to_string())), &marginMode));
if is_equal(&marginMode, &Value::Str("isolated".to_string())) && is_true(&(is_equal(&trigger, &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelAllOrders does not support isolated margin for stop orders".to_string()))));
}
}
let mut response: Value = Value::Null;
if is_equal(&trigger, &Value::Bool(true)) {
if is_true(&isMarginOrders) {
let __ws_arg_47 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delete_hf_margin_stop_order_cancel(&[__ws_arg_47]).await;
} else {
let __ws_arg_48 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delete_stop_order_cancel(&[__ws_arg_48]).await;
}
} else if is_true(&isMarginOrders) {
let __ws_arg_49 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delete_hf_margin_orders(&[__ws_arg_49]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
if is_equal(&symbol, &Value::Null) {
let __ws_arg_50 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delete_hf_orders_cancel_all(&[__ws_arg_50]).await;
} else {
let __ws_arg_51 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delete_hf_orders(&[__ws_arg_51]).await;
}
} else {
let __ws_arg_52 = self.extend(request.clone(), &[query.clone()]);
response = self.private_delete_orders(&[__ws_arg_52]).await;
}
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[])]);
Value::Null
}
/*
* @method
* @name kucoin#cancelAllContractOrders
* @description helper method for cancelling all contract orders
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-orders
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/cancel-all-stop-orders
* @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 {object} [params.trigger] When true, all the trigger orders will be cancelled
* @returns Response from the exchange
*/
pub async fn cancel_all_contract_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.market_id(symbol.clone()));
}
let mut trigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_true(&(!is_equal(&trigger, &Value::Null))) && is_true(&(!is_equal(&trigger, &Value::Bool(false)))) {
let __ws_arg_53 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_delete_stop_orders(&[__ws_arg_53]).await;
} else {
let __ws_arg_54 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_delete_orders(&[__ws_arg_54]).await;
}
//
// {
// "code": "200000",
// "data": {
// "cancelledOrderIds": [
// "619714b8b6353000014c505a",
// ],
// },
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m
}), &[])]);
Value::Null
}
/*
* @method
* @name kucoin#cancelAllUtaOrders
* @description helper method for cancelling all uta orders
* @see https://www.kucoin.com/docs-new/rest/ua/batch-cancel-order-by-symbol
* @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.trigger] true if cancelling all stop orders
* @param {string} [params.marginMode] 'CROSS' or 'ISOLATED'
* @returns Response from the exchange
*/
pub async fn cancel_all_uta_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument for uta endpoint".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut isContract: Value = get_value(&market, &Value::Str("contract".to_string()));
let mut tradeType: Value = ternary(is_true(&(is_equal(&isContract, &Value::Bool(true)))), Value::Str("FUTURES".to_string()), Value::Str("SPOT".to_string()));
let mut trigger: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_param_bool(params.clone(), Value::Str("trigger".to_string()), &[trigger.clone()]); trigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut orderFilter: Value = ternary(is_true(&(is_equal(&trigger, &Value::Bool(true)))), Value::Str("ADVANCED".to_string()), Value::Str("NORMAL".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountMode".to_string(), Value::Str("unified".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("tradeType".to_string(), tradeType.clone());
m.insert("orderFilter".to_string(), orderFilter.clone());
m
});
let __ws_arg_55 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_private_post_account_mode_order_cancel_all(&[__ws_arg_55]).await;
//
// {
// "code": "200000",
// "data": {
// "tradeType": "SPOT",
// "ts": 1774458644140000000,
// "items": [
// {
// "orderId": "426328635071352832"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), Value::Null, Value::Null, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name kucoin#fetchOrdersByStatus
* @description fetches a list of orders placed on the exchange
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-open-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-closed-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-list
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list
* @see https://www.kucoin.com/docs-new/rest/ua/get-open-order-list
* @see https://www.kucoin.com/docs-new/rest/ua/get-order-history
* @param {string} status 'active' or 'closed', only 'active' is valid for stop orders
* @param {string} symbol unified symbol for the market to retrieve orders from
* @param {int} [since] timestamp in ms of the earliest order to retrieve
* @param {int} [limit] The maximum number of orders to retrieve
* @param {object} [params] exchange specific parameters
* @param {boolean} [params.uta] true for fetch orders with uta endpoint (default is false)
* Check fetchSpotOrdersByStatus(), fetchContractOrdersByStatus() and fetchUtaOrdersByStatus() for more details on the extra parameters that can be used in params
* @returns An [array of order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders_by_status(&mut self, mut status: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrdersByStatus".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marketType: Value = Value::Null;
if is_equal(&symbol, &Value::Null) {
let mut type_var: Value = self.safe_string_k(params.clone(), "type", &[]); // exchange has specific param for order type
// todo check for better way to determine market type without symbol
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("margin".to_string())) || is_equal(&type_var, &Value::Str("swap".to_string())) || is_equal(&type_var, &Value::Str("future".to_string())) || is_equal(&type_var, &Value::Str("contract".to_string())) {
marketType = type_var.clone();
params = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
} else {
let mut methodOptions: Value = self.safe_dict_k(self.options.clone(), "fetchOrdersByStatus", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut methodDefaultType: Value = self.safe_string2(methodOptions.clone(), Value::Str("defaultType".to_string()), Value::Str("type".to_string()), &[]);
if is_equal(&methodDefaultType, &Value::Null) {
marketType = self.safe_string2(self.options.clone(), Value::Str("defaultType".to_string()), Value::Str("type".to_string()), &[Value::Str("spot".to_string())]);
} else {
marketType = methodDefaultType.clone();
}
}
} else {
let mut market: Value = self.market(symbol.clone());
marketType = get_value(&market, &Value::Str("type".to_string()));
}
if is_true(&uta) {
params = self.omit(params.clone(), Value::Str("uta".to_string()), &[]);
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marketType".to_string(), marketType.clone());
m
})]);
return self.fetch_uta_orders_by_status(status.clone(), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else if is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("margin".to_string())))) {
return self.fetch_spot_orders_by_status(status.clone(), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
return self.fetch_contract_orders_by_status(status.clone(), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name kucoin#fetchSpotOrdersByStatus
* @description fetch a list of spot orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-open-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-closed-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-list
* @param {string} status *not used for stop orders* 'open' or 'closed'
* @param {string} symbol unified market symbol
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] max number of orders to return
* @param {object} [params] exchange specific params
* @param {int} [params.until] end time in ms
* @param {string} [params.side] buy or sell
* @param {string} [params.type] limit, market, limit_stop or market_stop
* @param {string} [params.tradeType] TRADE for spot trading, MARGIN_TRADE or MARGIN_ISOLATED_TRADE for Margin Trading
* @param {int} [params.currentPage] *trigger orders only* current page
* @param {string} [params.orderIds] *trigger orders only* comma separated order ID list
* @param {bool} [params.trigger] True if fetching a trigger order
* @param {bool} [params.hf] false, // true for hf order
* @param {string} [params.marginMode] 'cross' or 'isolated', only for margin orders
* @returns An [array of order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_spot_orders_by_status(&mut self, mut status: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut lowercaseStatus: Value = to_lower(&status);
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&hf, &Value::Bool(true)))) && is_true(&(is_equal(&symbol, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrdersByStatus() requires a symbol parameter for hf orders".to_string()))));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string()), Value::Str("till".to_string()), Value::Str("until".to_string())]), &[]);
let mut marginModequeryVariable = self.handle_margin_mode_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[params.clone()]);
let mut marginMode: Value = get_value(&marginModequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marginModequeryVariable, &Value::Int(1));
let mut isMarginOrder: bool = !is_equal(&marginMode, &Value::Null);
if is_equal(&lowercaseStatus, &Value::Str("open".to_string())) {
lowercaseStatus = Value::Str("active".to_string());
} else if is_equal(&lowercaseStatus, &Value::Str("closed".to_string())) {
lowercaseStatus = Value::Str("done".to_string());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), self.safe_string(get_value(&self.options, &Value::Str("marginModes".to_string())), marginMode.clone(), &[Value::Str("TRADE".to_string())]));
let mut response: Value = Value::Null;
if is_true(&isMarginOrder) && is_equal(&lowercaseStatus, &Value::Str("active".to_string())) && is_true(&(!is_equal(&trigger, &Value::Bool(true)))) {
// hf margin open non-trigger orders require only symbol and tradeType params
let __ws_arg_56 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_hf_margin_orders_active(&[__ws_arg_56]).await;
} else {
if !is_true(&isMarginOrder) {
add_element_to_object(&mut request, &Value::Str("status".to_string()), lowercaseStatus.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
if is_true(&(!is_equal(&until, &Value::Null))) && is_true(&(!is_equal(&until, &Value::Int(0)))) {
add_element_to_object(&mut request, &Value::Str("endAt".to_string()), until.clone());
}
if is_equal(&trigger, &Value::Bool(true)) {
if is_true(&isMarginOrder) {
let __ws_arg_57 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_hf_margin_stop_orders(&[__ws_arg_57]).await;
} else {
let __ws_arg_58 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_stop_order(&[__ws_arg_58]).await;
}
} else if is_true(&isMarginOrder) {
let __ws_arg_59 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_hf_margin_orders_done(&[__ws_arg_59]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
if is_equal(&lowercaseStatus, &Value::Str("active".to_string())) {
let __ws_arg_60 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_hf_orders_active(&[__ws_arg_60]).await;
} else if is_equal(&lowercaseStatus, &Value::Str("done".to_string())) {
let __ws_arg_61 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_hf_orders_done(&[__ws_arg_61]).await;
}
} else {
let __ws_arg_62 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_orders(&[__ws_arg_62]).await;
}
}
let mut listData: Value = self.safe_list_k(response.clone(), "data", &[]);
if !is_equal(&listData, &Value::Null) {
return self.parse_orders(listData.clone(), &[market.clone(), since.clone(), limit.clone()]);
}
let mut responseData: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(responseData.clone(), "items", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchContractOrdersByStatus
* @description fetches a list of contract orders placed on the exchange
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list
* @param {string} status 'active' or 'closed', only 'active' is valid for stop orders
* @param {string} symbol unified symbol for the market to retrieve orders from
* @param {int} [since] timestamp in ms of the earliest order to retrieve
* @param {int} [limit] The maximum number of orders to retrieve
* @param {object} [params] exchange specific parameters
* @param {bool} [params.trigger] set to true to retrieve untriggered stop orders
* @param {int} [params.until] End time in ms
* @param {string} [params.side] buy or sell
* @param {string} [params.type] limit or market
* @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 An [array of order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_contract_orders_by_status(&mut self, mut status: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrdersByStatus".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchOrdersByStatus".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("until".to_string()), Value::Str("trigger".to_string())]), &[]);
if is_equal(&status, &Value::Str("closed".to_string())) {
status = Value::Str("done".to_string());
} else if is_equal(&status, &Value::Str("open".to_string())) {
status = Value::Str("active".to_string());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&trigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("status".to_string()), status.clone());
} else if !is_equal(&status, &Value::Str("active".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOrdersByStatus() can only fetch untriggered stop orders".to_string()))));
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endAt".to_string()), until.clone());
}
let mut response: Value = Value::Null;
if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_63 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_stop_orders(&[__ws_arg_63]).await;
} else {
let __ws_arg_64 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_orders(&[__ws_arg_64]).await;
}
//
// {
// "code": "200000",
// "data": {
// "currentPage": 1,
// "pageSize": 50,
// "totalNum": 4,
// "totalPage": 1,
// "items": [
// {
// "id": "64507d02921f1c0001ff6892",
// "symbol": "XBTUSDTM",
// "type": "market",
// "side": "buy",
// "price": null,
// "size": 1,
// "value": "27.992",
// "dealValue": "27.992",
// "dealSize": 1,
// "stp": "",
// "stop": "",
// "stopPriceType": "",
// "stopTriggered": false,
// "stopPrice": null,
// "timeInForce": "GTC",
// "postOnly": false,
// "hidden": false,
// "iceberg": false,
// "leverage": "17",
// "forceHold": false,
// "closeOrder": false,
// "visibleSize": null,
// "clientOid": null,
// "remark": null,
// "tags": null,
// "isActive": false,
// "cancelExist": false,
// "createdAt": 1682996482000,
// "updatedAt": 1682996483062,
// "endAt": 1682996483062,
// "orderTime": 1682996482953900677,
// "settleCurrency": "USDT",
// "status": "done",
// "filledValue": "27.992",
// "filledSize": 1,
// "reduceOnly": false
// }
// ]
// }
// }
//
let mut responseData: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(responseData.clone(), "items", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchUtaOrdersByStatus
* @description helper method for fetching orders by status with uta endpoint
* @see https://www.kucoin.com/docs-new/rest/ua/get-open-order-list
* @see https://www.kucoin.com/docs-new/rest/ua/get-order-history
* @param {string} status 'active' or 'closed', only 'active' is valid for stop orders
* @param {string} symbol unified symbol for the market to retrieve orders from
* @param {int} [since] timestamp in ms of the earliest order to retrieve
* @param {int} [limit] The maximum number of orders to retrieve
* @param {object} [params] exchange specific parameters
* @param {int} [params.until] End time in ms
* @param {string} [params.side] *closed orders only* 'BUY' or 'SELL'
* @param {string} [params.accountMode] 'unified' or 'classic' (default is unified)
* @param {string} [params.marginMode] 'cross' or 'isolated', only for margin orders (unified accountMode supports only cross margin)
* @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 An [array of order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_uta_orders_by_status(&mut self, mut status: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
let mut maxLimit: Value = Value::Int(200);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrdersByStatus".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchOrdersByStatus".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut accountMode: Value = Value::Str("unified".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchUtaOrdersByStatus".to_string()), Value::Str("accountMode".to_string()), &[accountMode.clone()]); accountMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountMode".to_string(), accountMode.clone());
m
});
let mut marketType: Value = Value::Null;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
marketType = get_value(&market, &Value::Str("type".to_string()));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
} else {
marketType = self.safe_string_k(params.clone(), "marketType", &[]);
}
params = self.omit(params.clone(), Value::Str("marketType".to_string()), &[]);
let mut isContract: Value = Value::Bool(is_true(&(!is_equal(&marketType, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(&marketType, &Value::Str("margin".to_string())))));
if !is_true(&isContract) && is_true(&(is_equal(&symbol, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrdersByStatus() requires a symbol argument for spot and margin markets when using uta endpoint".to_string()))));
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchOrdersByStatus".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isUnified: Value = Value::Bool(is_equal(&accountMode, &Value::Str("unified".to_string())));
let mut tradeType: Value = self.handle_trade_type(&[isContract.clone(), marginMode.clone(), isUnified.clone(), params.clone()]);
add_element_to_object(&mut params, &Value::Str("tradeType".to_string()), tradeType.clone());
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
let mut lowercaseStatus: Value = to_lower(&status);
if is_equal(&lowercaseStatus, &Value::Str("open".to_string())) {
lowercaseStatus = Value::Str("active".to_string());
} else if is_equal(&lowercaseStatus, &Value::Str("closed".to_string())) {
lowercaseStatus = Value::Str("done".to_string());
}
let mut response: Value = Value::Null;
if is_equal(&lowercaseStatus, &Value::Str("active".to_string())) {
//
// {
// "code": "200000",
// "data": {
// "pageNumber": 1,
// "pageSize": 50,
// "totalNum": 1,
// "totalPage": 1,
// "items": [
// {
// "orderId": "426328635071352832",
// "symbol": "ETH-USDT",
// "orderType": "LIMIT",
// "side": "BUY",
// "size": "0.001",
// "price": "1000",
// "timeInForce": "GTC",
// "tags": "partner:ccxt",
// "orderTime": 1774457869404794617,
// "stp": "",
// "cancelAfter": null,
// "postOnly": false,
// "reduceOnly": false,
// "triggerDirection": "",
// "triggerPrice": "",
// "triggerPriceType": "",
// "tpTriggerPrice": "",
// "tpTriggerPriceType": "",
// "slTriggerPrice": "",
// "slTriggerPriceType": "",
// "filledSize": "0",
// "avgPrice": "0",
// "fee": "0",
// "feeCurrency": "USDT",
// "tax": "0",
// "updatedTime": 1774457869469028819,
// "triggerOrderId": "",
// "cancelReason": "",
// "cancelSize": "0",
// "clientOid": "708987d5-c346-487a-a70c-ea267377b0ca",
// "sizeUnit": "BASECCY",
// "status": 2
// }
// ],
// "tradeType": "SPOT"
// }
// }
//
let __ws_arg_65 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_account_mode_order_open_list(&[__ws_arg_65]).await;
} else {
let __ws_arg_66 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_account_mode_order_history(&[__ws_arg_66]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-closed-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-orders
* @see https://www.kucoin.com/docs-new/rest/ua/get-order-history
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] end time in ms
* @param {string} [params.side] buy or sell
* @param {string} [params.type] limit, market, limit_stop or market_stop
* @param {string} [params.tradeType] TRADE for spot trading, MARGIN_TRADE for Margin Trading
* @param {bool} [params.trigger] True if fetching a trigger order
* @param {bool} [params.hf] false, // true for hf order
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchClosedOrders".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchClosedOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
return self.fetch_orders_by_status(Value::Str("done".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name kucoin#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-open-orders
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-orders-list
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-list
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-stop-order-list
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-open-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-closed-orders
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-list
* @see https://www.kucoin.com/docs-new/rest/ua/get-open-order-list
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] end time in ms
* @param {bool} [params.trigger] true if fetching trigger orders
* @param {string} [params.side] buy or sell
* @param {string} [params.type] limit, market, limit_stop or market_stop
* @param {string} [params.tradeType] TRADE for spot trading, MARGIN_TRADE for Margin Trading
* @param {int} [params.currentPage] *trigger orders only* current page
* @param {string} [params.orderIds] *trigger orders only* comma separated order ID list
* @param {bool} [params.hf] false, // true for hf order
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOpenOrders".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchOpenOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
return self.fetch_orders_by_status(Value::Str("active".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
/*
* @method
* @name kucoin#fetchOrder
* @description fetches information on an order made by the user
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/spot-trading/get-stop-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/futures-trading/get-stop-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/ua/get-order-details
* @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', used if symbol is not provided (default is 'spot')
* @param {bool} [params.uta] true if fetching an order with uta endpoint (default is false)
* Check fetchSpotOrder(), fetchContractOrder() and fetchUtaOrder() for more details on the extra parameters that can be used in params
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires an id argument".to_string()))));
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrder".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
params = self.omit(params.clone(), Value::Str("uta".to_string()), &[]);
return self.fetch_uta_order(id.clone(), &[symbol.clone(), params.clone()]).await;
}
let mut marketType: Value = Value::Null;
if is_equal(&symbol, &Value::Null) {
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
} else {
let mut market: Value = self.market(symbol.clone());
marketType = get_value(&market, &Value::Str("type".to_string()));
}
if is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("margin".to_string())))) {
return self.fetch_spot_order(id.clone(), &[symbol.clone(), params.clone()]).await;
} else {
return self.fetch_contract_order(id.clone(), &[symbol.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name kucoin#fetchSpotOrder
* @description fetch a spot order
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/spot-trading/get-stop-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-order-by-clientoid
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-stop-order-by-clientoid
* @param {string} id Order id
* @param {string} symbol not sent to exchange except for trigger orders with clientOid, but used internally by CCXT to filter
* @param {object} [params] exchange specific parameters
* @param {bool} [params.trigger] true if fetching a trigger order
* @param {bool} [params.hf] false, // true for hf order
* @param {bool} [params.clientOid] unique order id created by users to identify their orders
* @param {object} [params.marginMode] 'cross' or 'isolated'
* @returns An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_spot_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isMarginOrder: bool = !is_equal(&marginMode, &Value::Null);
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
if is_true(&(is_equal(&hf, &Value::Bool(true)))) || is_true(&isMarginOrder) {
if !is_equal(&trigger, &Value::Bool(true)) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol parameter for hf and margin orders".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut response: Value = Value::Null;
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
if is_equal(&trigger, &Value::Bool(true)) {
if is_true(&isMarginOrder) {
let __ws_arg_67 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_margin_stop_order_client_oid(&[__ws_arg_67]).await;
} else {
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
let __ws_arg_68 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_stop_order_query_order_by_client_oid(&[__ws_arg_68]).await;
}
} else if is_true(&isMarginOrder) {
let __ws_arg_69 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_margin_orders_client_order_client_oid(&[__ws_arg_69]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
let __ws_arg_70 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_orders_client_order_client_oid(&[__ws_arg_70]).await;
} else {
let __ws_arg_71 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_order_client_order_client_oid(&[__ws_arg_71]).await;
}
} else {
// a special case for undefined ids
// otherwise a wrong endpoint for all orders will be triggered
// https://github.com/ccxt/ccxt/issues/7234
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" fetchOrder() requires an order id".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
if is_equal(&trigger, &Value::Bool(true)) {
if is_true(&isMarginOrder) {
let __ws_arg_72 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_margin_stop_order_order_id(&[__ws_arg_72]).await;
} else {
let __ws_arg_73 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_stop_order_order_id(&[__ws_arg_73]).await;
}
} else if is_true(&isMarginOrder) {
let __ws_arg_74 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_margin_orders_order_id(&[__ws_arg_74]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
let __ws_arg_75 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_orders_order_id(&[__ws_arg_75]).await;
} else {
let __ws_arg_76 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_orders_order_id(&[__ws_arg_76]).await;
}
}
let mut responseData: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&Value::Bool(is_array(&responseData))) {
responseData = self.safe_value(responseData.clone(), Value::Int(0), &[]);
}
return self.parse_order(responseData.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchContractOrder
* @description fetc contract order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-order-by-orderld
* @see https://www.kucoin.com/docs-new/rest/futures-trading/get-stop-order-by-clientoid
* @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
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_contract_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let __ws_arg_77 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_orders_by_client_oid(&[__ws_arg_77]).await;
} else {
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires an order id argument or clientOrderId in params".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
let __ws_arg_78 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_orders_order_id(&[__ws_arg_78]).await;
}
//
// {
// "code": "200000",
// "data": {
// "id": "64507d02921f1c0001ff6892",
// "symbol": "XBTUSDTM",
// "type": "market",
// "side": "buy",
// "price": null,
// "size": 1,
// "value": "27.992",
// "dealValue": "27.992",
// "dealSize": 1,
// "stp": "",
// "stop": "",
// "stopPriceType": "",
// "stopTriggered": false,
// "stopPrice": null,
// "timeInForce": "GTC",
// "postOnly": false,
// "hidden": false,
// "iceberg": false,
// "leverage": "17",
// "forceHold": false,
// "closeOrder": false,
// "visibleSize": null,
// "clientOid": null,
// "remark": null,
// "tags": null,
// "isActive": false,
// "cancelExist": false,
// "createdAt": 1682996482000,
// "updatedAt": 1682996483000,
// "endAt": 1682996483000,
// "orderTime": 1682996482953900677,
// "settleCurrency": "USDT",
// "status": "done",
// "filledSize": 1,
// "filledValue": "27.992",
// "reduceOnly": false
// }
// }
//
let mut market: Value = ternary(is_true(&(!is_equal(&symbol, &Value::Null))), self.market(symbol.clone()), Value::Null);
let mut responseData: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(responseData.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchUtaOrder
* @description fetch uta order
* @see https://www.kucoin.com/docs-new/rest/ua/get-order-details
* @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.accountMode] 'unified' or 'classic' (default is 'unified')
* @param {string} [params.clientOrderId] client order id, required if id is not provided
* @param {string} [params.marginMode] 'cross' or 'isolated', required if fetching a margin order (unified accountMode supports only cross margin)
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_uta_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol argument for uta orders".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
} else {
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires an id argument or clientOrderId parameter".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let mut accountMode: Value = Value::Str("unified".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrder".to_string()), Value::Str("accountMode".to_string()), &[accountMode.clone()]); accountMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), accountMode.clone());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isUnified: Value = Value::Bool(is_equal(&accountMode, &Value::Str("unified".to_string())));
let mut tradeType: Value = self.handle_trade_type(&[get_value(&market, &Value::Str("contract".to_string())), marginMode.clone(), isUnified.clone(), params.clone()]);
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), tradeType.clone());
let __ws_arg_79 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_private_get_account_mode_order_detail(&[__ws_arg_79]).await;
//
// {
// "code": "200000",
// "data": {
// "orderId": "426319129738321920",
// "symbol": "ETH-USDT",
// "orderType": "LIMIT",
// "side": "BUY",
// "size": "0.001",
// "price": "1000",
// "timeInForce": "GTC",
// "tags": "partner:ccxt",
// "orderTime": 1774455603156417582,
// "stp": "",
// "cancelAfter": null,
// "postOnly": false,
// "reduceOnly": false,
// "triggerDirection": "",
// "triggerPrice": "",
// "triggerPriceType": "",
// "tpTriggerPrice": "",
// "tpTriggerPriceType": "",
// "slTriggerPrice": "",
// "slTriggerPriceType": "",
// "filledSize": "0",
// "avgPrice": "0",
// "fee": "0",
// "feeCurrency": "USDT",
// "tax": "0",
// "updatedTime": 1774455603371523690,
// "triggerOrderId": "",
// "cancelReason": "",
// "cancelSize": "0",
// "clientOid": "b896c118-a674-4863-baf4-a9ea3cd696c5",
// "sizeUnit": "BASECCY",
// "tradeType": "SPOT",
// "tradeId": "",
// "status": 2
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
pub fn handle_trade_type(&self, optional_args: &[Value]) -> Value {
let mut isContractMarket = get_arg(optional_args, 0, Value::Bool(false));
let mut marginMode = get_arg(optional_args, 1, Value::Null);
let mut isUnified = get_arg(optional_args, 2, Value::Bool(false));
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut tradeType: Value = self.safe_string_k(params.clone(), "tradeType", &[]);
if is_equal(&tradeType, &Value::Null) {
if is_true(&isContractMarket) {
tradeType = Value::Str("FUTURES".to_string());
} else if !is_equal(&marginMode, &Value::Null) {
tradeType = to_upper(&marginMode);
if is_true(&isUnified) {
if is_equal(&tradeType, &Value::Str("ISOLATED".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" spot isolated margin is not supported for unified accountMode".to_string()))));
} else {
tradeType = Value::Str("MARGIN".to_string());
}
}
} else {
tradeType = Value::Str("SPOT".to_string());
}
}
return tradeType;
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut tradeType: Value = self.safe_string_k(order.clone(), "tradeType", &[]);
let mut utaTradeTypes: Value = Value::List(vec![Value::Str("SPOT".to_string()), Value::Str("CROSS".to_string()), Value::Str("ISOLATED".to_string()), Value::Str("FUTURES".to_string())]); // tradeType specific for uta endpoint
let mut isUtaOrder: Value = self.in_array(tradeType.clone(), utaTradeTypes.clone());
if is_true(&Value::Bool(in_op(&order, &Value::Str("sizeUnit".to_string())))) {
isUtaOrder = Value::Bool(true);
}
if is_true(&isUtaOrder) {
return self.parse_uta_order(order.clone(), &[market.clone()]);
}
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
if is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))) {
return self.parse_contract_order(order.clone(), &[market.clone()]);
} else {
return self.parse_spot_order(order.clone(), &[market.clone()]);
}
Value::Null
}
pub fn parse_contract_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchOrder, fetchOrdersByStatus
//
// {
// "id": "64507d02921f1c0001ff6892",
// "symbol": "XBTUSDTM",
// "type": "market",
// "side": "buy",
// "price": null,
// "size": 1,
// "value": "27.992",
// "dealValue": "27.992",
// "dealSize": 1,
// "stp": "",
// "stop": "",
// "stopPriceType": "",
// "stopTriggered": false,
// "stopPrice": null,
// "timeInForce": "GTC",
// "postOnly": false,
// "hidden": false,
// "iceberg": false,
// "leverage": "17",
// "forceHold": false,
// "closeOrder": false,
// "visibleSize": null,
// "clientOid": null,
// "remark": null,
// "tags": null,
// "isActive": false,
// "cancelExist": false,
// "createdAt": 1682996482000,
// "updatedAt": 1682996483062,
// "endAt": 1682996483062,
// "orderTime": 1682996482953900677,
// "settleCurrency": "USDT",
// "status": "done",
// "filledValue": "27.992",
// "filledSize": 1,
// "reduceOnly": false
// }
//
// createOrder
//
// {
// "orderId": "619717484f1d010001510cde"
// }
//
// createOrders
//
// {
// "orderId": "80465574458560512",
// "clientOid": "5c52e11203aa677f33e491",
// "symbol": "ETHUSDTM",
// "code": "200000",
// "msg": "success"
// }
//
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut orderId: Value = self.safe_string2(order.clone(), Value::Str("id".to_string()), Value::Str("orderId".to_string()), &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut timestamp: Value = self.safe_integer_k(order.clone(), "createdAt", &[]);
let mut datetime: Value = self.iso8601(timestamp.clone());
let mut price: Value = self.safe_string_k(order.clone(), "price", &[]);
// price is zero for market order
// omitZero is called in safeOrder2
let mut side: Value = self.safe_string_k(order.clone(), "side", &[]);
let mut feeCurrencyId: Value = self.safe_string_k(order.clone(), "feeCurrency", &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
let mut feeCost: Value = self.safe_number_k(order.clone(), "fee", &[]);
let mut amount: Value = self.safe_string_k(order.clone(), "size", &[]);
let mut filled: Value = self.safe_string_k(order.clone(), "filledSize", &[]);
let mut cost: Value = self.safe_string_k(order.clone(), "filledValue", &[]);
let mut average: Value = self.safe_string_k(order.clone(), "avgDealPrice", &[]);
if is_true(&(is_equal(&average, &Value::Null))) && is_true(&crate::precise::Precise::stringGt(&filled, &Value::Str("0".to_string()))) {
let mut contractSize: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
average = crate::precise::Precise::stringDiv(&cost, &crate::precise::Precise::stringMul(&contractSize, &filled));
} else {
average = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(&contractSize, &filled), &cost);
}
}
// precision reported by their api is 8 d.p.
// const average = Precise.stringDiv (cost, Precise.stringMul (filled, market['contractSize']));
// bool
let mut isActive: Value = self.safe_value_k(order.clone(), "isActive", &[]);
let mut cancelExist: Value = self.safe_bool_k(order.clone(), "cancelExist", &[Value::Bool(false)]);
let mut status: Value = Value::Null;
if !is_equal(&isActive, &Value::Null) {
status = ternary(is_true(&(is_equal(&isActive, &Value::Bool(true)))), Value::Str("open".to_string()), Value::Str("closed".to_string()));
}
status = ternary(is_true(&(is_equal(&cancelExist, &Value::Bool(true)))), Value::Str("canceled".to_string()), status.clone());
let mut fee: Value = Value::Null;
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), feeCurrency.clone());
m.insert("cost".to_string(), feeCost.clone());
m
});
}
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "clientOid", &[]);
let mut timeInForce: Value = self.safe_string_k(order.clone(), "timeInForce", &[]);
let mut postOnly: Value = self.safe_value_k(order.clone(), "postOnly", &[]);
let mut reduceOnly: Value = self.safe_value_k(order.clone(), "reduceOnly", &[]);
let mut lastUpdateTimestamp: Value = self.safe_integer_k(order.clone(), "updatedAt", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("reduceOnly".to_string(), reduceOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), self.safe_number_k(order.clone(), "stopPrice", &[]));
m.insert("cost".to_string(), cost.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("status".to_string(), status.clone());
m.insert("info".to_string(), order.clone());
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.clone());
m.insert("average".to_string(), average.clone());
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_spot_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder
//
// {
// "orderId": "63c97e47d686c5000159a656"
// }
//
// cancelOrder
//
// {
// "cancelledOrderIds": [ "63c97e47d686c5000159a656" ]
// }
//
// fetchOpenOrders, fetchClosedOrders
//
// {
// "id": "63c97ce8d686c500015793bb",
// "symbol": "USDC-USDT",
// "opType": "DEAL",
// "type": "limit",
// "side": "sell",
// "price": "1.05",
// "size": "1",
// "funds": "0",
// "dealFunds": "0",
// "dealSize": "0",
// "fee": "0",
// "feeCurrency": "USDT",
// "stp": "",
// "stop": "",
// "stopTriggered": false,
// "stopPrice": "0",
// "timeInForce": "GTC",
// "postOnly": false,
// "hidden": false,
// "iceberg": false,
// "visibleSize": "0",
// "cancelAfter": 0,
// "channel": "API",
// "clientOid": "d602d73f-5424-4751-bef0-8debce8f0a82",
// "remark": null,
// "tags": "partner:ccxt",
// "isActive": true,
// "cancelExist": false,
// "createdAt": 1674149096927,
// "tradeType": "TRADE"
// }
//
// stop orders (fetchOpenOrders, fetchClosedOrders)
//
// {
// "id": "vs9f6ou9e864rgq8000t4qnm",
// "symbol": "USDC-USDT",
// "userId": "613a896885d8660006151f01",
// "status": "NEW",
// "type": "market",
// "side": "sell",
// "price": null,
// "size": "1.00000000000000000000",
// "funds": null,
// "stp": null,
// "timeInForce": "GTC",
// "cancelAfter": -1,
// "postOnly": false,
// "hidden": false,
// "iceberg": false,
// "visibleSize": null,
// "channel": "API",
// "clientOid": "5d3fd727-6456-438d-9550-40d9d85eee0b",
// "remark": null,
// "tags": "partner:ccxt",
// "relatedNo": null,
// "orderTime": 1674146316994000028,
// "domainId": "kucoin",
// "tradeSource": "USER",
// "tradeType": "MARGIN_TRADE",
// "feeCurrency": "USDT",
// "takerFeeRate": "0.00100000000000000000",
// "makerFeeRate": "0.00100000000000000000",
// "createdAt": 1674146316994,
// "stop": "loss",
// "stopTriggerTime": null,
// "stopPrice": "0.97000000000000000000"
// }
// hf order
// {
// "id":"6478cf1439bdfc0001528a1d",
// "symbol":"LTC-USDT",
// "opType":"DEAL",
// "type":"limit",
// "side":"buy",
// "price":"50",
// "size":"0.1",
// "funds":"5",
// "dealSize":"0",
// "dealFunds":"0",
// "fee":"0",
// "feeCurrency":"USDT",
// "stp":null,
// "timeInForce":"GTC",
// "postOnly":false,
// "hidden":false,
// "iceberg":false,
// "visibleSize":"0",
// "cancelAfter":0,
// "channel":"API",
// "clientOid":"d4d2016b-8e3a-445c-aa5d-dc6df5d1678d",
// "remark":null,
// "tags":"partner:ccxt",
// "cancelExist":false,
// "createdAt":1685638932074,
// "lastUpdatedAt":1685639013735,
// "tradeType":"TRADE",
// "inOrderBook":true,
// "cancelledSize":"0",
// "cancelledFunds":"0",
// "remainSize":"0.1",
// "remainFunds":"5",
// "active":true
// }
//
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(order.clone(), "createdAt", &[]);
let mut feeCurrencyId: Value = self.safe_string_k(order.clone(), "feeCurrency", &[]);
let mut cancelExist: Value = self.safe_bool_k(order.clone(), "cancelExist", &[Value::Bool(false)]);
let mut responseStop: Value = self.safe_string_k(order.clone(), "stop", &[]);
let mut trigger: bool = !is_equal(&responseStop, &Value::Null);
let mut stopTriggered: Value = self.safe_bool_k(order.clone(), "stopTriggered", &[Value::Bool(false)]);
let mut isActive: Value = self.safe_bool2(order.clone(), Value::Str("isActive".to_string()), Value::Str("active".to_string()), &[]);
let mut responseStatus: Value = self.safe_string_k(order.clone(), "status", &[]);
let mut status: Value = Value::Null;
if !is_equal(&isActive, &Value::Null) {
if is_equal(&isActive, &Value::Bool(true)) {
status = Value::Str("open".to_string());
} else {
status = Value::Str("closed".to_string());
}
}
if is_true(&trigger) {
if is_equal(&responseStatus, &Value::Str("NEW".to_string())) {
status = Value::Str("open".to_string());
} else if is_true(&(!is_equal(&isActive, &Value::Bool(true)))) && is_true(&(!is_equal(&stopTriggered, &Value::Bool(true)))) {
status = Value::Str("cancelled".to_string());
}
}
if is_equal(&cancelExist, &Value::Bool(true)) {
status = Value::Str("canceled".to_string());
}
if is_equal(&responseStatus, &Value::Str("fail".to_string())) {
status = Value::Str("rejected".to_string());
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("id".to_string()), Value::Str("orderId".to_string()), Value::Str("newOrderId".to_string()), Value::Str("cancelledOrderId".to_string())]), &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "clientOid", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("-".to_string())]));
m.insert("type".to_string(), self.safe_string_k(order.clone(), "type", &[]));
m.insert("timeInForce".to_string(), self.safe_string_k(order.clone(), "timeInForce", &[]));
m.insert("postOnly".to_string(), self.safe_bool_k(order.clone(), "postOnly", &[]));
m.insert("side".to_string(), self.safe_string_k(order.clone(), "side", &[]));
m.insert("amount".to_string(), self.safe_string_k(order.clone(), "size", &[]));
m.insert("price".to_string(), self.safe_string_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), self.safe_number_k(order.clone(), "stopPrice", &[]));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "dealFunds", &[]));
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "dealSize", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(feeCurrencyId.clone(), &[]));
m.insert("cost".to_string(), self.safe_number_k(order.clone(), "fee", &[]));
m
}));
m.insert("status".to_string(), status.clone());
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("average".to_string(), self.safe_string_k(order.clone(), "avgDealPrice", &[]));
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_uta_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder
// {
// "orderId": "426319129738321920",
// "tradeType": "SPOT",
// "ts": 1774455603216000000,
// "clientOid": "b896c118-a674-4863-baf4-a9ea3cd696c5"
// }
//
// fetchOrder
// {
// "orderId": "426319129738321920",
// "symbol": "ETH-USDT",
// "orderType": "LIMIT",
// "side": "BUY",
// "size": "0.001",
// "price": "1000",
// "timeInForce": "GTC",
// "tags": "partner:ccxt",
// "orderTime": 1774455603156417582,
// "stp": "",
// "cancelAfter": null,
// "postOnly": false,
// "reduceOnly": false,
// "triggerDirection": "",
// "triggerPrice": "",
// "triggerPriceType": "",
// "tpTriggerPrice": "",
// "tpTriggerPriceType": "",
// "slTriggerPrice": "",
// "slTriggerPriceType": "",
// "filledSize": "0",
// "avgPrice": "0",
// "fee": "0",
// "feeCurrency": "USDT",
// "tax": "0",
// "updatedTime": 1774455603371523690,
// "triggerOrderId": "",
// "cancelReason": "",
// "cancelSize": "0",
// "clientOid": "b896c118-a674-4863-baf4-a9ea3cd696c5",
// "sizeUnit": "BASECCY",
// "tradeType": "SPOT",
// "tradeId": "",
// "status": 2
// }
//
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer_product2(order.clone(), Value::Str("orderTime".to_string()), Value::Str("ts".to_string()), Value::Float(0.000001), &[]);
let mut lastUpdateTimestamp: Value = self.safe_integer_product(order.clone(), Value::Str("updatedTime".to_string()), Value::Float(0.000001), &[]);
let mut rawTimeInForce: Value = self.safe_string_k(order.clone(), "timeInForce", &[]);
let mut amount: Value = Value::Null;
let mut cost: Value = Value::Null;
let mut sizeUnit: Value = self.safe_string_k(order.clone(), "sizeUnit", &[]);
let mut size: Value = self.safe_string_k(order.clone(), "size", &[]);
let mut rawStatus: Value = self.safe_string_k(order.clone(), "status", &[]);
let mut average: Value = self.safe_string_k(order.clone(), "avgPrice", &[]);
let mut filled: Value = self.safe_string_k(order.clone(), "filledSize", &[]); // might be in base or quote, need to check sizeUnit
if is_true(&(is_equal(&sizeUnit, &Value::Str("BASECCY".to_string())))) || is_true(&(is_equal(&sizeUnit, &Value::Str("UNIT".to_string())))) {
amount = size.clone();
} else {
cost = filled.clone();
filled = crate::precise::Precise::stringDiv(&filled, &average);
filled = self.amount_to_precision(symbol.clone(), filled.clone());
}
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(order.clone(), "feeCurrency", &[]), &[]));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "fee", &[]));
m
});
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(), "clientOid", &[]));
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), self.safe_string_lower(order.clone(), Value::Str("orderType".to_string()), &[]));
m.insert("timeInForce".to_string(), self.parse_order_time_in_force(rawTimeInForce.clone()));
m.insert("postOnly".to_string(), self.safe_bool_k(order.clone(), "postOnly", &[]));
m.insert("reduceOnly".to_string(), self.safe_bool_k(order.clone(), "reduceOnly", &[]));
m.insert("side".to_string(), self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]));
m.insert("amount".to_string(), amount.clone());
m.insert("price".to_string(), self.safe_string_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), self.safe_string2(order.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]));
m.insert("cost".to_string(), cost.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fee".to_string(), fee.clone());
m.insert("status".to_string(), self.parse_order_status(rawStatus.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.clone());
m.insert("average".to_string(), average.clone());
m.insert("trades".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), self.safe_string_k(order.clone(), "slTriggerPrice", &[]));
m.insert("takeProfitPrice".to_string(), self.safe_string_k(order.clone(), "tpTriggerPrice", &[]));
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_order_time_in_force(&self, mut timeInForce: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("GTC".to_string()));
m.insert("IOC".to_string(), Value::Str("IOC".to_string()));
m.insert("FOK".to_string(), Value::Str("FOK".to_string()));
m.insert("GTT".to_string(), Value::Str("GTD".to_string()));
m
});
if is_equal(&timeInForce, &Value::Null) {
return Value::Null;
}
return self.safe_string(timeInForces.clone(), timeInForce.clone(), &[timeInForce.clone()]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("open".to_string()));
m.insert("1".to_string(), Value::Str("open".to_string()));
m.insert("2".to_string(), Value::Str("open".to_string()));
m.insert("3".to_string(), Value::Str("closed".to_string()));
m.insert("4".to_string(), Value::Str("open".to_string()));
m.insert("5".to_string(), Value::Str("canceled".to_string()));
m.insert("6".to_string(), Value::Str("closed".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-trade-history
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-trade-history
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-trade-history
* @see https://www.kucoin.com/docs-new/rest/ua/get-trade-history
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @param {boolean} [params.uta] set to true if fetching trades from uta endpoint, default is false.
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id.clone());
m
});
let __ws_arg_80 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_my_trades(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_80]).await;
Value::Null
}
/*
* @method
* @name kucoin#fetchMyTrades
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-trade-history
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-trade-history
* @see https://www.kucoin.com/docs-new/rest/ua/get-trade-history
* @description fetch all trades made by the user
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* Check fetchMySpotTrades() and fetchMyContractTrades() for more details on the extra parameters that can be used in params
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut marketType: Value = Value::Null;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marketType".to_string(), marketType.clone());
m
})]);
return self.fetch_my_uta_trades(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
if is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("margin".to_string())))) {
return self.fetch_my_spot_trades(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
return self.fetch_my_contract_trades(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name kucoin#fetchMySpotTrades
* @see https://www.kucoin.com/docs-new/rest/spot-trading/orders/get-trade-history
* @see https://www.kucoin.com/docs-new/rest/margin-trading/orders/get-trade-history
* @description fetch all spot trades made by the user
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {bool} [params.hf] false, // true for hf order
* @param {string} [params.marginMode] 'cross' or 'isolated', only for margin trades
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_spot_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchMyTrades".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isMargin: bool = !is_equal(&marginMode, &Value::Null);
if is_true(&isMargin) {
hf = Value::Bool(true);
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Null, self.safe_string(get_value(&self.options, &Value::Str("marginModes".to_string())), marginMode.clone(), &[marginMode.clone()])));
}
if is_true(&(is_equal(&hf, &Value::Bool(true)))) && is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol parameter for hf or margin orders".to_string()))));
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut method: Value = get_value(&self.options, &Value::Str("fetchMyTradesMethod".to_string()));
let mut parseResponseData: bool = false;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&hf, &Value::Bool(true)) {
// does not return trades earlier than 2019-02-18T00:00:00Z
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
// only returns trades up to one week after the since param
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if is_true(&isMargin) {
let __ws_arg_81 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_margin_fills(&[__ws_arg_81]).await;
} else {
let __ws_arg_82 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_fills(&[__ws_arg_82]).await;
}
} else if is_equal(&method, &Value::Str("private_get_fills".to_string())) {
// does not return trades earlier than 2019-02-18T00:00:00Z
if !is_equal(&since, &Value::Null) {
// only returns trades up to one week after the since param
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
let __ws_arg_83 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_fills(&[__ws_arg_83]).await;
} else if is_equal(&method, &Value::Str("private_get_limit_fills".to_string())) {
// does not return trades earlier than 2019-02-18T00:00:00Z
// takes no params
// only returns first 1000 trades (not only "in the last 24 hours" as stated in the docs)
parseResponseData = true;
let __ws_arg_84 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_limit_fills(&[__ws_arg_84]).await;
} else {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchMyTradesMethod() invalid method".to_string()))));
}
//
// {
// "currentPage": 1,
// "pageSize": 50,
// "totalNum": 1,
// "totalPage": 1,
// "items": [
// {
// "symbol":"BTC-USDT", // symbol
// "tradeId":"5c35c02709e4f67d5266954e", // trade id
// "orderId":"5c35c02703aa673ceec2a168", // order id
// "counterOrderId":"5c1ab46003aa676e487fa8e3", // counter order id
// "side":"buy", // transaction direction,include buy and sell
// "liquidity":"taker", // include taker and maker
// "forceTaker":true, // forced to become taker
// "price":"0.083", // order price
// "size":"0.8424304", // order quantity
// "funds":"0.0699217232", // order funds
// "fee":"0", // fee
// "feeRate":"0", // fee rate
// "feeCurrency":"USDT", // charge fee currency
// "stop":"", // stop type
// "type":"limit", // order type, e.g. limit, market, stop_limit.
// "createdAt":1547026472000 // time
// },
// //------------------------------------------------------
// // v1 (historical) trade response structure
// {
// "symbol": "SNOV-ETH",
// "dealPrice": "0.0000246",
// "dealValue": "0.018942",
// "amount": "770",
// "fee": "0.00001137",
// "side": "sell",
// "createdAt": 1540080199
// "id":"5c4d389e4c8c60413f78e2e5",
// }
// ]
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
// v1 (historical) returns the trade list directly under 'data', v2 nests it under 'items'
let mut trades: Value = Value::Null;
if is_true(&parseResponseData) {
trades = data.clone();
} else {
trades = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
}
// v1 may put a bare list or dict under data; normalize once for parseTrades
let mut tradesList: Value = Value::List(vec![]);
if !is_equal(&trades, &Value::Null) {
tradesList = self.to_array(trades.clone());
}
return self.parse_trades(tradesList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchMyContractTrades
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/get-trade-history
* @description fetch all contract trades made by the user
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] End time in ms
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_contract_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), crate::runtime::Math::min(&Value::Int(1000), &limit));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_85 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_fills(&[__ws_arg_85]).await;
//
// {
// "code": "200000",
// "data": {
// "currentPage": 1,
// "pageSize": 1,
// "totalNum": 251915,
// "totalPage": 251915,
// "items": [
// {
// "symbol": "XBTUSDM", // Ticker symbol of the contract
// "tradeId": "5ce24c1f0c19fc3c58edc47c", // Trade ID
// "orderId": "5ce24c16b210233c36ee321d", // Order ID
// "side": "sell", // Transaction side
// "liquidity": "taker", // Liquidity- taker or maker
// "price": "8302", // Filled price
// "size": 10, // Filled amount
// "value": "0.001204529", // Order value
// "feeRate": "0.0005", // Floating fees
// "fixFee": "0.00000006", // Fixed fees
// "feeCurrency": "XBT", // Charging currency
// "stop": "", // A mark to the stop order type
// "fee": "0.0000012022", // Transaction fee
// "orderType": "limit", // Order type
// "tradeType": "trade", // Trade type (trade, liquidation, ADL or settlement)
// "createdAt": 1558334496000, // Time the order created
// "settleCurrency": "XBT", // settlement currency
// "tradeTime": 1558334496000000000 // trade time in nanosecond
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
let mut tradesList: Value = Value::List(vec![]);
if !is_equal(&trades, &Value::Null) {
tradesList = trades.clone();
}
return self.parse_trades(tradesList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchMyUtaTrades
* @see https://www.kucoin.com/docs-new/rest/ua/get-trade-history
* @description fetch all trades made by the user
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve (default is 50, max is 200)
* @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 {string} [params.accountMode] 'unified' or 'classic', defaults to 'unified'
* @param {string} [params.marginMode] 'cross' or 'isolated', only for margin trades (unified accountMode support only cross margin)
* @param {string} [params.side] 'BUY' or 'SELL' (both if not provided)
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_uta_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut marketType: Value = self.safe_string_k(params.clone(), "marketType", &[]);
if !is_equal(&marketType, &Value::Null) {
params = self.omit(params.clone(), Value::Str("marketType".to_string()), &[]);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut isContract: Value = Value::Bool(false);
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
isContract = get_value(&market, &Value::Str("contract".to_string()));
} else if is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("margin".to_string())))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol parameter for uta spot or margin trades".to_string()))));
} else {
isContract = Value::Bool(true);
}
let mut accountMode: Value = Value::Str("unified".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("accountMode".to_string()), &[accountMode.clone()]); accountMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), accountMode.clone());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchMyTrades".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isUnified: Value = Value::Bool(is_equal(&accountMode, &Value::Str("unified".to_string())));
let mut tradeType: Value = self.handle_trade_type(&[isContract.clone(), marginMode.clone(), isUnified.clone(), params.clone()]);
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), tradeType.clone());
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_86 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_private_get_account_mode_order_execution(&[__ws_arg_86]).await;
//
// {
// "code": "200000",
// "data": {
// "tradeType": "FUTURES",
// "lastId": 30000000000531982,
// "items": [
// {
// "orderId": "426373228194254848",
// "symbol": "DOGEUSDTM",
// "orderType": "MARKET",
// "side": "BUY",
// "tradeId": "1711108516570",
// "size": "1",
// "price": "0.09641",
// "value": "9.641",
// "executionTime": 1774468501294000000,
// "fee": "0.0057846",
// "feeCurrency": "USDT",
// "tax": "",
// "liquidityRole": "TAKER",
// "fillType": "NORMAL"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
let mut tradesList: Value = Value::List(vec![]);
if !is_equal(&trades, &Value::Null) {
tradesList = trades.clone();
}
return self.parse_trades(tradesList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-trade-history
* @see https://www.kucoin.com/docs-new/rest/ua/get-trades
* @see https://www.kucoin.com/docs-new/rest/futures-trading/market-data/get-trade-history
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
// pagination is not supported on the exchange side anymore
// if (since !== undefined) {
// request['startAt'] = Math.floor (since / 1000);
// }
// if (limit !== undefined) {
// request['pageSize'] = limit;
// }
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTrades".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut trades: Value = Value::Null;
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTrades".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
if is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string())))) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("SPOT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("FUTURES".to_string()));
}
let __ws_arg_87 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_get_market_trade(&[__ws_arg_87]).await;
//
// {
// "code": "200000",
// "data": {
// "tradeType": "SPOT",
// "list": [
// {
// "sequence": "18746044393340932",
// "tradeId": "18746044393340932",
// "price": "104355.6",
// "size": "0.00011886",
// "side": "sell",
// "ts": 1762242540829000000
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
trades = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
} else if is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string())))) {
let __ws_arg_88 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_histories(&[__ws_arg_88]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "sequence": "1548764654235",
// "side": "sell",
// "size":"0.6841354",
// "price":"0.03202",
// "time":1548848575203567174
// }
// ]
// }
//
trades = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
} else {
let __ws_arg_89 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_trade_history(&[__ws_arg_89]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "sequence": 32114961,
// "side": "buy",
// "size": 39,
// "price": "4001.6500000000",
// "takerOrderId": "61c20742f172110001e0ebe4",
// "makerOrderId": "61c2073fcfc88100010fcb5d",
// "tradeId": "61c2074277a0c473e69029b8",
// "ts": 1640105794099993896 // filled time
// }
// ]
// }
//
trades = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
}
let mut tradesList: Value = Value::List(vec![]);
if !is_equal(&trades, &Value::Null) {
tradesList = trades.clone();
}
return self.parse_trades(tradesList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
if is_true(&Value::Bool(in_op(&trade, &Value::Str("liquidityRole".to_string())))) {
return self.parse_my_uta_trade(trade.clone(), &[market.clone()]);
}
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
if is_true(&(is_equal(&market, &Value::Null))) || is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) {
return self.parse_spot_or_uta_trade(trade.clone(), &[market.clone()]);
} else {
return self.parse_contract_trade(trade.clone(), &[market.clone()]);
}
Value::Null
}
pub fn parse_spot_or_uta_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades (public)
//
// {
// "sequence": "1548764654235",
// "side": "sell",
// "size":"0.6841354",
// "price":"0.03202",
// "time":1548848575203567174
// }
//
// {
// "sequence": "1568787654360",
// "symbol": "BTC-USDT",
// "side": "buy",
// "size": "0.00536577",
// "price": "9345",
// "takerOrderId": "5e356c4a9f1a790008f8d921",
// "time": "1580559434436443257",
// "type": "match",
// "makerOrderId": "5e356bffedf0010008fa5d7f",
// "tradeId": "5e356c4aeefabd62c62a1ece"
// }
//
// fetchMyTrades (private) v2
//
// {
// "symbol":"BTC-USDT",
// "tradeId":"5c35c02709e4f67d5266954e",
// "orderId":"5c35c02703aa673ceec2a168",
// "counterOrderId":"5c1ab46003aa676e487fa8e3",
// "side":"buy",
// "liquidity":"taker",
// "forceTaker":true,
// "price":"0.083",
// "size":"0.8424304",
// "funds":"0.0699217232",
// "fee":"0",
// "feeRate":"0",
// "feeCurrency":"USDT",
// "stop":"",
// "type":"limit",
// "createdAt":1547026472000
// }
//
// fetchMyTrades v2 alternative format since 2019-05-21 https://github.com/ccxt/ccxt/pull/5162
//
// {
// "symbol": "OPEN-BTC",
// "forceTaker": false,
// "orderId": "5ce36420054b4663b1fff2c9",
// "fee": "0",
// "feeCurrency": "",
// "type": "",
// "feeRate": "0",
// "createdAt": 1558417615000,
// "size": "12.8206",
// "stop": "",
// "price": "0",
// "funds": "0",
// "tradeId": "5ce390cf6e0db23b861c6e80"
// }
//
// fetchMyTrades (private) v1 (historical)
//
// {
// "symbol": "SNOV-ETH",
// "dealPrice": "0.0000246",
// "dealValue": "0.018942",
// "amount": "770",
// "fee": "0.00001137",
// "side": "sell",
// "createdAt": 1540080199
// "id":"5c4d389e4c8c60413f78e2e5",
// }
//
// uta fetchTrades
//
// {
// "sequence": "18746044393340932",
// "tradeId": "18746044393340932",
// "price": "104355.6",
// "size": "0.00011886",
// "side": "sell",
// "ts": 1762242540829000000
// }
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("-".to_string())]);
let mut id: Value = self.safe_string2(trade.clone(), Value::Str("tradeId".to_string()), Value::Str("id".to_string()), &[]);
let mut orderId: Value = self.safe_string_k(trade.clone(), "orderId", &[]);
let mut takerOrMaker: Value = self.safe_string_k(trade.clone(), "liquidity", &[]);
let mut timestamp: Value = self.safe_integer2(trade.clone(), Value::Str("time".to_string()), Value::Str("ts".to_string()), &[]);
if !is_equal(×tamp, &Value::Null) {
timestamp = self.parse_to_int(divide(×tamp, &Value::Int(1000000)));
} else {
timestamp = self.safe_integer_k(trade.clone(), "createdAt", &[]);
// if it's a historical v1 trade, the exchange returns timestamp in seconds
if is_true(&(Value::Bool(in_op(&trade, &Value::Str("dealValue".to_string()))))) && is_true(&(!is_equal(×tamp, &Value::Null))) {
timestamp = multiply(×tamp, &Value::Int(1000));
}
}
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("price".to_string()), Value::Str("dealPrice".to_string()), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("size".to_string()), Value::Str("amount".to_string()), &[]);
let mut side: Value = self.safe_string_k(trade.clone(), "side", &[]);
let mut fee: Value = Value::Null;
let mut feeCostString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
if !is_equal(&feeCostString, &Value::Null) {
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "feeCurrency", &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
if is_equal(&feeCurrency, &Value::Null) {
feeCurrency = ternary(is_true(&(is_equal(&side, &Value::Str("sell".to_string())))), get_value(&market, &Value::Str("quote".to_string())), get_value(&market, &Value::Str("base".to_string())));
}
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString.clone());
m.insert("currency".to_string(), feeCurrency.clone());
m.insert("rate".to_string(), self.safe_string_k(trade.clone(), "feeRate", &[]));
m
});
}
let mut type_var: Value = self.safe_string_k(trade.clone(), "type", &[]);
if is_equal(&type_var, &Value::Str("match".to_string())) {
type_var = Value::Null;
}
let mut costString: Value = self.safe_string2(trade.clone(), Value::Str("funds".to_string()), Value::Str("dealValue".to_string()), &[]);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), id.clone());
m.insert("order".to_string(), orderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), costString.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_contract_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades (public)
//
// {
// "sequence": 32114961,
// "side": "buy",
// "size": 39,
// "price": "4001.6500000000",
// "takerOrderId": "61c20742f172110001e0ebe4",
// "makerOrderId": "61c2073fcfc88100010fcb5d",
// "tradeId": "61c2074277a0c473e69029b8",
// "ts": 1640105794099993896 // filled time
// }
//
// fetchMyTrades (private) v2
//
// {
// "symbol":"BTC-USDT",
// "tradeId":"5c35c02709e4f67d5266954e",
// "orderId":"5c35c02703aa673ceec2a168",
// "counterOrderId":"5c1ab46003aa676e487fa8e3",
// "side":"buy",
// "liquidity":"taker",
// "forceTaker":true,
// "price":"0.083",
// "size":"0.8424304",
// "funds":"0.0699217232",
// "fee":"0",
// "feeRate":"0",
// "feeCurrency":"USDT",
// "stop":"",
// "type":"limit",
// "createdAt":1547026472000
// }
//
// fetchMyTrades (private) v1
//
// {
// "symbol":"DOGEUSDTM",
// "tradeId":"620ec41a96bab27b5f4ced56",
// "orderId":"620ec41a0d1d8a0001560bd0",
// "side":"sell",
// "liquidity":"taker",
// "forceTaker":true,
// "price":"0.13969",
// "size":1,
// "value":"13.969",
// "feeRate":"0.0006",
// "fixFee":"0",
// "feeCurrency":"USDT",
// "stop":"",
// "tradeTime":1645134874858018058,
// "fee":"0.0083814",
// "settleCurrency":"USDT",
// "orderType":"market",
// "tradeType":"trade",
// "createdAt":1645134874858
// }
//
// watchTrades
//
// {
// "makerUserId": "62286a4d720edf0001e81961",
// "symbol": "ADAUSDTM",
// "sequence": 41320766,
// "side": "sell",
// "size": 2,
// "price": 0.35904,
// "takerOrderId": "636dd9da9857ba00010cfa44",
// "makerOrderId": "636dd9c8df149d0001e62bc8",
// "takerUserId": "6180be22b6ab210001fa3371",
// "tradeId": "636dd9da0000d400d477eca7",
// "ts": 1668143578987357700
// }
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("-".to_string())]);
let mut id: Value = self.safe_string2(trade.clone(), Value::Str("tradeId".to_string()), Value::Str("id".to_string()), &[]);
let mut orderId: Value = self.safe_string_k(trade.clone(), "orderId", &[]);
let mut takerOrMaker: Value = self.safe_string_k(trade.clone(), "liquidity", &[]);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "ts", &[]);
if !is_equal(×tamp, &Value::Null) {
timestamp = self.parse_to_int(divide(×tamp, &Value::Int(1000000)));
} else {
timestamp = self.safe_integer_k(trade.clone(), "createdAt", &[]);
// if it's a historical v1 trade, the exchange returns timestamp in seconds
if is_true(&(Value::Bool(in_op(&trade, &Value::Str("dealValue".to_string()))))) && is_true(&(!is_equal(×tamp, &Value::Null))) {
timestamp = multiply(×tamp, &Value::Int(1000));
}
}
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("price".to_string()), Value::Str("dealPrice".to_string()), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("size".to_string()), Value::Str("amount".to_string()), &[]);
let mut side: Value = self.safe_string_k(trade.clone(), "side", &[]);
let mut fee: Value = Value::Null;
let mut feeCostString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
if !is_equal(&feeCostString, &Value::Null) {
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "feeCurrency", &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
if is_equal(&feeCurrency, &Value::Null) {
feeCurrency = ternary(is_true(&(is_equal(&side, &Value::Str("sell".to_string())))), get_value(&market, &Value::Str("quote".to_string())), get_value(&market, &Value::Str("base".to_string())));
}
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString.clone());
m.insert("currency".to_string(), feeCurrency.clone());
m.insert("rate".to_string(), self.safe_string_k(trade.clone(), "feeRate", &[]));
m
});
}
let mut type_var: Value = self.safe_string2(trade.clone(), Value::Str("type".to_string()), Value::Str("orderType".to_string()), &[]);
if is_equal(&type_var, &Value::Str("match".to_string())) {
type_var = Value::Null;
}
let mut costString: Value = self.safe_string2(trade.clone(), Value::Str("funds".to_string()), Value::Str("value".to_string()), &[]);
if is_equal(&costString, &Value::Null) {
let mut contractSize: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
let mut contractCost: Value = crate::precise::Precise::stringMul(&priceString, &amountString);
costString = crate::precise::Precise::stringMul(&contractCost, &contractSize);
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), id.clone());
m.insert("order".to_string(), orderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), costString.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_my_uta_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "orderId": "426373228194254848",
// "symbol": "DOGEUSDTM",
// "orderType": "MARKET",
// "side": "BUY",
// "tradeId": "1711108516570",
// "size": "1",
// "price": "0.09641",
// "value": "9.641",
// "executionTime": 1774468501294000000,
// "fee": "0.0057846",
// "feeCurrency": "USDT",
// "tax": "",
// "liquidityRole": "TAKER",
// "fillType": "NORMAL"
// }
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_product(trade.clone(), Value::Str("executionTime".to_string()), Value::Float(0.000001), &[]);
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.safe_string_k(trade.clone(), "fee", &[]));
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(trade.clone(), "feeCurrency", &[]), &[]));
m
});
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string_k(trade.clone(), "tradeId", &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), self.safe_string_lower(trade.clone(), Value::Str("orderType".to_string()), &[]));
m.insert("takerOrMaker".to_string(), self.safe_string_lower(trade.clone(), Value::Str("liquidityRole".to_string()), &[]));
m.insert("side".to_string(), self.safe_string_lower(trade.clone(), Value::Str("side".to_string()), &[]));
m.insert("price".to_string(), self.safe_string_k(trade.clone(), "price", &[]));
m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "size", &[]));
m.insert("cost".to_string(), self.safe_string_k(trade.clone(), "value", &[]));
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://www.kucoin.com/docs-new/rest/account-info/trade-fee/get-actual-fee-spot-margin
* @see https://www.kucoin.com/docs-new/rest/account-info/trade-fee/get-actual-fee-futures
* @see https://www.kucoin.com/docs-new/rest/ua/get-actual-fee
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta) endpoint, defaults to false
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_trading_fee(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTradingFee".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut entry: Value = Value::Null;
if is_true(&uta) {
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("SPOT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), Value::Str("FUTURES".to_string()));
}
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_90 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_user_fee_rate(&[__ws_arg_90]).await;
//
// {
// "code": "200000",
// "data": {
// "tradeType": "SPOT",
// "list": [
// {
// "symbol": "ETH-USDT",
// "takerFeeRate": "0.001",
// "makerFeeRate": "0.001"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut dataList: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
entry = self.safe_dict(dataList.clone(), Value::Int(0), &[]);
} else if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbols".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_91 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_trade_fees(&[__ws_arg_91]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "symbol": "BTC-USDT",
// "takerFeeRate": "0.001",
// "makerFeeRate": "0.001"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
entry = self.safe_dict(data.clone(), Value::Int(0), &[]);
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_92 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_trade_fees(&[__ws_arg_92]).await;
//
// {
// "code": "200000",
// "data": {
// "symbol": "ETHUSDTM",
// "takerFeeRate": "0.0006",
// "makerFeeRate": "0.0002",
// "feeTaxRate": "0"
// }
// }
//
entry = self.safe_dict_k(response.clone(), "data", &[]);
}
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("maker".to_string(), self.safe_number_k(entry.clone(), "makerFeeRate", &[]));
m.insert("taker".to_string(), self.safe_number_k(entry.clone(), "takerFeeRate", &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
/*
* @method
* @name kucoin#withdraw
* @description make a withdrawal
* @see https://www.kucoin.com/docs-new/rest/account-info/withdrawals/withdraw-v3
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
{ let __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.check_address(&[address.clone()]);
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("toAddress".to_string(), address.clone());
m.insert("withdrawType".to_string(), Value::Str("ADDRESS".to_string()));
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("memo".to_string()), tag.clone());
}
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
let mut _netIdTmp: Value = self.network_code_to_id(networkCode.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))]);
if !is_equal(&_netIdTmp, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), to_lower(&_netIdTmp));
}
}
let mut amountString: Value = self.currency_to_precision(code.clone(), amount.clone(), &[networkCode.clone()]);
if !is_equal(&amountString, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("amount".to_string()), crate::runtime::parse_float(&amountString));
}
let mut includeFee: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("withdraw".to_string()), Value::Str("includeFee".to_string()), &[Value::Bool(false)]); includeFee = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&includeFee) {
add_element_to_object(&mut request, &Value::Str("feeDeductType".to_string()), Value::Str("INTERNAL".to_string()));
}
let __ws_arg_93 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_withdrawals(&[__ws_arg_93]).await;
//
// the id is inside "data"
//
// {
// "code": 200000,
// "data": {
// "withdrawalId": "5bffb63303aa675e8bbe18f9"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(data.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SUCCESS".to_string(), Value::Str("ok".to_string()));
m.insert("PROCESSING".to_string(), Value::Str("pending".to_string()));
m.insert("WALLET_PROCESSING".to_string(), Value::Str("pending".to_string()));
m.insert("FAILURE".to_string(), Value::Str("failed".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchDeposits
//
// {
// "address": "0x5f047b29041bcfdbf0e4478cdfa753a336ba6989",
// "memo": "5c247c8a03aa677cea2a251d",
// "amount": 1,
// "fee": 0.0001,
// "currency": "KCS",
// "chain": "",
// "isInner": false,
// "walletTxId": "5bbb57386d99522d9f954c5a@test004",
// "status": "SUCCESS",
// "createdAt": 1544178843000,
// "updatedAt": 1544178891000
// "remark":"foobar"
// }
//
// fetchWithdrawals
//
// {
// "id": "5c2dc64e03aa675aa263f1ac",
// "address": "0x5bedb060b8eb8d823e2414d82acce78d38be7fe9",
// "memo": "",
// "currency": "ETH",
// "chain": "",
// "amount": 1.0000000,
// "fee": 0.0100000,
// "walletTxId": "3e2414d82acce78d38be7fe9",
// "isInner": false,
// "status": "FAILURE",
// "createdAt": 1546503758000,
// "updatedAt": 1546504603000
// "remark":"foobar"
// }
//
// withdraw
//
// {
// "withdrawalId": "5bffb63303aa675e8bbe18f9"
// }
//
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut address: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut amount: Value = self.safe_string_k(transaction.clone(), "amount", &[]);
let mut txid: Value = self.safe_string_k(transaction.clone(), "walletTxId", &[]);
if !is_equal(&txid, &Value::Null) {
let mut txidParts: Value = split(&txid, &Value::Str("@".to_string()));
let mut numTxidParts: Value = get_array_length(&txidParts);
if is_greater_than(&numTxidParts, &Value::Int(1)) {
if is_equal(&address, &Value::Null) {
if is_greater_than(&get_array_length(&get_value(&txidParts, &Value::Int(1))), &Value::Int(1)) {
address = get_value(&txidParts, &Value::Int(1));
}
}
}
txid = get_value(&txidParts, &Value::Int(0));
}
let mut type_var: Value = ternary(is_true(&(is_equal(&txid, &Value::Null))), Value::Str("withdrawal".to_string()), Value::Str("deposit".to_string()));
let mut rawStatus: Value = self.safe_string_k(transaction.clone(), "status", &[]);
let mut fee: Value = Value::Null;
let mut feeCost: Value = self.safe_string_k(transaction.clone(), "fee", &[]);
if !is_equal(&feeCost, &Value::Null) {
let mut rate: Value = Value::Null;
if !is_equal(&amount, &Value::Null) {
rate = crate::precise::Precise::stringDiv(&feeCost, &amount);
}
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeCost.clone(), &[]));
m.insert("rate".to_string(), self.parse_number(rate.clone(), &[]));
m.insert("currency".to_string(), code.clone());
m
});
}
let mut timestamp: Value = self.safe_integer2(transaction.clone(), Value::Str("createdAt".to_string()), Value::Str("createAt".to_string()), &[]);
let mut updated: Value = self.safe_integer_k(transaction.clone(), "updatedAt", &[]);
let mut isV1: bool = !is_true(&(Value::Bool(in_op(&transaction, &Value::Str("createdAt".to_string())))));
// if it's a v1 structure
if is_true(&isV1) {
type_var = ternary(is_true(&(Value::Bool(in_op(&transaction, &Value::Str("address".to_string()))))), Value::Str("withdrawal".to_string()), Value::Str("deposit".to_string()));
if !is_equal(×tamp, &Value::Null) {
timestamp = multiply(×tamp, &Value::Int(1000));
}
if !is_equal(&updated, &Value::Null) {
updated = multiply(&updated, &Value::Int(1000));
}
}
let mut internal: Value = self.safe_bool_k(transaction.clone(), "isInner", &[]);
let mut tag: Value = self.safe_string_k(transaction.clone(), "memo", &[]);
let mut chainId: Value = self.safe_string_k(transaction.clone(), "chain", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string2(transaction.clone(), Value::Str("id".to_string()), Value::Str("withdrawalId".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("network".to_string(), self.network_id_to_code(&[chainId.clone(), code.clone()]));
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), address.clone());
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), tag.clone());
m.insert("tagTo".to_string(), tag.clone());
m.insert("tagFrom".to_string(), Value::Null);
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("txid".to_string(), txid.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("status".to_string(), self.parse_transaction_status(rawStatus.clone()));
m.insert("comment".to_string(), self.safe_string_k(transaction.clone(), "remark", &[]));
m.insert("internal".to_string(), internal.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("updated".to_string(), updated.clone());
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchDeposits
* @description fetch all deposits made to an account
* @see https://www.kucoin.com/docs-new/rest/account-info/deposit/get-deposit-history
* @see https://www.kucoin.com/docs-new/abandoned-endpoints/account-funding/get-deposit-history-old
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] *main account only* default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @param {string} [params.accountType] 'main' or 'contract' (default is 'main')
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountType: Value = Value::Str("main".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchDeposits".to_string()), Value::Str("accountType".to_string()), &[accountType.clone()]); accountType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
accountType = self.safe_string(accountsByType.clone(), accountType.clone(), &[accountType.clone()]);
if is_equal(&accountType, &Value::Str("contract".to_string())) {
return self.fetch_contract_deposits(&[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchDeposits".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchDeposits".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if !is_equal(&since, &Value::Null) && is_less_than(&since, &Value::Int(1550448000000)) {
// if since is earlier than 2019-02-18T00:00:00Z
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
let __ws_arg_94 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hist_deposits(&[__ws_arg_94]).await;
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
let __ws_arg_95 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_deposits(&[__ws_arg_95]).await;
}
//
// {
// "code": "200000",
// "data": {
// "currentPage": 1,
// "pageSize": 5,
// "totalNum": 2,
// "totalPage": 1,
// "items": [
// //--------------------------------------------------
// // version 2 deposit response structure
// {
// "address": "0x5f047b29041bcfdbf0e4478cdfa753a336ba6989",
// "memo": "5c247c8a03aa677cea2a251d",
// "amount": 1,
// "fee": 0.0001,
// "currency": "KCS",
// "isInner": false,
// "walletTxId": "5bbb57386d99522d9f954c5a@test004",
// "status": "SUCCESS",
// "createdAt": 1544178843000,
// "updatedAt": 1544178891000
// "remark":"foobar"
// },
// //--------------------------------------------------
// // version 1 (historical) deposit response structure
// {
// "currency": "BTC",
// "createAt": 1528536998,
// "amount": "0.03266638",
// "walletTxId": "55c643bc2c68d6f17266383ac1be9e454038864b929ae7cee0bc408cc5c869e8@12ffGWmMMD1zA1WbFm7Ho3JZ1w6NYXjpFk@234",
// "isInner": false,
// "status": "SUCCESS",
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_transactions(items.clone(), &[currency.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("deposit".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name kucoin#fetchContractDeposits
* @description helper method for fetching deposits for futures accounts
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_contract_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
let __ws_arg_96 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_deposit_list(&[__ws_arg_96]).await;
//
// {
// "code": "200000",
// "data": {
// "currentPage": 1,
// "pageSize": 5,
// "totalNum": 2,
// "totalPage": 1,
// "items": [
// {
// "address": "0x5f047b29041bcfdbf0e4478cdfa753a336ba6989",
// "memo": "5c247c8a03aa677cea2a251d",
// "amount": 1,
// "fee": 0.0001,
// "currency": "KCS",
// "isInner": false,
// "walletTxId": "5bbb57386d99522d9f954c5a@test004",
// "status": "SUCCESS",
// "createdAt": 1544178843000,
// "updatedAt": 1544178891000
// "remark":"foobar"
// },
// ...
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut responseData: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_transactions(responseData.clone(), &[currency.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("deposit".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name kucoin#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://www.kucoin.com/docs-new/rest/account-info/withdrawals/get-withdrawal-history
* @see https://www.kucoin.com/docs-new/abandoned-endpoints/account-funding/get-withdrawal-history-old
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] *main account only* default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @param {string} [params.accountType] 'main' or 'contract' (default is 'main')
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountType: Value = Value::Str("main".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchWithdrawals".to_string()), Value::Str("accountType".to_string()), &[accountType.clone()]); accountType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
accountType = self.safe_string(accountsByType.clone(), accountType.clone(), &[accountType.clone()]);
if is_equal(&accountType, &Value::Str("contract".to_string())) {
return self.fetch_contract_withdrawals(&[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut maxLimit: Value = Value::Int(500);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchWithdrawals".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchWithdrawals".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if !is_equal(&since, &Value::Null) && is_less_than(&since, &Value::Int(1550448000000)) {
// if since is earlier than 2019-02-18T00:00:00Z
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
let __ws_arg_97 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hist_withdrawals(&[__ws_arg_97]).await;
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
let __ws_arg_98 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_withdrawals(&[__ws_arg_98]).await;
}
//
// {
// "code": "200000",
// "data": {
// "currentPage": 1,
// "pageSize": 5,
// "totalNum": 2,
// "totalPage": 1,
// "items": [
// //--------------------------------------------------
// // version 2 withdrawal response structure
// {
// "id": "5c2dc64e03aa675aa263f1ac",
// "address": "0x5bedb060b8eb8d823e2414d82acce78d38be7fe9",
// "memo": "",
// "currency": "ETH",
// "amount": 1.0000000,
// "fee": 0.0100000,
// "walletTxId": "3e2414d82acce78d38be7fe9",
// "isInner": false,
// "status": "FAILURE",
// "createdAt": 1546503758000,
// "updatedAt": 1546504603000
// },
// //--------------------------------------------------
// // version 1 (historical) withdrawal response structure
// {
// "currency": "BTC",
// "createAt": 1526723468,
// "amount": "0.534",
// "address": "33xW37ZSW4tQvg443Pc7NLCAs167Yc2XUV",
// "walletTxId": "aeacea864c020acf58e51606169240e96774838dcd4f7ce48acf38e3651323f4",
// "isInner": false,
// "status": "SUCCESS"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_transactions(items.clone(), &[currency.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("withdrawal".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name kucoin#fetchContractWithdrawals
* @description helper method for fetching withdrawals for futures accounts
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_contract_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
let __ws_arg_99 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_withdrawal_list(&[__ws_arg_99]).await;
//
// {
// "code": "200000",
// "data": {
// "currentPage": 1,
// "pageSize": 5,
// "totalNum": 2,
// "totalPage": 1,
// "items": [
// {
// "id": "5c2dc64e03aa675aa263f1ac",
// "address": "0x5bedb060b8eb8d823e2414d82acce78d38be7fe9",
// "memo": "",
// "currency": "ETH",
// "amount": 1.0000000,
// "fee": 0.0100000,
// "walletTxId": "3e2414d82acce78d38be7fe9",
// "isInner": false,
// "status": "FAILURE",
// "createdAt": 1546503758000,
// "updatedAt": 1546504603000
// },
// ...
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut responseData: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_transactions(responseData.clone(), &[currency.clone(), since.clone(), limit.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("withdrawal".to_string()));
m
})]);
Value::Null
}
pub fn parse_balance_helper(&self, mut entry: Value) -> Value {
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string2(entry.clone(), Value::Str("holdBalance".to_string()), Value::Str("hold".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string2(entry.clone(), Value::Str("availableBalance".to_string()), Value::Str("available".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string2(entry.clone(), Value::Str("totalBalance".to_string()), Value::Str("total".to_string()), &[]));
let mut debt: Value = self.safe_string_k(entry.clone(), "liability", &[]);
let mut interest: Value = self.safe_string_k(entry.clone(), "interest", &[]);
add_element_to_object(&mut account, &Value::Str("debt".to_string()), crate::precise::Precise::stringAdd(&debt, &interest));
return account;
Value::Null
}
/*
* @method
* @name kucoin#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-detail-spot
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-cross-margin
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-isolated-margin
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-futures
* @see https://www.kucoin.com/docs-new/rest/ua/get-account-currency-assets-uta
* @see https://www.kucoin.com/docs-new/rest/ua/get-account-currency-assets-classic
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.marginMode] 'cross' or 'isolated', margin type for fetching margin balance
* @param {object} [params.type] extra parameters specific to the exchange API endpoint
* @param {object} [params.hf] *default if false* if true, the result includes the balance of the high frequency account
* @param {boolean} [params.uta] set to true for the unified trading account (uta) endpoint, defaults to false
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
return self.fetch_uta_balance(&[params.clone()]).await;
}
let mut response: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut code: Value = self.safe_string_k(params.clone(), "code", &[]);
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut requestedType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); requestedType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut type_var: Value = self.safe_string(accountsByType.clone(), requestedType.clone(), &[requestedType.clone()]);
params = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
if is_equal(&type_var, &Value::Str("contract".to_string())) {
return self.fetch_contract_balance(&[params.clone()]).await;
}
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&hf, &Value::Bool(true)))) && is_true(&(!is_equal(&type_var, &Value::Str("main".to_string())))) {
type_var = Value::Str("trade_hf".to_string());
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBalance".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isolated: bool = is_true(&(is_equal(&marginMode, &Value::Str("isolated".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("isolated".to_string()))));
let mut cross: bool = is_true(&(is_equal(&marginMode, &Value::Str("cross".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("margin".to_string()))));
if is_true(&isolated) {
if !is_equal(¤cy, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("balanceCurrency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let __ws_arg_100 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_isolated_accounts(&[__ws_arg_100]).await;
} else if is_true(&cross) {
let __ws_arg_101 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_margin_account(&[__ws_arg_101]).await;
} else {
if !is_equal(¤cy, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
add_element_to_object(&mut request, &Value::Str("type".to_string()), type_var.clone());
let __ws_arg_102 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_accounts(&[__ws_arg_102]).await;
}
//
// Spot
//
// {
// "code": "200000",
// "data": [
// {
// "balance": "0.00009788",
// "available": "0.00009788",
// "holds": "0",
// "currency": "BTC",
// "id": "5c6a4fd399a1d81c4f9cc4d0",
// "type": "trade",
// },
// ]
// }
//
// Cross
//
// {
// "code": "200000",
// "data": {
// "debtRatio": "0",
// "accounts": [
// {
// "currency": "USDT",
// "totalBalance": "5",
// "availableBalance": "5",
// "holdBalance": "0",
// "liability": "0",
// "maxBorrowSize": "20"
// },
// ]
// }
// }
//
// Isolated
//
// {
// "code": "200000",
// "data": {
// "totalAssetOfQuoteCurrency": "0",
// "totalLiabilityOfQuoteCurrency": "0",
// "timestamp": 1712085661155,
// "assets": [
// {
// "symbol": "MANA-USDT",
// "status": "EFFECTIVE",
// "debtRatio": "0",
// "baseAsset": {
// "currency": "MANA",
// "borrowEnabled": true,
// "transferInEnabled": true,
// "total": "0",
// "hold": "0",
// "available": "0",
// "liability": "0",
// "interest": "0",
// "maxBorrowSize": "0"
// },
// "quoteAsset": {
// "currency": "USDT",
// "borrowEnabled": true,
// "transferInEnabled": true,
// "total": "0",
// "hold": "0",
// "available": "0",
// "liability": "0",
// "interest": "0",
// "maxBorrowSize": "0"
// }
// },
// ...
// ]
// }
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
if is_true(&isolated) {
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut assets: Value = self.safe_value_k(data.clone(), "assets", &[data.clone()]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_887: bool = true;
while { if !__for_first_887 { i = add(&i, &Value::Int(1)); } __for_first_887 = false; is_less_than(&i, &get_array_length(&assets)) } {
let mut entry: Value = get_value(&assets, &i);
let mut entry: Value = get_value(&assets, &i);
let mut base: Value = self.safe_dict_k(entry.clone(), "baseAsset", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut quote: Value = self.safe_dict_k(entry.clone(), "quoteAsset", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut baseCode: Value = self.safe_currency_code(self.safe_string_k(base.clone(), "currency", &[]), &[]);
let mut quoteCode: Value = self.safe_currency_code(self.safe_string_k(quote.clone(), "currency", &[]), &[]);
if !is_equal(&baseCode, &Value::Null) {
result = self.merge_balance_account(result.clone(), baseCode.clone(), self.parse_balance_helper(base.clone()));
}
if !is_equal("eCode, &Value::Null) {
result = self.merge_balance_account(result.clone(), quoteCode.clone(), self.parse_balance_helper(quote.clone()));
}
}
}
} else if is_true(&cross) {
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut accounts: Value = self.safe_list_k(data.clone(), "accounts", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_888: bool = true;
while { if !__for_first_888 { i = add(&i, &Value::Int(1)); } __for_first_888 = false; is_less_than(&i, &get_array_length(&accounts)) } {
let mut balance: Value = get_value(&accounts, &i);
let mut balance: Value = get_value(&accounts, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut codeInner: Value = self.safe_currency_code(currencyId.clone(), &[]);
if !is_equal(&codeInner, &Value::Null) {
add_element_to_object(&mut result, &codeInner, self.parse_balance_helper(balance.clone()));
}
}
}
} else {
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_889: bool = true;
while { if !__for_first_889 { i = add(&i, &Value::Int(1)); } __for_first_889 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut balance: Value = get_value(&data, &i);
let mut balance: Value = get_value(&data, &i);
let mut balanceType: Value = self.safe_string_k(balance.clone(), "type", &[]);
if is_equal(&balanceType, &type_var) {
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut codeInner2: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "balance", &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "available", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "holds", &[]));
if !is_equal(&codeInner2, &Value::Null) {
add_element_to_object(&mut result, &codeInner2, account.clone());
}
}
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name kucoin#fetchContractBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-futures
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.code] the unified currency code to fetch the balance for, if not provided, the default .options['fetchBalance']['code'] will be used
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_contract_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
// only fetches one balance at a time
let mut defaultCode: Value = self.safe_string_k(self.options.clone(), "code", &[]);
let mut fetchBalanceOptions: Value = self.safe_value_k(self.options.clone(), "fetchBalance", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
defaultCode = self.safe_string_k(fetchBalanceOptions.clone(), "code", &[defaultCode.clone()]);
let mut code: Value = self.safe_string_k(params.clone(), "code", &[defaultCode.clone()]);
if is_equal(&code, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchContractBalance() requires a code parameter".to_string()))));
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_103 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_account_overview(&[__ws_arg_103]).await;
//
// {
// "code": "200000",
// "data": {
// "accountEquity": 0.00005,
// "unrealisedPNL": 0,
// "marginBalance": 0.00005,
// "positionMargin": 0,
// "orderMargin": 0,
// "frozenFunds": 0,
// "availableBalance": 0.00005,
// "currency": "XBT"
// }
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
let mut currencyId: Value = self.safe_string_k(data.clone(), "currency", &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(data.clone(), "availableBalance", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(data.clone(), "accountEquity", &[]));
if !is_equal(¤cyCode, &Value::Null) {
add_element_to_object(&mut result, ¤cyCode, account.clone());
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name kucoin#fetchUtaBalance
* @description helper method for fetching balance with unified trading account (uta) endpoint
* @see https://www.kucoin.com/docs-new/rest/ua/get-account-currency-assets-uta
* @see https://www.kucoin.com/docs-new/rest/ua/get-account-currency-assets-classic
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'unified', 'spot', 'funding', 'cross', 'isolated' or 'swap' (default is 'unified')
* @param {string} [params.marginMode] 'cross' or 'isolated', margin type for fetching margin balance, only applicable if type is margin (default is cross)
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_uta_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut requestedType: Value = Value::Str("unified".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchUtaBalance".to_string()), &[Value::Null, params.clone(), requestedType.clone()]); requestedType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&requestedType, &Value::Str("margin".to_string())) {
// assume cross margin if margin is specified but marginMode is not specified
let mut marginMode: Value = Value::Str("cross".to_string());
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchUtaBalance".to_string()), &[params.clone(), marginMode.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
requestedType = marginMode.clone();
}
let mut utaAccountsByType: Value = self.safe_dict_k(self.options.clone(), "utaAccountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut type_var: Value = Value::Null;
type_var = self.safe_string(utaAccountsByType.clone(), requestedType.clone(), &[requestedType.clone()]);
let mut isIsolated: bool = is_equal(&type_var, &Value::Str("ISOLATED".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("unified".to_string())) {
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), type_var.clone());
// uta
// {
// "code": "200000",
// "data": {
// "accountType": "UNIFIED",
// "ts": 1764731696945,
// "accounts": [
// {
// "currencies": [
// {
// "currency": "USDT",
// "equity": "97.9936711985",
// "hold": "0.0000000000",
// "balance": "97.9936711985",
// "available": "97.9936711985",
// "liability": "0.0000000000"
// },
// {
// "currency": "BTC",
// "equity": "0.0000216000",
// "hold": "0.0000000000",
// "balance": "0.0000216000",
// "available": "0.0000216000",
// "liability": "0.0000000000"
// }
// ]
// }
// ]
// }
// }
//
let __ws_arg_104 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_account_mode_account_balance(&[__ws_arg_104]).await;
} else {
add_element_to_object(&mut request, &Value::Str("accountType".to_string()), type_var.clone());
//
// isolated
// {
// "code": "200000",
// "data": {
// "accountType": "ISOLATED",
// "ts": 1774244660519,
// "accounts": [
// {
// "accountSubtype": "LTC-USDT",
// "riskRatio": "0",
// "currencies": [
// {
// "currency": "LTC",
// "hold": "0",
// "available": "0",
// "liability": "0",
// "balance": "0",
// "equity": "0"},{
// "currency": "USDT",
// "hold": "0",
// "available": "6",
// "liability": "0",
// "balance": "6",
// "equity": "6"
// }
// ]
// }
// ]
// }
// }
//
let __ws_arg_105 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_account_balance(&[__ws_arg_105]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "ts", &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
let mut accounts: Value = self.safe_list_k(data.clone(), "accounts", &[Value::List(vec![])]);
if is_true(&isIsolated) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_891: bool = true;
while { if !__for_first_891 { i = add(&i, &Value::Int(1)); } __for_first_891 = false; is_less_than(&i, &get_array_length(&accounts)) } {
let mut entry: Value = get_value(&accounts, &i);
let mut entry: Value = get_value(&accounts, &i);
let mut currencies: Value = self.safe_list_k(entry.clone(), "currencies", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_890: bool = true;
while { if !__for_first_890 { j = add(&j, &Value::Int(1)); } __for_first_890 = false; is_less_than(&j, &get_array_length(¤cies)) } {
let mut currencyEntry: Value = self.safe_dict(currencies.clone(), j.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyId: Value = self.safe_string_k(currencyEntry.clone(), "currency", &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.clone(), &[]);
if !is_equal(¤cyCode, &Value::Null) {
result = self.merge_balance_account(result.clone(), currencyCode.clone(), self.parse_balance_helper(currencyEntry.clone()));
}
}
}
}
}
} else {
let mut firstAccount: Value = self.safe_dict(accounts.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencies: Value = self.safe_list_k(firstAccount.clone(), "currencies", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_892: bool = true;
while { if !__for_first_892 { i = add(&i, &Value::Int(1)); } __for_first_892 = false; is_less_than(&i, &get_array_length(¤cies)) } {
let mut currencyEntry: Value = self.safe_dict(currencies.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyId: Value = self.safe_string_k(currencyEntry.clone(), "currency", &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.clone(), &[]);
if !is_equal(¤cyCode, &Value::Null) {
add_element_to_object(&mut result, ¤cyCode, self.parse_balance_helper(currencyEntry.clone()));
}
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name kucoin#transfer
* @description transfer currency internally between wallets on the same account
* @see https://www.kucoin.com/docs-new/rest/account-info/transfer/flex-transfer?lang=en_US&
* @see https://www.kucoin.com/docs-new/rest/ua/flex-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta) endpoint, defaults to false
* Check transferClassic() and transferUta() for more details on params
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("transfer".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
return self.transfer_uta(code.clone(), amount.clone(), fromAccount.clone(), toAccount.clone(), &[params.clone()]).await;
}
return self.transfer_classic(code.clone(), amount.clone(), fromAccount.clone(), toAccount.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name kucoin#transferUta
* @description transfer currency internally between wallets on the same account with uta endpoint
* @see https://www.kucoin.com/docs-new/rest/ua/flex-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.transferType] INTERNAL, PARENT_TO_SUB, SUB_TO_PARENT, SUB_TO_SUB (default is INTERNAL)
* @param {string} [params.fromUserId] required if transferType is SUB_TO_PARENT or SUB_TO_SUB
* @param {string} [params.toUserId] required if transferType is PARENT_TO_SUB or SUB_TO_SUB
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer_uta(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut requestedAmount: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), requestedAmount.clone());
m
});
let mut transferType: Value = Value::Str("INTERNAL".to_string());
{ let __destr_tmp = self.handle_param_string2(params.clone(), Value::Str("transferType".to_string()), Value::Str("type".to_string()), &[transferType.clone()]); transferType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut fromUserId: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string2(params.clone(), Value::Str("fromUserId".to_string()), Value::Str("fromUid".to_string()), &[fromUserId.clone()]); fromUserId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut toUserId: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string2(params.clone(), Value::Str("toUserId".to_string()), Value::Str("toUid".to_string()), &[toUserId.clone()]); toUserId = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&transferType, &Value::Str("PARENT_TO_SUB".to_string())) || is_equal(&transferType, &Value::Str("SUB_TO_SUB".to_string())) {
if is_equal(&toUserId, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" transfer() requires a toUserId param for PARENT_TO_SUB or SUB_TO_SUB transfers".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("toUid".to_string()), toUserId.clone());
}
} else if is_equal(&transferType, &Value::Str("SUB_TO_PARENT".to_string())) || is_equal(&transferType, &Value::Str("SUB_TO_SUB".to_string())) {
if is_equal(&fromUserId, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" transfer() requires a fromUserId param for SUB_TO_PARENT or SUB_TO_SUB transfers".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("fromUid".to_string()), fromUserId.clone());
}
}
let mut clientOid: Value = self.uuid(&[]);
{ let __destr_tmp = self.handle_param_string2(params.clone(), Value::Str("clientOid".to_string()), Value::Str("clientOrderId".to_string()), &[clientOid.clone()]); clientOid = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), clientOid.clone());
let mut fromId: Value = self.convert_type_to_account(fromAccount.clone());
let mut toId: Value = self.convert_type_to_account(toAccount.clone());
let mut exchangeIds: Value = ternary(is_true(&(is_equal(&self.ids, &Value::Null))), Value::List(vec![]), self.ids.clone());
let mut fromIsolated: Value = self.in_array(fromId.clone(), exchangeIds.clone());
let mut toIsolated: Value = self.in_array(toId.clone(), exchangeIds.clone());
if is_true(&fromIsolated) {
add_element_to_object(&mut request, &Value::Str("fromAccountSymbol".to_string()), fromId.clone());
fromId = Value::Str("ISOLATED".to_string());
}
if is_true(&toIsolated) {
add_element_to_object(&mut request, &Value::Str("toAccountSymbol".to_string()), toId.clone());
toId = Value::Str("ISOLATED".to_string());
}
let mut utaAccountsByType: Value = self.safe_dict_k(self.options.clone(), "utaAccountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
fromId = self.safe_string(utaAccountsByType.clone(), fromId.clone(), &[fromId.clone()]);
toId = self.safe_string(utaAccountsByType.clone(), toId.clone(), &[toId.clone()]);
add_element_to_object(&mut request, &Value::Str("fromAccountType".to_string()), to_upper(&fromId));
add_element_to_object(&mut request, &Value::Str("toAccountType".to_string()), to_upper(&toId));
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("INTERNAL".to_string(), Value::Str("0".to_string()));
m.insert("PARENT_TO_SUB".to_string(), Value::Str("1".to_string()));
m.insert("SUB_TO_PARENT".to_string(), Value::Str("2".to_string()));
m.insert("SUB_TO_SUB".to_string(), Value::Str("3".to_string()));
m
});
add_element_to_object(&mut request, &Value::Str("type".to_string()), self.safe_string(types.clone(), transferType.clone(), &[transferType.clone()]));
let __ws_arg_106 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_private_post_account_transfer(&[__ws_arg_106]).await;
//
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut transfer: Value = self.parse_transfer(data.clone(), &[currency.clone()]);
let mut transferOptions: Value = self.safe_dict_k(self.options.clone(), "transfer", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fillResponseFromRequest: Value = self.safe_bool_k(transferOptions.clone(), "fillResponseFromRequest", &[Value::Bool(true)]);
if is_equal(&fillResponseFromRequest, &Value::Bool(true)) {
add_element_to_object(&mut transfer, &Value::Str("amount".to_string()), amount.clone());
add_element_to_object(&mut transfer, &Value::Str("fromAccount".to_string()), fromAccount.clone());
add_element_to_object(&mut transfer, &Value::Str("toAccount".to_string()), toAccount.clone());
add_element_to_object(&mut transfer, &Value::Str("status".to_string()), Value::Str("ok".to_string()));
}
return transfer;
Value::Null
}
/*
* @method
* @name kucoin#transferClassic
* @description transfer currency internally between wallets on the same account with classic endpoints
* @see https://www.kucoin.com/docs-new/rest/account-info/transfer/flex-transfer?lang=en_US&
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.transferType] INTERNAL, PARENT_TO_SUB, SUB_TO_PARENT (default is INTERNAL)
* @param {string} [params.fromUserId] required if transferType is SUB_TO_PARENT
* @param {string} [params.toUserId] required if transferType is PARENT_TO_SUB
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer_classic(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut requestedAmount: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), requestedAmount.clone());
m
});
let mut transferType: Value = Value::Str("INTERNAL".to_string());
{ let __destr_tmp = self.handle_param_string2(params.clone(), Value::Str("transferType".to_string()), Value::Str("type".to_string()), &[transferType.clone()]); transferType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&transferType, &Value::Str("PARENT_TO_SUB".to_string())) {
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("toUserId".to_string()))))) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" transfer() requires a toUserId param for PARENT_TO_SUB transfers".to_string()))));
}
} else if is_equal(&transferType, &Value::Str("SUB_TO_PARENT".to_string())) {
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("fromUserId".to_string()))))) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" transfer() requires a fromUserId param for SUB_TO_PARENT transfers".to_string()))));
}
}
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("clientOid".to_string()))))) {
add_element_to_object(&mut request, &Value::Str("clientOid".to_string()), self.uuid(&[]));
}
let mut fromId: Value = self.convert_type_to_account(fromAccount.clone());
let mut toId: Value = self.convert_type_to_account(toAccount.clone());
let mut exchangeIds: Value = ternary(is_true(&(is_equal(&self.ids, &Value::Null))), Value::List(vec![]), self.ids.clone());
let mut fromIsolated: Value = self.in_array(fromId.clone(), exchangeIds.clone());
let mut toIsolated: Value = self.in_array(toId.clone(), exchangeIds.clone());
if is_true(&fromIsolated) {
add_element_to_object(&mut request, &Value::Str("fromAccountTag".to_string()), fromId.clone());
fromId = Value::Str("isolated".to_string());
}
if is_true(&toIsolated) {
add_element_to_object(&mut request, &Value::Str("toAccountTag".to_string()), toId.clone());
toId = Value::Str("isolated".to_string());
}
let mut hfOrMining: Value = self.is_hf_or_mining(fromId.clone(), toId.clone());
let mut response: Value = Value::Null;
if is_true(&hfOrMining) {
// new endpoint does not support hf and mining transfers
// use old endpoint for hf and mining transfers
add_element_to_object(&mut request, &Value::Str("from".to_string()), fromId.clone());
add_element_to_object(&mut request, &Value::Str("to".to_string()), toId.clone());
let __ws_arg_107 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_accounts_inner_transfer(&[__ws_arg_107]).await;
} else {
add_element_to_object(&mut request, &Value::Str("type".to_string()), transferType.clone());
add_element_to_object(&mut request, &Value::Str("fromAccountType".to_string()), to_upper(&fromId));
add_element_to_object(&mut request, &Value::Str("toAccountType".to_string()), to_upper(&toId));
//
// {
// "code": "200000",
// "data": {
// "orderId": "694fcb5b08bb1600015cda75"
// }
// }
//
let __ws_arg_108 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_accounts_universal_transfer(&[__ws_arg_108]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut transfer: Value = self.parse_transfer(data.clone(), &[currency.clone()]);
let mut transferOptions: Value = self.safe_dict_k(self.options.clone(), "transfer", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fillResponseFromRequest: Value = self.safe_bool_k(transferOptions.clone(), "fillResponseFromRequest", &[Value::Bool(true)]);
if is_equal(&fillResponseFromRequest, &Value::Bool(true)) {
add_element_to_object(&mut transfer, &Value::Str("amount".to_string()), amount.clone());
add_element_to_object(&mut transfer, &Value::Str("fromAccount".to_string()), fromAccount.clone());
add_element_to_object(&mut transfer, &Value::Str("toAccount".to_string()), toAccount.clone());
add_element_to_object(&mut transfer, &Value::Str("status".to_string()), Value::Str("ok".to_string()));
}
return transfer;
Value::Null
}
pub fn is_hf_or_mining(&self, mut fromId: Value, mut toId: Value) -> Value {
return Value::Bool(is_equal(&fromId, &Value::Str("trade_hf".to_string())) || is_equal(&toId, &Value::Str("trade_hf".to_string())) || is_equal(&fromId, &Value::Str("pool".to_string())) || is_equal(&toId, &Value::Str("pool".to_string())));
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// transfer (spot)
//
// {
// "orderId": "605a6211e657f00006ad0ad6"
// }
//
// {
// "code": "200000",
// "msg": "Failed to transfer out. The amount exceeds the upper limit"
// }
//
// transfer (futures)
//
// {
// "applyId": "605a87217dff1500063d485d",
// "bizNo": "bcd6e5e1291f4905af84dc",
// "payAccountType": "CONTRACT",
// "payTag": "DEFAULT",
// "remark": '',
// "recAccountType": "MAIN",
// "recTag": "DEFAULT",
// "recRemark": '',
// "recSystem": "KUCOIN",
// "status": "PROCESSING",
// "currency": "XBT",
// "amount": "0.00001",
// "fee": "0",
// "sn": "573688685663948",
// "reason": '',
// "createdAt": 1616545569000,
// "updatedAt": 1616545569000
// }
//
// ledger entry - from account ledgers API (for fetchTransfers)
//
// {
// "id": "611a1e7c6a053300067a88d9",
// "currency": "USDT",
// "amount": "10.00059547",
// "fee": "0",
// "balance": "0",
// "accountType": "MAIN",
// "bizType": "Transfer",
// "direction": "in",
// "createdAt": 1629101692950,
// "context": "{\"orderId\":\"611a1e7c6a053300067a88d9\"}"
// }
//
// ledger entry from contracts API
// {
// "time": 1771765696000,
// "type": "TransferIn",
// "amount": 10.0,
// "fee": 0.0,
// "accountEquity": 54.53821148,
// "status": "Completed",
// "remark": "Transferred from Trading Account",
// "offset": 71904927,
// "currency": "USDT"
// }
let mut timestamp: Value = self.safe_integer2(transfer.clone(), Value::Str("createdAt".to_string()), Value::Str("time".to_string()), &[]);
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "currency", &[]);
let mut rawStatus: Value = self.safe_string_k(transfer.clone(), "status", &[]);
let mut bizType: Value = self.safe_string_k(transfer.clone(), "bizType", &[]);
let mut isLedgerEntry: bool = !is_equal(&bizType, &Value::Null);
let mut accountFromRaw: Value = Value::Null;
let mut accountToRaw: Value = Value::Null;
if is_true(&isLedgerEntry) {
// Ledger entry format: uses accountType + direction
let mut accountType: Value = self.safe_string_lower(transfer.clone(), Value::Str("accountType".to_string()), &[]);
let mut direction: Value = self.safe_string_k(transfer.clone(), "direction", &[]);
if is_equal(&direction, &Value::Str("out".to_string())) {
accountFromRaw = accountType.clone();
} else if is_equal(&direction, &Value::Str("in".to_string())) {
accountToRaw = accountType.clone();
}
} else {
// Transfer API format: uses payAccountType/recAccountType
accountFromRaw = self.safe_string_lower(transfer.clone(), Value::Str("payAccountType".to_string()), &[]);
accountToRaw = self.safe_string_lower(transfer.clone(), Value::Str("recAccountType".to_string()), &[]);
}
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[]);
let mut accountFrom: Value = ternary(is_true(&(is_equal(&accountFromRaw, &Value::Null))), Value::Null, self.safe_string(accountsByType.clone(), accountFromRaw.clone(), &[accountFromRaw.clone()]));
let mut accountTo: Value = ternary(is_true(&(is_equal(&accountToRaw, &Value::Null))), Value::Null, self.safe_string(accountsByType.clone(), accountToRaw.clone(), &[accountToRaw.clone()]));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_n(transfer.clone(), Value::List(vec![Value::Str("id".to_string()), Value::Str("applyId".to_string()), Value::Str("orderId".to_string())]), &[]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("amount".to_string(), self.safe_number_k(transfer.clone(), "amount", &[]));
m.insert("fromAccount".to_string(), accountFrom.clone());
m.insert("toAccount".to_string(), accountTo.clone());
m.insert("status".to_string(), self.parse_transfer_status(rawStatus.clone()));
m.insert("info".to_string(), transfer.clone());
m
});
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("PROCESSING".to_string(), Value::Str("pending".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Assets Transferred in After Upgrading".to_string(), Value::Str("transfer".to_string()));
m.insert("Deposit".to_string(), Value::Str("transaction".to_string()));
m.insert("Withdrawal".to_string(), Value::Str("transaction".to_string()));
m.insert("Transfer".to_string(), Value::Str("transfer".to_string()));
m.insert("Trade_Exchange".to_string(), Value::Str("trade".to_string()));
m.insert("KuCoin Bonus".to_string(), Value::Str("bonus".to_string()));
m.insert("Referral Bonus".to_string(), Value::Str("referral".to_string()));
m.insert("Rewards".to_string(), Value::Str("bonus".to_string()));
m.insert("Airdrop/Fork".to_string(), Value::Str("airdrop".to_string()));
m.insert("Other rewards".to_string(), Value::Str("bonus".to_string()));
m.insert("Fee Rebate".to_string(), Value::Str("rebate".to_string()));
m.insert("Buy Crypto".to_string(), Value::Str("trade".to_string()));
m.insert("Sell Crypto".to_string(), Value::Str("sell".to_string()));
m.insert("Public Offering Purchase".to_string(), Value::Str("trade".to_string()));
m.insert("Refunded Fees".to_string(), Value::Str("fee".to_string()));
m.insert("KCS Pay Fees".to_string(), Value::Str("fee".to_string()));
m.insert("Margin Trade".to_string(), Value::Str("trade".to_string()));
m.insert("Loans".to_string(), Value::Str("Loans".to_string()));
m.insert("Instant Exchange".to_string(), Value::Str("trade".to_string()));
m.insert("Sub-account transfer".to_string(), Value::Str("transfer".to_string()));
m.insert("Liquidation Fees".to_string(), Value::Str("fee".to_string()));
m.insert("RealisedPNL".to_string(), Value::Str("trade".to_string()));
m.insert("TransferIn".to_string(), Value::Str("transfer".to_string()));
m.insert("TransferOut".to_string(), Value::Str("transfer".to_string()));
m.insert("TRADE_EXCHANGE".to_string(), Value::Str("trade".to_string()));
m.insert("TRANSFER".to_string(), Value::Str("transfer".to_string()));
m.insert("SUB_TRANSFER".to_string(), Value::Str("transfer".to_string()));
m.insert("RETURNED_FEES".to_string(), Value::Str("fee".to_string()));
m.insert("DEDUCTION_FEES".to_string(), Value::Str("fee".to_string()));
m.insert("OTHER".to_string(), Value::Str("other".to_string()));
m.insert("SUB_TO_SUB_TRANSFER".to_string(), Value::Str("transfer".to_string()));
m.insert("SPOT_EXCHANGE".to_string(), Value::Str("trade".to_string()));
m.insert("SPOT_EXCHANGE_REBATE".to_string(), Value::Str("rebate".to_string()));
m.insert("FUTURES_EXCHANGE_OPEN".to_string(), Value::Str("trade".to_string()));
m.insert("FUTURES_EXCHANGE_CLOSE".to_string(), Value::Str("trade".to_string()));
m.insert("FUTURES_EXCHANGE_REBATE".to_string(), Value::Str("rebate".to_string()));
m.insert("FUNDING_FEE".to_string(), Value::Str("fee".to_string()));
m.insert("LIABILITY_INTEREST".to_string(), Value::Str("fee".to_string()));
m.insert("KCS_DEDUCTION_FEES".to_string(), Value::Str("fee".to_string()));
m.insert("KCS_RETURNED_FEES".to_string(), Value::Str("fee".to_string()));
m.insert("AUTO_EXCHANGE_USER".to_string(), Value::Str("trade".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn parse_ledger_direction(&self, mut direction: Value) -> Value {
let mut directions: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("in".to_string(), Value::Str("in".to_string()));
m.insert("out".to_string(), Value::Str("out".to_string()));
m.insert("TransferIn".to_string(), Value::Str("in".to_string()));
m.insert("TransferOut".to_string(), Value::Str("out".to_string()));
m.insert("IN".to_string(), Value::Str("in".to_string()));
m.insert("OUT".to_string(), Value::Str("out".to_string()));
m
});
return self.safe_string(directions.clone(), direction.clone(), &[direction.clone()]);
Value::Null
}
pub fn parse_ledger_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Completed".to_string(), Value::Str("ok".to_string()));
m.insert("Pending".to_string(), Value::Str("pending".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": "611a1e7c6a053300067a88d9", //unique key for each ledger entry
// "currency": "USDT", //Currency
// "amount": "10.00059547", //The total amount of assets (fees included) involved in assets changes such as transaction, withdrawal and bonus distribution.
// "fee": "0", //Deposit or withdrawal fee
// "balance": "0", //Total assets of a currency remaining funds after transaction
// "accountType": "MAIN", //Account Type
// "bizType": "Loans Repaid", //business type
// "direction": "in", //side, in or out
// "createdAt": 1629101692950, //Creation time
// "context": "{\"borrowerUserId\":\"601ad03e50dc810006d242ea\",\"loanRepayDetailNo\":\"611a1e7cc913d000066cf7ec\"}" //Business core parameters
// }
//
// ledger entry from contracts API
// {
// "time": 1771765696000,
// "type": "TransferIn",
// "amount": 10.0,
// "fee": 0.0,
// "accountEquity": 54.53821148,
// "status": "Completed",
// "remark": "Transferred from Trading Account",
// "offset": 71904927,
// "currency": "USDT"
// }
//
// ledger entry from UTA API
// {
// "accountType": "UNIFIED",
// "id": "30000000001200350",
// "currency": "USDT",
// "direction": "IN",
// "businessType": "TRANSFER",
// "amount": "30",
// "balance": "30",
// "fee": "0",
// "tax": "0",
// "remark": "Funding Account",
// "ts": 1774241648267000000
// }
//
let mut id: Value = self.safe_string_k(item.clone(), "id", &[]);
let mut currencyId: Value = self.safe_string_k(item.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut amount: Value = self.safe_string_k(item.clone(), "amount", &[]);
let mut balanceAfter: Value = self.safe_number_omit_zero(item.clone(), Value::Str("balance".to_string()), &[]);
let mut bizType: Value = self.safe_string_n(item.clone(), Value::List(vec![Value::Str("bizType".to_string()), Value::Str("businessType".to_string()), Value::Str("type".to_string())]), &[]);
let mut type_var: Value = self.parse_ledger_entry_type(bizType.clone());
let mut direction: Value = self.safe_string2(item.clone(), Value::Str("direction".to_string()), Value::Str("type".to_string()), &[]);
let mut account: Value = self.safe_string_k(item.clone(), "accountType", &[]); // MAIN, TRADE, MARGIN, or CONTRACT
let mut timestamp: Value = self.safe_integer_k(item.clone(), "createdAt", &[]);
if is_equal(×tamp, &Value::Null) {
timestamp = self.safe_integer_k(item.clone(), "time", &[]);
if !is_equal(×tamp, &Value::Null) {
account = Value::Str("CONTRACT".to_string()); // contract ledger entries do not have an accountType field, so we set it to CONTRACT if the time field is present
} else {
timestamp = self.safe_integer_product(item.clone(), Value::Str("ts".to_string()), Value::Float(0.000001), &[]); // for UTA API
}
}
let mut datetime: Value = self.iso8601(timestamp.clone());
let mut context: Value = self.safe_string_k(item.clone(), "context", &[]); // contains other information about the ledger entry
//
// withdrawal transaction
//
// "{\"orderId\":\"617bb2d09e7b3b000196dac8\",\"txId\":\"0x79bb9855f86b351a45cab4dc69d78ca09586a94c45dde49475722b98f401b054\"}"
//
// deposit to MAIN, trade via MAIN
//
// "{\"orderId\":\"617ab9949e7b3b0001948081\",\"txId\":\"0x7a06b16bbd6b03dbc3d96df5683b15229fc35e7184fd7179a5f3a310bd67d1fa@default@0\"}"
//
// sell trade
//
// "{\"symbol\":\"ETH-USDT\",\"orderId\":\"617adcd1eb3fa20001dd29a1\",\"tradeId\":\"617adcd12e113d2b91222ff9\"}"
//
let mut referenceId: Value = Value::Null;
if !is_equal(&context, &Value::Null) && !is_equal(&context, &Value::Str("".to_string())) {
let _try_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let mut parsed: Value = json_parse(&context);
let mut orderId: Value = self.safe_string_k(parsed.clone(), "orderId", &[]);
let mut tradeId: Value = self.safe_string_k(parsed.clone(), "tradeId", &[]);
// transactions only have an orderId but for trades we wish to use tradeId
if !is_equal(&tradeId, &Value::Null) {
referenceId = tradeId.clone();
} else {
referenceId = orderId.clone();
}
#[allow(unreachable_code)] { Value::Null }}));
if let Err(_try_err) = _try_result { let exc: Value = panic_to_value(_try_err);
referenceId = context.clone();
}
}
let mut fee: Value = Value::Null;
let mut feeCostString: Value = self.safe_string_k(item.clone(), "fee", &[]);
let mut feeCost: Value = ternary(is_true(&(is_equal(&feeCostString, &Value::Null))), Value::Null, self.omit_zero(feeCostString.clone()));
let mut feeCurrency: Value = Value::Null;
if !is_equal(&feeCost, &Value::Null) {
feeCurrency = code.clone();
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeCost.clone(), &[]));
m.insert("currency".to_string(), feeCurrency.clone());
m
});
}
let mut status: Value = self.safe_string_k(item.clone(), "status", &[]);
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), id.clone());
m.insert("direction".to_string(), self.parse_ledger_direction(direction.clone()));
m.insert("account".to_string(), account.clone());
m.insert("referenceId".to_string(), referenceId.clone());
m.insert("referenceAccount".to_string(), account.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&amount), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), balanceAfter.clone());
m.insert("status".to_string(), self.parse_ledger_status(status.clone()));
m.insert("fee".to_string(), fee.clone());
m
}), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-spot-margin
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-tradehf
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-marginhf
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-futures
* @see https://www.kucoin.com/docs-new/rest/ua/get-account-ledger
* @param {string} [code] unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {object} [params.type] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.hf] default false, when true will fetch ledger entries for the high frequency trading account
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.uta] default false, when true will fetch ledger entries for the unified trading account (UTA) instead of the regular accounts endpoint
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.load_accounts(&[]).await;
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLedger".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut hf: Value = Value::Null;
{ let __destr_tmp = self.handle_hf_and_params(&[params.clone()]); hf = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut requestedType: Value = Value::Null;
if is_true(&uta) {
requestedType = Value::Str("UNIFIED".to_string());
}
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, params.clone(), requestedType.clone()]); requestedType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchLedger".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) && is_true(&(is_equal(&requestedType, &Value::Str("margin".to_string())))) {
marginMode = ternary(is_true(&(is_equal(&marginMode, &Value::Null))), Value::Str("cross".to_string()), marginMode.clone()); // default to cross margin for UTA if margin is requested but marginMode is not specified
requestedType = marginMode.clone();
}
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[]);
if is_true(&uta) {
accountsByType = self.safe_dict_k(self.options.clone(), "utaAccountsByType", &[]);
}
let mut type_var: Value = Value::Null;
type_var = self.safe_string(accountsByType.clone(), requestedType.clone(), &[requestedType.clone()]);
let mut maxLimit: Value = Value::Int(500); // for spot non-uta and margin
if is_equal(&hf, &Value::Bool(true)) {
maxLimit = Value::Int(200);
} else if is_equal(&type_var, &Value::Str("contract".to_string())) {
maxLimit = Value::Int(50);
} else if is_true(&uta) {
if is_true(&(is_equal(&type_var, &Value::Str("UNIFIED".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("SPOT".to_string())))) {
maxLimit = Value::Int(200);
} else if is_equal(&type_var, &Value::Str("FUTURES".to_string())) {
maxLimit = Value::Int(100);
}
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLedger".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchLedger".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
// atm only single currency retrieval is supported
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
if is_equal(&type_var, &Value::Str("contract".to_string())) {
add_element_to_object(&mut request, &Value::Str("maxCount".to_string()), limit.clone());
} else if is_equal(&hf, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
}
let mut response: Value = Value::Null;
if is_true(&uta) {
add_element_to_object(&mut request, &Value::Str("accountType".to_string()), type_var.clone());
let __ws_arg_109 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_account_ledger(&[__ws_arg_109]).await;
} else if is_equal(&hf, &Value::Bool(true)) {
if !is_equal(&marginMode, &Value::Null) {
let __ws_arg_110 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_margin_account_ledgers(&[__ws_arg_110]).await;
} else {
let __ws_arg_111 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_hf_accounts_ledgers(&[__ws_arg_111]).await;
}
} else if is_equal(&type_var, &Value::Str("contract".to_string())) {
//
// {
// "code": "200000",
// "data": {
// "dataList": [
// {
// "time": 1771765696000,
// "type": "TransferIn",
// "amount": 10.0,
// "fee": 0.0,
// "accountEquity": 54.53821148,
// "status": "Completed",
// "remark": "Transferred from Trading Account",
// "offset": 71904927,
// "currency": "USDT"
// }
// ],
// "hasMore": false
// }
// }
//
let __ws_arg_112 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_transaction_history(&[__ws_arg_112]).await;
} else {
let __ws_arg_113 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_accounts_ledgers(&[__ws_arg_113]).await;
}
//
// {
// "code":"200000",
// "data":{
// "currentPage":1,
// "pageSize":50,
// "totalNum":1,
// "totalPage":1,
// "items":[
// {
// "id":"617cc528729f5f0001c03ceb",
// "currency":"GAS",
// "amount":"0.00000339",
// "fee":"0",
// "balance":"0",
// "accountType":"MAIN",
// "bizType":"Distribution",
// "direction":"in",
// "createdAt":1635566888183,
// "context":"{\"orderId\":\"617cc47a1c47ed0001ce3606\",\"description\":\"Holding NEO,distribute GAS(2021/10/30)\"}"
// }
// {
// "id": "611a1e7c6a053300067a88d9",//unique key
// "currency": "USDT", //Currency
// "amount": "10.00059547", //Change amount of the funds
// "fee": "0", //Deposit or withdrawal fee
// "balance": "0", //Total assets of a currency
// "accountType": "MAIN", //Account Type
// "bizType": "Loans Repaid", //business type
// "direction": "in", //side, in or out
// "createdAt": 1629101692950, //Creation time
// "context": "{\"borrowerUserId\":\"601ad03e50dc810006d242ea\",\"loanRepayDetailNo\":\"611a1e7cc913d000066cf7ec\"}"
// },
// ]
// }
// }
//
let mut dataList: Value = self.safe_list_k(response.clone(), "data", &[]);
if !is_equal(&dataList, &Value::Null) {
return self.parse_ledger(dataList.clone(), &[currency.clone(), since.clone(), limit.clone()]);
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut items: Value = self.safe_list2(data.clone(), Value::Str("items".to_string()), Value::Str("dataList".to_string()), &[Value::List(vec![])]);
return self.parse_ledger(items.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn calculate_rate_limiter_cost(&self, mut api: Value, mut method: Value, mut path: Value, mut params: Value, optional_args: &[Value]) -> Value {
let mut config = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut versions: Value = self.safe_dict_k(self.options.clone(), "versions", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut apiVersions: Value = self.safe_dict(versions.clone(), api.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut methodVersions: Value = self.safe_dict(apiVersions.clone(), method.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultVersion: Value = self.safe_string(methodVersions.clone(), path.clone(), &[get_value(&self.options, &Value::Str("version".to_string()))]);
let mut version: Value = self.safe_string_k(params.clone(), "version", &[defaultVersion.clone()]);
if is_equal(&version, &Value::Str("v3".to_string())) && is_true(&(Value::Bool(in_op(&config, &Value::Str("v3".to_string()))))) {
return get_value(&config, &Value::Str("v3".to_string()));
} else if is_equal(&version, &Value::Str("v2".to_string())) && is_true(&(Value::Bool(in_op(&config, &Value::Str("v2".to_string()))))) {
return get_value(&config, &Value::Str("v2".to_string()));
} else if is_equal(&version, &Value::Str("v1".to_string())) && is_true(&(Value::Bool(in_op(&config, &Value::Str("v1".to_string()))))) {
return get_value(&config, &Value::Str("v1".to_string()));
}
return self.safe_value_k(config.clone(), "cost", &[Value::Int(1)]);
Value::Null
}
pub fn parse_borrow_rate(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "tradeId": "62db2dcaff219600012b56cd",
// "currency": "USDT",
// "size": "10",
// "dailyIntRate": "0.00003",
// "term": 7,
// "timestamp": 1658531274508488480
// },
//
// {
// "createdAt": 1697783812257,
// "currency": "XMR",
// "interestAmount": "0.1",
// "dayRatio": "0.001"
// }
//
// fetchCrossBorrowRate
// {
// "currentRateHourly": "0.00000353",
// "currentRateDaily": "0.00008466",
// "borrowLimitTotal": "600.00000000000000000000",
// "borrowLimitTotalHold": "0.00000000000000000000",
// "borrowLimitHold": "0.00000000000000000000",
// "interestFreeBorrowLimit": "0.60000000000000000000"
// }
//
let mut timestampId: Value = self.safe_string2(info.clone(), Value::Str("createdAt".to_string()), Value::Str("timestamp".to_string()), &[]);
let mut timestamp: Value = self.milliseconds();
if !is_equal(×tampId, &Value::Null) {
timestamp = self.parse_to_int(slice(×tampId, &Value::Int(0), &Value::Int(13)));
}
let mut currencyId: Value = self.safe_string_k(info.clone(), "currency", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("rate".to_string(), self.safe_number_n(info.clone(), Value::List(vec![Value::Str("dailyIntRate".to_string()), Value::Str("dayRatio".to_string()), Value::Str("currentRateDaily".to_string())]), &[]));
m.insert("period".to_string(), Value::Int(86400000));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), info.clone());
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchBorrowInterest
* @description fetch the interest owed by the user for borrowing currency for margin trading
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-cross-margin
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-isolated-margin
* @param {string} [code] unified currency code
* @param {string} [symbol] unified market symbol, required for isolated margin
* @param {int} [since] the earliest time in ms to fetch borrrow interest for
* @param {int} [limit] the maximum number of structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] 'cross' or 'isolated' default is 'cross'
* @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/?id=borrow-interest-structure}
*/
pub async fn fetch_borrow_interest(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut symbol = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBorrowInterest".to_string()), &[params.clone(), Value::Str("cross".to_string())]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
add_element_to_object(&mut request, &Value::Str("balanceCurrency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("quoteCurrency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut response: Value = Value::Null;
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
let __ws_arg_114 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_isolated_accounts(&[__ws_arg_114]).await;
} else {
let __ws_arg_115 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_margin_accounts(&[__ws_arg_115]).await;
}
//
// Cross
//
// {
// "code": "200000",
// "data": {
// "totalAssetOfQuoteCurrency": "0",
// "totalLiabilityOfQuoteCurrency": "0",
// "debtRatio": "0",
// "status": "EFFECTIVE",
// "accounts": [
// {
// "currency": "1INCH",
// "total": "0",
// "available": "0",
// "hold": "0",
// "liability": "0",
// "maxBorrowSize": "0",
// "borrowEnabled": true,
// "transferInEnabled": true
// }
// ]
// }
// }
//
// Isolated
//
// {
// "code": "200000",
// "data": {
// "totalConversionBalance": "0.02138647",
// "liabilityConversionBalance": "0.01480001",
// "assets": [
// {
// "symbol": "MANA-USDT",
// "debtRatio": "0",
// "status": "BORROW",
// "baseAsset": {
// "currency": "MANA",
// "borrowEnabled": true,
// "repayEnabled": true,
// "transferEnabled": true,
// "borrowed": "0",
// "totalAsset": "0",
// "available": "0",
// "hold": "0",
// "maxBorrowSize": "1000"
// },
// "quoteAsset": {
// "currency": "USDT",
// "borrowEnabled": true,
// "repayEnabled": true,
// "transferEnabled": true,
// "borrowed": "0",
// "totalAsset": "0",
// "available": "0",
// "hold": "0",
// "maxBorrowSize": "50000"
// }
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut assets: Value = ternary(is_true(&(is_equal(&marginMode, &Value::Str("isolated".to_string())))), self.safe_list_k(data.clone(), "assets", &[Value::List(vec![])]), self.safe_list_k(data.clone(), "accounts", &[Value::List(vec![])]));
let mut interest: Value = self.parse_borrow_interests(assets.clone(), &[market.clone()]);
let mut filteredByCurrency: Value = self.filter_by_currency_since_limit(interest.clone(), &[code.clone(), since.clone(), limit.clone()]);
return self.filter_by_symbol_since_limit(filteredByCurrency.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_borrow_interest(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// Cross
//
// {
// "currency": "DOGE",
// "total": "119.99995308",
// "available": "119.99995308",
// "hold": "0",
// "liability": "10.00004692",
// "liabilityPrincipal": "10",
// "liabilityInterest": "0.00004692",
// "maxBorrowSize": "1140",
// "borrowEnabled": true,
// "transferInEnabled": true
// }
//
// Isolated
//
// {
// "symbol": "DOGE-USDT",
// "status": "EFFECTIVE",
// "debtRatio": "0.0822",
// "baseAsset": {
// "currency": "DOGE",
// "borrowEnabled": true,
// "transferInEnabled": true,
// "liability": "10.00009385",
// "liabilityPrincipal": "10.00004692",
// "liabilityInterest": "0.00004693",
// "total": "10",
// "available": "10",
// "hold": "0",
// "maxBorrowSize": "990"
// },
// "quoteAsset": {
// "currency": "USDT",
// "borrowEnabled": true,
// "transferInEnabled": true,
// "liability": "0",
// "liabilityPrincipal": "0",
// "liabilityInterest": "0",
// "total": "10",
// "available": "10",
// "hold": "0",
// "maxBorrowSize": "89"
// }
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut marginMode: Value = ternary(is_true(&(is_equal(&marketId, &Value::Null))), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut isolatedBase: Value = self.safe_dict_k(info.clone(), "baseAsset", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut amountBorrowed: Value = Value::Null;
let mut interest: Value = Value::Null;
let mut currencyId: Value = Value::Null;
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
amountBorrowed = self.safe_number_k(isolatedBase.clone(), "liabilityPrincipal", &[]);
interest = self.safe_number_k(isolatedBase.clone(), "liabilityInterest", &[]);
currencyId = self.safe_string_k(isolatedBase.clone(), "currency", &[]);
} else {
amountBorrowed = self.safe_number_k(info.clone(), "liabilityPrincipal", &[]);
interest = self.safe_number_k(info.clone(), "liabilityInterest", &[]);
currencyId = self.safe_string_k(info.clone(), "currency", &[]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[]));
m.insert("interest".to_string(), interest.clone());
m.insert("interestRate".to_string(), self.safe_number_k(info.clone(), "dailyIntRate", &[]));
m.insert("amountBorrowed".to_string(), amountBorrowed.clone());
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchBorrowRateHistories
* @description retrieves a history of a multiple currencies borrow interest rate at specific time slots, returns all currencies if no symbols passed, default is undefined
* @see https://www.kucoin.com/docs-new/rest/margin-trading/debit/get-interest-history
* @param {string[]|undefined} codes list of unified currency codes, default is undefined
* @param {int} [since] timestamp in ms of the earliest borrowRate, default is undefined
* @param {int} [limit] max number of borrow rate prices to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] 'cross' or 'isolated' default is 'cross'
* @param {int} [params.until] the latest time in ms to fetch entries for
* @returns {object} a dictionary of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure} indexed by the market symbol
*/
pub async fn fetch_borrow_rate_histories(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut marginResult: Value = self.handle_margin_mode_and_params(Value::Str("fetchBorrowRateHistories".to_string()), &[params.clone()]);
let mut marginMode: Value = self.safe_string(marginResult.clone(), Value::Int(0), &[Value::Str("cross".to_string())]);
let mut isIsolated: Value = Value::Bool(is_equal(&marginMode, &Value::Str("isolated".to_string()))); // true-isolated, false-cross
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("isIsolated".to_string(), isIsolated.clone());
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone()); // default:50, min:10, max:500
}
let __ws_arg_116 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_margin_interest(&[__ws_arg_116]).await;
//
// {
// "code": "200000",
// "data": {
// "timestamp": 1710829939673,
// "currentPage": 1,
// "pageSize": 50,
// "totalNum": 0,
// "totalPage": 0,
// "items": [
// {
// "createdAt": 1697783812257,
// "currency": "XMR",
// "interestAmount": "0.1",
// "dayRatio": "0.001"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut rows: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_borrow_rate_histories(rows.clone(), codes.clone(), since.clone(), limit.clone());
Value::Null
}
/*
* @method
* @name kucoin#fetchBorrowRateHistory
* @description retrieves a history of a currencies borrow interest rate at specific time slots
* @see https://www.kucoin.com/docs-new/rest/margin-trading/debit/get-interest-history
* @param {string} code unified currency code
* @param {int} [since] timestamp for the earliest borrow rate
* @param {int} [limit] the maximum number of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure} to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] 'cross' or 'isolated' default is 'cross'
* @param {int} [params.until] the latest time in ms to fetch entries for
* @returns {object[]} an array of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure}
*/
pub async fn fetch_borrow_rate_history(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut marginResult: Value = self.handle_margin_mode_and_params(Value::Str("fetchBorrowRateHistories".to_string()), &[params.clone()]);
let mut marginMode: Value = self.safe_string(marginResult.clone(), Value::Int(0), &[Value::Str("cross".to_string())]);
let mut isIsolated: Value = Value::Bool(is_equal(&marginMode, &Value::Str("isolated".to_string()))); // true-isolated, false-cross
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("isIsolated".to_string(), isIsolated.clone());
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone()); // default:50, min:10, max:500
}
let __ws_arg_117 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_margin_interest(&[__ws_arg_117]).await;
//
// {
// "code": "200000",
// "data": {
// "timestamp": 1710829939673,
// "currentPage": 1,
// "pageSize": 50,
// "totalNum": 0,
// "totalPage": 0,
// "items": [
// {
// "createdAt": 1697783812257,
// "currency": "XMR",
// "interestAmount": "0.1",
// "dayRatio": "0.001"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut rows: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_borrow_rate_history(rows.clone(), code.clone(), since.clone(), limit.clone());
Value::Null
}
pub fn parse_borrow_rate_histories(&self, mut response: Value, mut codes: Value, mut since: Value, mut limit: Value) -> Value {
//
// [
// {
// "createdAt": 1697783812257,
// "currency": "XMR",
// "interestAmount": "0.1",
// "dayRatio": "0.001"
// }
// ]
//
let mut borrowRateHistories: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_893: bool = true;
while { if !__for_first_893 { i = add(&i, &Value::Int(1)); } __for_first_893 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut item: Value = get_value(&response, &i);
let mut item: Value = get_value(&response, &i);
let mut code: Value = self.safe_currency_code(self.safe_string_k(item.clone(), "currency", &[]), &[]);
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(is_equal(&codes, &Value::Null) || is_true(&self.in_array(code.clone(), codes.clone())))) {
if !is_true(&(Value::Bool(in_op(&borrowRateHistories, &code)))) {
add_element_to_object(&mut borrowRateHistories, &code, Value::List(vec![]));
}
let mut borrowRateStructure: Value = self.parse_borrow_rate(item.clone(), &[]);
let mut borrowRateHistoriesCode: Value = get_value(&borrowRateHistories, &code);
append_to_array(&mut borrowRateHistoriesCode, borrowRateStructure.clone());
crate::set_value(&mut borrowRateHistories, &code, borrowRateHistoriesCode.clone());
}
}
}
let mut keys: Value = object_keys(&borrowRateHistories);
{
let mut i: Value = Value::Int(0);
let mut __for_first_894: bool = true;
while { if !__for_first_894 { i = add(&i, &Value::Int(1)); } __for_first_894 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut code: Value = get_value(&keys, &i);
let mut code: Value = get_value(&keys, &i);
{ let __be_tmp = self.filter_by_currency_since_limit(get_value(&borrowRateHistories, &code), &[code.clone(), since.clone(), limit.clone()]); add_element_to_object(&mut borrowRateHistories, &code, __be_tmp); };
}
}
return borrowRateHistories;
Value::Null
}
/*
* @method
* @name kucoin#fetchCrossBorrowRate
* @description fetch the rate of interest to borrow a currency for margin trading
* @see https://www.kucoin.com/docs-new/rest/ua/get-borrowing-rates-and-limits
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [borrow rate structure]{@link https://docs.ccxt.com/?id=borrow-rate-structure}
*/
pub async fn fetch_cross_borrow_rate(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_118 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_private_get_account_interest_limits(&[__ws_arg_118]).await;
//
// {
// "code": "200000",
// "data": {
// "currentRateHourly": "0.00000353",
// "currentRateDaily": "0.00008466",
// "borrowLimitTotal": "600.00000000000000000000",
// "borrowLimitTotalHold": "0.00000000000000000000",
// "borrowLimitHold": "0.00000000000000000000",
// "interestFreeBorrowLimit": "0.60000000000000000000"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_borrow_rate(data.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#borrowCrossMargin
* @description create a loan to borrow margin
* @see https://www.kucoin.com/docs-new/rest/margin-trading/debit/borrow
* @param {string} code unified currency code of the currency to borrow
* @param {float} amount the amount to borrow
* @param {object} [params] extra parameters specific to the exchange API endpoints
* @param {string} [params.timeInForce] either IOC or FOK
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn borrow_cross_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("size".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("timeInForce".to_string(), Value::Str("FOK".to_string()));
m
});
let __ws_arg_119 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_margin_borrow(&[__ws_arg_119]).await;
//
// {
// "success": true,
// "code": "200",
// "msg": "success",
// "retry": false,
// "data": {
// "orderNo": "5da6dba0f943c0c81f5d5db5",
// "actualSize": 10
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_loan(data.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#borrowIsolatedMargin
* @description create a loan to borrow margin
* @see https://www.kucoin.com/docs-new/rest/margin-trading/debit/borrow
* @param {string} symbol unified market symbol, required for isolated margin
* @param {string} code unified currency code of the currency to borrow
* @param {float} amount the amount to borrow
* @param {object} [params] extra parameters specific to the exchange API endpoints
* @param {string} [params.timeInForce] either IOC or FOK
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn borrow_isolated_margin(&mut self, mut symbol: Value, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("size".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("timeInForce".to_string(), Value::Str("FOK".to_string()));
m.insert("isIsolated".to_string(), Value::Bool(true));
m
});
let __ws_arg_120 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_margin_borrow(&[__ws_arg_120]).await;
//
// {
// "success": true,
// "code": "200",
// "msg": "success",
// "retry": false,
// "data": {
// "orderNo": "5da6dba0f943c0c81f5d5db5",
// "actualSize": 10
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_loan(data.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#repayCrossMargin
* @description repay borrowed margin and interest
* @see https://www.kucoin.com/docs-new/rest/margin-trading/debit/repay
* @param {string} code unified currency code of the currency to repay
* @param {float} amount the amount to repay
* @param {object} [params] extra parameters specific to the exchange API endpoints
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn repay_cross_margin(&mut self, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("size".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let __ws_arg_121 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_margin_repay(&[__ws_arg_121]).await;
//
// {
// "success": true,
// "code": "200",
// "msg": "success",
// "retry": false,
// "data": {
// "orderNo": "5da6dba0f943c0c81f5d5db5",
// "actualSize": 10
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_loan(data.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#repayIsolatedMargin
* @description repay borrowed margin and interest
* @see https://www.kucoin.com/docs-new/rest/margin-trading/debit/repay
* @param {string} symbol unified market symbol
* @param {string} code unified currency code of the currency to repay
* @param {float} amount the amount to repay
* @param {object} [params] extra parameters specific to the exchange API endpoints
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn repay_isolated_margin(&mut self, mut symbol: Value, mut code: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("size".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("isIsolated".to_string(), Value::Bool(true));
m
});
let __ws_arg_122 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_margin_repay(&[__ws_arg_122]).await;
//
// {
// "success": true,
// "code": "200",
// "msg": "success",
// "retry": false,
// "data": {
// "orderNo": "5da6dba0f943c0c81f5d5db5",
// "actualSize": 10
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_loan(data.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_margin_loan(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "orderNo": "5da6dba0f943c0c81f5d5db5",
// "actualSize": 10
// }
//
let mut timestamp: Value = self.milliseconds();
let mut currencyId: Value = self.safe_string_k(info.clone(), "currency", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(info.clone(), "orderNo", &[]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "actualSize", &[]));
m.insert("symbol".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), info.clone());
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees - *IMPORTANT* use fetchDepositWithdrawFee to get more in-depth info
* @see https://www.kucoin.com/docs-new/rest/spot-trading/market-data/get-all-currencies
* @param {string[]|undefined} codes list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.public_get_currencies(&[params.clone()]).await;
//
// [
// {
// "currency": "CSP",
// "name": "CSP",
// "fullName": "Caspian",
// "precision": 8,
// "confirms": 12,
// "contractAddress": "0xa6446d655a0c34bc4f05042ee88170d056cbaf45",
// "withdrawalMinSize": "2000",
// "withdrawalMinFee": "1000",
// "isWithdrawEnabled": true,
// "isDepositEnabled": true,
// "isMarginEnabled": false,
// "isDebitEnabled": false
// },
// ]
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_deposit_withdraw_fees(data.clone(), &[codes.clone(), Value::Str("currency".to_string())]);
Value::Null
}
/*
* @method
* @name kucoin#fetchLeverage
* @description fetch the set leverage for a market
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-cross-margin-leverage
* @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
}));
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(symbol.clone(), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Str("cross".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLeverage() currently supports only params[\"marginMode\"] = \"cross\"".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLeverage() supports contract markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_123 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_get_cross_user_leverage(&[__ws_arg_123]).await;
//
// {
// "code": "200000",
// "data": {
// "symbol": "XBTUSDTM",
// "leverage": "3"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut parsed: Value = self.parse_leverage(data.clone(), &[market.clone()]);
return self.extend(parsed.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), marginMode.clone());
m
})]);
Value::Null
}
/*
* @method
* @name kucoin#setLeverage
* @description set the level of leverage for a market
* @see https://www.kucoin.com/docs-new/rest/margin-trading/debit/modify-leverage // margin
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/modify-cross-margin-leverage // contract
* @see https://www.kucoin.com/docs-new/rest/ua/modify-cross-margin-leverage-uta // margin uta
* @see https://www.kucoin.com/docs-new/rest/ua/modify-leverage-uta // contract uta
* @param {int } [leverage] New leverage multiplier. Must be greater than 1 and up to two decimal places, and cannot be less than the user's current debt leverage or greater than the system's maximum leverage
* @param {string} [symbol] unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta)
* @param {string} [params.marginMode] *spot non-uta only* 'cross' or 'isolated' default is 'cross'
* @param {string} [params.code] *uta margin only* the unified currency code for the margin to set the leverage for
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("setLeverage".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(!is_equal(&symbol, &Value::Null))) || is_true(&(is_true(&(!is_equal(&marketType, &Value::Str("spot".to_string())))) && is_true(&(!is_equal(&marketType, &Value::Str("margin".to_string())))))) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage requires a symbol argument for contract markets".to_string()))));
}
market = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
return self.set_contract_leverage(leverage.clone(), &[symbol.clone(), params.clone()]).await;
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), self.number_to_string(leverage.clone()));
m
});
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setLeverage".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("setLeverage".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_true(&uta) {
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" unified trading account does not support isolated margin".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), Value::Str("unified".to_string()));
let mut code: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("setLeverage".to_string()), Value::Str("currency".to_string()), Value::Str("code".to_string()), &[]); code = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&code, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage requires a currency code in the params[\"code\"] for unified trading account".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("currency".to_string()), self.currency_id(code.clone()));
let __ws_arg_124 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_post_account_mode_account_modify_leverage_margin_cross(&[__ws_arg_124]).await;
} else {
if is_equal(&marginMode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage requires a marginMode parameter".to_string()))));
}
if is_equal(&marginMode, &Value::Str("isolated".to_string())) && is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage requires a symbol parameter for isolated margin".to_string()))));
}
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
add_element_to_object(&mut request, &Value::Str("isIsolated".to_string()), Value::Bool((is_equal(&marginMode, &Value::Str("isolated".to_string())))));
let __ws_arg_125 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_position_update_user_leverage(&[__ws_arg_125]).await;
}
return response;
Value::Null
}
/*
* @method
* @name kucoin#setContractLeverage
* @description set the level of leverage for a market
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/modify-cross-margin-leverage
* @see https://www.kucoin.com/docs-new/rest/ua/modify-leverage-uta
* @param {float} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta)
* @returns {object} response from the exchange
*/
pub async fn set_contract_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(symbol.clone(), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(!is_equal(&marginMode, &Value::Null))) && is_true(&(!is_equal(&marginMode, &Value::Str("cross".to_string())))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setLeverage() currently supports only params[\"marginMode\"] = \"cross\" for contracts".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("leverage".to_string(), to_string_val(&leverage));
m
});
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("setLeverage".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&uta) {
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), Value::Str("unified".to_string()));
let __ws_arg_126 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_post_account_mode_account_modify_leverage(&[__ws_arg_126]).await;
} else {
//
// {
// "code": "200000",
// "data": true
// }
//
let __ws_arg_127 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_post_change_cross_user_leverage(&[__ws_arg_127]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut leverageNum: Value = self.safe_number_k(data.clone(), "leverage", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("marginMode".to_string(), Value::Null);
m.insert("longLeverage".to_string(), leverageNum.clone());
m.insert("shortLeverage".to_string(), leverageNum.clone());
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchFundingInterval
* @description fetch the current funding rate interval
* @see https://www.kucoin.com/docs-new/rest/ua/get-current-funding-rate
* @see https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-current-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_interval(&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
}));
return self.fetch_funding_rate(symbol.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name kucoin#fetchFundingRate
* @description fetch the current funding rate
* @see https://www.kucoin.com/docs-new/rest/ua/get-current-funding-rate
* @see https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-current-funding-rate
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta)
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRate".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&uta) {
//
// {
// "code": "200000",
// "data": {
// "symbol": ".ETHUSDTMFPI8H",
// "nextFundingRate": -3.4E-5,
// "fundingTime": 1776700800000,
// "fundingRateCap": 0.00375,
// "fundingRateFloor": -0.00375,
// "currentGranularity": 28800000,
// "newGranularity": 28800000,
// "newGranularityStartTime": 1750147200000
// }
// }
//
let __ws_arg_128 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_get_market_funding_rate(&[__ws_arg_128]).await;
} else {
//
// {
// "code": "200000",
// "data": {
// "symbol": ".ETHUSDTMFPI8H",
// "granularity": 28800000,
// "timePoint": 1776672000000,
// "value": -3.2E-5,
// "dailyInterestRate": 3.0E-4,
// "fundingRateCap": 0.00375,
// "fundingRateFloor": -0.00375,
// "period": 1,
// "fundingTime": 1776700800000
// }
// }
//
let __ws_arg_129 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_funding_rate_symbol_current(&[__ws_arg_129]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
// uta
// {
// "symbol": ".ETHUSDTMFPI8H",
// "nextFundingRate": -3.4E-5,
// "fundingTime": 1776700800000,
// "fundingRateCap": 0.00375,
// "fundingRateFloor": -0.00375,
// "currentGranularity": 28800000,
// "newGranularity": 28800000,
// "newGranularityStartTime": 1750147200000
// }
//
// futures
// {
// "symbol": ".ETHUSDTMFPI8H",
// "granularity": 28800000,
// "timePoint": 1776672000000,
// "value": -3.2E-5,
// "dailyInterestRate": 3.0E-4,
// "fundingRateCap": 0.00375,
// "fundingRateFloor": -0.00375,
// "period": 1,
// "fundingTime": 1776700800000
// }
//
let mut fundingTimestamp: Value = self.safe_integer_k(data.clone(), "fundingTime", &[]);
let mut previousFundingTimestamp: Value = self.safe_integer_k(data.clone(), "timePoint", &[]);
let mut nextFundingTimestamp: Value = self.safe_integer_k(data.clone(), "newGranularityStartTime", &[]);
let mut marketId: Value = self.safe_string_k(data.clone(), "symbol", &[]);
let mut granularity: Value = self.safe_string2(data.clone(), Value::Str("granularity".to_string()), Value::Str("currentGranularity".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), self.safe_number_k(data.clone(), "dailyInterestRate", &[]));
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number2(data.clone(), Value::Str("nextFundingRate".to_string()), Value::Str("value".to_string()), &[]));
m.insert("fundingTimestamp".to_string(), fundingTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTimestamp.clone()));
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), previousFundingTimestamp.clone());
m.insert("previousFundingDatetime".to_string(), self.iso8601(previousFundingTimestamp.clone()));
m.insert("interval".to_string(), self.parse_funding_interval(granularity.clone()));
m
});
Value::Null
}
pub fn parse_funding_interval(&self, mut interval: Value) -> Value {
let mut intervals: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("3600000".to_string(), Value::Str("1h".to_string()));
m.insert("14400000".to_string(), Value::Str("4h".to_string()));
m.insert("28800000".to_string(), Value::Str("8h".to_string()));
m.insert("57600000".to_string(), Value::Str("16h".to_string()));
m.insert("86400000".to_string(), Value::Str("24h".to_string()));
m
});
return self.safe_string(intervals.clone(), interval.clone(), &[interval.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-public-funding-history
* @see https://www.kucoin.com/docs-new/rest/ua/get-history-funding-rate
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] not used by kucuoinfutures
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] end time in ms
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to true
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
let mut start: Value = since.clone();
let mut end: Value = until.clone();
if is_equal(&since, &Value::Null) {
start = Value::Int(0);
}
if is_equal(&until, &Value::Null) {
end = self.milliseconds();
}
let mut response: Value = Value::Null;
let mut resultKey: Value = Value::Str("data".to_string());
if is_true(&uta) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), start.clone());
add_element_to_object(&mut request, &Value::Str("endAt".to_string()), end.clone());
//
// {
// "code": "200000",
// "data": {
// "symbol": "XBTUSDTM",
// "list": [
// {
// "fundingRate": 7.6E-5,
// "ts": 1706097600000
// },
// ]
// }
// }
//
let __ws_arg_130 = self.extend(request.clone(), &[params.clone()]);
let mut utaResponse: Value = self.uta_get_market_funding_rate_history(&[__ws_arg_130]).await;
response = self.safe_dict_k(utaResponse.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
resultKey = Value::Str("list".to_string());
} else {
add_element_to_object(&mut request, &Value::Str("from".to_string()), start.clone());
add_element_to_object(&mut request, &Value::Str("to".to_string()), end.clone());
//
// {
// "code": "200000",
// "data": [
// {
// "symbol": "IDUSDTM",
// "fundingRate": 2.26E-4,
// "timepoint": 1702296000000
// }
// ]
// }
//
let __ws_arg_131 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_public_get_contract_funding_rates(&[__ws_arg_131]).await;
}
let mut result: Value = self.safe_list(response.clone(), resultKey.clone(), &[Value::List(vec![])]);
return self.parse_funding_rate_histories(result.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_funding_rate_history(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// uta
// {
// "fundingRate": 7.6E-5,
// "ts": 1706097600000
// }
//
// futures
// {
// "symbol": "IDUSDTM",
// "fundingRate": 2.26E-4,
// "timepoint": 1702296000000
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer2(info.clone(), Value::Str("ts".to_string()), Value::Str("timepoint".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("fundingRate".to_string(), self.safe_number_k(info.clone(), "fundingRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://www.kucoin.com/docs-new/rest/futures-trading/funding-fees/get-private-funding-history
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch funding history for
* @param {int} [limit] the maximum number of funding history structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object} a [funding history structure]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
pub async fn fetch_funding_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingHistory".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
} else if !is_true(&uta) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingHistory() requires a symbol argument".to_string()))));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
let mut dataList: Value = Value::List(vec![]);
if is_true(&uta) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_132 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_private_get_position_funding_history(&[__ws_arg_132]).await;
//
// {
// "code": "200000",
// "data": {
// "lastId": 2125247170385112,
// "items": [
// {
// "symbol": "DOGEUSDTM",
// "marginMode": "CROSS",
// "fundingRate": "0.000172",
// "markPrice": "0.09326",
// "size": "-1",
// "positionValue": "-9.326",
// "fundingFee": "0.00160407",
// "settleCurrency": "USDT",
// "settlementTime": 1775030400000
// }
// ]
// }
// }
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
dataList = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
} else {
if !is_equal(&limit, &Value::Null) {
// * Since is ignored if limit is defined
add_element_to_object(&mut request, &Value::Str("maxCount".to_string()), limit.clone());
}
let __ws_arg_133 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_funding_history(&[__ws_arg_133]).await;
//
// {
// "code": "200000",
// "data": {
// "dataList": [
// {
// "id": 239471298749817,
// "symbol": "ETHUSDTM",
// "timePoint": 1638532800000,
// "fundingRate": 0.000100,
// "markPrice": 4612.8300000000,
// "positionQty": 12,
// "positionCost": 553.5396000000,
// "funding": -0.0553539600,
// "settleCurrency": "USDT"
// },
// ...
// ],
// "hasMore": true
// }
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
dataList = self.safe_list_k(data.clone(), "dataList", &[Value::List(vec![])]);
}
let mut fees: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_895: bool = true;
while { if !__for_first_895 { i = add(&i, &Value::Int(1)); } __for_first_895 = false; is_less_than(&i, &get_array_length(&dataList)) } {
let mut listItem: Value = get_value(&dataList, &i);
let mut listItem: Value = get_value(&dataList, &i);
let mut timestamp: Value = self.safe_integer2(listItem.clone(), Value::Str("timePoint".to_string()), Value::Str("settlementTime".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(listItem.clone(), "symbol", &[]);
append_to_array(&mut fees, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), listItem.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("code".to_string(), self.safe_currency_code(self.safe_string_k(listItem.clone(), "settleCurrency", &[]), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), self.safe_number_k(listItem.clone(), "id", &[]));
m.insert("amount".to_string(), self.safe_number2(listItem.clone(), Value::Str("funding".to_string()), Value::Str("fundingFee".to_string()), &[]));
m.insert("fundingRate".to_string(), self.safe_number_k(listItem.clone(), "fundingRate", &[]));
m.insert("markPrice".to_string(), self.safe_number_k(listItem.clone(), "markPrice", &[]));
m.insert("positionQty".to_string(), self.safe_number2(listItem.clone(), Value::Str("positionQty".to_string()), Value::Str("size".to_string()), &[]));
m.insert("positionCost".to_string(), self.safe_number2(listItem.clone(), Value::Str("positionCost".to_string()), Value::Str("positionValue".to_string()), &[]));
m
}));
}
}
return fees;
Value::Null
}
/*
* @method
* @name kucoin#fetchPosition
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-details
* @see https://www.kucoin.com/docs-new/rest/ua/get-position-list-uta
* @description fetch data on an open position
* @param {string} symbol unified market symbol of the market the position is held in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @param {integer} [params.pageSize] *uta only* page size for the uta endpoint (default 50, max 200)
* @param {integer} [params.pageNumber] *uta only* page number for the uta endpoint (default 1)
* @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPosition".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut position: Value = Value::Null;
if is_true(&uta) {
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), Value::Str("unified".to_string()));
let __ws_arg_134 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_account_mode_position_open_list(&[__ws_arg_134]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "symbol": "DOGEUSDTM",
// "id": "30000000000084351",
// "marginMode": "CROSS",
// "size": "2",
// "entryPrice": "0.093795",
// "positionValue": "18.298",
// "markPrice": "0.09149",
// "leverage": "3",
// "unrealizedPnL": "-0.461",
// "realizedPnL": "-0.01122489",
// "initialMargin": "6.0993333327234",
// "mmr": "0.007",
// "maintenanceMargin": "0.128086",
// "creationTime": 1774469753178000000
// "updateTime": 1774469753178000000
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
position = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
let __ws_arg_135 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_position(&[__ws_arg_135]).await;
//
// {
// "code": "200000",
// "data": {
// "id": "6505ee6eaff4070001f651c4",
// "symbol": "XBTUSDTM",
// "autoDeposit": false,
// "maintMarginReq": 0,
// "riskLimit": 200,
// "realLeverage": 0.0,
// "crossMode": false,
// "delevPercentage": 0.0,
// "currentTimestamp": 1694887534594,
// "currentQty": 0,
// "currentCost": 0.0,
// "currentComm": 0.0,
// "unrealisedCost": 0.0,
// "realisedGrossCost": 0.0,
// "realisedCost": 0.0,
// "isOpen": false,
// "markPrice": 26611.71,
// "markValue": 0.0,
// "posCost": 0.0,
// "posCross": 0,
// "posInit": 0.0,
// "posComm": 0.0,
// "posLoss": 0.0,
// "posMargin": 0.0,
// "posMaint": 0.0,
// "maintMargin": 0.0,
// "realisedGrossPnl": 0.0,
// "realisedPnl": 0.0,
// "unrealisedPnl": 0.0,
// "unrealisedPnlPcnt": 0,
// "unrealisedRoePcnt": 0,
// "avgEntryPrice": 0.0,
// "liquidationPrice": 0.0,
// "bankruptPrice": 0.0,
// "settleCurrency": "USDT",
// "maintainMargin": 0,
// "riskLimitLevel": 1
// }
// }
//
position = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_position(position.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchPositions
* @description fetch all open positions
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-list
* @see https://www.kucoin.com/docs-new/rest/ua/get-position-list-uta
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @param {integer} [params.pageSize] *uta only* page size for the uta endpoint (default 50, max 200)
* @param {integer} [params.pageNumber] *uta only* page number for the uta endpoint (default 1)
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPositions".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&uta) {
let __ws_arg_136 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountMode".to_string(), Value::Str("unified".to_string()));
m.insert("limit".to_string(), Value::Int(200));
m
}), &[params.clone()]);
response = self.uta_private_get_account_mode_position_open_list(&[__ws_arg_136]).await;
} else {
response = self.futures_private_get_positions(&[params.clone()]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_positions(data.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchPositionsHistory
* @description fetches historical positions
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-positions-history
* @see https://www.kucoin.com/docs-new/rest/ua/get-position-history-uta
* @param {string[]} [symbols] list of unified market symbols
* @param {int} [since] the earliest time in ms to fetch position history for
* @param {int} [limit] the maximum number of entries to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] closing end time
* @param {int} [params.pageId] page id
* @param {boolean} [params.uta] set to true for the unified trading account (uta), defaults to false
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPositionsHistory".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
symbols = self.market_symbols(&[symbols.clone()]);
if !is_equal(&symbols, &Value::Null) {
let mut length: Value = get_array_length(&symbols);
if is_equal(&length, &Value::Int(1)) {
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
if is_true(&uta) {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
//
// {
// "code": "200000",
// "data": {
// "items": [
// {
// "symbol": "DOGEUSDTM",
// "closeId": "30000000000162175",
// "marginMode": "CROSS",
// "side": "LONG",
// "entryPrice": "0.09641",
// "closePrice": "0.09613",
// "maxSize": "1",
// "avgClosePrice": "0.09613",
// "leverage": "3",
// "realizedPnL": "-0.0395524",
// "fee": "0.0115524",
// "tax": "0",
// "fundingFee": "0",
// "closingTime": 1774469647311000000,
// "creationTime": 1774468501294000000
// }
// ],
// "lastId": 30000000000162175
// }
// }
//
let __ws_arg_137 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_get_position_history(&[__ws_arg_137]).await;
} else {
if is_equal(&limit, &Value::Null) {
limit = Value::Int(200);
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("from".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("to".to_string()), until.clone());
}
//
// {
// "success": true,
// "code": "200",
// "msg": "success",
// "retry": false,
// "data": {
// "currentPage": 1,
// "pageSize": 10,
// "totalNum": 25,
// "totalPage": 3,
// "items": [
// {
// "closeId": "300000000000000030",
// "positionId": "300000000000000009",
// "uid": 99996908309485,
// "userId": "6527d4fc8c7f3d0001f40f5f",
// "symbol": "XBTUSDM",
// "settleCurrency": "XBT",
// "leverage": "0.0",
// "type": "LIQUID_LONG",
// "side": null,
// "closeSize": null,
// "pnl": "-1.0000003793999999",
// "realisedGrossCost": "0.9993849748999999",
// "withdrawPnl": "0.0",
// "roe": null,
// "tradeFee": "0.0006154045",
// "fundingFee": "0.0",
// "openTime": 1713785751181,
// "closeTime": 1713785752784,
// "openPrice": null,
// "closePrice": null
// }
// ]
// }
// }
//
let __ws_arg_138 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_get_history_positions(&[__ws_arg_138]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut items: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_positions(items.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "code": "200000",
// "data": [
// {
// "id": "615ba79f83a3410001cde321", // Position ID
// "symbol": "ETHUSDTM", // Symbol
// "autoDeposit": false, // Auto deposit margin or not
// "maintMarginReq": 0.005, // Maintenance margin requirement
// "riskLimit": 1000000, // Risk limit
// "realLeverage": 25.92, // Leverage of the order
// "crossMode": false, // Cross mode or not
// "delevPercentage": 0.76, // ADL ranking percentile
// "openingTimestamp": 1638578546031, // Open time
// "currentTimestamp": 1638578563580, // Current timestamp
// "currentQty": 2, // Current postion quantity
// "currentCost": 83.787, // Current postion value
// "currentComm": 0.0167574, // Current commission
// "unrealisedCost": 83.787, // Unrealised value
// "realisedGrossCost": 0.0, // Accumulated realised gross profit value
// "realisedCost": 0.0167574, // Current realised position value
// "isOpen": true, // Opened position or not
// "markPrice": 4183.38, // Mark price
// "markValue": 83.6676, // Mark value
// "posCost": 83.787, // Position value
// "posCross": 0.0, // added margin
// "posInit": 3.35148, // Leverage margin
// "posComm": 0.05228309, // Bankruptcy cost
// "posLoss": 0.0, // Funding fees paid out
// "posMargin": 3.40376309, // Position margin
// "posMaint": 0.50707892, // Maintenance margin
// "maintMargin": 3.28436309, // Position margin
// "realisedGrossPnl": 0.0, // Accumulated realised gross profit value
// "realisedPnl": -0.0167574, // Realised profit and loss
// "unrealisedPnl": -0.1194, // Unrealised profit and loss
// "unrealisedPnlPcnt": -0.0014, // Profit-loss ratio of the position
// "unrealisedRoePcnt": -0.0356, // Rate of return on investment
// "avgEntryPrice": 4189.35, // Average entry price
// "liquidationPrice": 4044.55, // Liquidation price
// "bankruptPrice": 4021.75, // Bankruptcy price
// "settleCurrency": "USDT", // Currency used to clear and settle the trades
// "isInverse": false
// }
// ]
// }
// position history
// {
// "closeId": "300000000000000030",
// "positionId": "300000000000000009",
// "uid": 99996908309485,
// "userId": "6527d4fc8c7f3d0001f40f5f",
// "symbol": "XBTUSDM",
// "settleCurrency": "XBT",
// "leverage": "0.0",
// "type": "LIQUID_LONG",
// "side": null,
// "closeSize": null,
// "pnl": "-1.0000003793999999",
// "realisedGrossCost": "0.9993849748999999",
// "withdrawPnl": "0.0",
// "roe": null,
// "tradeFee": "0.0006154045",
// "fundingFee": "0.0",
// "openTime": 1713785751181,
// "closeTime": 1713785752784,
// "openPrice": null,
// "closePrice": null
// }
//
// uta fetchPositions
// {
// "symbol": "DOGEUSDTM",
// "id": "30000000000084351",
// "marginMode": "CROSS",
// "size": "2",
// "entryPrice": "0.093795",
// "positionValue": "18.298",
// "markPrice": "0.09149",
// "leverage": "3",
// "unrealizedPnL": "-0.461",
// "realizedPnL": "-0.01122489",
// "initialMargin": "6.0993333327234",
// "mmr": "0.007",
// "maintenanceMargin": "0.128086",
// "creationTime": 1774469753178000000
// "updateTime": 1774469753178000000
// }
//
// uta fetchPositionsHistory
// {
// "symbol": "DOGEUSDTM",
// "closeId": "30000000000162175",
// "marginMode": "CROSS",
// "side": "LONG",
// "entryPrice": "0.09641",
// "closePrice": "0.09613",
// "maxSize": "1",
// "avgClosePrice": "0.09613",
// "leverage": "3",
// "realizedPnL": "-0.0395524",
// "fee": "0.0115524",
// "tax": "0",
// "fundingFee": "0",
// "closingTime": 1774469647311000000,
// "creationTime": 1774468501294000000
// }
//
let mut symbol: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[symbol.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "currentTimestamp", &[]);
if is_equal(×tamp, &Value::Null) {
timestamp = self.safe_integer_product(position.clone(), Value::Str("creationTime".to_string()), Value::Float(0.000001), &[]);
}
let mut size: Value = self.safe_string_n(position.clone(), Value::List(vec![Value::Str("currentQty".to_string()), Value::Str("size".to_string()), Value::Str("maxSize".to_string()), Value::Str("closeSize".to_string())]), &[]);
let mut side: Value = self.safe_string_lower(position.clone(), Value::Str("side".to_string()), &[]);
let mut type_var: Value = self.safe_string_lower(position.clone(), Value::Str("type".to_string()), &[]);
if is_equal(&side, &Value::Null) {
if !is_equal(&size, &Value::Null) {
if is_true(&crate::precise::Precise::stringGt(&size, &Value::Str("0".to_string()))) {
side = Value::Str("long".to_string());
} else if is_true(&crate::precise::Precise::stringLt(&size, &Value::Str("0".to_string()))) {
side = Value::Str("short".to_string());
}
} else if !is_equal(&type_var, &Value::Null) {
if is_greater_than(&get_index_of(&type_var, &Value::Str("long".to_string())), &negate(&Value::Int(1))) {
side = Value::Str("long".to_string());
} else {
side = Value::Str("short".to_string());
}
}
}
let mut notional: Value = crate::precise::Precise::stringAbs(&self.safe_string2(position.clone(), Value::Str("posCost".to_string()), Value::Str("positionValue".to_string()), &[]));
let mut initialMargin: Value = self.safe_string2(position.clone(), Value::Str("posInit".to_string()), Value::Str("initialMargin".to_string()), &[]);
let mut initialMarginPercentage: Value = crate::precise::Precise::stringDiv(&initialMargin, ¬ional);
// const marginRatio = Precise.stringDiv (maintenanceRate, collateral);
let mut unrealisedPnl: Value = self.safe_string2(position.clone(), Value::Str("unrealisedPnl".to_string()), Value::Str("unrealizedPnL".to_string()), &[]);
let mut crossMode: Value = self.safe_value_k(position.clone(), "crossMode", &[]);
// currently crossMode is always set to false and only isolated positions are supported
let mut marginMode: Value = self.safe_string_lower(position.clone(), Value::Str("marginMode".to_string()), &[]);
if !is_equal(&crossMode, &Value::Null) {
marginMode = ternary(is_true(&(is_equal(&crossMode, &Value::Bool(true)))), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
}
let mut lastUpdateTimestamp: Value = self.safe_integer_k(position.clone(), "closeTime", &[]);
if is_equal(&lastUpdateTimestamp, &Value::Null) {
if is_true(&Value::Bool(in_op(&position, &Value::Str("closingTime".to_string())))) {
lastUpdateTimestamp = self.safe_integer_product(position.clone(), Value::Str("closingTime".to_string()), Value::Float(0.000001), &[]);
} else if is_true(&Value::Bool(in_op(&position, &Value::Str("updateTime".to_string())))) {
lastUpdateTimestamp = self.safe_integer_product(position.clone(), Value::Str("updateTime".to_string()), Value::Float(0.000001), &[]);
}
}
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_n(position.clone(), Value::List(vec![Value::Str("id".to_string()), Value::Str("positionId".to_string()), Value::Str("closeId".to_string())]), &[]));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.clone());
m.insert("initialMargin".to_string(), self.parse_number(initialMargin.clone(), &[]));
m.insert("initialMarginPercentage".to_string(), self.parse_number(initialMarginPercentage.clone(), &[]));
m.insert("maintenanceMargin".to_string(), self.safe_number2(position.clone(), Value::Str("posMaint".to_string()), Value::Str("maintenanceMargin".to_string()), &[]));
m.insert("maintenanceMarginPercentage".to_string(), self.safe_number2(position.clone(), Value::Str("maintMarginReq".to_string()), Value::Str("mmr".to_string()), &[]));
m.insert("entryPrice".to_string(), self.safe_number_n(position.clone(), Value::List(vec![Value::Str("avgEntryPrice".to_string()), Value::Str("openPrice".to_string()), Value::Str("entryPrice".to_string())]), &[]));
m.insert("notional".to_string(), self.parse_number(notional.clone(), &[]));
m.insert("leverage".to_string(), self.safe_number2(position.clone(), Value::Str("realLeverage".to_string()), Value::Str("leverage".to_string()), &[]));
m.insert("unrealizedPnl".to_string(), self.parse_number(unrealisedPnl.clone(), &[]));
m.insert("contracts".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&size), &[]));
m.insert("contractSize".to_string(), self.safe_value_k(market.clone(), "contractSize", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_n(position.clone(), Value::List(vec![Value::Str("realisedPnl".to_string()), Value::Str("pnl".to_string()), Value::Str("realizedPnL".to_string())]), &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liquidationPrice", &[]));
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "markPrice", &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "closePrice", &[]));
m.insert("collateral".to_string(), self.safe_number_k(position.clone(), "maintMargin", &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("side".to_string(), side.clone());
m.insert("percentage".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name kucoin#cancelOrders
* @description cancel multiple orders for contract markets
* @see https://www.kucoin.com/docs-new/3470241e0
* @see https://www.kucoin.com/docs-new/rest/ua/batch-cancel-order-by-id
* @param {string[]} ids order ids
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string[]} [params.clientOrderIds] client order ids
* @param {boolean} [params.uta] set to true to use the unified trading account (uta) endpoint, defaults to false for the contract orders
* @param {string} [params.accountMode] *for uta endpoint only* 'unified' or 'classic' (default is 'unified')
* @param {string} [params.marginMode] *for margin orders only* 'cross' or 'isolated' (unified accountMode supports cross margin only)
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut uta: Value = self.is_uta_enabled(&[]).await;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelOrders".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market: Value = Value::Null;
let mut isContractMarket: Value = Value::Bool(true); // default to contract market orders if symbol is not provided, uta endpoint requires a symbol to be provided
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
isContractMarket = get_value(&market, &Value::Str("contract".to_string()));
if !is_equal(&isContractMarket, &Value::Bool(true)) {
uta = Value::Bool(true); // spot market orders can only be cancelled via the uta endpoint
}
} else if is_true(&uta) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol argument for uta endpoint".to_string()))));
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut clientOrderIds: Value = self.safe_list2(params.clone(), Value::Str("clientOrderIds".to_string()), Value::Str("clientOids".to_string()), &[Value::List(vec![])]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderIds".to_string()), Value::Str("clientOids".to_string())]), &[]);
let mut useClientorderId: bool = false;
{
let mut i: Value = Value::Int(0);
let mut __for_first_896: bool = true;
while { if !__for_first_896 { i = add(&i, &Value::Int(1)); } __for_first_896 = false; is_less_than(&i, &get_array_length(&clientOrderIds)) } {
useClientorderId = true;
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol argument when cancelling by clientOrderIds".to_string()))));
}
append_to_array(&mut ordersRequests, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id", &[]));
m.insert("clientOid".to_string(), self.safe_string(clientOrderIds.clone(), i.clone(), &[]));
m
}));
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_897: bool = true;
while { if !__for_first_897 { i = add(&i, &Value::Int(1)); } __for_first_897 = false; is_less_than(&i, &get_array_length(&ids)) } {
let mut orderId: Value = get_value(&ids, &i);
let mut orderId: Value = get_value(&ids, &i);
if is_true(&uta) {
append_to_array(&mut ordersRequests, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), orderId.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "id", &[]));
m
}));
} else {
append_to_array(&mut ordersRequests, get_value(&ids, &i));
}
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut orders: Value = Value::List(vec![]);
if is_true(&uta) {
let mut accountMode: Value = Value::Str("unified".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("cancelOrders".to_string()), Value::Str("accountMode".to_string()), &[accountMode.clone()]); accountMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("accountMode".to_string()), accountMode.clone());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("cancelOrders".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isUnified: Value = Value::Bool(is_equal(&accountMode, &Value::Str("unified".to_string())));
let mut tradeType: Value = self.handle_trade_type(&[isContractMarket.clone(), marginMode.clone(), isUnified.clone(), params.clone()]);
add_element_to_object(&mut request, &Value::Str("tradeType".to_string()), tradeType.clone());
add_element_to_object(&mut request, &Value::Str("cancelOrderList".to_string()), ordersRequests.clone());
let __ws_arg_139 = self.extend(request.clone(), &[params.clone()]);
response = self.uta_private_post_account_mode_order_cancel_batch(&[__ws_arg_139]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
orders = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
} else {
let mut requestKey: Value = ternary(is_true(&useClientorderId), Value::Str("clientOidsList".to_string()), Value::Str("orderIdsList".to_string()));
add_element_to_object(&mut request, &requestKey, ordersRequests.clone());
let __ws_arg_140 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_delete_orders_multi_cancel(&[__ws_arg_140]).await;
//
// {
// "code": "200000",
// "data":
// [
// {
// "orderId": "80465574458560512",
// "clientOid": null,
// "code": "200",
// "msg": "success"
// },
// {
// "orderId": "80465575289094144",
// "clientOid": null,
// "code": "200",
// "msg": "success"
// }
// ]
// }
//
orders = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
}
return self.parse_orders(orders.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#addMargin
* @description add margin
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/add-isolated-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.positionSide] *required for hedged position* 'BOTH', 'LONG' or 'SHORT' (default is 'BOTH')
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut uuid: Value = self.uuid(&[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("margin".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("bizNo".to_string(), uuid.clone());
m
});
let __ws_arg_141 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_post_position_margin_deposit_margin(&[__ws_arg_141]).await;
//
// {
// "code": "200000",
// "data": {
// "id": "62311d26064e8f00013f2c6d",
// "symbol": "XRPUSDTM",
// "autoDeposit": false,
// "maintMarginReq": 0.01,
// "riskLimit": 200000,
// "realLeverage": 0.88,
// "crossMode": false,
// "delevPercentage": 0.4,
// "openingTimestamp": 1647385894798,
// "currentTimestamp": 1647414510672,
// "currentQty": -1,
// "currentCost": -7.658,
// "currentComm": 0.0053561,
// "unrealisedCost": -7.658,
// "realisedGrossCost": 0,
// "realisedCost": 0.0053561,
// "isOpen": true,
// "markPrice": 0.7635,
// "markValue": -7.635,
// "posCost": -7.658,
// "posCross": 1.00016084,
// "posInit": 7.658,
// "posComm": 0.00979006,
// "posLoss": 0,
// "posMargin": 8.6679509,
// "posMaint": 0.08637006,
// "maintMargin": 8.6909509,
// "realisedGrossPnl": 0,
// "realisedPnl": -0.0038335,
// "unrealisedPnl": 0.023,
// "unrealisedPnlPcnt": 0.003,
// "unrealisedRoePcnt": 0.003,
// "avgEntryPrice": 0.7658,
// "liquidationPrice": 1.6239,
// "bankruptPrice": 1.6317,
// "settleCurrency": "USDT"
// }
// }
//
//
// {
// "code":"200000",
// "msg":"Position does not exist"
// }
//
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
let __ws_arg_142 = self.parse_margin_modification(data.clone(), &[market.clone()]);
let __ws_arg_143 = self.amount_to_precision(symbol.clone(), amount.clone());
return self.extend(__ws_arg_142, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), __ws_arg_143);
m.insert("direction".to_string(), Value::Str("in".to_string()));
m
})]);
Value::Null
}
/*
* @method
* @name kucoin#reduceMargin
* @description remove margin from a position
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/remove-isolated-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.positionSide] *required for hedged position* 'BOTH', 'LONG' or 'SHORT' (default is 'BOTH')
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("withdrawAmount".to_string(), amountString.clone());
m
});
let __ws_arg_144 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_post_margin_withdraw_margin(&[__ws_arg_144]).await;
//
// {
// "code": "200000",
// "data": "0.1"
// }
//
let mut currencyId: Value = self.safe_string_k(market.clone(), "settle", &[]);
let mut responseCode: Value = self.safe_string_k(response.clone(), "code", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), Value::Str("reduce".to_string()));
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), self.parse_number(amountString.clone(), &[]));
m.insert("total".to_string(), Value::Null);
m.insert("code".to_string(), self.safe_currency_code(currencyId.clone(), &[]));
m.insert("status".to_string(), ternary(is_true(&(is_equal(&responseCode, &Value::Str("200000".to_string())))), Value::Str("ok".to_string()), Value::Null));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_margin_modification(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": "62311d26064e8f00013f2c6d",
// "symbol": "XRPUSDTM",
// "autoDeposit": false,
// "maintMarginReq": 0.01,
// "riskLimit": 200000,
// "realLeverage": 0.88,
// "crossMode": false,
// "delevPercentage": 0.4,
// "openingTimestamp": 1647385894798,
// "currentTimestamp": 1647414510672,
// "currentQty": -1,
// "currentCost": -7.658,
// "currentComm": 0.0053561,
// "unrealisedCost": -7.658,
// "realisedGrossCost": 0,
// "realisedCost": 0.0053561,
// "isOpen": true,
// "markPrice": 0.7635,
// "markValue": -7.635,
// "posCost": -7.658,
// "posCross": 1.00016084,
// "posInit": 7.658,
// "posComm": 0.00979006,
// "posLoss": 0,
// "posMargin": 8.6679509,
// "posMaint": 0.08637006,
// "maintMargin": 8.6909509,
// "realisedGrossPnl": 0,
// "realisedPnl": -0.0038335,
// "unrealisedPnl": 0.023,
// "unrealisedPnlPcnt": 0.003,
// "unrealisedRoePcnt": 0.003,
// "avgEntryPrice": 0.7658,
// "liquidationPrice": 1.6239,
// "bankruptPrice": 1.6317,
// "settleCurrency": "USDT"
// }
//
// {
// "code":"200000",
// "msg":"Position does not exist"
// }
//
let mut id: Value = self.safe_string_k(info.clone(), "id", &[]);
market = self.safe_market(&[id.clone(), market.clone()]);
let mut currencyId: Value = self.safe_string_k(info.clone(), "settleCurrency", &[]);
let mut crossMode: Value = self.safe_value_k(info.clone(), "crossMode", &[]);
let mut mode: Value = ternary(is_true(&(is_equal(&crossMode, &Value::Bool(true)))), Value::Str("cross".to_string()), Value::Str("isolated".to_string()));
let mut marketId: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "currentTimestamp", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), mode.clone());
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), Value::Null);
m.insert("code".to_string(), self.safe_currency_code(currencyId.clone(), &[]));
m.insert("status".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name kucoin#fetchMarginMode
* @description fetches the margin mode of a trading pair
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-margin-mode
* @param {string} symbol unified symbol of the market to fetch the margin mode for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin mode structure]{@link https://docs.ccxt.com/?id=margin-mode-structure}
*/
pub async fn fetch_margin_mode(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_145 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_get_position_get_margin_mode(&[__ws_arg_145]).await;
//
// {
// "code": "200000",
// "data": {
// "symbol": "XBTUSDTM",
// "marginMode": "ISOLATED"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_mode(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_mode(&self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marginType: Value = self.safe_string_k(marginMode.clone(), "marginMode", &[]);
marginType = ternary(is_true(&(is_equal(&marginType, &Value::Str("ISOLATED".to_string())))), Value::Str("isolated".to_string()), Value::Str("cross".to_string()));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), marginMode.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("marginMode".to_string(), marginType.clone());
m
});
Value::Null
}
/*
* @method
* @name kucoin#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/switch-margin-mode
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_margin_mode(&mut self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a symbol argument".to_string()))));
}
self.check_required_argument(Value::Str("setMarginMode".to_string()), marginMode.clone(), Value::Str("marginMode".to_string()), &[Value::List(vec![Value::Str("cross".to_string()), Value::Str("isolated".to_string())])]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setMarginMode() supports contract markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("marginMode".to_string(), to_upper(&marginMode));
m
});
let __ws_arg_146 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_post_position_change_margin_mode(&[__ws_arg_146]).await;
//
// {
// "code": "200000",
// "data": {
// "symbol": "XBTUSDTM",
// "marginMode": "ISOLATED"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_mode(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#setPositionMode
* @description set hedged to true or false for a market
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/switch-position-mode
* @param {bool} hedged set to true to use two way position
* @param {string} [symbol] not used by setPositionMode ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a response from the exchange
*/
pub async fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut posMode: Value = ternary(is_true(&hedged), Value::Str("1".to_string()), Value::Str("0".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("positionMode".to_string(), posMode.clone());
m
});
let __ws_arg_147 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_private_post_position_switch_position_mode(&[__ws_arg_147]).await;
return response;
Value::Null
}
/*
* @method
* @name kucoin#fetchPositionMode
* @description fetchs the position mode, hedged or one way
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-mode
* @param {string} [symbol] unified symbol of the market to fetch the position mode for (not used in blofin fetchPositionMode)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an object detailing whether the market is in hedged or one-way mode
*/
pub async fn fetch_position_mode(&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
}));
let mut response: Value = self.futures_private_get_position_get_position_mode(&[params.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positionMode: Value = self.safe_integer_k(data.clone(), "positionMode", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("hedged".to_string(), Value::Bool(is_equal(&positionMode, &Value::Int(1))));
m
});
Value::Null
}
/*
* @method
* @name kucoin#closePosition
* @description closes open positions for a market
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order
* @see https://www.kucoin.com/docs-new/rest/futures-trading/orders/add-order-test
* @param {string} symbol Unified CCXT market symbol
* @param {string} side not used by kucoin closePositions
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client order id of the order
* @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
let mut testOrder: Value = self.safe_bool_k(params.clone(), "test", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("test".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
if is_equal(&clientOrderId, &Value::Null) {
clientOrderId = self.number_to_string(self.nonce());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("closeOrder".to_string(), Value::Bool(true));
m.insert("clientOid".to_string(), clientOrderId.clone());
m.insert("type".to_string(), Value::Str("market".to_string()));
m
});
let mut response: Value = Value::Null;
if is_equal(&testOrder, &Value::Bool(true)) {
let __ws_arg_148 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_post_orders_test(&[__ws_arg_148]).await;
} else {
let __ws_arg_149 = self.extend(request.clone(), &[params.clone()]);
response = self.futures_private_post_orders(&[__ws_arg_149]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchMarketLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-isolated-margin-risk-limit
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.uta] set to true to fetch leverage tiers for unified trading account instead of futures account (default is false)
* @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
*/
pub async fn fetch_market_leverage_tiers(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchMarketLeverageTiers() supports contract markets only".to_string()))));
}
let mut uta: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMarketLeverageTiers".to_string()), Value::Str("uta".to_string()), &[uta.clone()]); uta = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&uta) {
let mut result: Value = self.fetch_leverage_tiers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return self.safe_list(result.clone(), symbol.clone(), &[Value::List(vec![])]);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_150 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.futures_public_get_contracts_risk_limit_symbol(&[__ws_arg_150]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "symbol": "ETHUSDTM",
// "level": 1,
// "maxRiskLimit": 300000,
// "minRiskLimit": 0,
// "maxLeverage": 100,
// "initialMargin": 0.0100000000,
// "maintainMargin": 0.0050000000
// },
// ...
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_market_leverage_tiers(data.clone(), &[market.clone()]);
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);
/*
* @ignore
* @method
* @name kucoin#parseMarketLeverageTiers
* @param {object} info Exchange market response for 1 market
* @param {object} market CCXT market
*/
//
// futures
// {
// "symbol": "ETHUSDTM",
// "level": 1,
// "maxRiskLimit": 300000,
// "minRiskLimit": 0,
// "maxLeverage": 100,
// "initialMargin": 0.0100000000,
// "maintainMargin": 0.0050000000
// }
//
// uta
// {
// "symbol": "XBTUSDTM",
// "tier": 2,
// "maxSize": "600000",
// "minSize": "250000",
// "maxLeverage": "100",
// "initialMarginRate": "0.0100000000",
// "maintainMarginRate": "0.0050000000"
// }
//
let mut tiers: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_898: bool = true;
while { if !__for_first_898 { i = add(&i, &Value::Int(1)); } __for_first_898 = false; is_less_than(&i, &get_array_length(&info)) } {
let mut tier: Value = self.safe_dict(info.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(tier.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_number2(tier.clone(), Value::Str("level".to_string()), Value::Str("tier".to_string()), &[]));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("currency".to_string(), get_value(&market, &Value::Str("base".to_string())));
m.insert("minNotional".to_string(), self.safe_number2(tier.clone(), Value::Str("minRiskLimit".to_string()), Value::Str("minSize".to_string()), &[]));
m.insert("maxNotional".to_string(), self.safe_number2(tier.clone(), Value::Str("maxRiskLimit".to_string()), Value::Str("maxSize".to_string()), &[]));
m.insert("maintenanceMarginRate".to_string(), self.safe_number2(tier.clone(), Value::Str("maintainMargin".to_string()), Value::Str("maintainMarginRate".to_string()), &[]));
m.insert("maxLeverage".to_string(), self.safe_number_k(tier.clone(), "maxLeverage", &[]));
m.insert("info".to_string(), tier.clone());
m
}));
}
}
return tiers;
Value::Null
}
/*
* @method
* @name kucoin#fetchLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
* @see https://www.kucoin.com/docs-new/rest/ua/get-position-tiers
* @param {string[]} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}, indexed by market symbols
*/
pub async fn fetch_leverage_tiers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchLeverageTiers() requires a symbols argument".to_string()))));
}
symbols = self.market_symbols(&[symbols.clone(), Value::Str("swap".to_string()), Value::Bool(false), Value::Bool(true)]);
let mut marginMode: Value = Value::Str("cross".to_string());
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchLeverageTiers".to_string()), &[params.clone(), marginMode.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
marginMode = to_upper(&marginMode);
if !is_equal(&marginMode, &Value::Str("CROSS".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchLeverageTiers() supports cross margin only".to_string()))));
}
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradeType".to_string(), Value::Str("FUTURES".to_string()));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("data".to_string(), Value::Str("RISK_LIMIT".to_string()));
m.insert("accountType".to_string(), Value::Str("UNIFIED".to_string()));
m.insert("symbol".to_string(), join(&marketIds, &Value::Str(",".to_string())));
m
});
let __ws_arg_151 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_get_market_position_tiers(&[__ws_arg_151]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "symbol": "XBTUSDTM",
// "tier": 1,
// "maxSize": "250000",
// "minSize": "0",
// "maxLeverage": "125",
// "initialMarginRate": "0.0080000000",
// "maintainMarginRate": "0.0040000000"
// },
// {
// "symbol": "XBTUSDTM",
// "tier": 2,
// "maxSize": "600000",
// "minSize": "250000",
// "maxLeverage": "100",
// "initialMarginRate": "0.0100000000",
// "maintainMarginRate": "0.0050000000"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut tiers: Value = self.parse_market_leverage_tiers(data.clone(), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_899: bool = true;
while { if !__for_first_899 { i = add(&i, &Value::Int(1)); } __for_first_899 = false; is_less_than(&i, &get_array_length(&tiers)) } {
let mut tier: Value = self.safe_dict(tiers.clone(), i.clone(), &[]);
let mut symbol: Value = self.safe_string_k(tier.clone(), "symbol", &[]);
if !is_equal(&symbol, &Value::Null) {
if !is_true(&(Value::Bool(in_op(&result, &symbol)))) {
add_element_to_object(&mut result, &symbol, Value::List(vec![]));
}
crate::runtime::append_to_object_array(&mut result, &symbol, tier.clone());
}
}
}
return result;
Value::Null
}
/*
* @method
* @name kucoin#fetchOpenInterests
* @description Retrieves the open interest for a list of symbols
* @see https://www.kucoin.com/docs-new/rest/ua/get-futures-open-interset
* @param {string[]} [symbols] Unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @returns {object} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interests(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut length: Value = get_array_length(&symbols);
if is_less_than(&length, &Value::Int(11)) {
// the endpoint does not accept more than 10 symbols at a time
// if user provided more than 10 symbols, we will fetch all symbols
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), join(&marketIds, &Value::Str(",".to_string())));
}
}
let __ws_arg_152 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_get_market_open_interest(&[__ws_arg_152]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "symbol": "ETHUSDTM",
// "openInterest": "8053960",
// "ts": 1774007467050
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_open_interests(data.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETHUSDTM",
// "openInterest": "8053960",
// "ts": 1774007467050
// }
//
let mut marketId: Value = self.safe_string_k(interest.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(interest.clone(), "ts", &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[]));
m.insert("openInterestAmount".to_string(), self.safe_number_k(interest.clone(), "openInterest", &[]));
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchOpenInterestHistory
* @description Retrieves the open interest history of a currency
* @see https://www.kucoin.com/docs-new/rest/ua/get-futures-open-interset
* @param {string} symbol Unified CCXT market symbol
* @param {string} timeframe '5m', '15m', '30m', '1h', '4h' or '1d'
* @param {int} [since] the time(ms) of the earliest record to retrieve as a unix timestamp
* @param {int} [limit] default 30,max 200
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} an array of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("5m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut timeframes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("5m".to_string(), Value::Str("5min".to_string()));
m.insert("15m".to_string(), Value::Str("15min".to_string()));
m.insert("30m".to_string(), Value::Str("30min".to_string()));
m.insert("1h".to_string(), Value::Str("1hour".to_string()));
m.insert("4h".to_string(), Value::Str("4hour".to_string()));
m.insert("1d".to_string(), Value::Str("1day".to_string()));
m.insert("5min".to_string(), Value::Str("5min".to_string()));
m.insert("15min".to_string(), Value::Str("15min".to_string()));
m.insert("30min".to_string(), Value::Str("30min".to_string()));
m.insert("1hour".to_string(), Value::Str("1hour".to_string()));
m.insert("4hour".to_string(), Value::Str("4hour".to_string()));
m.insert("1day".to_string(), Value::Str("1day".to_string()));
m
});
let mut interval: Value = self.safe_string(timeframes.clone(), timeframe.clone(), &[]);
if is_equal(&interval, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOpenInterestHistory() invalid timeframe, supported are 5m, 15m, 30m, 1h, 4h, 1d".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut maxLimit: Value = Value::Int(200);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOpenInterestHistory".to_string()), Value::Str("paginate".to_string()), &[paginate.clone()]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOpenInterestHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), interval.clone());
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_153 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.uta_get_market_open_interest(&[__ws_arg_153]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_open_interests_history(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#isUTAEnabled
* @see https://www.kucoin.com/docs-new/rest/ua/get-account-mode
* @description returns true or false so the user can check if unified account is enabled
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {boolean} true if unified account is enabled, false otherwise
*/
pub async fn is_uta_enabled(&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 uta: Value = self.safe_bool_k(self.options.clone(), "uta", &[]);
if is_equal(&uta, &Value::Null) {
let mut response: Value = self.uta_private_get_account_mode(&[params.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut accountMode: Value = self.safe_string_k(data.clone(), "selfAccountMode", &[]);
uta = Value::Bool(is_equal(&accountMode, &Value::Str("UNIFIED".to_string())));
add_element_to_object(&mut self.options, &Value::Str("uta".to_string()), uta.clone());
}
return uta;
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
//
// the v2 URL is https://openapi-v2.kucoin.com/api/v1/endpoint
// ↑ ↑
// ↑ ↑
//
let mut versions: Value = self.safe_dict_k(self.options.clone(), "versions", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut apiVersions: Value = self.safe_dict(versions.clone(), api.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut methodVersions: Value = self.safe_dict(apiVersions.clone(), method.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultVersion: Value = self.safe_string(methodVersions.clone(), path.clone(), &[get_value(&self.options, &Value::Str("version".to_string()))]);
let mut version: Value = self.safe_string_k(params.clone(), "version", &[defaultVersion.clone()]);
params = self.omit(params.clone(), Value::Str("version".to_string()), &[]);
let mut endpoint: Value = add(&add(&add(&Value::Str("/api/".to_string()), &version), &Value::Str("/".to_string())), &self.implode_params(path.clone(), params.clone()));
if is_equal(&api, &Value::Str("webExchange".to_string())) {
endpoint = add(&Value::Str("/".to_string()), &self.implode_params(path.clone(), params.clone()));
}
if is_equal(&api, &Value::Str("earn".to_string())) {
endpoint = add(&Value::Str("/api/v1/".to_string()), &self.implode_params(path.clone(), params.clone()));
}
let mut isUtaPrivate: bool = false;
if is_true(&(is_equal(&api, &Value::Str("uta".to_string())))) || is_true(&(is_equal(&api, &Value::Str("utaPrivate".to_string())))) {
endpoint = add(&Value::Str("/api/ua/v1/".to_string()), &self.implode_params(path.clone(), params.clone()));
if is_equal(&api, &Value::Str("utaPrivate".to_string())) {
isUtaPrivate = true;
}
}
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut endpart: Value = Value::Str("".to_string());
headers = ternary(is_true(&(!is_equal(&headers, &Value::Null))), headers.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api);
let mut tradeType: Value = self.safe_string_k(query.clone(), "tradeType", &[]);
if !is_true(&self.is_empty(query.clone())) {
if is_true(&(is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))))) && is_true(&(!is_equal(&path, &Value::Str("orders/multi-cancel".to_string())))) {
endpoint = add(&endpoint, &add(&Value::Str("?".to_string()), &self.rawencode(query.clone(), &[])));
} else {
if is_true(&(is_equal(&endpoint, &Value::Str("/api/ua/v1/classic/order/place".to_string())))) || is_true(&(is_equal(&endpoint, &Value::Str("/api/ua/v1/classic/order/place/batch".to_string())))) || is_true(&(is_equal(&endpoint, &Value::Str("/api/ua/v1/classic/order/cancel".to_string())))) || is_true(&(is_equal(&endpoint, &Value::Str("/api/ua/v1/classic/order/cancel/batch".to_string())))) {
endpoint = add(&endpoint, &add(&Value::Str("?tradeType=".to_string()), &tradeType));
}
body = self.json(query.clone());
endpart = body.clone();
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
}
}
url = add(&url, &endpoint);
let mut isFuturePrivate: bool = is_equal(&api, &Value::Str("futuresPrivate".to_string()));
let mut isPrivate: bool = is_equal(&api, &Value::Str("private".to_string()));
let mut isBroker: bool = is_equal(&api, &Value::Str("broker".to_string()));
let mut isEarn: bool = is_equal(&api, &Value::Str("earn".to_string()));
if is_true(&isPrivate) || is_true(&isFuturePrivate) || is_true(&isBroker) || is_true(&isEarn) || is_true(&isUtaPrivate) {
self.check_required_credentials(&[]);
let mut timestamp: Value = to_string_val(&self.nonce());
headers = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("KC-API-KEY-VERSION".to_string(), Value::Str("2".to_string()));
m.insert("KC-API-KEY".to_string(), self.apiKey.clone());
m.insert("KC-API-TIMESTAMP".to_string(), timestamp.clone());
m
}), &[headers.clone()]);
headers = ternary(is_true(&(is_equal(&headers, &Value::Null))), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), headers.clone());
let mut apiKeyVersion: Value = self.safe_string_k(headers.clone(), "KC-API-KEY-VERSION", &[]);
if is_equal(&apiKeyVersion, &Value::Str("2".to_string())) {
let mut passphrase: Value = self.hmac(self.encode(self.password.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
add_element_to_object(&mut headers, &Value::Str("KC-API-PASSPHRASE".to_string()), passphrase.clone());
} else {
add_element_to_object(&mut headers, &Value::Str("KC-API-PASSPHRASE".to_string()), self.password.clone());
}
let mut payload: Value = add(&add(&add(×tamp, &method), &endpoint), &endpart);
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
add_element_to_object(&mut headers, &Value::Str("KC-API-SIGN".to_string()), signature.clone());
let mut partner: Value = self.safe_dict_k(self.options.clone(), "partner", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut isUtaFuturePrivate: bool = is_true(&isUtaPrivate) && is_true(&(is_equal(&tradeType, &Value::Str("FUTURES".to_string()))));
let mut isFuturePartner: bool = is_true(&isFuturePrivate) || is_true(&isUtaFuturePrivate);
partner = ternary(is_true(&isFuturePartner), self.safe_value_k(partner.clone(), "future", &[partner.clone()]), self.safe_value_k(partner.clone(), "spot", &[partner.clone()]));
let mut partnerId: Value = self.safe_string_k(partner.clone(), "id", &[]);
let mut partnerSecret: Value = self.safe_string2(partner.clone(), Value::Str("secret".to_string()), Value::Str("key".to_string()), &[]);
if is_true(&(!is_equal(&partnerId, &Value::Null))) && is_true(&(!is_equal(&partnerSecret, &Value::Null))) {
let mut partnerPayload: Value = add(&add(×tamp, &partnerId), &self.apiKey);
let mut partnerSignature: Value = self.hmac(self.encode(partnerPayload.clone()), self.encode(partnerSecret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
add_element_to_object(&mut headers, &Value::Str("KC-API-PARTNER-SIGN".to_string()), partnerSignature.clone());
add_element_to_object(&mut headers, &Value::Str("KC-API-PARTNER".to_string()), partnerId.clone());
add_element_to_object(&mut headers, &Value::Str("KC-API-PARTNER-VERIFY".to_string()), Value::Str("true".to_string()));
}
if is_true(&isBroker) {
let mut brokerName: Value = self.safe_string_k(partner.clone(), "name", &[]);
if !is_equal(&brokerName, &Value::Null) {
add_element_to_object(&mut headers, &Value::Str("KC-BROKER-NAME".to_string()), brokerName.clone());
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_true(&(is_equal(&response, &Value::Null))) || is_true(&(is_equal(&response, &Value::Null))) {
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), body.clone(), body.clone());
return Value::Null;
}
//
// bad
// { "code": "400100", "msg": "validation.createOrder.clientOidIsRequired" }
// good
// { code: '200000', data: { ... }}
//
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut message: Value = self.safe_string2(response.clone(), Value::Str("msg".to_string()), Value::Str("data".to_string()), &[Value::Str("".to_string())]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), body.clone(), feedback.clone());
if !is_equal(&errorCode, &Value::Str("200000".to_string())) && !is_equal(&errorCode, &Value::Str("200".to_string())) {
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
/*
* @method
* @name kucoin#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://www.kucoin.com/docs-new/rest/account-info/account-funding/get-account-ledgers-spot-margin
* @param {string} [code] unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfer structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch transfers for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn fetch_transfers(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTransfers".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTransfers".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bizType".to_string(), Value::Str("TRANSFER".to_string()));
m
});
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("endAt".to_string()), until.clone());
}
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startAt".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), Value::Int(500));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endAt".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_154 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_accounts_ledgers(&[__ws_arg_154]).await;
//
// {
// "code": "200000",
// "data": {
// "currentPage": 1,
// "pageSize": 50,
// "totalNum": 1,
// "totalPage": 1,
// "items": [
// {
// "id": "611a1e7c6a053300067a88d9",
// "currency": "USDT",
// "amount": "10.00059547",
// "fee": "0",
// "balance": "0",
// "accountType": "MAIN",
// "bizType": "Transfer",
// "direction": "in",
// "createdAt": 1629101692950,
// "context": "{\"orderId\":\"611a1e7c6a053300067a88d9\"}"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut items: Value = self.safe_list_k(data.clone(), "items", &[Value::List(vec![])]);
return self.parse_transfers(items.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kucoin#fetchPositionsADLRank
* @description fetches the auto deleveraging rank and risk percentage for a list of symbols
* @see https://www.kucoin.com/docs-new/rest/futures-trading/positions/get-position-list
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of [auto de leverage structures]{@link https://docs.ccxt.com/?id=auto-de-leverage-structure}
*/
pub async fn fetch_positions_adl_rank(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut response: Value = self.futures_private_get_positions(&[params.clone()]).await;
//
// {
// "code": "200000",
// "data": [
// {
// "id": "600000000001260912",
// "symbol": "XBTUSDTM",
// "crossMode": true,
// "maintMarginReq": 0.0040000133,
// "delevPercentage": 0.0,
// "openingTimestamp": 1768481882915,
// "currentTimestamp": 1768481897988,
// "currentQty": 1,
// "currentCost": 96.9768,
// "currentComm": 0.05818608,
// "unrealisedCost": 96.9768,
// "realisedGrossCost": 0.0,
// "realisedCost": 0.05818608,
// "isOpen": true,
// "markPrice": 96985.6,
// "markValue": 96.9856,
// "posCost": 96.9768,
// "posInit": 4.84884,
// "posMargin": 4.84928,
// "posMaint": 0.38794369,
// "realisedGrossPnl": 0.0,
// "realisedPnl": -0.05818608,
// "unrealisedPnl": 0.0088,
// "unrealisedPnlPcnt": 1.0E-4,
// "unrealisedRoePcnt": 0.0018,
// "avgEntryPrice": 96976.8,
// "liquidationPrice": 52351.69,
// "bankruptPrice": 52110.87,
// "settleCurrency": "USDT",
// "isInverse": false,
// "maintainMargin": 0.0040000133,
// "marginMode": "CROSS",
// "positionSide": "LONG",
// "leverage": 20,
// "dealComm": -0.05818608,
// "fundingFee": 0,
// "tax": 0
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_adl_ranks(data.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_adl_rank(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchPositionsADLRank
//
// {
// "id": "600000000001260912",
// "symbol": "XBTUSDTM",
// "crossMode": true,
// "maintMarginReq": 0.0040000133,
// "delevPercentage": 0.0,
// "openingTimestamp": 1768481882915,
// "currentTimestamp": 1768481897988,
// "currentQty": 1,
// "currentCost": 96.9768,
// "currentComm": 0.05818608,
// "unrealisedCost": 96.9768,
// "realisedGrossCost": 0.0,
// "realisedCost": 0.05818608,
// "isOpen": true,
// "markPrice": 96985.6,
// "markValue": 96.9856,
// "posCost": 96.9768,
// "posInit": 4.84884,
// "posMargin": 4.84928,
// "posMaint": 0.38794369,
// "realisedGrossPnl": 0.0,
// "realisedPnl": -0.05818608,
// "unrealisedPnl": 0.0088,
// "unrealisedPnlPcnt": 1.0E-4,
// "unrealisedRoePcnt": 0.0018,
// "avgEntryPrice": 96976.8,
// "liquidationPrice": 52351.69,
// "bankruptPrice": 52110.87,
// "settleCurrency": "USDT",
// "isInverse": false,
// "maintainMargin": 0.0040000133,
// "marginMode": "CROSS",
// "positionSide": "LONG",
// "leverage": 20,
// "dealComm": -0.05818608,
// "fundingFee": 0,
// "tax": 0
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "openingTimestamp", &[]);
let mut percentage: Value = self.safe_string_k(info.clone(), "delevPercentage", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("rank".to_string(), Value::Null);
m.insert("rating".to_string(), Value::Null);
m.insert("percentage".to_string(), self.parse_number(crate::precise::Precise::stringMul(&percentage, &Value::Str("100".to_string())), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
}