// 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 KrakenCore {
pub exchange: crate::exchange::Exchange,
}
impl KrakenCore {
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 = KrakenCore::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 KrakenCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_order(self, order, &[market.clone()])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_position(self, position, &[market.clone()])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::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 KrakenCore.
KrakenCore::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 KrakenCore.
KrakenCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_currency(self, currency)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on KrakenCore.
KrakenCore::parse_transaction(self, transaction, &[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 KrakenCore.
KrakenCore::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 KrakenCore.
KrakenCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for KrakenCore {
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_pagination_cursor_to_result" => self.add_pagination_cursor_to_result(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders_after" => self.cancel_all_orders_after(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"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_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,
"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,
"fee_to_precision" => self.fee_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_methods" => self.fetch_deposit_methods(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger_entries_by_ids" => self.fetch_ledger_entries_by_ids(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger_entry" => self.fetch_ledger_entry(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_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_ids" => self.fetch_orders_by_ids(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"find_market_by_altname_or_id" => self.find_market_by_altname_or_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"get_delisted_market_by_id" => self.get_delisted_market_by_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"order_request" => self.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).cloned().unwrap_or(crate::Value::Null), &args.get(5..).unwrap_or(&[]).to_vec()[..]),
"parse_account_type" => self.parse_account_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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_network" => self.parse_network(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_book_bid_ask" => self.parse_order_book_bid_ask(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_type" => self.parse_order_type(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_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transactions_by_type" => self.parse_transactions_by_type(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"safe_currency_code" => self.safe_currency_code(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_out" => self.transfer_out(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,
"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 KrakenCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for KrakenCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl KrakenCore {
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("kraken".to_string()));
m.insert("name".to_string(), Value::Str("Kraken".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("US".to_string())]));
m.insert("version".to_string(), Value::Str("0".to_string()));
m.insert("rateLimit".to_string(), Value::Int(1000));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("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(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(true));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Bool(true));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
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("fetchOrderTrades".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Int(1));
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("4h".to_string(), Value::Int(240));
m.insert("1d".to_string(), Value::Int(1440));
m.insert("1w".to_string(), Value::Int(10080));
m.insert("2w".to_string(), Value::Int(21600));
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/76173629-fc67fb00-61b1-11ea-84fe-f2de582f58a3.jpg".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.kraken.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api.kraken.com".to_string()));
m.insert("zendesk".to_string(), Value::Str("https://kraken.zendesk.com/api/v2/help_center/en-us/articles".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.kraken.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://docs.kraken.com/api-reference/".to_string()));
m.insert("fees".to_string(), Value::Str("https://www.kraken.com/en-us/features/fee-schedule".to_string()));
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.0026".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0016".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.0026".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000".to_string()), &[]), self.parse_number(Value::Str("0.0024".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000".to_string()), &[]), self.parse_number(Value::Str("0.0022".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("250000".to_string()), &[]), self.parse_number(Value::Str("0.0020".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.0018".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.0016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.0014".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.0012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.0001".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.0016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000".to_string()), &[]), self.parse_number(Value::Str("0.0014".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000".to_string()), &[]), self.parse_number(Value::Str("0.0012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("250000".to_string()), &[]), self.parse_number(Value::Str("0.0010".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.0008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.0002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.0".to_string()), &[])])]));
m
}));
m
}));
m
}));
m.insert("handleContentTypeApplicationZip".to_string(), Value::Bool(true));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("zendesk".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("360000292886".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("201893608".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("SystemStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("Assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("AssetPairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("Ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("OHLC".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.2));
m
}));
m.insert("Depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.2));
m
}));
m.insert("GroupedBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.2));
m
}));
m.insert("Trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.2));
m
}));
m.insert("Spread".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("PreTrade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("PostTrade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Level3".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.2));
m
}));
m.insert("Balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("BalanceEx".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("CreditLines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("TradeBalance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("OpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("ClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("QueryOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("OrderAmends".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("TradesHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("QueryTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("OpenPositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Ledgers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("QueryLedgers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("TradeVolume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("AddExport".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("ExportStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("RetrieveExport".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("RemoveExport".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("GetApiKeyInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("AddOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(0));
m
}));
m.insert("AmendOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(0));
m
}));
m.insert("CancelOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(0));
m
}));
m.insert("CancelAll".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("CancelAllOrdersAfter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("GetWebSocketsToken".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("AddOrderBatch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(0));
m
}));
m.insert("CancelOrderBatch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(0));
m
}));
m.insert("EditOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(0));
m
}));
m.insert("DepositMethods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("DepositAddresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("DepositStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("WithdrawMethods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("WithdrawAddresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("WithdrawInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("WithdrawStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("WithdrawCancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("WalletTransfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("CreateSubaccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("AccountTransfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Earn/Allocate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Earn/Deallocate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Earn/AllocateStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Earn/DeallocateStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Earn/Strategies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("Earn/Allocations".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m
}));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("LUNA".to_string(), Value::Str("LUNC".to_string()));
m.insert("LUNA2".to_string(), Value::Str("LUNA".to_string()));
m.insert("REPV2".to_string(), Value::Str("REP".to_string()));
m.insert("REP".to_string(), Value::Str("REPV1".to_string()));
m.insert("UST".to_string(), Value::Str("USTC".to_string()));
m.insert("XBT".to_string(), Value::Str("BTC".to_string()));
m.insert("XDG".to_string(), Value::Str("DOGE".to_string()));
m.insert("FEE".to_string(), Value::Str("KFEE".to_string()));
m.insert("XETC".to_string(), Value::Str("ETC".to_string()));
m.insert("XETH".to_string(), Value::Str("ETH".to_string()));
m.insert("XLTC".to_string(), Value::Str("LTC".to_string()));
m.insert("XMLN".to_string(), Value::Str("MLN".to_string()));
m.insert("XREP".to_string(), Value::Str("REP".to_string()));
m.insert("XXBT".to_string(), Value::Str("BTC".to_string()));
m.insert("XXDG".to_string(), Value::Str("DOGE".to_string()));
m.insert("XXLM".to_string(), Value::Str("XLM".to_string()));
m.insert("XXMR".to_string(), Value::Str("XMR".to_string()));
m.insert("XXRP".to_string(), Value::Str("XRP".to_string()));
m.insert("XZEC".to_string(), Value::Str("ZEC".to_string()));
m.insert("ZAUD".to_string(), Value::Str("AUD".to_string()));
m.insert("ZCAD".to_string(), Value::Str("CAD".to_string()));
m.insert("ZEUR".to_string(), Value::Str("EUR".to_string()));
m.insert("ZGBP".to_string(), Value::Str("GBP".to_string()));
m.insert("ZJPY".to_string(), Value::Str("JPY".to_string()));
m.insert("ZUSD".to_string(), Value::Str("USD".to_string()));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mica".to_string(), Value::Bool(true));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("marketsByAltname".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("delistedMarketsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("inactiveCurrencies".to_string(), Value::List(vec![Value::Str("CAD".to_string()), Value::Str("USD".to_string()), Value::Str("JPY".to_string()), Value::Str("GBP".to_string())]));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("TRX".to_string(), Value::Str("TRC20".to_string()));
m
}));
m.insert("depositMethods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1INCH".to_string(), add(&add(&Value::Str("1inch".to_string()), &Value::Str(" ".to_string())), &Value::Str("(1INCH)".to_string())));
m.insert("AAVE".to_string(), Value::Str("Aave".to_string()));
m.insert("ADA".to_string(), Value::Str("ADA".to_string()));
m.insert("ALGO".to_string(), Value::Str("Algorand".to_string()));
m.insert("ANKR".to_string(), add(&add(&Value::Str("ANKR".to_string()), &Value::Str(" ".to_string())), &Value::Str("(ANKR)".to_string())));
m.insert("ANT".to_string(), add(&add(&Value::Str("Aragon".to_string()), &Value::Str(" ".to_string())), &Value::Str("(ANT)".to_string())));
m.insert("ATOM".to_string(), Value::Str("Cosmos".to_string()));
m.insert("AXS".to_string(), add(&add(&Value::Str("Axie Infinity Shards".to_string()), &Value::Str(" ".to_string())), &Value::Str("(AXS)".to_string())));
m.insert("BADGER".to_string(), add(&add(&Value::Str("Bager DAO".to_string()), &Value::Str(" ".to_string())), &Value::Str("(BADGER)".to_string())));
m.insert("BAL".to_string(), add(&add(&Value::Str("Balancer".to_string()), &Value::Str(" ".to_string())), &Value::Str("(BAL)".to_string())));
m.insert("BAND".to_string(), add(&add(&Value::Str("Band Protocol".to_string()), &Value::Str(" ".to_string())), &Value::Str("(BAND)".to_string())));
m.insert("BAT".to_string(), Value::Str("BAT".to_string()));
m.insert("BCH".to_string(), Value::Str("Bitcoin Cash".to_string()));
m.insert("BNC".to_string(), add(&add(&Value::Str("Bifrost".to_string()), &Value::Str(" ".to_string())), &Value::Str("(BNC)".to_string())));
m.insert("BNT".to_string(), add(&add(&Value::Str("Bancor".to_string()), &Value::Str(" ".to_string())), &Value::Str("(BNT)".to_string())));
m.insert("BTC".to_string(), Value::Str("Bitcoin".to_string()));
m.insert("CHZ".to_string(), add(&add(&Value::Str("Chiliz".to_string()), &Value::Str(" ".to_string())), &Value::Str("(CHZ)".to_string())));
m.insert("COMP".to_string(), add(&add(&Value::Str("Compound".to_string()), &Value::Str(" ".to_string())), &Value::Str("(COMP)".to_string())));
m.insert("CQT".to_string(), add(&add(&Value::Str("\tCovalent Query Token".to_string()), &Value::Str(" ".to_string())), &Value::Str("(CQT)".to_string())));
m.insert("CRV".to_string(), add(&add(&Value::Str("Curve DAO Token".to_string()), &Value::Str(" ".to_string())), &Value::Str("(CRV)".to_string())));
m.insert("CTSI".to_string(), add(&add(&Value::Str("Cartesi".to_string()), &Value::Str(" ".to_string())), &Value::Str("(CTSI)".to_string())));
m.insert("DAI".to_string(), Value::Str("Dai".to_string()));
m.insert("DASH".to_string(), Value::Str("Dash".to_string()));
m.insert("DOGE".to_string(), Value::Str("Dogecoin".to_string()));
m.insert("DOT".to_string(), Value::Str("Polkadot".to_string()));
m.insert("DYDX".to_string(), add(&add(&Value::Str("dYdX".to_string()), &Value::Str(" ".to_string())), &Value::Str("(DYDX)".to_string())));
m.insert("ENJ".to_string(), add(&add(&Value::Str("Enjin Coin".to_string()), &Value::Str(" ".to_string())), &Value::Str("(ENJ)".to_string())));
m.insert("EOS".to_string(), Value::Str("EOS".to_string()));
m.insert("ETC".to_string(), add(&add(&Value::Str("Ether Classic".to_string()), &Value::Str(" ".to_string())), &Value::Str("(Hex)".to_string())));
m.insert("ETH".to_string(), add(&add(&Value::Str("Ether".to_string()), &Value::Str(" ".to_string())), &Value::Str("(Hex)".to_string())));
m.insert("EWT".to_string(), Value::Str("Energy Web Token".to_string()));
m.insert("FEE".to_string(), Value::Str("Kraken Fee Credit".to_string()));
m.insert("FIL".to_string(), Value::Str("Filecoin".to_string()));
m.insert("FLOW".to_string(), Value::Str("Flow".to_string()));
m.insert("GHST".to_string(), add(&add(&Value::Str("Aavegotchi".to_string()), &Value::Str(" ".to_string())), &Value::Str("(GHST)".to_string())));
m.insert("GNO".to_string(), Value::Str("GNO".to_string()));
m.insert("GRT".to_string(), Value::Str("GRT".to_string()));
m.insert("ICX".to_string(), Value::Str("Icon".to_string()));
m.insert("INJ".to_string(), add(&add(&Value::Str("Injective Protocol".to_string()), &Value::Str(" ".to_string())), &Value::Str("(INJ)".to_string())));
m.insert("KAR".to_string(), add(&add(&Value::Str("Karura".to_string()), &Value::Str(" ".to_string())), &Value::Str("(KAR)".to_string())));
m.insert("KAVA".to_string(), Value::Str("Kava".to_string()));
m.insert("KEEP".to_string(), add(&add(&Value::Str("Keep Token".to_string()), &Value::Str(" ".to_string())), &Value::Str("(KEEP)".to_string())));
m.insert("KNC".to_string(), add(&add(&Value::Str("Kyber Network".to_string()), &Value::Str(" ".to_string())), &Value::Str("(KNC)".to_string())));
m.insert("KSM".to_string(), Value::Str("Kusama".to_string()));
m.insert("LINK".to_string(), Value::Str("Link".to_string()));
m.insert("LPT".to_string(), add(&add(&Value::Str("Livepeer Token".to_string()), &Value::Str(" ".to_string())), &Value::Str("(LPT)".to_string())));
m.insert("LRC".to_string(), add(&add(&Value::Str("Loopring".to_string()), &Value::Str(" ".to_string())), &Value::Str("(LRC)".to_string())));
m.insert("LSK".to_string(), Value::Str("Lisk".to_string()));
m.insert("LTC".to_string(), Value::Str("Litecoin".to_string()));
m.insert("MANA".to_string(), Value::Str("MANA".to_string()));
m.insert("MATIC".to_string(), add(&add(&Value::Str("Polygon".to_string()), &Value::Str(" ".to_string())), &Value::Str("(MATIC)".to_string())));
m.insert("MINA".to_string(), Value::Str("Mina".to_string()));
m.insert("MIR".to_string(), add(&add(&Value::Str("Mirror Protocol".to_string()), &Value::Str(" ".to_string())), &Value::Str("(MIR)".to_string())));
m.insert("MKR".to_string(), add(&add(&Value::Str("Maker".to_string()), &Value::Str(" ".to_string())), &Value::Str("(MKR)".to_string())));
m.insert("MLN".to_string(), Value::Str("MLN".to_string()));
m.insert("MOVR".to_string(), add(&add(&Value::Str("Moonriver".to_string()), &Value::Str(" ".to_string())), &Value::Str("(MOVR)".to_string())));
m.insert("NANO".to_string(), Value::Str("NANO".to_string()));
m.insert("OCEAN".to_string(), Value::Str("OCEAN".to_string()));
m.insert("OGN".to_string(), add(&add(&Value::Str("Origin Protocol".to_string()), &Value::Str(" ".to_string())), &Value::Str("(OGN)".to_string())));
m.insert("OMG".to_string(), Value::Str("OMG".to_string()));
m.insert("OXT".to_string(), add(&add(&Value::Str("Orchid".to_string()), &Value::Str(" ".to_string())), &Value::Str("(OXT)".to_string())));
m.insert("OXY".to_string(), add(&add(&Value::Str("Oxygen".to_string()), &Value::Str(" ".to_string())), &Value::Str("(OXY)".to_string())));
m.insert("PAXG".to_string(), add(&add(&Value::Str("PAX".to_string()), &Value::Str(" ".to_string())), &Value::Str("(Gold)".to_string())));
m.insert("PERP".to_string(), add(&add(&Value::Str("Perpetual Protocol".to_string()), &Value::Str(" ".to_string())), &Value::Str("(PERP)".to_string())));
m.insert("PHA".to_string(), add(&add(&Value::Str("Phala".to_string()), &Value::Str(" ".to_string())), &Value::Str("(PHA)".to_string())));
m.insert("QTUM".to_string(), Value::Str("QTUM".to_string()));
m.insert("RARI".to_string(), add(&add(&Value::Str("Rarible".to_string()), &Value::Str(" ".to_string())), &Value::Str("(RARI)".to_string())));
m.insert("RAY".to_string(), add(&add(&Value::Str("Raydium".to_string()), &Value::Str(" ".to_string())), &Value::Str("(RAY)".to_string())));
m.insert("REN".to_string(), add(&add(&Value::Str("Ren Protocol".to_string()), &Value::Str(" ".to_string())), &Value::Str("(REN)".to_string())));
m.insert("REP".to_string(), Value::Str("REPv2".to_string()));
m.insert("REPV1".to_string(), Value::Str("REP".to_string()));
m.insert("SAND".to_string(), add(&add(&Value::Str("The Sandbox".to_string()), &Value::Str(" ".to_string())), &Value::Str("(SAND)".to_string())));
m.insert("SC".to_string(), Value::Str("Siacoin".to_string()));
m.insert("SDN".to_string(), add(&add(&Value::Str("Shiden".to_string()), &Value::Str(" ".to_string())), &Value::Str("(SDN)".to_string())));
m.insert("SOL".to_string(), Value::Str("Solana".to_string()));
m.insert("SNX".to_string(), add(&add(&Value::Str("Synthetix Network".to_string()), &Value::Str(" ".to_string())), &Value::Str("(SNX)".to_string())));
m.insert("SRM".to_string(), Value::Str("Serum".to_string()));
m.insert("STORJ".to_string(), add(&add(&Value::Str("Storj".to_string()), &Value::Str(" ".to_string())), &Value::Str("(STORJ)".to_string())));
m.insert("SUSHI".to_string(), add(&add(&Value::Str("Sushiswap".to_string()), &Value::Str(" ".to_string())), &Value::Str("(SUSHI)".to_string())));
m.insert("TBTC".to_string(), Value::Str("tBTC".to_string()));
m.insert("TRX".to_string(), Value::Str("Tron".to_string()));
m.insert("UNI".to_string(), Value::Str("UNI".to_string()));
m.insert("USDC".to_string(), Value::Str("USDC".to_string()));
m.insert("USDT".to_string(), add(&add(&Value::Str("Tether USD".to_string()), &Value::Str(" ".to_string())), &Value::Str("(ERC20)".to_string())));
m.insert("USDT-TRC20".to_string(), add(&add(&Value::Str("Tether USD".to_string()), &Value::Str(" ".to_string())), &Value::Str("(TRC20)".to_string())));
m.insert("WAVES".to_string(), Value::Str("Waves".to_string()));
m.insert("WBTC".to_string(), add(&add(&Value::Str("Wrapped Bitcoin".to_string()), &Value::Str(" ".to_string())), &Value::Str("(WBTC)".to_string())));
m.insert("XLM".to_string(), Value::Str("Stellar XLM".to_string()));
m.insert("XMR".to_string(), Value::Str("Monero".to_string()));
m.insert("XRP".to_string(), Value::Str("Ripple XRP".to_string()));
m.insert("XTZ".to_string(), Value::Str("XTZ".to_string()));
m.insert("YFI".to_string(), Value::Str("YFI".to_string()));
m.insert("ZEC".to_string(), add(&add(&Value::Str("Zcash".to_string()), &Value::Str(" ".to_string())), &Value::Str("(Transparent)".to_string())));
m.insert("ZRX".to_string(), add(&add(&Value::Str("0x".to_string()), &Value::Str(" ".to_string())), &Value::Str("(ZRX)".to_string())));
m
}));
m.insert("withdrawMethods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Lightning".to_string(), Value::Str("Lightning".to_string()));
m.insert("Bitcoin".to_string(), Value::Str("BTC".to_string()));
m.insert("Ripple".to_string(), Value::Str("XRP".to_string()));
m.insert("Litecoin".to_string(), Value::Str("LTC".to_string()));
m.insert("Dogecoin".to_string(), Value::Str("DOGE".to_string()));
m.insert("Stellar".to_string(), Value::Str("XLM".to_string()));
m.insert("Ethereum".to_string(), Value::Str("ERC20".to_string()));
m.insert("Arbitrum One".to_string(), Value::Str("Arbitrum".to_string()));
m.insert("Polygon".to_string(), Value::Str("MATIC".to_string()));
m.insert("Arbitrum Nova".to_string(), Value::Str("Arbitrum".to_string()));
m.insert("Optimism".to_string(), Value::Str("Optimism".to_string()));
m.insert("zkSync Era".to_string(), Value::Str("zkSync".to_string()));
m.insert("Ethereum Classic".to_string(), Value::Str("ETC".to_string()));
m.insert("Zcash".to_string(), Value::Str("ZEC".to_string()));
m.insert("Monero".to_string(), Value::Str("XMR".to_string()));
m.insert("Tron".to_string(), Value::Str("TRC20".to_string()));
m.insert("Solana".to_string(), Value::Str("SOL".to_string()));
m.insert("EOS".to_string(), Value::Str("EOS".to_string()));
m.insert("Bitcoin Cash".to_string(), Value::Str("BCH".to_string()));
m.insert("Cardano".to_string(), Value::Str("ADA".to_string()));
m.insert("Qtum".to_string(), Value::Str("QTUM".to_string()));
m.insert("Tezos".to_string(), Value::Str("XTZ".to_string()));
m.insert("Cosmos".to_string(), Value::Str("ATOM".to_string()));
m.insert("Nano".to_string(), Value::Str("NANO".to_string()));
m.insert("Siacoin".to_string(), Value::Str("SC".to_string()));
m.insert("Lisk".to_string(), Value::Str("LSK".to_string()));
m.insert("Waves".to_string(), Value::Str("WAVES".to_string()));
m.insert("ICON".to_string(), Value::Str("ICX".to_string()));
m.insert("Algorand".to_string(), Value::Str("ALGO".to_string()));
m.insert("Polygon - USDC.e".to_string(), Value::Str("MATIC".to_string()));
m.insert("Arbitrum One - USDC.e".to_string(), Value::Str("Arbitrum".to_string()));
m.insert("Polkadot".to_string(), Value::Str("DOT".to_string()));
m.insert("Kava".to_string(), Value::Str("KAVA".to_string()));
m.insert("Filecoin".to_string(), Value::Str("FIL".to_string()));
m.insert("Kusama".to_string(), Value::Str("KSM".to_string()));
m.insert("Flow".to_string(), Value::Str("FLOW".to_string()));
m.insert("Energy Web".to_string(), Value::Str("EW".to_string()));
m.insert("Mina".to_string(), Value::Str("MINA".to_string()));
m.insert("Centrifuge".to_string(), Value::Str("CFG".to_string()));
m.insert("Karura".to_string(), Value::Str("KAR".to_string()));
m.insert("Moonriver".to_string(), Value::Str("MOVR".to_string()));
m.insert("Shiden".to_string(), Value::Str("SDN".to_string()));
m.insert("Khala".to_string(), Value::Str("PHA".to_string()));
m.insert("Bifrost Kusama".to_string(), Value::Str("BNC".to_string()));
m.insert("Songbird".to_string(), Value::Str("SGB".to_string()));
m.insert("Terra classic".to_string(), Value::Str("LUNC".to_string()));
m.insert("KILT".to_string(), Value::Str("KILT".to_string()));
m.insert("Basilisk".to_string(), Value::Str("BSX".to_string()));
m.insert("Flare".to_string(), Value::Str("FLR".to_string()));
m.insert("Avalanche C-Chain".to_string(), Value::Str("AVAX".to_string()));
m.insert("Kintsugi".to_string(), Value::Str("KINT".to_string()));
m.insert("Altair".to_string(), Value::Str("AIR".to_string()));
m.insert("Moonbeam".to_string(), Value::Str("GLMR".to_string()));
m.insert("Acala".to_string(), Value::Str("ACA".to_string()));
m.insert("Astar".to_string(), Value::Str("ASTR".to_string()));
m.insert("Akash".to_string(), Value::Str("AKT".to_string()));
m.insert("Robonomics".to_string(), Value::Str("XRT".to_string()));
m.insert("Fantom".to_string(), Value::Str("FTM".to_string()));
m.insert("Elrond".to_string(), Value::Str("EGLD".to_string()));
m.insert("THORchain".to_string(), Value::Str("RUNE".to_string()));
m.insert("Secret".to_string(), Value::Str("SCRT".to_string()));
m.insert("Near".to_string(), Value::Str("NEAR".to_string()));
m.insert("Internet Computer Protocol".to_string(), Value::Str("ICP".to_string()));
m.insert("Picasso".to_string(), Value::Str("PICA".to_string()));
m.insert("Crust Shadow".to_string(), Value::Str("CSM".to_string()));
m.insert("Integritee".to_string(), Value::Str("TEER".to_string()));
m.insert("Parallel Finance".to_string(), Value::Str("PARA".to_string()));
m.insert("HydraDX".to_string(), Value::Str("HDX".to_string()));
m.insert("Interlay".to_string(), Value::Str("INTR".to_string()));
m.insert("Fetch.ai".to_string(), Value::Str("FET".to_string()));
m.insert("NYM".to_string(), Value::Str("NYM".to_string()));
m.insert("Terra 2.0".to_string(), Value::Str("LUNA2".to_string()));
m.insert("Juno".to_string(), Value::Str("JUNO".to_string()));
m.insert("Nodle".to_string(), Value::Str("NODL".to_string()));
m.insert("Stacks".to_string(), Value::Str("STX".to_string()));
m.insert("Ethereum PoW".to_string(), Value::Str("ETHW".to_string()));
m.insert("Aptos".to_string(), Value::Str("APT".to_string()));
m.insert("Sui".to_string(), Value::Str("SUI".to_string()));
m.insert("Genshiro".to_string(), Value::Str("GENS".to_string()));
m.insert("Aventus".to_string(), Value::Str("AVT".to_string()));
m.insert("Sei".to_string(), Value::Str("SEI".to_string()));
m.insert("OriginTrail".to_string(), Value::Str("OTP".to_string()));
m.insert("Celestia".to_string(), Value::Str("TIA".to_string()));
m
}));
m.insert("marketHelperProps".to_string(), Value::List(vec![Value::Str("marketsByAltname".to_string()), Value::Str("delistedMarketsById".to_string())]));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(false));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(true));
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("min".to_string(), Value::Int(2));
m.insert("max".to_string(), Value::Int(15));
m.insert("sameSymbolOnly".to_string(), Value::Bool(true));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
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::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(100000));
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("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(720));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("rollingWindowSize".to_string(), Value::Int(10000));
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("EQuery:Invalid asset pair".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("EAPI:Invalid key".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("EFunding:Unknown withdraw key".to_string(), Value::Str("InvalidAddress".to_string()).clone());
m.insert("EFunding:Invalid amount".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("EService:Unavailable".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("EDatabase:Internal error".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("EService:Busy".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("EQuery:Unknown asset".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("EAPI:Rate limit exceeded".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("EOrder:Rate limit exceeded".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("EGeneral:Internal error".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("EGeneral:Temporary lockout".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("EGeneral:Permission denied".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("EGeneral:Invalid arguments:price".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("EOrder:Unknown order".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("EOrder:Invalid price:Invalid price argument".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("EOrder:Order minimum not met".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("EOrder:Insufficient funds".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("EGeneral:Invalid arguments".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("ESession:Invalid session".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("EAPI:Invalid nonce".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("EFunding:No funding method".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("EFunding:Unknown asset".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("EService:Market in post_only mode".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("EService:Market in cancel_only mode".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("EGeneral:Too many requests".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("ETrade:User Locked".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert(":Invalid order".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert(":Invalid arguments:volume".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert(":Invalid arguments:viqc".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert(":Invalid nonce".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert(":IInsufficient funds".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert(":Cancel pending".to_string(), Value::Str("CancelPending".to_string()).clone());
m.insert(":Rate limit exceeded".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m
}));
m
}));
m
})]);
Value::Null
}
pub fn fee_to_precision(&self, mut symbol: Value, mut fee: Value) -> Value {
return self.decimal_to_precision(fee.clone(), Value::Int(crate::runtime::TRUNCATE), get_value(&get_value(&self.market(symbol.clone()), &Value::Str("precision".to_string())), &Value::Str("amount".to_string())), &[self.precisionMode.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchMarkets
* @description retrieves data on all markets for kraken
* @see https://docs.kraken.com/api-reference/market-data/get-tradable-asset-pairs
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut promises: Value = Value::List(vec![]);
append_to_array(&mut promises, self.public_get_asset_pairs(&[params.clone()]).await);
if is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
append_to_array(&mut promises, self.load_time_difference(&[]).await);
}
let mut responses: Value = promise_all(&promises).await;
let mut assetsResponse: Value = get_value(&responses, &Value::Int(0));
//
// {
// "error": [],
// "result": {
// "ADAETH": {
// "altname": "ADAETH",
// "wsname": "ADA\/ETH",
// "aclass_base": "currency",
// "base": "ADA",
// "aclass_quote": "currency",
// "quote": "XETH",
// "lot": "unit",
// "pair_decimals": 7,
// "lot_decimals": 8,
// "lot_multiplier": 1,
// "leverage_buy": [],
// "leverage_sell": [],
// "fees": [
// [0, 0.26],
// [50000, 0.24],
// [100000, 0.22],
// [250000, 0.2],
// [500000, 0.18],
// [1000000, 0.16],
// [2500000, 0.14],
// [5000000, 0.12],
// [10000000, 0.1]
// ],
// "fees_maker": [
// [0, 0.16],
// [50000, 0.14],
// [100000, 0.12],
// [250000, 0.1],
// [500000, 0.08],
// [1000000, 0.06],
// [2500000, 0.04],
// [5000000, 0.02],
// [10000000, 0]
// ],
// "fee_volume_currency": "ZUSD",
// "margin_call": 80,
// "margin_stop": 40,
// "ordermin": "1"
// },
// }
// }
//
let mut markets: Value = self.safe_dict_k(assetsResponse.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cachedCurrencies: Value = self.safe_dict_k(self.options.clone(), "cachedCurrencies", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut keys: Value = object_keys(&markets);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_837: bool = true;
while { if !__for_first_837 { i = add(&i, &Value::Int(1)); } __for_first_837 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut id: Value = get_value(&keys, &i);
let mut id: Value = get_value(&keys, &i);
let mut isSynthetic: bool = false;
if is_greater_than_or_equal(&get_index_of(&id, &Value::Str(":BTNL".to_string())), &Value::Int(0)) {
isSynthetic = true;
}
let mut market: Value = get_value(&markets, &id);
let mut market: Value = get_value(&markets, &id);
let mut baseIdRaw: Value = self.safe_string_k(market.clone(), "base", &[]);
let mut quoteIdRaw: Value = self.safe_string_k(market.clone(), "quote", &[]);
let mut baseId: Value = self.safe_currency_code(baseIdRaw.clone(), &[]);
let mut quoteId: Value = self.safe_currency_code(quoteIdRaw.clone(), &[]);
let mut base: Value = baseId.clone();
let mut quote: Value = quoteId.clone();
let mut makerFees: Value = self.safe_list_k(market.clone(), "fees_maker", &[Value::List(vec![])]);
let mut firstMakerFee: Value = self.safe_list(makerFees.clone(), Value::Int(0), &[Value::List(vec![])]);
let mut firstMakerFeeRate: Value = self.safe_string(firstMakerFee.clone(), Value::Int(1), &[]);
let mut maker: Value = Value::Null;
if !is_equal(&firstMakerFeeRate, &Value::Null) {
maker = self.parse_number(crate::precise::Precise::stringDiv(&firstMakerFeeRate, &Value::Str("100".to_string())), &[]);
}
let mut takerFees: Value = self.safe_list_k(market.clone(), "fees", &[Value::List(vec![])]);
let mut firstTakerFee: Value = self.safe_list(takerFees.clone(), Value::Int(0), &[Value::List(vec![])]);
let mut firstTakerFeeRate: Value = self.safe_string(firstTakerFee.clone(), Value::Int(1), &[]);
let mut taker: Value = Value::Null;
if !is_equal(&firstTakerFeeRate, &Value::Null) {
taker = self.parse_number(crate::precise::Precise::stringDiv(&firstTakerFeeRate, &Value::Str("100".to_string())), &[]);
}
let mut leverageBuy: Value = self.safe_list_k(market.clone(), "leverage_buy", &[Value::List(vec![])]);
let mut leverageBuyLength: Value = get_array_length(&leverageBuy);
let mut precisionPrice: Value = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "pair_decimals", &[])]), &[]);
let mut precisionAmount: Value = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "lot_decimals", &[])]), &[]);
let mut spot: Value = Value::Bool(true);
// fix https://github.com/freqtrade/freqtrade/issues/11765#issuecomment-2894224103
if is_equal(&base, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing base".to_string()))));
}
if is_true(&spot) && is_true(&(Value::Bool(in_op(&cachedCurrencies, &base)))) {
let mut currency: Value = self.safe_value(cachedCurrencies.clone(), base.clone(), &[]);
let mut currencyPrecision: Value = self.safe_number_k(currency.clone(), "precision", &[]);
// if currency precision is greater (e.g. 0.01) than market precision (e.g. 0.001)
if is_equal(¤cyPrecision, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing currencyPrecision".to_string()))));
}
if is_greater_than(¤cyPrecision, &precisionAmount) {
precisionAmount = currencyPrecision.clone();
}
}
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut isActive: Value = Value::Bool(is_equal(&status, &Value::Str("online".to_string())));
let mut symbol: Value = ternary(is_true(&(!is_true(&isSynthetic))), (add(&add(&base, &Value::Str("/".to_string())), "e)), id.clone());
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("wsId".to_string(), self.safe_string_k(market.clone(), "wsname", &[]));
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(), 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("altname".to_string(), get_value(&market, &Value::Str("altname".to_string())));
m.insert("type".to_string(), Value::Str("spot".to_string()));
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), Value::Bool((is_greater_than(&leverageBuyLength, &Value::Int(0)))));
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(), isActive.clone());
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("taker".to_string(), taker.clone());
m.insert("maker".to_string(), maker.clone());
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(), precisionAmount.clone());
m.insert("price".to_string(), precisionPrice.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(leverageBuy.clone(), subtract(&leverageBuyLength, &Value::Int(1)), &[Value::Int(1)]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "ordermin", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "costmin", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
}));
}
}
{ let __be_tmp = self.index_by(result.clone(), Value::Str("altname".to_string())); add_element_to_object(&mut self.options, &Value::Str("marketsByAltname".to_string()), __be_tmp); };
return result;
Value::Null
}
/*
* @method
* @name kraken#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://docs.kraken.com/api-reference/market-data/get-system-status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_system_status(&[params.clone()]).await;
//
// {
// error: [],
// result: { status: 'online', timestamp: '2024-07-22T16:34:44Z' }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
let mut statusRaw: Value = self.safe_string_k(result.clone(), "status", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), ternary(is_true(&(is_equal(&statusRaw, &Value::Str("online".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 kraken#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://docs.kraken.com/api-reference/market-data/get-asset-info
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_assets(&[params.clone()]).await;
//
// {
// "error": [],
// "result": {
// "ATOM": {
// "aclass": "currency",
// "altname": "ATOM",
// "collateral_value": "0.7",
// "decimals": 8,
// "display_decimals": 6,
// "margin_rate": 0.02,
// "status": "enabled",
// },
// "ATOM.S": {
// "aclass": "currency",
// "altname": "ATOM.S",
// "decimals": 8,
// "display_decimals": 6,
// "status": "enabled",
// },
// "XXBT": {
// "aclass": "currency",
// "altname": "XBT",
// "decimals": 10,
// "display_decimals": 5,
// "margin_rate": 0.01,
// "status": "enabled",
// },
// "XETH": {
// "aclass": "currency",
// "altname": "ETH",
// "decimals": 10,
// "display_decimals": 5
// "margin_rate": 0.02,
// "status": "enabled",
// },
// "XBT.M": {
// "aclass": "currency",
// "altname": "XBT.M",
// "decimals": 10,
// "display_decimals": 5
// "status": "enabled",
// },
// "ETH.M": {
// "aclass": "currency",
// "altname": "ETH.M",
// "decimals": 10,
// "display_decimals": 5
// "status": "enabled",
// },
// ...
// },
// }
//
let mut currencies: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut enhancedArray: Value = self.add_key_in_array_items(currencies.clone(), Value::Str("_coin_id".to_string()));
return self.parse_currencies(enhancedArray.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
// todo: will need to rethink the fees
// see: https://support.kraken.com/hc/en-us/articles/201893608-What-are-the-withdrawal-fees-
// to add support for multiple withdrawal/deposit methods and
// differentiated fees for each particular method
//
// Notes about abbreviations:
// Z and X prefixes: https://support.kraken.com/hc/en-us/articles/360001206766-Bitcoin-currency-code-XBT-vs-BTC
// S and M suffixes: https://support.kraken.com/hc/en-us/articles/360039879471-What-is-Asset-S-and-Asset-M-
//
let mut id: Value = self.safe_string_k(rawCurrency.clone(), "_coin_id", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
// the below cannot be reliably done in `safeCurrencyCode`, so we have to do it here
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseCurrency() missing id".to_string()))));
}
if is_less_than(&get_index_of(&id, &Value::Str(".".to_string())), &Value::Int(0)) {
let mut altName: Value = self.safe_string_k(rawCurrency.clone(), "altname", &[]);
// handle cases like below:
//
// id | altname
// ---------------
// XXBT | XBT
// ZUSD | USD
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseCurrency() missing id".to_string()))));
}
if !is_equal(&id, &altName) && is_true(&(is_true(&Value::Bool(starts_with(&id, &Value::Str("X".to_string())))) || is_true(&Value::Bool(starts_with(&id, &Value::Str("Z".to_string())))))) {
code = self.safe_currency_code(altName.clone(), &[]);
// also, add map in commonCurrencies:
if is_true(&(!is_equal(&id, &Value::Null))) && is_true(&(!is_equal(&code, &Value::Null))) {
add_element_to_object(&mut self.commonCurrencies.clone(), &id, code.clone());
}
} else {
code = self.safe_currency_code(id.clone(), &[]);
}
}
if is_equal(&code, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseCurrency() missing code".to_string()))));
}
let mut isFiat: bool = is_greater_than_or_equal(&get_index_of(&code, &Value::Str(".HOLD".to_string())), &Value::Int(0));
rawCurrency = self.omit(rawCurrency.clone(), Value::Str("_coin_id".to_string()), &[]);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("code".to_string(), code.clone());
m.insert("info".to_string(), rawCurrency.clone());
m.insert("name".to_string(), self.safe_string_k(rawCurrency.clone(), "altname", &[]));
m.insert("active".to_string(), Value::Bool(is_equal(&self.safe_string_k(rawCurrency.clone(), "status", &[]), &Value::Str("enabled".to_string()))));
m.insert("type".to_string(), ternary(is_true(&isFiat), Value::Str("fiat".to_string()), Value::Str("crypto".to_string())));
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(rawCurrency.clone(), "decimals", &[])]), &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
Value::Null
}
pub fn safe_currency_code(&self, mut currencyId: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
if is_equal(¤cyId, &Value::Null) {
return currencyId;
}
if is_greater_than(&get_index_of(¤cyId, &Value::Str(".".to_string())), &Value::Int(0)) {
// if ID contains .M, .S or .F, then it can't contain X or Z prefix. in such case, ID equals to ALTNAME
let mut parts: Value = split(¤cyId, &Value::Str(".".to_string()));
let mut firstPart: Value = self.safe_string(parts.clone(), Value::Int(0), &[]);
let mut secondPart: Value = self.safe_string(parts.clone(), Value::Int(1), &[]);
return add(&add(&self.super_safe_currency_code(firstPart.clone(), currency.clone()), &Value::Str(".".to_string())), &secondPart);
}
return self.super_safe_currency_code(currencyId.clone(), currency.clone());
Value::Null
}
/*
* @method
* @name kraken#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://docs.kraken.com/api-reference/account-data/get-trade-volume
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_trading_fee(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("fee-info".to_string(), Value::Bool(true));
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_trade_volume(&[__ws_arg_0]).await;
//
// {
// "error": [],
// "result": {
// "currency": 'ZUSD',
// "volume": '0.0000',
// "fees": {
// "XXBTZUSD": {
// "fee": '0.2600',
// "minfee": '0.1000',
// "maxfee": '0.2600',
// "nextfee": '0.2400',
// "tiervolume": '0.0000',
// "nextvolume": '50000.0000'
// }
// },
// "fees_maker": {
// "XXBTZUSD": {
// "fee": '0.1600',
// "minfee": '0.0000',
// "maxfee": '0.1600',
// "nextfee": '0.1400',
// "tiervolume": '0.0000',
// "nextvolume": '50000.0000'
// }
// }
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(result.clone(), market.clone());
Value::Null
}
pub fn parse_trading_fee(&self, mut response: Value, mut market: Value) -> Value {
let mut makerFees: Value = self.safe_value_k(response.clone(), "fees_maker", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut takerFees: Value = self.safe_value_k(response.clone(), "fees", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut symbolMakerFee: Value = self.safe_value(makerFees.clone(), get_value(&market, &Value::Str("id".to_string())), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut symbolTakerFee: Value = self.safe_value(takerFees.clone(), get_value(&market, &Value::Str("id".to_string())), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
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("maker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string_k(symbolMakerFee.clone(), "fee", &[]), &Value::Str("100".to_string())), &[]));
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&self.safe_string_k(symbolTakerFee.clone(), "fee", &[]), &Value::Str("100".to_string())), &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
pub fn parse_order_book_bid_ask(&self, mut bidask: Value, optional_args: &[Value]) -> Value {
let mut priceKey = get_arg(optional_args, 0, Value::Int(0));
let mut amountKey = get_arg(optional_args, 1, Value::Int(1));
let mut countOrIdKey = get_arg(optional_args, 2, Value::Int(2));
let mut price: Value = self.safe_number(bidask.clone(), priceKey.clone(), &[]);
let mut amount: Value = self.safe_number(bidask.clone(), amountKey.clone(), &[]);
let mut timestamp: Value = self.safe_integer(bidask.clone(), Value::Int(2), &[]);
return Value::List(vec![price.clone(), amount.clone(), timestamp.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.kraken.com/api-reference/market-data/get-order-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("count".to_string()), limit.clone()); // 100
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_depth(&[__ws_arg_1]).await;
//
// {
// "error":[],
// "result":{
// "XETHXXBT":{
// "asks":[
// ["0.023480","4.000",1586321307],
// ["0.023490","50.095",1586321306],
// ["0.023500","28.535",1586321302],
// ],
// "bids":[
// ["0.023470","59.580",1586321307],
// ["0.023460","20.000",1586321301],
// ["0.023440","67.832",1586321306],
// ]
// }
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderbook: Value = self.safe_value(result.clone(), get_value(&market, &Value::Str("id".to_string())), &[]);
// sometimes kraken returns wsname instead of market id
// https://github.com/ccxt/ccxt/issues/8662
let mut marketInfo: Value = self.safe_value_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut wsName: Value = self.safe_value_k(marketInfo.clone(), "wsname", &[]);
if !is_equal(&wsName, &Value::Null) {
orderbook = self.safe_value(result.clone(), wsName.clone(), &[orderbook.clone()]);
}
return self.parse_order_book(orderbook.clone(), symbol.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);
//
// {
// "a":["2432.77000","1","1.000"],
// "b":["2431.37000","2","2.000"],
// "c":["2430.58000","0.04408910"],
// "v":["4147.94474901","8896.96086304"],
// "p":["2456.22239","2568.63032"],
// "t":[3907,10056],
// "l":["2302.18000","2302.18000"],
// "h":["2621.14000","2860.01000"],
// "o":"2571.56000"
// }
//
let mut symbol: Value = self.safe_symbol(Value::Null, &[market.clone()]);
let mut v: Value = self.safe_value_k(ticker.clone(), "v", &[Value::List(vec![])]);
let mut baseVolume: Value = self.safe_string(v.clone(), Value::Int(1), &[]);
let mut p: Value = self.safe_value_k(ticker.clone(), "p", &[Value::List(vec![])]);
let mut vwap: Value = self.safe_string(p.clone(), Value::Int(1), &[]);
let mut quoteVolume: Value = crate::precise::Precise::stringMul(&baseVolume, &vwap);
let mut c: Value = self.safe_value_k(ticker.clone(), "c", &[Value::List(vec![])]);
let mut last: Value = self.safe_string(c.clone(), Value::Int(0), &[]);
let mut high: Value = self.safe_value_k(ticker.clone(), "h", &[Value::List(vec![])]);
let mut low: Value = self.safe_value_k(ticker.clone(), "l", &[Value::List(vec![])]);
let mut bid: Value = self.safe_value_k(ticker.clone(), "b", &[Value::List(vec![])]);
let mut ask: Value = self.safe_value_k(ticker.clone(), "a", &[Value::List(vec![])]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), self.safe_string(high.clone(), Value::Int(1), &[]));
m.insert("low".to_string(), self.safe_string(low.clone(), Value::Int(1), &[]));
m.insert("bid".to_string(), self.safe_string(bid.clone(), Value::Int(0), &[]));
m.insert("bidVolume".to_string(), self.safe_string(bid.clone(), Value::Int(2), &[]));
m.insert("ask".to_string(), self.safe_string(ask.clone(), Value::Int(0), &[]));
m.insert("askVolume".to_string(), self.safe_string(ask.clone(), Value::Int(2), &[]));
m.insert("vwap".to_string(), vwap.clone());
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "o", &[]));
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://docs.kraken.com/api-reference/market-data/get-ticker-information
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
let mut marketIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_838: bool = true;
while { if !__for_first_838 { i = add(&i, &Value::Int(1)); } __for_first_838 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("active".to_string())), &Value::Bool(true)) {
append_to_array(&mut marketIds, get_value(&market, &Value::Str("id".to_string())));
}
}
}
add_element_to_object(&mut request, &Value::Str("pair".to_string()), join(&marketIds, &Value::Str(",".to_string())));
}
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_ticker(&[__ws_arg_2]).await;
let mut tickers: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ids: Value = object_keys(&tickers);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_839: bool = true;
while { if !__for_first_839 { i = add(&i, &Value::Int(1)); } __for_first_839 = false; is_less_than(&i, &get_array_length(&ids)) } {
let mut id: Value = get_value(&ids, &i);
let mut id: Value = get_value(&ids, &i);
let mut market: Value = self.safe_market(&[id.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut ticker: Value = get_value(&tickers, &id);
let mut ticker: Value = get_value(&tickers, &id);
add_element_to_object(&mut result, &symbol, self.parse_ticker(ticker.clone(), &[market.clone()]));
}
}
return self.filter_by_array_tickers(result.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://docs.kraken.com/api-reference/market-data/get-ticker-information
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_ticker(&[__ws_arg_3]).await;
let mut tickerResult: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ticker: Value = self.safe_value(tickerResult.clone(), get_value(&market, &Value::Str("id".to_string())), &[]);
return self.parse_ticker(ticker.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);
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(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(6), &[])]);
Value::Null
}
/*
* @method
* @name kraken#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://docs.kraken.com/api-reference/market-data/get-ohlc-data
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(720)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut parsedTimeframe: Value = self.safe_integer(self.timeframes.clone(), timeframe.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&parsedTimeframe, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("interval".to_string()), parsedTimeframe.clone());
} else {
add_element_to_object(&mut request, &Value::Str("interval".to_string()), timeframe.clone());
}
if !is_equal(&since, &Value::Null) {
let mut scaledSince: Value = self.parse_to_int(divide(&since, &Value::Int(1000)));
if is_equal(&parsedTimeframe, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchOHLCV() missing parsedTimeframe".to_string()))));
}
let mut timeFrameInSeconds: Value = multiply(&parsedTimeframe, &Value::Int(60));
add_element_to_object(&mut request, &Value::Str("since".to_string()), self.number_to_string(subtract(&scaledSince, &timeFrameInSeconds))); // expected to be in seconds
}
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_ohlc(&[__ws_arg_4]).await;
//
// {
// "error":[],
// "result":{
// "XETHXXBT":[
// [1591475580,"0.02499","0.02499","0.02499","0.02499","0.00000","0.00000000",0],
// [1591475640,"0.02500","0.02500","0.02500","0.02500","0.02500","9.12201000",5],
// [1591475700,"0.02499","0.02499","0.02499","0.02499","0.02499","1.28681415",2],
// [1591475760,"0.02499","0.02499","0.02499","0.02499","0.02499","0.08800000",1],
// ],
// "last":1591517580
// }
// }
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ohlcvs: Value = self.safe_list(result.clone(), get_value(&market, &Value::Str("id".to_string())), &[Value::List(vec![])]);
return self.parse_ohlc_vs(ohlcvs.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade".to_string(), Value::Str("trade".to_string()));
m.insert("withdrawal".to_string(), Value::Str("transaction".to_string()));
m.insert("deposit".to_string(), Value::Str("transaction".to_string()));
m.insert("transfer".to_string(), Value::Str("transfer".to_string()));
m.insert("margin".to_string(), Value::Str("margin".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// 'LTFK7F-N2CUX-PNY4SX': {
// "refid": "TSJTGT-DT7WN-GPPQMJ",
// "time": 1520102320.555,
// "type": "trade",
// "aclass": "currency",
// "asset": "XETH",
// "amount": "0.1087194600",
// "fee": "0.0000000000",
// "balance": "0.2855851000"
// },
// ...
// }
//
let mut id: Value = self.safe_string_k(item.clone(), "id", &[]);
let mut direction: Value = Value::Null;
let mut account: Value = Value::Null;
let mut referenceId: Value = self.safe_string_k(item.clone(), "refid", &[]);
let mut referenceAccount: Value = Value::Null;
let mut type_var: Value = self.parse_ledger_entry_type(self.safe_string_k(item.clone(), "type", &[]));
let mut currencyId: Value = self.safe_string_k(item.clone(), "asset", &[]);
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", &[]);
if is_true(&crate::precise::Precise::stringLt(&amount, &Value::Str("0".to_string()))) {
direction = Value::Str("out".to_string());
amount = crate::precise::Precise::stringAbs(&amount);
} else {
direction = Value::Str("in".to_string());
}
let mut timestamp: Value = self.safe_integer_product(item.clone(), Value::Str("time".to_string()), Value::Int(1000), &[]);
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(), direction.clone());
m.insert("account".to_string(), account.clone());
m.insert("referenceId".to_string(), referenceId.clone());
m.insert("referenceAccount".to_string(), referenceAccount.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), self.safe_number_k(item.clone(), "balance", &[]));
m.insert("status".to_string(), Value::Str("ok".to_string()));
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("cost".to_string(), self.safe_number_k(item.clone(), "fee", &[]));
m.insert("currency".to_string(), code.clone());
m
}));
m
}), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://docs.kraken.com/api-reference/account-data/get-ledgers-info
* @param {string} [code] unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest ledger entry
* @param {int} [params.end] timestamp in seconds of the latest ledger entry
* @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
}));
// https://www.kraken.com/features/api#get-ledgers-info
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("asset".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut until: Value = self.safe_string2(params.clone(), Value::Str("until".to_string()), Value::Str("till".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string()), Value::Str("till".to_string())]), &[]);
let mut untilDivided: Value = crate::precise::Precise::stringDiv(&until, &Value::Str("1000".to_string()));
add_element_to_object(&mut request, &Value::Str("end".to_string()), self.parse_to_int(crate::precise::Precise::stringAdd(&untilDivided, &Value::Str("1".to_string()))));
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_ledgers(&[__ws_arg_5]).await;
// { error: [],
// "result": { ledger: { 'LPUAIB-TS774-UKHP7X': { refid: "A2B4HBV-L4MDIE-JU4N3N",
// "time": 1520103488.314,
// "type": "withdrawal",
// "aclass": "currency",
// "asset": "XETH",
// "amount": "-0.2805800000",
// "fee": "0.0050000000",
// "balance": "0.0000051000" },
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ledger: Value = self.safe_value_k(result.clone(), "ledger", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut keys: Value = object_keys(&ledger);
let mut items: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_840: bool = true;
while { if !__for_first_840 { i = add(&i, &Value::Int(1)); } __for_first_840 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
let mut value: Value = get_value(&ledger, &key);
add_element_to_object(&mut value, &Value::Str("id".to_string()), key.clone());
crate::set_value(&mut ledger, &key, value.clone());
append_to_array(&mut items, value.clone());
}
}
return self.parse_ledger(items.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub async fn fetch_ledger_entries_by_ids(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// https://www.kraken.com/features/api#query-ledgers
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
ids = join(&ids, &Value::Str(",".to_string()));
let mut request: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), ids.clone());
m
}), &[params.clone()]);
let mut response: Value = self.private_post_query_ledgers(&[request.clone()]).await;
// { error: [],
// "result": { 'LPUAIB-TS774-UKHP7X': { refid: "A2B4HBV-L4MDIE-JU4N3N",
// "time": 1520103488.314,
// "type": "withdrawal",
// "aclass": "currency",
// "asset": "XETH",
// "amount": "-0.2805800000",
// "fee": "0.0050000000",
// "balance": "0.0000051000" } } }
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut keys: Value = object_keys(&result);
let mut items: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_841: bool = true;
while { if !__for_first_841 { i = add(&i, &Value::Int(1)); } __for_first_841 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
let mut value: Value = get_value(&result, &key);
add_element_to_object(&mut value, &Value::Str("id".to_string()), key.clone());
crate::set_value(&mut result, &key, value.clone());
append_to_array(&mut items, value.clone());
}
}
return self.parse_ledger(items.clone(), &[]);
Value::Null
}
pub async fn fetch_ledger_entry(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut code = 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 items: Value = self.fetch_ledger_entries_by_ids(Value::List(vec![id.clone()]), &[code.clone(), params.clone()]).await;
return get_value(&items, &Value::Int(0));
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades (public)
//
// [
// "0.032310", // price
// "4.28169434", // amount
// 1541390792.763, // timestamp
// "s", // sell or buy
// "l", // limit or market
// ""
// ]
//
// fetchOrderTrades (private)
//
// {
// "id": 'TIMIRG-WUNNE-RRJ6GT', // injected from outside
// "ordertxid": 'OQRPN2-LRHFY-HIFA7D',
// "postxid": 'TKH2SE-M7IF5-CFI7LT',
// "pair": 'USDCUSDT',
// "time": 1586340086.457,
// "type": 'sell',
// "ordertype": 'market',
// "price": '0.99860000',
// "cost": '22.16892001',
// "fee": '0.04433784',
// "vol": '22.20000000',
// "margin": '0.00000000',
// "misc": ''
// }
//
// fetchMyTrades
//
// {
// "ordertxid": "OSJVN7-A2AE-63WZV",
// "postxid": "TBP7O6-PNXI-CONU",
// "pair": "XXBTZUSD",
// "time": 1710429248.3052235,
// "type": "sell",
// "ordertype": "liquidation market",
// "price": "72026.50000",
// "cost": "7.20265",
// "fee": "0.01873",
// "vol": "0.00010000",
// "margin": "1.44053",
// "leverage": "5",
// "misc": "closing",
// "trade_id": 68230622,
// "maker": false
// }
//
// watchTrades
//
// {
// "symbol": "BTC/USD",
// "side": "buy",
// "price": 109601.2,
// "qty": 0.04561994,
// "ord_type": "market",
// "trade_id": 83449369,
// "timestamp": "2025-05-27T11:24:03.847761Z"
// }
//
let mut timestamp: Value = Value::Null;
let mut datetime: Value = Value::Null;
let mut side: Value = Value::Null;
let mut type_var: Value = Value::Null;
let mut price: Value = Value::Null;
let mut amount: Value = Value::Null;
let mut id: Value = Value::Null;
let mut orderId: Value = Value::Null;
let mut fee: Value = Value::Null;
let mut symbol: Value = Value::Null;
if is_true(&Value::Bool(is_array(&trade))) {
timestamp = self.safe_timestamp(trade.clone(), Value::Int(2), &[]);
side = ternary(is_true(&(is_equal(&get_value(&trade, &Value::Int(3)), &Value::Str("s".to_string())))), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
type_var = ternary(is_true(&(is_equal(&get_value(&trade, &Value::Int(4)), &Value::Str("l".to_string())))), Value::Str("limit".to_string()), Value::Str("market".to_string()));
price = self.safe_string(trade.clone(), Value::Int(0), &[]);
amount = self.safe_string(trade.clone(), Value::Int(1), &[]);
let mut tradeLength: Value = get_array_length(&trade);
if is_greater_than(&tradeLength, &Value::Int(6)) {
id = self.safe_string(trade.clone(), Value::Int(6), &[]); // artificially added as per #1794
}
} else if is_string(&trade) {
id = trade.clone();
} else if is_true(&Value::Bool(in_op(&trade, &Value::Str("ordertxid".to_string())))) {
let mut marketId: Value = self.safe_string_k(trade.clone(), "pair", &[]);
let mut foundMarket: Value = self.find_market_by_altname_or_id(marketId.clone());
if !is_equal(&foundMarket, &Value::Null) {
market = foundMarket.clone();
} else if !is_equal(&marketId, &Value::Null) {
// delisted market ids go here
market = self.get_delisted_market_by_id(marketId.clone());
}
orderId = self.safe_string_k(trade.clone(), "ordertxid", &[]);
id = self.safe_string2(trade.clone(), Value::Str("id".to_string()), Value::Str("postxid".to_string()), &[]);
timestamp = self.safe_timestamp(trade.clone(), Value::Str("time".to_string()), &[]);
side = self.safe_string_k(trade.clone(), "type", &[]);
type_var = self.safe_string_k(trade.clone(), "ordertype", &[]);
price = self.safe_string_k(trade.clone(), "price", &[]);
amount = self.safe_string_k(trade.clone(), "vol", &[]);
if is_true(&Value::Bool(in_op(&trade, &Value::Str("fee".to_string())))) {
let mut currency: Value = Value::Null;
if !is_equal(&market, &Value::Null) {
currency = get_value(&market, &Value::Str("quote".to_string()));
}
fee = 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(), currency.clone());
m
});
}
} else {
symbol = self.safe_string_k(trade.clone(), "symbol", &[]);
datetime = self.safe_string_k(trade.clone(), "timestamp", &[]);
id = self.safe_string_k(trade.clone(), "trade_id", &[]);
side = self.safe_string_k(trade.clone(), "side", &[]);
type_var = self.safe_string_k(trade.clone(), "ord_type", &[]);
price = self.safe_string_k(trade.clone(), "price", &[]);
amount = self.safe_string_k(trade.clone(), "qty", &[]);
}
if !is_equal(&market, &Value::Null) {
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
let mut cost: Value = self.safe_string_k(trade.clone(), "cost", &[]);
let mut maker: Value = self.safe_bool_k(trade.clone(), "maker", &[]);
let mut takerOrMaker: Value = Value::Null;
if !is_equal(&maker, &Value::Null) {
takerOrMaker = ternary(is_true(&maker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
if is_equal(&datetime, &Value::Null) {
datetime = self.iso8601(timestamp.clone());
} else {
timestamp = self.parse8601(datetime.clone());
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("order".to_string(), orderId.clone());
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), price.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://docs.kraken.com/api-reference/market-data/get-recent-trades
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::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 id: Value = get_value(&market, &Value::Str("id".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pair".to_string(), id.clone());
m
});
// https://support.kraken.com/hc/en-us/articles/218198197-How-to-pull-all-trade-data-using-the-Kraken-REST-API
// https://github.com/ccxt/ccxt/issues/5677
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("since".to_string()), self.number_to_string(self.parse_to_int(divide(&since, &Value::Int(1000))))); // expected to be in seconds
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("count".to_string()), limit.clone());
}
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_trades(&[__ws_arg_6]).await;
//
// {
// "error": [],
// "result": {
// "XETHXXBT": [
// ["0.032310","4.28169434",1541390792.763,"s","l",""]
// ],
// "last": "1541439421200678657"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_value(result.clone(), id.clone(), &[]);
// trades is a sorted array: last (most recent trade) goes last
let mut length: Value = get_array_length(&trades);
if is_less_than_or_equal(&length, &Value::Int(0)) {
return Value::List(vec![]);
}
let mut lastTrade: Value = get_value(&trades, &subtract(&length, &Value::Int(1)));
let mut lastTradeId: Value = self.safe_string_k(result.clone(), "last", &[]);
append_to_array(&mut lastTrade, lastTradeId.clone());
add_element_to_object(&mut trades, &subtract(&length, &Value::Int(1)), lastTrade.clone());
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut balances: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
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 currencyIds: Value = object_keys(&balances);
{
let mut i: Value = Value::Int(0);
let mut __for_first_842: bool = true;
while { if !__for_first_842 { i = add(&i, &Value::Int(1)); } __for_first_842 = false; is_less_than(&i, &get_array_length(¤cyIds)) } {
let mut currencyId: Value = get_value(¤cyIds, &i);
let mut currencyId: Value = get_value(¤cyIds, &i);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut balance: Value = self.safe_value(balances.clone(), currencyId.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "hold_trade", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "balance", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name kraken#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.kraken.com/api-reference/account-data/get-extended-balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 response: Value = self.private_post_balance_ex(&[params.clone()]).await;
return self.parse_balance(response.clone());
Value::Null
}
/*
* @method
* @name kraken#createMarketOrderWithCost
* @description create a market order by providing the symbol, side and cost
* @see https://docs.kraken.com/api-reference/trading/add-order
* @param {string} symbol unified symbol of the market to create an order in (only USD markets are supported)
* @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;
}
// only buy orders are supported by the endpoint
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), cost.clone());
m
});
let __ws_arg_7 = 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_7]).await;
Value::Null
}
/*
* @method
* @name kraken#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol, side and cost
* @see https://docs.kraken.com/api-reference/trading/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 kraken#createOrder
* @description create a trade order
* @see https://docs.kraken.com/api-reference/trading/add-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
* @param {bool} [params.reduceOnly] *margin only* indicates if this order is to reduce the size of a position
* @param {float} [params.stopLossPrice] *margin only* the price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] *margin only* the price that a take profit order is triggered at
* @param {string} [params.trailingAmount] *margin only* the quote amount to trail away from the current market price
* @param {string} [params.trailingPercent] *margin only* the percent to trail away from the current market price
* @param {string} [params.trailingLimitAmount] *margin only* the quote amount away from the trailingAmount
* @param {string} [params.trailingLimitPercent] *margin only* the percent away from the trailingAmount
* @param {string} [params.offset] *margin only* '+' or '-' whether you want the trailingLimitAmount value to be positive or negative, default is negative '-'
* @param {string} [params.trigger] *margin only* the activation price type, 'last' or 'index', default is 'last'
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pair".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("type".to_string(), side.clone());
m.insert("ordertype".to_string(), type_var.clone());
m.insert("volume".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
let mut orderRequest: Value = self.order_request(Value::Str("createOrder".to_string()), symbol.clone(), type_var.clone(), request.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut flags: Value = self.safe_string(get_value(&orderRequest, &Value::Int(0)), Value::Str("oflags".to_string()), &[Value::Str("".to_string())]);
let mut isUsingCost: Value = Value::Bool(is_greater_than(&get_index_of(&flags, &Value::Str("viqc".to_string())), &negate(&Value::Int(1))));
let __ws_arg_8 = self.extend(get_value(&orderRequest, &Value::Int(0)), &[get_value(&orderRequest, &Value::Int(1))]);
let mut response: Value = self.private_post_add_order(&[__ws_arg_8]).await;
//
// {
// "error": [],
// "result": {
// "descr": { order: 'buy 0.02100000 ETHUSDT @ limit 330.00' }, // see more examples in "parseOrder"
// "txid": [ 'OEKVV2-IH52O-TPL6GZ' ]
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
add_element_to_object(&mut result, &Value::Str("usingCost".to_string()), isUsingCost.clone());
return self.parse_order(result.clone(), &[]);
Value::Null
}
/*
* @method
* @name kraken#createOrders
* @description create a list of trade orders
* @see https://docs.kraken.com/api-reference/trading/add-order-batch
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut orderSymbols: Value = Value::List(vec![]);
let mut symbol: Value = Value::Null;
let mut market: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_843: bool = true;
while { if !__for_first_843 { i = add(&i, &Value::Int(1)); } __for_first_843 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
if is_equal(&symbol, &Value::Null) {
symbol = marketId.clone();
} else {
if !is_equal(&symbol, &marketId) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrders() requires all orders to have the same symbol".to_string()))));
}
}
market = self.market(marketId.clone());
append_to_array(&mut orderSymbols, marketId.clone());
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut parsedAmount: Value = self.amount_to_precision(get_value(&market, &Value::Str("symbol".to_string())), amount.clone());
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), side.clone());
m.insert("ordertype".to_string(), type_var.clone());
m.insert("volume".to_string(), parsedAmount.clone());
m
});
let mut orderRequest: Value = self.order_request(Value::Str("createOrders".to_string()), marketId.clone(), type_var.clone(), req.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, get_value(&orderRequest, &Value::Int(0)));
}
}
orderSymbols = self.market_symbols(&[orderSymbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut response: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), ordersRequests.clone());
m.insert("pair".to_string(), self.safe_string_k(market.clone(), "id", &[]));
m
});
request = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_add_order_batch(&[request.clone()]).await;
//
// {
// "error":[
// ],
// "result":{
// "orders":[
// {
// "txid":"OEPPJX-34RMM-OROGZE",
// "descr":{
// "order":"sell 6.000000 ADAUSDC @ limit 0.400000"
// }
// },
// {
// "txid":"OLQY7O-OYBXW-W23PGL",
// "descr":{
// "order":"sell 6.000000 ADAUSDC @ limit 0.400000"
// }
// }
// ]
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_orders(self.safe_list_k(result.clone(), "orders", &[]), &[]);
Value::Null
}
pub fn find_market_by_altname_or_id(&self, mut id: Value) -> Value {
let mut marketsByAltname: Value = self.safe_value_k(self.options.clone(), "marketsByAltname", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&Value::Bool(in_op(&marketsByAltname, &id))) {
return get_value(&marketsByAltname, &id);
} else {
return self.safe_market(&[id.clone()]);
}
Value::Null
}
pub fn get_delisted_market_by_id(&self, mut id: Value) -> Value {
if is_equal(&id, &Value::Null) {
return id;
}
let mut market: Value = self.safe_value(get_value(&self.options, &Value::Str("delistedMarketsById".to_string())), id.clone(), &[]);
if !is_equal(&market, &Value::Null) {
return market;
}
let mut baseIdStart: Value = Value::Int(0);
let mut baseIdEnd: Value = Value::Int(3);
let mut quoteIdStart: Value = Value::Int(3);
let mut quoteIdEnd: Value = Value::Int(6);
if is_equal(&get_array_length(&id), &Value::Int(8)) {
baseIdEnd = Value::Int(4);
quoteIdStart = Value::Int(4);
quoteIdEnd = Value::Int(8);
} else if is_equal(&get_array_length(&id), &Value::Int(7)) {
baseIdEnd = Value::Int(4);
quoteIdStart = Value::Int(4);
quoteIdEnd = Value::Int(7);
}
let mut baseId: Value = slice(&id, &baseIdStart, &baseIdEnd);
let mut quoteId: Value = slice(&id, "eIdStart, "eIdEnd);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
market = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m
});
add_element_to_object(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("delistedMarketsById".to_string())), &id, market.clone());
return market;
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("pending".to_string(), Value::Str("open".to_string()));
m.insert("open".to_string(), Value::Str("open".to_string()));
m.insert("pending_new".to_string(), Value::Str("open".to_string()));
m.insert("new".to_string(), Value::Str("open".to_string()));
m.insert("partially_filled".to_string(), Value::Str("open".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("closed".to_string(), Value::Str("closed".to_string()));
m.insert("canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("expired".to_string(), Value::Str("expired".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order_type(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("take-profit".to_string(), Value::Str("market".to_string()));
m.insert("stop-loss".to_string(), Value::Str("market".to_string()));
m.insert("stop-loss-limit".to_string(), Value::Str("limit".to_string()));
m.insert("take-profit-limit".to_string(), Value::Str("limit".to_string()));
m.insert("trailing-stop-limit".to_string(), Value::Str("limit".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder
//
// {
// "descr": {
// "order": "buy 0.02100000 ETHUSDT @ limit 330.00" // limit orders
// "buy 0.12345678 ETHUSDT @ market" // market order
// "sell 0.28002676 ETHUSDT @ stop loss 0.0123 -> limit 0.0.1222" // stop order
// "sell 0.00100000 ETHUSDT @ stop loss 2677.00 -> limit 2577.00 with 5:1 leverage"
// "buy 0.10000000 LTCUSDT @ take profit 75.00000 -> limit 74.00000"
// "sell 10.00000000 XRPEUR @ trailing stop +50.0000%" // trailing stop
// },
// "txid": [ 'OEKVV2-IH52O-TPL6GZ' ]
// }
//
// editOrder
//
// {
// "amend_id": "TJSMEH-AA67V-YUSQ6O"
// }
//
// ws - createOrder
// {
// "order_id": "OXM2QD-EALR2-YBAVEU"
// }
//
// ws - editOrder
// {
// "amend_id": "TJSMEH-AA67V-YUSQ6O",
// "order_id": "OXM2QD-EALR2-YBAVEU"
// }
//
// {
// "error": [],
// "result": {
// "open": {
// "OXVPSU-Q726F-L3SDEP": {
// "refid": null,
// "userref": 0,
// "status": "open",
// "opentm": 1706893367.4656649,
// "starttm": 0,
// "expiretm": 0,
// "descr": {
// "pair": "XRPEUR",
// "type": "sell",
// "ordertype": "trailing-stop",
// "price": "+50.0000%",
// "price2": "0",
// "leverage": "none",
// "order": "sell 10.00000000 XRPEUR @ trailing stop +50.0000%",
// "close": ""
// },
// "vol": "10.00000000",
// "vol_exec": "0.00000000",
// "cost": "0.00000000",
// "fee": "0.00000000",
// "price": "0.00000000",
// "stopprice": "0.23424000",
// "limitprice": "0.46847000",
// "misc": "",
// "oflags": "fciq",
// "trigger": "index"
// }
// }
// }
//
// fetchOpenOrders
//
// {
// "refid": null,
// "userref": null,
// "cl_ord_id": "1234",
// "status": "open",
// "opentm": 1733815269.370054,
// "starttm": 0,
// "expiretm": 0,
// "descr": {
// "pair": "XBTUSD",
// "type": "buy",
// "ordertype": "limit",
// "price": "70000.0",
// "price2": "0",
// "leverage": "none",
// "order": "buy 0.00010000 XBTUSD @ limit 70000.0",
// "close": ""
// },
// "vol": "0.00010000",
// "vol_exec": "0.00000000",
// "cost": "0.00000",
// "fee": "0.00000",
// "price": "0.00000",
// "stopprice": "0.00000",
// "limitprice": "0.00000",
// "misc": "",
// "oflags": "fciq"
// }
//
let mut isUsingCost: Value = self.safe_bool_k(order.clone(), "usingCost", &[Value::Bool(false)]);
order = self.omit(order.clone(), Value::Str("usingCost".to_string()), &[]);
let mut description: Value = self.safe_dict_k(order.clone(), "descr", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderDescriptionObj: Value = self.safe_dict_k(order.clone(), "descr", &[]); // can be null
let mut orderDescription: Value = Value::Null;
if !is_equal(&orderDescriptionObj, &Value::Null) {
orderDescription = self.safe_string_k(orderDescriptionObj.clone(), "order", &[]);
} else {
orderDescription = self.safe_string_k(order.clone(), "descr", &[]);
}
let mut side: Value = Value::Null;
let mut rawType: Value = Value::Null;
let mut marketId: Value = Value::Null;
let mut price: Value = Value::Null;
let mut amount: Value = Value::Null;
let mut cost: Value = Value::Null;
let mut triggerPrice: Value = Value::Null;
if !is_equal(&orderDescription, &Value::Null) {
let mut parts: Value = split(&orderDescription, &Value::Str(" ".to_string()));
side = self.safe_string(parts.clone(), Value::Int(0), &[]);
if !is_equal(&isUsingCost, &Value::Bool(true)) {
amount = self.safe_string(parts.clone(), Value::Int(1), &[]);
} else {
cost = self.safe_string(parts.clone(), Value::Int(1), &[]);
}
marketId = self.safe_string(parts.clone(), Value::Int(2), &[]);
let mut part4: Value = self.safe_string(parts.clone(), Value::Int(4), &[]);
let mut part5: Value = self.safe_string(parts.clone(), Value::Int(5), &[]);
if is_equal(&part4, &Value::Str("limit".to_string())) || is_equal(&part4, &Value::Str("market".to_string())) {
rawType = part4.clone(); // eg, limit, market
} else {
rawType = add(&add(&part4, &Value::Str(" ".to_string())), &part5); // eg. stop loss, take profit, trailing stop
}
if is_equal(&rawType, &Value::Str("stop loss".to_string())) || is_equal(&rawType, &Value::Str("take profit".to_string())) {
triggerPrice = self.safe_string(parts.clone(), Value::Int(6), &[]);
price = self.safe_string(parts.clone(), Value::Int(9), &[]);
} else if is_equal(&rawType, &Value::Str("limit".to_string())) {
price = self.safe_string(parts.clone(), Value::Int(5), &[]);
}
}
side = self.safe_string_k(description.clone(), "type", &[side.clone()]);
rawType = self.safe_string_k(description.clone(), "ordertype", &[rawType.clone()]); // orderType has dash, e.g. trailing-stop
marketId = self.safe_string_k(description.clone(), "pair", &[marketId.clone()]);
let mut foundMarket: Value = self.find_market_by_altname_or_id(marketId.clone());
let mut symbol: Value = Value::Null;
if !is_equal(&foundMarket, &Value::Null) {
market = foundMarket.clone();
} else if !is_equal(&marketId, &Value::Null) {
// delisted market ids go here
market = self.get_delisted_market_by_id(marketId.clone());
}
let mut timestamp: Value = self.safe_timestamp(order.clone(), Value::Str("opentm".to_string()), &[]);
amount = self.safe_string_k(order.clone(), "vol", &[amount.clone()]);
let mut filled: Value = self.safe_string_k(order.clone(), "vol_exec", &[]);
let mut fee: Value = Value::Null;
// kraken truncates the cost in the api response so we will ignore it and calculate it from average & filled
// const cost = this.safeString (order, 'cost');
price = self.safe_string_k(description.clone(), "price", &[price.clone()]);
// when type = trailing stop returns price = '+50.0000%'
if is_true(&(!is_equal(&price, &Value::Null))) && is_true(&(is_true(&Value::Bool(ends_with(&price, &Value::Str("%".to_string())))) || is_true(&crate::precise::Precise::stringEquals(&price, &Value::Str("0.00000".to_string()))) || is_true(&crate::precise::Precise::stringEquals(&price, &Value::Str("0".to_string()))))) {
price = Value::Null; // this is not the price we want
}
if is_equal(&price, &Value::Null) {
price = self.safe_string_k(description.clone(), "price2", &[]);
price = self.safe_string2(order.clone(), Value::Str("limitprice".to_string()), Value::Str("price".to_string()), &[price.clone()]);
}
let mut flags: Value = self.safe_string_k(order.clone(), "oflags", &[Value::Str("".to_string())]);
let mut isPostOnly: Value = Value::Bool(is_greater_than(&get_index_of(&flags, &Value::Str("post".to_string())), &negate(&Value::Int(1))));
let mut average: Value = self.safe_number_k(order.clone(), "price", &[]);
if !is_equal(&market, &Value::Null) {
symbol = get_value(&market, &Value::Str("symbol".to_string()));
if is_true(&Value::Bool(in_op(&order, &Value::Str("fee".to_string())))) {
let mut feeCost: Value = self.safe_string_k(order.clone(), "fee", &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("rate".to_string(), Value::Null);
m
});
if is_greater_than_or_equal(&get_index_of(&flags, &Value::Str("fciq".to_string())), &Value::Int(0)) {
add_element_to_object(&mut fee, &Value::Str("currency".to_string()), get_value(&market, &Value::Str("quote".to_string())));
} else if is_greater_than_or_equal(&get_index_of(&flags, &Value::Str("fcib".to_string())), &Value::Int(0)) {
add_element_to_object(&mut fee, &Value::Str("currency".to_string()), get_value(&market, &Value::Str("base".to_string())));
}
}
}
let mut status: Value = self.parse_order_status(self.safe_string_k(order.clone(), "status", &[]));
let mut id: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("id".to_string()), Value::Str("txid".to_string()), Value::Str("order_id".to_string()), Value::Str("amend_id".to_string())]), &[]);
if is_true(&(is_equal(&id, &Value::Null))) || is_true(&(Value::Bool(starts_with(&id, &Value::Str("[".to_string()))))) {
let mut txid: Value = self.safe_list_k(order.clone(), "txid", &[]);
id = self.safe_string(txid.clone(), Value::Int(0), &[]);
}
let mut userref: Value = self.safe_string_k(order.clone(), "userref", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "cl_ord_id", &[userref.clone()]);
let mut rawTrades: Value = self.safe_value_k(order.clone(), "trades", &[Value::List(vec![])]);
let mut trades: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_844: bool = true;
while { if !__for_first_844 { i = add(&i, &Value::Int(1)); } __for_first_844 = false; is_less_than(&i, &get_array_length(&rawTrades)) } {
let mut rawTrade: Value = get_value(&rawTrades, &i);
let mut rawTrade: Value = get_value(&rawTrades, &i);
if is_string(&rawTrade) {
append_to_array(&mut trades, self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), rawTrade.clone());
m.insert("orderId".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}), &[]));
} else {
append_to_array(&mut trades, rawTrade.clone());
}
}
}
// as mentioned in #24192 PR, this field is not something consistent/actual
// triggerPrice = this.omitZero (this.safeString (order, 'stopprice', triggerPrice));
let mut stopLossPrice: Value = Value::Null;
let mut takeProfitPrice: Value = Value::Null;
// the dashed strings are not provided from fields (eg. fetch order)
// while spaced strings from "order" sentence (when other fields not available)
if !is_equal(&rawType, &Value::Null) {
if is_true(&Value::Bool(starts_with(&rawType, &Value::Str("take-profit".to_string())))) {
takeProfitPrice = self.safe_string_k(description.clone(), "price", &[]);
price = self.omit_zero(self.safe_string_k(description.clone(), "price2", &[]));
} else if is_true(&Value::Bool(starts_with(&rawType, &Value::Str("stop-loss".to_string())))) {
stopLossPrice = self.safe_string_k(description.clone(), "price", &[]);
price = self.omit_zero(self.safe_string_k(description.clone(), "price2", &[]));
} else if is_equal(&rawType, &Value::Str("take profit".to_string())) {
takeProfitPrice = triggerPrice.clone();
} else if is_equal(&rawType, &Value::Str("stop loss".to_string())) {
stopLossPrice = triggerPrice.clone();
}
}
let mut typeParsed: Value = self.parse_order_type(rawType.clone());
// unlike from endpoints which provide eg: "take-profit-limit"
// for "space-delimited" orders we dont have market/limit suffixes, their format is
// eg: `stop loss > limit 123`, so we need to parse them manually
if is_true(&self.in_array(typeParsed.clone(), Value::List(vec![Value::Str("stop loss".to_string()), Value::Str("take profit".to_string())]))) {
typeParsed = ternary(is_true(&(is_equal(&price, &Value::Null))), Value::Str("market".to_string()), Value::Str("limit".to_string()));
}
let mut amendId: Value = self.safe_string_k(order.clone(), "amend_id", &[]);
if !is_equal(&amendId, &Value::Null) {
isPostOnly = Value::Null;
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("info".to_string(), order.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_timestamp(order.clone(), Value::Str("closetm".to_string()), &[]));
m.insert("status".to_string(), status.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), typeParsed.clone());
m.insert("timeInForce".to_string(), Value::Null);
m.insert("postOnly".to_string(), isPostOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("takeProfitPrice".to_string(), takeProfitPrice.clone());
m.insert("stopLossPrice".to_string(), stopLossPrice.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("average".to_string(), average.clone());
m.insert("remaining".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), self.safe_bool2(order.clone(), Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), &[]));
m.insert("fee".to_string(), fee.clone());
m.insert("trades".to_string(), trades.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn order_request(&self, mut method: Value, mut symbol: Value, mut type_var: Value, mut request: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string())]), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cl_ord_id".to_string()), clientOrderId.clone());
}
let mut stopLossTriggerPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitTriggerPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut isStopLossTriggerOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitTriggerOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
let mut isStopLossOrTakeProfitTrigger: bool = is_true(&isStopLossTriggerOrder) || is_true(&isTakeProfitTriggerOrder);
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut trailingPercent: Value = self.safe_string_k(params.clone(), "trailingPercent", &[]);
let mut trailingLimitAmount: Value = self.safe_string_k(params.clone(), "trailingLimitAmount", &[]);
let mut trailingLimitPercent: Value = self.safe_string_k(params.clone(), "trailingLimitPercent", &[]);
let mut isTrailingAmountOrder: bool = !is_equal(&trailingAmount, &Value::Null);
let mut isTrailingPercentOrder: bool = !is_equal(&trailingPercent, &Value::Null);
let mut isLimitOrder: bool = is_true(&(!is_equal(&type_var, &Value::Null))) && is_true(&Value::Bool(ends_with(&type_var, &Value::Str("limit".to_string())))); // supporting limit, stop-loss-limit, take-profit-limit, etc
let mut isMarketOrder: bool = is_equal(&type_var, &Value::Str("market".to_string()));
let mut cost: Value = self.safe_string_k(params.clone(), "cost", &[]);
let mut flags: Value = self.safe_string_k(params.clone(), "oflags", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("cost".to_string()), Value::Str("oflags".to_string())]), &[]);
let mut isViqcOrder: bool = is_true(&(!is_equal(&flags, &Value::Null))) && is_true(&(is_greater_than(&get_index_of(&flags, &Value::Str("viqc".to_string())), &negate(&Value::Int(1))))); // volume in quote currency
if is_true(&isMarketOrder) && is_true(&(!is_equal(&cost, &Value::Null) || is_true(&isViqcOrder))) {
if is_equal(&cost, &Value::Null) && is_true(&(!is_equal(&amount, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("volume".to_string()), self.cost_to_precision(symbol.clone(), self.number_to_string(amount.clone())));
} else {
add_element_to_object(&mut request, &Value::Str("volume".to_string()), self.cost_to_precision(symbol.clone(), cost.clone()));
}
let mut extendedOflags: Value = ternary(is_true(&(!is_equal(&flags, &Value::Null))), add(&flags, &Value::Str(",viqc".to_string())), Value::Str("viqc".to_string()));
add_element_to_object(&mut request, &Value::Str("oflags".to_string()), extendedOflags.clone());
} else if is_true(&isLimitOrder) && !is_true(&isTrailingAmountOrder) && !is_true(&isTrailingPercentOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut reduceOnly: Value = self.safe_bool2(params.clone(), Value::Str("reduceOnly".to_string()), Value::Str("reduce_only".to_string()), &[]);
if is_true(&isStopLossOrTakeProfitTrigger) {
if is_true(&isStopLossTriggerOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
if is_true(&isLimitOrder) {
add_element_to_object(&mut request, &Value::Str("ordertype".to_string()), Value::Str("stop-loss-limit".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("ordertype".to_string()), Value::Str("stop-loss".to_string()));
}
} else if is_true(&isTakeProfitTriggerOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
if is_true(&isLimitOrder) {
add_element_to_object(&mut request, &Value::Str("ordertype".to_string()), Value::Str("take-profit-limit".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("ordertype".to_string()), Value::Str("take-profit".to_string()));
}
}
if is_true(&isLimitOrder) {
add_element_to_object(&mut request, &Value::Str("price2".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
} else if is_true(&isTrailingAmountOrder) || is_true(&isTrailingPercentOrder) {
let mut trailingPercentString: Value = Value::Null;
if !is_equal(&trailingPercent, &Value::Null) {
trailingPercentString = ternary(is_true(&(Value::Bool(ends_with(&trailingPercent, &Value::Str("%".to_string()))))), (add(&Value::Str("+".to_string()), &trailingPercent)), (add(&add(&Value::Str("+".to_string()), &trailingPercent), &Value::Str("%".to_string()))));
}
let mut trailingAmountString: Value = ternary(is_true(&(!is_equal(&trailingAmount, &Value::Null))), add(&Value::Str("+".to_string()), &trailingAmount), Value::Null); // must use + for this
let mut offset: Value = self.safe_string_k(params.clone(), "offset", &[Value::Str("-".to_string())]); // can use + or - for this
let mut trailingLimitAmountString: Value = ternary(is_true(&(!is_equal(&trailingLimitAmount, &Value::Null))), add(&offset, &self.number_to_string(trailingLimitAmount.clone())), Value::Null);
let mut trailingActivationPriceType: Value = self.safe_string_k(params.clone(), "trigger", &[Value::Str("last".to_string())]);
add_element_to_object(&mut request, &Value::Str("trigger".to_string()), trailingActivationPriceType.clone());
if is_true(&isLimitOrder) || is_true(&(!is_equal(&trailingLimitAmount, &Value::Null))) || is_true(&(!is_equal(&trailingLimitPercent, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("ordertype".to_string()), Value::Str("trailing-stop-limit".to_string()));
if !is_equal(&trailingLimitPercent, &Value::Null) {
let mut trailingLimitPercentString: Value = ternary(is_true(&(Value::Bool(ends_with(&trailingLimitPercent, &Value::Str("%".to_string()))))), (add(&offset, &trailingLimitPercent)), (add(&add(&offset, &trailingLimitPercent), &Value::Str("%".to_string()))));
add_element_to_object(&mut request, &Value::Str("price".to_string()), trailingPercentString.clone());
add_element_to_object(&mut request, &Value::Str("price2".to_string()), trailingLimitPercentString.clone());
} else if !is_equal(&trailingLimitAmount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), trailingAmountString.clone());
add_element_to_object(&mut request, &Value::Str("price2".to_string()), trailingLimitAmountString.clone());
}
} else {
add_element_to_object(&mut request, &Value::Str("ordertype".to_string()), Value::Str("trailing-stop".to_string()));
if !is_equal(&trailingPercent, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), trailingPercentString.clone());
} else {
add_element_to_object(&mut request, &Value::Str("price".to_string()), trailingAmountString.clone());
}
}
}
if is_equal(&reduceOnly, &Value::Bool(true)) {
if is_equal(&method, &Value::Str("createOrderWs".to_string())) {
add_element_to_object(&mut request, &Value::Str("reduce_only".to_string()), Value::Bool(true)); // ws request can't have stringified bool
} else {
add_element_to_object(&mut request, &Value::Str("reduce_only".to_string()), Value::Str("true".to_string())); // not using boolean in this case, because the urlencodedNested transforms it into 'True' string
}
}
let mut close: Value = self.safe_dict_k(params.clone(), "close", &[]);
if !is_equal(&close, &Value::Null) {
close = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[close.clone()]);
close = ternary(is_true(&(is_equal(&close, &Value::Null))), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), close.clone());
let mut closePrice: Value = self.safe_value_k(close.clone(), "price", &[]);
if !is_equal(&closePrice, &Value::Null) {
add_element_to_object(&mut close, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), closePrice.clone()));
}
let mut closePrice2: Value = self.safe_value_k(close.clone(), "price2", &[]); // stopPrice
if !is_equal(&closePrice2, &Value::Null) {
add_element_to_object(&mut close, &Value::Str("price2".to_string()), self.price_to_precision(symbol.clone(), closePrice2.clone()));
}
add_element_to_object(&mut request, &Value::Str("close".to_string()), close.clone());
}
let mut timeInForce: Value = self.safe_string2(params.clone(), Value::Str("timeInForce".to_string()), Value::Str("timeinforce".to_string()), &[]);
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeinforce".to_string()), timeInForce.clone());
}
let mut isMarket: Value = Value::Bool(is_equal(&type_var, &Value::Str("market".to_string())));
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(isMarket.clone(), 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)) {
let mut extendedPostFlags: Value = ternary(is_true(&(!is_equal(&flags, &Value::Null))), add(&flags, &Value::Str(",post".to_string())), Value::Str("post".to_string()));
add_element_to_object(&mut request, &Value::Str("oflags".to_string()), extendedPostFlags.clone());
}
if is_true(&(!is_equal(&flags, &Value::Null))) && !is_true(&(Value::Bool(in_op(&request, &Value::Str("oflags".to_string()))))) {
add_element_to_object(&mut request, &Value::Str("oflags".to_string()), flags.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("timeInForce".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("trailingLimitAmount".to_string()), Value::Str("trailingLimitPercent".to_string()), Value::Str("offset".to_string())]), &[]);
return Value::List(vec![request.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name kraken#editOrder
* @description edit a trade order
* @see https://docs.kraken.com/api-reference/trading/amend-order
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} [amount] how much of the currency you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.stopLossPrice] the price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] the price that a take profit order is triggered at
* @param {string} [params.trailingAmount] the quote amount to trail away from the current market price
* @param {string} [params.trailingPercent] the percent to trail away from the current market price
* @param {string} [params.trailingLimitAmount] the quote amount away from the trailingAmount
* @param {string} [params.trailingLimitPercent] the percent away from the trailingAmount
* @param {string} [params.offset] '+' or '-' whether you want the trailingLimitAmount value to be positive or negative
* @param {boolean} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately
* @param {string} [params.clientOrderId] the orders client order id
* @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());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" editOrder() does not support ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" orders, only spot orders are accepted".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("txid".to_string(), id.clone());
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("cl_ord_id".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cl_ord_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("cl_ord_id".to_string())]), &[]);
request = self.omit(request.clone(), Value::Str("txid".to_string()), &[]);
}
let mut isMarket: Value = Value::Bool(is_equal(&type_var, &Value::Str("market".to_string())));
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(isMarket.clone(), 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("post_only".to_string()), Value::Str("true".to_string())); // not using boolean in this case, because the urlencodedNested transforms it into 'True' string
}
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("order_qty".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit_price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut allTriggerPrices: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("trailingLimitAmount".to_string()), Value::Str("trailingLimitPercent".to_string())]), &[]);
if !is_equal(&allTriggerPrices, &Value::Null) {
let mut offset: Value = self.safe_string_k(params.clone(), "offset", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("trailingLimitAmount".to_string()), Value::Str("trailingLimitPercent".to_string()), Value::Str("offset".to_string())]), &[]);
if !is_equal(&offset, &Value::Null) {
allTriggerPrices = add(&offset, &allTriggerPrices);
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), allTriggerPrices.clone());
} else {
add_element_to_object(&mut request, &Value::Str("trigger_price".to_string()), self.price_to_precision(symbol.clone(), allTriggerPrices.clone()));
}
}
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_amend_order(&[__ws_arg_9]).await;
//
// {
// "error": [],
// "result": {
// "amend_id": "TJSMEH-AA67V-YUSQ6O"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchOrder
* @description fetches information on an order made by the user
* @see https://docs.kraken.com/api-reference/account-data/query-orders-info
* @param {string} id order id
* @param {string} symbol not used by kraken fetchOrder
* @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_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_value2(params.clone(), Value::Str("userref".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trades".to_string(), Value::Bool(true));
m.insert("txid".to_string(), id.clone());
m
});
let mut query: Value = params.clone();
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("userref".to_string()), clientOrderId.clone());
query = self.omit(params.clone(), Value::List(vec![Value::Str("userref".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
}
let __ws_arg_10 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.private_post_query_orders(&[__ws_arg_10]).await;
//
// {
// "error":[],
// "result":{
// "OTLAS3-RRHUF-NDWH5A":{
// "refid":null,
// "userref":null,
// "status":"closed",
// "reason":null,
// "opentm":1586822919.3342,
// "closetm":1586822919.365,
// "starttm":0,
// "expiretm":0,
// "descr":{
// "pair":"XBTUSDT",
// "type":"sell",
// "ordertype":"market",
// "price":"0",
// "price2":"0",
// "leverage":"none",
// "order":"sell 0.21804000 XBTUSDT @ market",
// "close":""
// },
// "vol":"0.21804000",
// "vol_exec":"0.21804000",
// "cost":"1493.9",
// "fee":"3.8",
// "price":"6851.5",
// "stopprice":"0.00000",
// "limitprice":"0.00000",
// "misc":"",
// "oflags":"fciq",
// "trades":["TT5UC3-GOIRW-6AZZ6R"]
// }
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::List(vec![])]);
if !is_true(&(Value::Bool(in_op(&result, &id)))) {
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&self.id, &Value::Str(" fetchOrder() could not find order id ".to_string())), &id)));
}
let __ws_arg_11 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
}), &[get_value(&result, &id)]);
return self.parse_order(__ws_arg_11, &[]);
Value::Null
}
/*
* @method
* @name kraken#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://docs.kraken.com/api-reference/account-data/query-trades-info
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut orderTrades: Value = self.safe_value_k(params.clone(), "trades", &[]);
let mut tradeIds: Value = Value::List(vec![]);
if is_equal(&orderTrades, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrderTrades() requires a unified order structure in the params argument or a 'trades' param (an array of trade id strings)".to_string()))));
} else {
{
let mut i: Value = Value::Int(0);
let mut __for_first_845: bool = true;
while { if !__for_first_845 { i = add(&i, &Value::Int(1)); } __for_first_845 = false; is_less_than(&i, &get_array_length(&orderTrades)) } {
let mut orderTrade: Value = get_value(&orderTrades, &i);
let mut orderTrade: Value = get_value(&orderTrades, &i);
if is_string(&orderTrade) {
append_to_array(&mut tradeIds, orderTrade.clone());
} else {
append_to_array(&mut tradeIds, get_value(&orderTrade, &Value::Str("id".to_string())));
}
}
}
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if !is_equal(&symbol, &Value::Null) {
symbol = self.symbol(symbol.clone());
}
let mut options: Value = self.safe_value_k(self.options.clone(), "fetchOrderTrades", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut batchSize: Value = self.safe_integer_k(options.clone(), "batchSize", &[Value::Int(20)]);
let mut numTradeIds: Value = get_array_length(&tradeIds);
let mut numBatches: Value = self.parse_to_int(divide(&numTradeIds, &batchSize));
numBatches = self.sum(&[numBatches.clone(), Value::Int(1)]);
let mut result: Value = Value::List(vec![]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_848: bool = true;
while { if !__for_first_848 { j = add(&j, &Value::Int(1)); } __for_first_848 = false; is_less_than(&j, &numBatches) } {
let mut requestIds: Value = Value::List(vec![]);
{
let mut k: Value = Value::Int(0);
let mut __for_first_846: bool = true;
while { if !__for_first_846 { k = add(&k, &Value::Int(1)); } __for_first_846 = false; is_less_than(&k, &batchSize) } {
let mut index: Value = self.sum(&[multiply(&j, &batchSize), k.clone()]);
if is_less_than(&index, &numTradeIds) {
append_to_array(&mut requestIds, get_value(&tradeIds, &index));
}
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("txid".to_string(), join(&requestIds, &Value::Str(",".to_string())));
m
});
let mut response: Value = self.private_post_query_trades(&[request.clone()]).await;
//
// {
// "error": [],
// "result": {
// 'TIMIRG-WUNNE-RRJ6GT': {
// "ordertxid": 'OQRPN2-LRHFY-HIFA7D',
// "postxid": 'TKH2SE-M7IF5-CFI7LT',
// "pair": 'USDCUSDT',
// "time": 1586340086.457,
// "type": 'sell',
// "ordertype": 'market',
// "price": '0.99860000',
// "cost": '22.16892001',
// "fee": '0.04433784',
// "vol": '22.20000000',
// "margin": '0.00000000',
// "misc": ''
// }
// }
// }
//
let mut rawTrades: Value = self.safe_value_k(response.clone(), "result", &[]);
let mut ids: Value = object_keys(&rawTrades);
{
let mut i: Value = Value::Int(0);
let mut __for_first_847: bool = true;
while { if !__for_first_847 { i = add(&i, &Value::Int(1)); } __for_first_847 = false; is_less_than(&i, &get_array_length(&ids)) } {
add_element_to_object(get_value_mut(&mut rawTrades, &get_value(&ids, &i)), &Value::Str("id".to_string()), get_value(&ids, &i));
}
}
let mut trades: Value = self.parse_trades(rawTrades.clone(), &[Value::Null, since.clone(), limit.clone()]);
let mut tradesFilteredBySymbol: Value = self.filter_by_symbol(trades.clone(), &[symbol.clone()]);
result = self.array_concat(result.clone(), tradesFilteredBySymbol.clone());
}
}
return result;
Value::Null
}
/*
* @method
* @name kraken#fetchOrdersByIds
* @description fetch orders by the list of order id
* @see https://docs.kraken.com/api-reference/account-data/get-closed-orders
* @param {string[]} [ids] list of order id
* @param {string} [symbol] unified ccxt market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders_by_ids(&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 __ws_arg_12 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trades".to_string(), Value::Bool(true));
m.insert("txid".to_string(), join(&ids, &Value::Str(",".to_string())));
m
}), &[params.clone()]);
let mut response: Value = self.private_post_query_orders(&[__ws_arg_12]).await;
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = Value::List(vec![]);
let mut orderIds: Value = object_keys(&result);
{
let mut i: Value = Value::Int(0);
let mut __for_first_849: bool = true;
while { if !__for_first_849 { i = add(&i, &Value::Int(1)); } __for_first_849 = false; is_less_than(&i, &get_array_length(&orderIds)) } {
let mut id: Value = get_value(&orderIds, &i);
let mut id: Value = get_value(&orderIds, &i);
let mut item: Value = get_value(&result, &id);
let mut item: Value = get_value(&result, &id);
let __ws_arg_13 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
}), &[item.clone()]);
let mut order: Value = self.parse_order(__ws_arg_13, &[]);
append_to_array(&mut orders, order.clone());
}
}
return orders;
Value::Null
}
/*
* @method
* @name kraken#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.kraken.com/api-reference/account-data/get-trades-history
* @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] timestamp in ms of the latest trade entry
* @param {int} [params.end] timestamp in seconds of the latest trade entry
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut until: Value = self.safe_string2(params.clone(), Value::Str("until".to_string()), Value::Str("till".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string()), Value::Str("till".to_string())]), &[]);
let mut untilDivided: Value = crate::precise::Precise::stringDiv(&until, &Value::Str("1000".to_string()));
add_element_to_object(&mut request, &Value::Str("end".to_string()), self.parse_to_int(crate::precise::Precise::stringAdd(&untilDivided, &Value::Str("1".to_string()))));
}
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_trades_history(&[__ws_arg_14]).await;
//
// {
// "error": [],
// "result": {
// "trades": {
// "GJ3NYQ-XJRTF-THZABF": {
// "ordertxid": "TKH2SE-ZIF5E-CFI7LT",
// "postxid": "OEN3VX-M7IF5-JNBJAM",
// "pair": "XICNXETH",
// "time": 1527213229.4491,
// "type": "sell",
// "ordertype": "limit",
// "price": "0.001612",
// "cost": "0.025792",
// "fee": "0.000026",
// "vol": "16.00000000",
// "margin": "0.000000",
// "leverage": "5",
// "misc": ""
// "trade_id": 68230622,
// "maker": false
// },
// ...
// },
// "count": 9760,
// },
// }
//
let mut tradesResult: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_dict_k(tradesResult.clone(), "trades", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ids: Value = object_keys(&trades);
{
let mut i: Value = Value::Int(0);
let mut __for_first_850: bool = true;
while { if !__for_first_850 { i = add(&i, &Value::Int(1)); } __for_first_850 = false; is_less_than(&i, &get_array_length(&ids)) } {
add_element_to_object(get_value_mut(&mut trades, &get_value(&ids, &i)), &Value::Str("id".to_string()), get_value(&ids, &i));
}
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut tradesList: Value = self.to_array(trades.clone());
return self.parse_trades(tradesList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kraken#cancelOrder
* @description cancels an open order
* @see https://docs.kraken.com/api-reference/trading/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.clientOrderId] the orders client order id
* @param {int} [params.userref] the orders user reference id
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
let mut requestId: Value = self.safe_value_k(params.clone(), "userref", &[id.clone()]); // string or integer
params = self.omit(params.clone(), Value::Str("userref".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("txid".to_string(), requestId.clone());
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("cl_ord_id".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cl_ord_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("cl_ord_id".to_string())]), &[]);
request = self.omit(request.clone(), Value::Str("txid".to_string()), &[]);
}
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_cancel_order(&[__ws_arg_15]).await;
#[allow(unreachable_code)] { Value::Null }})).await;
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
if is_true(&(!is_equal(&self.last_http_response, &Value::Null))) && is_true(&(!is_equal(&self.last_http_response, &Value::Str("".to_string())))) {
if is_greater_than_or_equal(&get_index_of(&self.last_http_response, &Value::Str("EOrder:Unknown order".to_string())), &Value::Int(0)) {
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&self.id, &Value::Str(" cancelOrder() error ".to_string())), &self.last_http_response)));
}
}
panic!("{}", e);
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[]);
Value::Null
}
/*
* @method
* @name kraken#cancelOrders
* @description cancel multiple orders
* @see https://docs.kraken.com/api-reference/trading/cancel-order-batch
* @param {string[]} ids open orders transaction ID (txid) or user reference (userref)
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), ids.clone());
m
});
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_cancel_order_batch(&[__ws_arg_16]).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 kraken#cancelAllOrders
* @description cancel all open orders
* @see https://docs.kraken.com/api-reference/trading/cancel-all-orders
* @param {string} [symbol] unified market symbol, not used by kraken cancelAllOrders (all open orders are cancelled)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_post_cancel_all(&[params.clone()]).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 kraken#cancelAllOrdersAfter
* @description dead man's switch, cancel all orders after the given timeout
* @see https://docs.kraken.com/api-reference/trading/cancel-all-orders-after-x
* @param {number} timeout time in milliseconds, 0 represents cancel the timer
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the api result
*/
pub async fn cancel_all_orders_after(&mut self, mut timeout: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&timeout, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" cancelAllOrdersAfter() missing timeout".to_string()))));
}
if is_greater_than(&timeout, &Value::Int(86400000)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelAllOrdersAfter timeout should be less than 86400000 milliseconds".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&timeout, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" cancelAllOrdersAfter() missing timeout".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeout".to_string(), ternary(is_true(&(is_greater_than(&timeout, &Value::Int(0)))), (self.parse_to_int(divide(&timeout, &Value::Int(1000)))), Value::Int(0)));
m
});
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_cancel_all_orders_after(&[__ws_arg_17]).await;
return response;
Value::Null
}
/*
* @method
* @name kraken#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://docs.kraken.com/api-reference/account-data/get-open-orders
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] the orders client order id
* @param {int} [params.userref] the orders user reference id
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut userref: Value = self.safe_integer_k(params.clone(), "userref", &[]);
if !is_equal(&userref, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("userref".to_string()), userref.clone());
params = self.omit(params.clone(), Value::Str("userref".to_string()), &[]);
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cl_ord_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
}
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_open_orders(&[__ws_arg_18]).await;
//
// {
// "error": [],
// "result": {
// "open": {
// "O45M52-BFD5S-YXKQOU": {
// "refid": null,
// "userref": null,
// "cl_ord_id": "1234",
// "status": "open",
// "opentm": 1733815269.370054,
// "starttm": 0,
// "expiretm": 0,
// "descr": {
// "pair": "XBTUSD",
// "type": "buy",
// "ordertype": "limit",
// "price": "70000.0",
// "price2": "0",
// "leverage": "none",
// "order": "buy 0.00010000 XBTUSD @ limit 70000.0",
// "close": ""
// },
// "vol": "0.00010000",
// "vol_exec": "0.00000000",
// "cost": "0.00000",
// "fee": "0.00000",
// "price": "0.00000",
// "stopprice": "0.00000",
// "limitprice": "0.00000",
// "misc": "",
// "oflags": "fciq"
// }
// }
// }
// }
//
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut open: Value = self.safe_dict_k(result.clone(), "open", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = Value::List(vec![]);
let mut orderIds: Value = object_keys(&open);
{
let mut i: Value = Value::Int(0);
let mut __for_first_851: bool = true;
while { if !__for_first_851 { i = add(&i, &Value::Int(1)); } __for_first_851 = false; is_less_than(&i, &get_array_length(&orderIds)) } {
let mut id: Value = get_value(&orderIds, &i);
let mut id: Value = get_value(&orderIds, &i);
let mut item: Value = get_value(&open, &id);
let mut item: Value = get_value(&open, &id);
append_to_array(&mut orders, self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
}), &[item.clone()]));
}
}
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://docs.kraken.com/api-reference/account-data/get-closed-orders
* @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] timestamp in ms of the latest entry
* @param {string} [params.clientOrderId] the orders client order id
* @param {int} [params.userref] the orders user reference id
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut userref: Value = self.safe_integer_k(params.clone(), "userref", &[]);
if !is_equal(&userref, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("userref".to_string()), userref.clone());
params = self.omit(params.clone(), Value::Str("userref".to_string()), &[]);
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cl_ord_id".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_closed_orders(&[__ws_arg_19]).await;
//
// {
// "error":[],
// "result":{
// "closed":{
// "OETZYO-UL524-QJMXCT":{
// "refid":null,
// "userref":null,
// "status":"canceled",
// "reason":"User requested",
// "opentm":1601489313.3898,
// "closetm":1601489346.5507,
// "starttm":0,
// "expiretm":0,
// "descr":{
// "pair":"ETHUSDT",
// "type":"buy",
// "ordertype":"limit",
// "price":"330.00",
// "price2":"0",
// "leverage":"none",
// "order":"buy 0.02100000 ETHUSDT @ limit 330.00",
// "close":""
// },
// "vol":"0.02100000",
// "vol_exec":"0.00000000",
// "cost":"0.00000",
// "fee":"0.00000",
// "price":"0.00000",
// "stopprice":"0.00000",
// "limitprice":"0.00000",
// "misc":"",
// "oflags":"fciq"
// },
// },
// "count":16
// }
// }
//
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut closed: Value = self.safe_dict_k(result.clone(), "closed", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = Value::List(vec![]);
let mut orderIds: Value = object_keys(&closed);
{
let mut i: Value = Value::Int(0);
let mut __for_first_852: bool = true;
while { if !__for_first_852 { i = add(&i, &Value::Int(1)); } __for_first_852 = false; is_less_than(&i, &get_array_length(&orderIds)) } {
let mut id: Value = get_value(&orderIds, &i);
let mut id: Value = get_value(&orderIds, &i);
let mut item: Value = get_value(&closed, &id);
let mut item: Value = get_value(&closed, &id);
append_to_array(&mut orders, self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
}), &[item.clone()]));
}
}
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
// IFEX transaction states
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Initial".to_string(), Value::Str("pending".to_string()));
m.insert("Pending".to_string(), Value::Str("pending".to_string()));
m.insert("Success".to_string(), Value::Str("ok".to_string()));
m.insert("Settled".to_string(), Value::Str("pending".to_string()));
m.insert("Failure".to_string(), Value::Str("failed".to_string()));
m.insert("Partial".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_network(&self, mut network: Value) -> Value {
let mut withdrawMethods: Value = self.safe_value_k(self.options.clone(), "withdrawMethods", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_string(withdrawMethods.clone(), network.clone(), &[network.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
//
// {
// "method": "Ether (Hex)",
// "aclass": "currency",
// "asset": "XETH",
// "refid": "Q2CANKL-LBFVEE-U4Y2WQ",
// "txid": "0x57fd704dab1a73c20e24c8696099b695d596924b401b261513cfdab23…",
// "info": "0x615f9ba7a9575b0ab4d571b2b36b1b324bd83290",
// "amount": "7.9999257900",
// "fee": "0.0000000000",
// "time": 1529223212,
// "status": "Success"
// }
//
// there can be an additional 'status-prop' field present
// deposit pending review by exchange => 'on-hold'
// the deposit is initiated by the exchange => 'return'
//
// {
// "type": 'deposit',
// "method": 'Fidor Bank AG (Wire Transfer)',
// "aclass": 'currency',
// "asset": 'ZEUR',
// "refid": 'xxx-xxx-xxx',
// "txid": '12341234',
// "info": 'BANKCODEXXX',
// "amount": '38769.08',
// "fee": '0.0000',
// "time": 1644306552,
// "status": 'Success',
// status-prop: 'on-hold'
// }
//
//
// fetchWithdrawals
//
// {
// "method": "Ether",
// "aclass": "currency",
// "asset": "XETH",
// "refid": "A2BF34S-O7LBNQ-UE4Y4O",
// "txid": "0x288b83c6b0904d8400ef44e1c9e2187b5c8f7ea3d838222d53f701a15b5c274d",
// "info": "0x7cb275a5e07ba943fee972e165d80daa67cb2dd0",
// "amount": "9.9950000000",
// "fee": "0.0050000000",
// "time": 1530481750,
// "status": "Success"
// "key":"Huobi wallet",
// "network":"Tron"
// status-prop: 'on-hold' // this field might not be present in some cases
// }
//
// withdraw
//
// {
// "refid": "AGBSO6T-UFMTTQ-I7KGS6"
// }
//
let mut id: Value = self.safe_string_k(transaction.clone(), "refid", &[]);
let mut txid: Value = self.safe_string_k(transaction.clone(), "txid", &[]);
let mut timestamp: Value = self.safe_timestamp(transaction.clone(), Value::Str("time".to_string()), &[]);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "asset", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut address: Value = self.safe_string_k(transaction.clone(), "info", &[]);
let mut amount: Value = self.safe_number_k(transaction.clone(), "amount", &[]);
let mut status: Value = self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[]));
let mut statusProp: Value = self.safe_string_k(transaction.clone(), "status-prop", &[]);
let mut isOnHoldDeposit: bool = is_equal(&statusProp, &Value::Str("on-hold".to_string()));
let mut isCancellationRequest: bool = is_equal(&statusProp, &Value::Str("cancel-pending".to_string()));
let mut isOnHoldWithdrawal: bool = is_equal(&statusProp, &Value::Str("onhold".to_string()));
if is_true(&isOnHoldDeposit) || is_true(&isCancellationRequest) || is_true(&isOnHoldWithdrawal) {
status = Value::Str("pending".to_string());
}
let mut type_var: Value = self.safe_string_k(transaction.clone(), "type", &[]); // injected from the outside
let mut feeCost: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
if is_equal(&feeCost, &Value::Null) {
if is_equal(&type_var, &Value::Str("deposit".to_string())) {
feeCost = Value::Int(0);
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.clone());
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("network".to_string(), self.parse_network(self.safe_string_k(transaction.clone(), "network", &[])));
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("updated".to_string(), Value::Null);
m.insert("txid".to_string(), txid.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("cost".to_string(), feeCost.clone());
m
}));
m
});
Value::Null
}
pub fn parse_transactions_by_type(&self, mut type_var: Value, mut transactions: Value, 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 result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_853: bool = true;
while { if !__for_first_853 { i = add(&i, &Value::Int(1)); } __for_first_853 = false; is_less_than(&i, &get_array_length(&transactions)) } {
let __ws_arg_20 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var.clone());
m
}), &[get_value(&transactions, &i)]);
let mut transaction: Value = self.parse_transaction(__ws_arg_20, &[]);
append_to_array(&mut result, transaction.clone());
}
}
return self.filter_by_currency_since_limit(result.clone(), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchDeposits
* @description fetch all deposits made to an account
* @see https://docs.kraken.com/api-reference/funding/get-status-of-recent-deposits
* @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] timestamp in ms of the latest transaction entry
* @param {int} [params.end] timestamp in seconds of the latest transaction entry
* @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
}));
// https://www.kraken.com/en-us/help/api#deposit-status
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(&code, &Value::Null) {
let mut currency: Value = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("asset".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
let mut sinceString: Value = self.number_to_string(since.clone());
add_element_to_object(&mut request, &Value::Str("start".to_string()), crate::precise::Precise::stringDiv(&sinceString, &Value::Str("1000".to_string())));
}
let mut until: Value = self.safe_string2(params.clone(), Value::Str("until".to_string()), Value::Str("till".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string()), Value::Str("till".to_string())]), &[]);
let mut untilDivided: Value = crate::precise::Precise::stringDiv(&until, &Value::Str("1000".to_string()));
add_element_to_object(&mut request, &Value::Str("end".to_string()), crate::precise::Precise::stringAdd(&untilDivided, &Value::Str("1".to_string())));
}
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_deposit_status(&[__ws_arg_21]).await;
//
// { error: [],
// "result": [ { "method": "Ether (Hex)",
// "aclass": "currency",
// "asset": "XETH",
// "refid": "Q2CANKL-LBFVEE-U4Y2WQ",
// "txid": "0x57fd704dab1a73c20e24c8696099b695d596924b401b261513cfdab23…",
// "info": "0x615f9ba7a9575b0ab4d571b2b36b1b324bd83290",
// "amount": "7.9999257900",
// "fee": "0.0000000000",
// "time": 1529223212,
// "status": "Success" } ] }
//
let mut depositResult: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_transactions_by_type(Value::Str("deposit".to_string()), depositResult.clone(), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name kraken#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://docs.kraken.com/api-reference/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
}));
// https://www.kraken.com/en-us/features/api#get-server-time
let mut response: Value = self.public_get_time(&[params.clone()]).await;
//
// {
// "error": [],
// "result": {
// "unixtime": 1591502873,
// "rfc1123": "Sun, 7 Jun 20 04:07:53 +0000"
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_timestamp(result.clone(), Value::Str("unixtime".to_string()), &[]);
Value::Null
}
/*
* @method
* @name kraken#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://docs.kraken.com/api-reference/funding/get-status-of-recent-withdrawals
* @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] timestamp in ms of the latest transaction entry
* @param {int} [params.end] timestamp in seconds of the latest transaction entry
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchWithdrawals".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
add_element_to_object(&mut params, &Value::Str("cursor".to_string()), Value::Bool(true));
return self.fetch_paginated_call_cursor(Value::Str("fetchWithdrawals".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("next_cursor".to_string()), Value::Str("cursor".to_string())]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&code, &Value::Null) {
let mut currency: Value = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("asset".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
let mut sinceString: Value = self.number_to_string(since.clone());
add_element_to_object(&mut request, &Value::Str("start".to_string()), crate::precise::Precise::stringDiv(&sinceString, &Value::Str("1000".to_string())));
}
let mut until: Value = self.safe_string2(params.clone(), Value::Str("until".to_string()), Value::Str("till".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string()), Value::Str("till".to_string())]), &[]);
let mut untilDivided: Value = crate::precise::Precise::stringDiv(&until, &Value::Str("1000".to_string()));
add_element_to_object(&mut request, &Value::Str("end".to_string()), crate::precise::Precise::stringAdd(&untilDivided, &Value::Str("1".to_string())));
}
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_withdraw_status(&[__ws_arg_22]).await;
//
// with no pagination
// { error: [],
// "result": [ { "method": "Ether",
// "aclass": "currency",
// "asset": "XETH",
// "refid": "A2BF34S-O7LBNQ-UE4Y4O",
// "txid": "0x298c83c7b0904d8400ef43e1c9e2287b518f7ea3d838822d53f704a1565c274d",
// "info": "0x7cb275a5e07ba943fee972e165d80daa67cb2dd0",
// "amount": "9.9950000000",
// "fee": "0.0050000000",
// "time": 1530481750,
// "status": "Success" } ] }
// with pagination
// {
// "error":[],
// "result":{
// "withdrawals":[
// {
// "method":"Tether USD (TRC20)",
// "aclass":"currency",
// "asset":"USDT",
// "refid":"BSNFZU2-MEFN4G-J3NEZV",
// "txid":"1c7a642fb7387bbc2c6a2c509fd1ae146937f4cf793b4079a4f0715e3a02615a",
// "info":"TQmdxSuC16EhFg8FZWtYgrfFRosoRF7bCp",
// "amount":"1996.50000000",
// "fee":"2.50000000",
// "time":1669126657,
// "status":"Success",
// "key":"poloniex",
// "network":"Tron"
// },
// ...
// ],
// "next_cursor":"HgAAAAAAAABGVFRSd3k1LVF4Y0JQY05Gd0xRY0NxenFndHpybkwBAQH2AwEBAAAAAQAAAAAAAAABAAAAAAAZAAAAAAAAAA=="
// }
// }
//
let mut rawWithdrawals: Value = Value::Null;
let mut result: Value = self.safe_value_k(response.clone(), "result", &[]);
if !is_true(&Value::Bool(is_array(&result))) {
rawWithdrawals = self.add_pagination_cursor_to_result(result.clone());
} else {
rawWithdrawals = result.clone();
}
return self.parse_transactions_by_type(Value::Str("withdrawal".to_string()), rawWithdrawals.clone(), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn add_pagination_cursor_to_result(&self, mut result: Value) -> Value {
let mut cursor: Value = self.safe_string_k(result.clone(), "next_cursor", &[]);
let mut data: Value = self.safe_value_k(result.clone(), "withdrawals", &[]);
let mut dataLength: Value = get_array_length(&data);
if !is_equal(&cursor, &Value::Null) && is_greater_than(&dataLength, &Value::Int(0)) {
let mut last: Value = get_value(&data, &subtract(&dataLength, &Value::Int(1)));
add_element_to_object(&mut last, &Value::Str("next_cursor".to_string()), cursor.clone());
add_element_to_object(&mut data, &subtract(&dataLength, &Value::Int(1)), last.clone());
}
return data;
Value::Null
}
/*
* @method
* @name kraken#createDepositAddress
* @description create a currency deposit address
* @see https://docs.kraken.com/api-reference/funding/get-deposit-addresses
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} 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
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("new".to_string(), Value::Str("true".to_string()));
m
});
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_deposit_address(code.clone(), &[__ws_arg_23]).await;
Value::Null
}
/*
* @method
* @name kraken#fetchDepositMethods
* @description fetch deposit methods for a currency associated with this account
* @see https://docs.kraken.com/api-reference/funding/get-deposit-methods
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} of deposit methods
*/
pub async fn fetch_deposit_methods(&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("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_deposit_methods(&[__ws_arg_24]).await;
return self.safe_value_k(response.clone(), "result", &[]);
Value::Null
}
/*
* @method
* @name kraken#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://docs.kraken.com/api-reference/funding/get-deposit-addresses
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut network: Value = self.safe_string_upper(params.clone(), Value::Str("network".to_string()), &[]);
let mut networks: Value = self.safe_value_k(self.options.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
network = self.safe_string(networks.clone(), network.clone(), &[network.clone()]); // support ETH > ERC20 aliases
params = self.omit(params.clone(), Value::Str("network".to_string()), &[]);
if is_true(&(is_equal(&code, &Value::Str("USDT".to_string())))) && is_true(&(is_equal(&network, &Value::Str("TRC20".to_string())))) {
code = add(&add(&code, &Value::Str("-".to_string())), &network);
}
let mut defaultDepositMethods: Value = self.safe_value_k(self.options.clone(), "depositMethods", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultDepositMethod: Value = self.safe_string(defaultDepositMethods.clone(), code.clone(), &[]);
let mut depositMethod: Value = self.safe_string_k(params.clone(), "method", &[defaultDepositMethod.clone()]);
// if the user has specified an exchange-specific method in params
// we pass it as is, otherwise we take the 'network' unified param
if is_equal(&depositMethod, &Value::Null) {
let mut depositMethods: Value = self.fetch_deposit_methods(code.clone(), &[]).await;
if !is_equal(&network, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_854: bool = true;
while { if !__for_first_854 { i = add(&i, &Value::Int(1)); } __for_first_854 = false; is_less_than(&i, &get_array_length(&depositMethods)) } {
let mut entry: Value = self.safe_string_k(get_value(&depositMethods, &i), "method", &[]);
if is_equal(&entry, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchDepositAddress() missing entry".to_string()))));
}
if is_greater_than_or_equal(&get_index_of(&entry, &network), &Value::Int(0)) {
depositMethod = entry.clone();
break;
}
}
}
}
// if depositMethod was not specified, fallback to the first available deposit method
if is_equal(&depositMethod, &Value::Null) {
let mut firstDepositMethod: Value = self.safe_value(depositMethods.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
depositMethod = self.safe_string_k(firstDepositMethod.clone(), "method", &[]);
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("method".to_string(), depositMethod.clone());
m
});
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_deposit_addresses(&[__ws_arg_25]).await;
//
// {
// "error":[],
// "result":[
// {"address":"0x77b5051f97efa9cc52c9ad5b023a53fc15c200d3","expiretm":"0"}
// ]
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::List(vec![])]);
let mut firstResult: Value = self.safe_value(result.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_equal(&firstResult, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_address(add(&add(&self.id, &Value::Str(" privatePostDepositAddresses() returned no addresses for ".to_string())), &code)));
}
return self.parse_deposit_address(firstResult.clone(), &[currency.clone()]);
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);
//
// {
// "address":"0x77b5051f97efa9cc52c9ad5b023a53fc15c200d3",
// "expiretm":"0"
// }
//
let mut address: Value = self.safe_string_k(depositAddress.clone(), "address", &[]);
let mut tag: Value = self.safe_string_k(depositAddress.clone(), "tag", &[]);
currency = self.safe_currency(Value::Null, &[currency.clone()]);
let mut code: Value = get_value(¤cy, &Value::Str("code".to_string()));
self.check_address(&[address.clone()]);
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(), Value::Null);
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m
});
Value::Null
}
/*
* @method
* @name kraken#withdraw
* @description make a withdrawal
* @see https://docs.kraken.com/api-reference/funding/withdraw-funds
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to, not required can be '' or undefined/none/null
* @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_true(&Value::Bool(in_op(¶ms, &Value::Str("key".to_string())))) {
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("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), amount.clone());
m
});
if !is_equal(&address, &Value::Null) && !is_equal(&address, &Value::Str("".to_string())) {
add_element_to_object(&mut request, &Value::Str("address".to_string()), address.clone());
self.check_address(&[address.clone()]);
}
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_withdraw(&[__ws_arg_26]).await;
//
// {
// "error": [],
// "result": {
// "refid": "AGBSO6T-UFMTTQ-I7KGS6"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(result.clone(), &[currency.clone()]);
}
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" withdraw() requires a 'key' parameter (withdrawal key name, as set up on your account)".to_string()))));
Value::Null
}
/*
* @method
* @name kraken#fetchPositions
* @description fetch all open positions
* @see https://docs.kraken.com/api-reference/account-data/get-open-positions
* @param {string[]} [symbols] not used by fetchPositions ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("docalcs".to_string(), Value::Str("true".to_string()));
m.insert("consolidation".to_string(), Value::Str("market".to_string()));
m
});
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_open_positions(&[__ws_arg_27]).await;
//
// no consolidation
//
// {
// "error": [],
// "result": {
// 'TGUFMY-FLESJ-VYIX3J': {
// "ordertxid": "O3LRNU-ZKDG5-XNCDFR",
// "posstatus": "open",
// "pair": "ETHUSDT",
// "time": 1611557231.4584,
// "type": "buy",
// "ordertype": "market",
// "cost": "28.49800",
// "fee": "0.07979",
// "vol": "0.02000000",
// "vol_closed": "0.00000000",
// "margin": "14.24900",
// "terms": "0.0200% per 4 hours",
// "rollovertm": "1611571631",
// "misc": "",
// "oflags": ""
// }
// }
// }
//
// consolidation by market
//
// {
// "error": [],
// "result": [
// {
// "pair": "ETHUSDT",
// "positions": "1",
// "type": "buy",
// "leverage": "2.00000",
// "cost": "28.49800",
// "fee": "0.07979",
// "vol": "0.02000000",
// "vol_closed": "0.00000000",
// "margin": "14.24900"
// }
// ]
// }
//
symbols = self.market_symbols(&[symbols.clone()]);
let mut result: Value = self.safe_list_k(response.clone(), "result", &[]);
let mut results: Value = self.parse_positions(result.clone(), &[symbols.clone()]);
return self.filter_by_array_positions(results.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "pair": "ETHUSDT",
// "positions": "1",
// "type": "buy",
// "leverage": "2.00000",
// "cost": "28.49800",
// "fee": "0.07979",
// "vol": "0.02000000",
// "vol_closed": "0.00000000",
// "margin": "14.24900"
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "pair", &[]);
let mut rawSide: Value = self.safe_string_k(position.clone(), "type", &[]);
let mut side: Value = ternary(is_true(&(is_equal(&rawSide, &Value::Str("buy".to_string())))), Value::Str("long".to_string()), Value::Str("short".to_string()));
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("notional".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), Value::Null);
m.insert("entryPrice".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "net", &[]));
m.insert("realizedPnl".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "vol", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "margin", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn parse_account_type(&self, mut account: Value) -> Value {
let mut accountByType: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("Spot Wallet".to_string()));
m.insert("swap".to_string(), Value::Str("Futures Wallet".to_string()));
m.insert("future".to_string(), Value::Str("Futures Wallet".to_string()));
m
});
return self.safe_string(accountByType.clone(), account.clone(), &[account.clone()]);
Value::Null
}
/*
* @method
* @name kraken#transferOut
* @description transfer from spot wallet to futures wallet
* @see https://docs.kraken.com/api-reference/transfers/initiate-wallet-transfer
* @param {str} code Unified currency code
* @param {float} amount Size of the transfer
* @param {dict} [params] Exchange specific parameters
* @returns a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer_out(&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
}));
return self.transfer(code.clone(), amount.clone(), Value::Str("spot".to_string()), Value::Str("swap".to_string()), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name kraken#transfer
* @see https://docs.kraken.com/api-reference/transfers/initiate-wallet-transfer
* @description transfers currencies between sub-accounts (only spot->swap direction is supported)
* @param {string} code Unified currency code
* @param {float} amount Size of the transfer
* @param {string} fromAccount 'spot' or 'Spot Wallet'
* @param {string} toAccount 'swap' or 'Futures Wallet'
* @param {object} [params] Exchange specific parameters
* @returns a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut fromAccountParsed: Value = self.parse_account_type(fromAccount.clone());
let mut toAccountParsed: Value = self.parse_account_type(toAccount.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("from".to_string(), fromAccountParsed.clone());
m.insert("to".to_string(), toAccountParsed.clone());
m.insert("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
if !is_equal(&fromAccountParsed, &Value::Str("Spot Wallet".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&add(&add(&self.id, &Value::Str(" transfer cannot transfer from ".to_string())), &fromAccountParsed), &Value::Str(" to ".to_string())), &toAccountParsed), &Value::Str(". Use krakenfutures instead to transfer from the futures account.".to_string()))));
}
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_wallet_transfer(&[__ws_arg_28]).await;
//
// {
// "error":[
// ],
// "result":{
// "refid":"BOIUSIF-M7DLMN-UXZ3P5"
// }
// }
//
let mut transfer: Value = self.parse_transfer(response.clone(), &[currency.clone()]);
return self.extend(transfer.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m.insert("fromAccount".to_string(), fromAccountParsed.clone());
m.insert("toAccount".to_string(), toAccountParsed.clone());
m
})]);
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
//
// {
// "error":[
// ],
// "result":{
// "refid":"BOIUSIF-M7DLMN-UXZ3P5"
// }
// }
//
let mut result: Value = self.safe_value_k(transfer.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut refid: Value = self.safe_string_k(result.clone(), "refid", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), refid.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("currency".to_string(), self.safe_string_k(currency.clone(), "code", &[]));
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), Value::Str("sucess".to_string()));
m
});
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut url: Value = add(&add(&add(&add(&add(&Value::Str("/".to_string()), &self.version), &Value::Str("/".to_string())), &api), &Value::Str("/".to_string())), &path);
if is_equal(&api, &Value::Str("public".to_string())) {
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
// rawencode is used to address https://github.com/ccxt/ccxt/issues/12872
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode_nested(params.clone(), &[])));
}
} else if is_equal(&api, &Value::Str("private".to_string())) {
let mut price: Value = self.safe_string_k(params.clone(), "price", &[]);
let mut isTriggerPercent: Value = Value::Bool(false);
if !is_equal(&price, &Value::Null) {
isTriggerPercent = ternary(is_true(&(Value::Bool(ends_with(&price, &Value::Str("%".to_string()))))), Value::Bool(true), Value::Bool(false));
}
let mut isCancelOrderBatch: bool = is_equal(&path, &Value::Str("CancelOrderBatch".to_string()));
let mut isBatchOrder: bool = is_equal(&path, &Value::Str("AddOrderBatch".to_string()));
self.check_required_credentials(&[]);
let mut nonce: Value = to_string_val(&self.nonce());
if is_true(&isCancelOrderBatch) || is_true(&isTriggerPercent) || is_true(&isBatchOrder) {
let __ws_arg_29 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("nonce".to_string(), nonce.clone());
m
}), &[params.clone()]);
body = self.json(__ws_arg_29);
} else {
// rawencode is used to address https://github.com/ccxt/ccxt/issues/12872
let __ws_arg_30 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("nonce".to_string(), nonce.clone());
m
}), &[params.clone()]);
body = self.urlencode_nested(__ws_arg_30, &[]);
}
let mut auth: Value = self.encode(add(&nonce, &body));
let mut hash: Value = self.hash(auth.clone(), Value::Str("sha256".to_string()), &[Value::Str("binary".to_string())]);
let mut binary: Value = self.encode(url.clone());
let mut binhash: Value = self.binary_concat(binary.clone(), &[hash.clone()]);
let mut secret: Value = self.base64_to_binary(self.secret.clone(), &[]);
let mut signature: Value = self.hmac(binhash.clone(), secret.clone(), Value::Str("sha512".to_string()), &[Value::Str("base64".to_string())]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("API-Key".to_string(), self.apiKey.clone());
m.insert("API-Sign".to_string(), signature.clone());
m
});
if is_true(&isCancelOrderBatch) || is_true(&isTriggerPercent) || is_true(&isBatchOrder) {
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
} else {
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/x-www-form-urlencoded".to_string()));
}
} else {
url = add(&Value::Str("/".to_string()), &path);
}
url = add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &url);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&code, &Value::Int(520)) {
panic!("{}", crate::exchange_errors::exchange_not_available(add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &to_string_val(&code)), &Value::Str(" ".to_string())), &reason)));
}
if is_equal(&response, &Value::Null) {
return Value::Null;
}
if is_equal(&get_value(&body, &Value::Int(0)), &Value::Str("{".to_string())) {
if !is_string(&response) {
let mut message: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
if is_true(&Value::Bool(in_op(&response, &Value::Str("error".to_string())))) {
let mut numErrors: Value = get_array_length(&get_value(&response, &Value::Str("error".to_string())));
if is_greater_than(&numErrors, &Value::Int(0)) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_855: bool = true;
while { if !__for_first_855 { i = add(&i, &Value::Int(1)); } __for_first_855 = false; is_less_than(&i, &get_array_length(&get_value(&response, &Value::Str("error".to_string())))) } {
let mut error: Value = get_value(&get_value(&response, &Value::Str("error".to_string())), &i);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), error.clone(), message.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), error.clone(), message.clone());
}
}
panic!("{}", crate::exchange_errors::exchange_error(message));
}
}
// handleCreateOrdersErrors:
if is_true(&Value::Bool(in_op(&response, &Value::Str("result".to_string())))) {
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_true(&Value::Bool(in_op(&result, &Value::Str("orders".to_string())))) {
let mut orders: Value = self.safe_list_k(result.clone(), "orders", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_856: bool = true;
while { if !__for_first_856 { i = add(&i, &Value::Int(1)); } __for_first_856 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = get_value(&orders, &i);
let mut order: Value = get_value(&orders, &i);
let mut error: Value = self.safe_string_k(order.clone(), "error", &[]);
if !is_equal(&error, &Value::Null) {
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), error.clone(), message.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), error.clone(), message.clone());
panic!("{}", crate::exchange_errors::exchange_error(message));
}
}
}
}
}
}
}
return Value::Null;
Value::Null
}
}