#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
use crate::exchange::CallDynamicChecked;
pub struct FoxbitCore {
pub exchange: crate::exchange::Exchange,
}
impl FoxbitCore {
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 = FoxbitCore::describe(self);
self.initialize_properties(described);
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for FoxbitCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
FoxbitCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
FoxbitCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
FoxbitCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
FoxbitCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
FoxbitCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
FoxbitCore::parse_deposit_address(self, depositAddress, &[currency])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
FoxbitCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
FoxbitCore::parse_currency(self, currency)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
FoxbitCore::parse_transaction(self, transaction, &[currency])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
FoxbitCore::sign(self, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
FoxbitCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for FoxbitCore {
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 {
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).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[4.min(args.len())..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_canceled_orders" => self.fetch_canceled_orders(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_orders_by_status" => self.fetch_orders_by_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_status" => self.fetch_status(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_transactions" => self.fetch_transactions(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null),
args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for FoxbitCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for FoxbitCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl FoxbitCore {
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("foxbit".into()));
m.insert("name".to_string(), Value::Str("Foxbit".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("pt-BR".into())]));
m.insert("rateLimit".to_string(), Value::Float(33.334));
m.insert("version".to_string(), Value::Str("1".into()));
m.insert("comment".to_string(), Value::Str("Foxbit Exchange".into()));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(false));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Bool(true));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), Value::Null);
m.insert("future".to_string(), Value::Null);
m.insert("option".to_string(), Value::Null);
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("createLimitBuyOrder".to_string(), Value::Bool(true));
m.insert("createLimitSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrder".to_string(), Value::Bool(true));
m.insert("createMarketSellOrder".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchL2OrderBook".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(true));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactions".to_string(), Value::Bool(true));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("loadMarkets".to_string(), Value::Bool(true));
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(true));
m.insert("ws".to_string(), Value::Bool(false));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("15m".to_string(), Value::Str("15m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("2h".to_string(), Value::Str("2h".into()));
m.insert("4h".to_string(), Value::Str("4h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("12h".to_string(), Value::Str("12h".into()));
m.insert("1d".to_string(), Value::Str("1d".into()));
m.insert("1w".to_string(), Value::Str("1w".into()));
m.insert("2w".to_string(), Value::Str("2w".into()));
m.insert("1M".to_string(), Value::Str("1M".into()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/1f8faca2-ae2f-4222-b33e-5671e7d873dd".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.foxbit.com.br".into()));
m.insert("private".to_string(), Value::Str("https://api.foxbit.com.br".into()));
m.insert("status".to_string(), Value::Str("https://metadata-v2.foxbit.com.br/api".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://app.foxbit.com.br".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://docs.foxbit.com.br".into())]));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("400".to_string(), Value::Str("BadRequest".into()));
m.insert("429".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("404".to_string(), Value::Str("BadRequest".into()));
m.insert("500".to_string(), Value::Str("ExchangeError".into()));
m.insert("2001".to_string(), Value::Str("AuthenticationError".into()));
m.insert("2002".to_string(), Value::Str("AuthenticationError".into()));
m.insert("2003".to_string(), Value::Str("AuthenticationError".into()));
m.insert("2004".to_string(), Value::Str("BadRequest".into()));
m.insert("2005".to_string(), Value::Str("PermissionDenied".into()));
m.insert("3001".to_string(), Value::Str("PermissionDenied".into()));
m.insert("3002".to_string(), Value::Str("PermissionDenied".into()));
m.insert("3003".to_string(), Value::Str("AccountSuspended".into()));
m.insert("4001".to_string(), Value::Str("BadRequest".into()));
m.insert("4002".to_string(), Value::Str("InsufficientFunds".into()));
m.insert("4003".to_string(), Value::Str("InvalidOrder".into()));
m.insert("4004".to_string(), Value::Str("BadSymbol".into()));
m.insert("4005".to_string(), Value::Str("BadRequest".into()));
m.insert("4007".to_string(), Value::Str("ExchangeError".into()));
m.insert("4008".to_string(), Value::Str("InvalidOrder".into()));
m.insert("4009".to_string(), Value::Str("PermissionDenied".into()));
m.insert("4011".to_string(), Value::Str("RateLimitExceeded".into()));
m.insert("4012".to_string(), Value::Str("ExchangeError".into()));
m.insert("5001".to_string(), Value::Str("ExchangeNotAvailable".into()));
m.insert("5002".to_string(), Value::Str("OnMaintenance".into()));
m.insert("5003".to_string(), Value::Str("OnMaintenance".into()));
m.insert("5004".to_string(), Value::Str("InvalidOrder".into()));
m.insert("5005".to_string(), Value::Str("InvalidOrder".into()));
m.insert("5006".to_string(), Value::Str("InvalidOrder".into()));
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v3".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("markets/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(60));
m
}));
m.insert("markets/{market}/orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("markets/{market}/candlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("markets/{market}/trades/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(12));
m
}));
m.insert("markets/{market}/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("markets/sparkline/{window}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("travel_rule/operation_reasons".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("accounts/{symbol}/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(60));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders/by-order-id/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(6));
m
}));
m.insert("deposits/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("deposits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("me/fees/trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(60));
m
}));
m.insert("prime_desk/executions/{quote_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("orders/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(7.5));
m
}));
m.insert("orders/cancel-replace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("withdrawals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("deposits/{deposit_sn}/travel_rule".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m.insert("status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("get".into()));
m.insert("tierBased".to_string(), Value::Bool(false));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.005".into()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0025".into()), &[]));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandboxMode".to_string(), Value::Bool(false));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("algorand".to_string(), Value::Str("ALGO".into()));
m.insert("arbitrum".to_string(), Value::Str("ARBITRUM".into()));
m.insert("avalanchecchain".to_string(), Value::Str("AVAX".into()));
m.insert("bitcoin".to_string(), Value::Str("BTC".into()));
m.insert("bitcoincash".to_string(), Value::Str("BCH".into()));
m.insert("bsc".to_string(), Value::Str("BEP20".into()));
m.insert("cardano".to_string(), Value::Str("ADA".into()));
m.insert("cosmos".to_string(), Value::Str("ATOM".into()));
m.insert("dogecoin".to_string(), Value::Str("DOGE".into()));
m.insert("erc20".to_string(), Value::Str("ERC20".into()));
m.insert("hedera".to_string(), Value::Str("HBAR".into()));
m.insert("litecoin".to_string(), Value::Str("LTC".into()));
m.insert("near".to_string(), Value::Str("NEAR".into()));
m.insert("optimism".to_string(), Value::Str("OPTIMISM".into()));
m.insert("polkadot".to_string(), Value::Str("DOT".into()));
m.insert("polygon".to_string(), Value::Str("MATIC".into()));
m.insert("ripple".to_string(), Value::Str("XRP".into()));
m.insert("solana".to_string(), Value::Str("SOL".into()));
m.insert("stacks".to_string(), Value::Str("STX".into()));
m.insert("stellar".to_string(), Value::Str("XLM".into()));
m.insert("tezos".to_string(), Value::Str("XTZ".into()));
m.insert("trc20".to_string(), Value::Str("TRC20".into()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ALGO".to_string(), Value::Str("algorand".into()));
m.insert("ARBITRUM".to_string(), Value::Str("arbitrum".into()));
m.insert("AVAX".to_string(), Value::Str("avalanchecchain".into()));
m.insert("BTC".to_string(), Value::Str("bitcoin".into()));
m.insert("BCH".to_string(), Value::Str("bitcoincash".into()));
m.insert("BEP20".to_string(), Value::Str("bsc".into()));
m.insert("ADA".to_string(), Value::Str("cardano".into()));
m.insert("ATOM".to_string(), Value::Str("cosmos".into()));
m.insert("DOGE".to_string(), Value::Str("dogecoin".into()));
m.insert("ERC20".to_string(), Value::Str("erc20".into()));
m.insert("HBAR".to_string(), Value::Str("hedera".into()));
m.insert("LTC".to_string(), Value::Str("litecoin".into()));
m.insert("NEAR".to_string(), Value::Str("near".into()));
m.insert("OPTIMISM".to_string(), Value::Str("optimism".into()));
m.insert("DOT".to_string(), Value::Str("polkadot".into()));
m.insert("MATIC".to_string(), Value::Str("polygon".into()));
m.insert("XRP".to_string(), Value::Str("ripple".into()));
m.insert("SOL".to_string(), Value::Str("solana".into()));
m.insert("STX".to_string(), Value::Str("stacks".into()));
m.insert("XLM".to_string(), Value::Str("stellar".into()));
m.insert("XTZ".to_string(), Value::Str("tezos".into()));
m.insert("TRC20".to_string(), Value::Str("trc20".into()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(false));
m.insert("index".to_string(), Value::Bool(false));
m
}));
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("IOC".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("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("expire_maker".to_string(), Value::Bool(true));
m.insert("expire_taker".to_string(), Value::Bool(true));
m.insert("expire_both".to_string(), Value::Bool(true));
m.insert("none".to_string(), Value::Bool(true));
m
}));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("icebergAmount".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(5));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("untilDays".to_string(), Value::Int(10000));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
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::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("untilDays".to_string(), Value::Int(10000));
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("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("daysBackCanceled".to_string(), Value::Int(90));
m.insert("untilDays".to_string(), Value::Int(10000));
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(500));
m
}));
m
}));
m
}));
m
})]);
Value::Null
}
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.v3_public_get_currencies(&[params]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_currencies(data);
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut currencyId: Option<String> = self.safe_string_k_opt(rawCurrency.clone(), "symbol", &[]);
let mut name: Option<String> = self.safe_string_k_opt(rawCurrency.clone(), "name", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut depositInfo: Value = self.safe_dict_k(rawCurrency.clone(), "deposit_info", &[]);
let mut withdrawInfo: Value = self.safe_dict_k(rawCurrency.clone(), "withdraw_info", &[]);
let mut networks: Value = self.safe_list_k(rawCurrency.clone(), "networks", &[Value::from(vec![])]);
let mut type_var: Option<String> = self.safe_string_lower_k_opt(rawCurrency.clone(), "type", &[]);
let mut parsedNetworks: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: i64 = 0;
let mut __for_first_676: bool = true;
while { if !__for_first_676 { j += 1; } __for_first_676 = false; j < (networks.len() as i64) } {
let mut network: Value = self.safe_dict(networks.clone(), Value::Int(j), &[]);
let mut networkId: Option<String> = self.safe_string_k_opt(network.clone(), "code", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone().map(Value::from).unwrap_or(Value::Null), code.clone()]);
let mut networkWithdrawInfo: Value = self.safe_dict_k(network.clone(), "withdraw_info", &[]);
let mut networkDepositInfo: Value = self.safe_dict_k(network.clone(), "deposit_info", &[]);
let mut isWithdrawEnabled: Value = Value::Bool(self.safe_string_k(networkWithdrawInfo.clone(), "status", &[]).as_str() == Some("ENABLED"));
let mut isDepositEnabled: Value = Value::Bool(self.safe_string_k(networkDepositInfo, "status", &[]).as_str() == Some("ENABLED"));
if (networkCode != Value::Null) {
parsedNetworks.insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rawCurrency.clone());
m.insert("id".to_string(), networkId.map(Value::from).unwrap_or(Value::Null));
m.insert("network".to_string(), networkCode.clone());
m.insert("name".to_string(), self.safe_string_k(network, "name", &[]));
m.insert("deposit".to_string(), isDepositEnabled);
m.insert("withdraw".to_string(), isWithdrawEnabled);
m.insert("active".to_string(), Value::Bool(true));
m.insert("precision".to_string(), Value::Null);
m.insert("fee".to_string(), self.safe_number_k(networkWithdrawInfo, "fee", &[]));
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("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(depositInfo.clone(), "min_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(withdrawInfo.clone(), "min_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), currencyId.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("code".to_string(), code);
m.insert("info".to_string(), rawCurrency.clone());
m.insert("name".to_string(), name.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("active".to_string(), Value::Bool(true));
m.insert("type".to_string(), type_var.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("deposit".to_string(), self.safe_bool_k(depositInfo.clone(), "enabled", &[Value::Bool(false)]));
m.insert("withdraw".to_string(), self.safe_bool_k(withdrawInfo.clone(), "enabled", &[Value::Bool(false)]));
m.insert("fee".to_string(), self.safe_number_k(withdrawInfo.clone(), "fee", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(rawCurrency, "precision", &[])]), &[]));
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("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(depositInfo, "min_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(withdrawInfo, "min_amount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), Value::Map(parsedNetworks));
m
}));
Value::Null
}
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 response: Value = self.v3_public_get_markets(&[params]).await;
let mut markets: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_markets(markets);
Value::Null
}
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_0 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_public_get_markets_market_ticker24hr(&[__ws_arg_0]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(result, &[market]);
Value::Null
}
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.v3_public_get_markets_ticker24hr(&[params]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_tickers(data, &[symbolsNormalized]);
Value::Null
}
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v3_private_get_me_fees_trading(&[params]).await;
let mut data: Vec<Value> = self.safe_list_k(response, "data", &[Value::from(vec![])]).as_array().cloned().unwrap_or_default();
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: i64 = 0;
let mut __for_first_677: bool = true;
while { if !__for_first_677 { i += 1; } __for_first_677 = false; i < (data.len() as i64) } {
let mut entry: Value = data.get(i as usize).cloned().unwrap_or(Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(entry.clone(), "market_symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.map(Value::from).unwrap_or(Value::Null)]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), self.parse_trading_fee(entry, &[market])); }
}
}
return result;
Value::Null
}
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol.clone()).as_map().cloned().unwrap_or_default();
let mut defaultLimit: Value = Value::Int(20);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m.insert("depth".to_string(), (if (limit == Value::Null) { defaultLimit } else { limit }));
m
});
let __ws_arg_1 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_public_get_markets_market_orderbook(&[__ws_arg_1]).await;
let mut timestamp: Value = self.safe_integer_k(response.clone(), "timestamp", &[]);
return self.parse_order_book(response, symbol, &[timestamp]);
Value::Null
}
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
request.insert("page_size".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((200i64) as f64) {
request.insert("page_size".into(), Value::Int(200));
}
}
let __ws_arg_2 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_public_get_markets_market_trades_history(&[__ws_arg_2]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_trades(data, &[market, since, limit]);
Value::Null
}
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut interval: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("interval".to_string(), interval.clone());
m
});
if (since != Value::Null) {
request.insert("start_time".into(), self.iso8601(since.clone()));
}
if (limit != Value::Null) {
request.insert("limit".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((500i64) as f64) {
request.insert("limit".into(), Value::Int(500));
}
}
let __ws_arg_3 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_public_get_markets_market_candlesticks(&[__ws_arg_3]).await;
return self.parse_ohlc_vs(self.to_array(response), &[market, interval, since, limit]);
Value::Null
}
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.v3_private_get_accounts(&[params]).await;
let mut accounts: Value = self.safe_list_k(response.clone(), "data", &[Value::from(vec![])]);
let mut result: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
});
{
let mut i: i64 = 0;
let mut __for_first_678: bool = true;
while { if !__for_first_678 { i += 1; } __for_first_678 = false; i < (accounts.len() as i64) } {
let mut account: Value = self.safe_dict(accounts.clone(), Value::Int(i), &[]);
let mut currencyId: Option<String> = self.safe_string_k_opt(account.clone(), "currency_symbol", &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.map(Value::from).unwrap_or(Value::Null), &[]);
let mut total: Option<String> = self.safe_string_k_opt(account.clone(), "balance", &[]);
let mut used: Option<String> = self.safe_string_k_opt(account.clone(), "balance_locked", &[]);
let mut free: Option<String> = self.safe_string_k_opt(account, "balance_available", &[]);
let mut balanceObj: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), free.map(Value::from).unwrap_or(Value::Null));
m.insert("used".to_string(), used.map(Value::from).unwrap_or(Value::Null));
m.insert("total".to_string(), total.map(Value::from).unwrap_or(Value::Null));
m
});
if (currencyCode != Value::Null) {
result.insert(crate::runtime::stringify_param(¤cyCode), Value::Map(balanceObj));
}
}
}
return self.safe_balance(Value::Map(result));
Value::Null
}
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
}));
return self.fetch_orders_by_status(Value::Str("ACTIVE".into()), &[symbol, since, limit, params]).await;
Value::Null
}
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
}));
return self.fetch_orders_by_status(Value::Str("FILLED".into()), &[symbol, since, limit, params]).await;
Value::Null
}
pub async fn fetch_canceled_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_orders_by_status(Value::Str("CANCELED".into()), &[symbol, since, limit, params]).await;
Value::Null
}
pub async fn fetch_orders_by_status(&mut self, mut status: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("state".to_string(), status);
m
});
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("market_symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (since != Value::Null) {
request.insert("start_time".into(), self.iso8601(since));
}
if (limit != Value::Null) {
request.insert("page_size".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((100i64) as f64) {
request.insert("page_size".into(), Value::Int(100));
}
}
let __ws_arg_4 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_orders(&[__ws_arg_4]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_orders(data, &[]);
Value::Null
}
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut typeValue: Value = (if let Some(__s) = type_var.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
if (typeValue.as_str() != Some("LIMIT")) && (typeValue.as_str() != Some("MARKET")) && (typeValue.as_str() != Some("STOP_MARKET")) && (typeValue.as_str() != Some("STOP_LIMIT")) && (typeValue.as_str() != Some("INSTANT")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Invalid order type: ".into()), typeValue).into()), Value::Str(". Must be one of: limit, market, stop_market, stop_limit, instant.".into()))));
}
let mut timeInForce: Option<String> = self.safe_string_upper_k_opt(params.clone(), "timeInForce", &[]);
let mut postOnly: bool = self.safe_bool_k_opt(params.clone(), "postOnly", &[Value::Bool(false)]).unwrap_or(false);
let mut triggerPrice: Value = self.safe_number_k(params.clone(), "triggerPrice", &[]);
self.check_required_argument(Value::Str("createOrder".into()), side.clone(), Value::Str("side".into()), &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("market_symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), (if let Some(__s) = side.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }));
m.insert("type".to_string(), typeValue.clone());
m
});
if (typeValue.as_str() == Some("STOP_MARKET")) || (typeValue.as_str() == Some("STOP_LIMIT")) {
if (triggerPrice == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Invalid order type: ".into()), typeValue).into()), Value::Str(". Must have triggerPrice.".into()))));
}
}
if (timeInForce.is_some()) {
if (timeInForce.as_deref() == Some("PO")) {
request.insert("post_only".into(), Value::Bool(true));
} else {
request.insert("time_in_force".into(), timeInForce.map(Value::from).unwrap_or(Value::Null));
}
}
if postOnly {
request.insert("post_only".into(), Value::Bool(true));
}
if (triggerPrice != Value::Null) {
request.insert("stop_price".into(), self.price_to_precision(symbol.clone(), triggerPrice));
}
if (typeValue.as_str() == Some("INSTANT")) {
request.insert("amount".into(), self.price_to_precision(symbol.clone(), amount.clone()));
} else {
request.insert("quantity".into(), self.amount_to_precision(symbol.clone(), amount));
}
if (typeValue.as_str() == Some("LIMIT")) || (typeValue.as_str() == Some("STOP_LIMIT")) {
request.insert("price".into(), self.price_to_precision(symbol, price));
}
let mut clientOrderId: Option<String> = self.safe_string_k_opt(params.clone(), "clientOrderId", &[]);
if (clientOrderId.is_some()) {
request.insert("client_order_id".into(), clientOrderId.map(Value::from).unwrap_or(Value::Null));
}
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("timeInForce".into()), Value::Str("postOnly".into()), Value::Str("triggerPrice".into()), Value::Str("clientOrderId".into())]), &[]);
let __ws_arg_5 = self.extend(Value::Map(request), &[paramsOmitted]);
let mut response: Value = self.v3_private_post_orders(&[__ws_arg_5]).await;
return self.parse_order(response, &[market]);
Value::Null
}
pub async fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Vec<Value> = Vec::new();
{
let mut i: i64 = 0;
let mut __for_first_679: bool = true;
while { if !__for_first_679 { i += 1; } __for_first_679 = false; i < (orders.len() as i64) } {
let mut order: Value = self.safe_dict(orders.clone(), Value::Int(i), &[]);
let mut symbol: Option<String> = self.safe_string_k_opt(order.clone(), "symbol", &[]);
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol.clone().map(Value::from).unwrap_or(Value::Null)).as_map().cloned().unwrap_or_default();
let mut type_var: Value = self.safe_string_upper_k(order.clone(), "type", &[Value::Str("".into())]);
let mut orderParams: Value = self.safe_dict_k(order.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if (type_var.as_str() != Some("LIMIT")) && (type_var.as_str() != Some("MARKET")) && (type_var.as_str() != Some("STOP_MARKET")) && (type_var.as_str() != Some("STOP_LIMIT")) && (type_var.as_str() != Some("INSTANT")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Invalid order type: ".into()), type_var).into()), Value::Str(". Must be one of: limit, market, stop_market, stop_limit, instant.".into()))));
}
let mut timeInForce: Option<String> = self.safe_string_upper_k_opt(orderParams.clone(), "timeInForce", &[]);
let mut postOnly: bool = self.safe_bool_k_opt(orderParams.clone(), "postOnly", &[Value::Bool(false)]).unwrap_or(false);
let mut triggerPrice: Value = self.safe_number_k(orderParams.clone(), "triggerPrice", &[]);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("market_symbol".to_string(), market.get("id").cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), self.safe_string_upper_k(order.clone(), "side", &[]));
m.insert("type".to_string(), type_var.clone());
m
});
if (type_var.as_str() == Some("STOP_MARKET")) || (type_var.as_str() == Some("STOP_LIMIT")) {
if (triggerPrice == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Invalid order type: ".into()), type_var).into()), Value::Str(". Must have triggerPrice.".into()))));
}
}
if (timeInForce.is_some()) {
if (timeInForce.as_deref() == Some("PO")) {
request.insert("post_only".into(), Value::Bool(true));
} else {
request.insert("time_in_force".into(), timeInForce.map(Value::from).unwrap_or(Value::Null));
}
if let Value::Dict(__d) = &mut orderParams { std::sync::Arc::make_mut(__d).shift_remove("timeInForce"); }
}
if postOnly {
request.insert("post_only".into(), Value::Bool(true));
if let Value::Dict(__d) = &mut orderParams { std::sync::Arc::make_mut(__d).shift_remove("postOnly"); }
}
if (triggerPrice != Value::Null) {
request.insert("stop_price".into(), self.price_to_precision(symbol.clone().map(Value::from).unwrap_or(Value::Null), triggerPrice));
if let Value::Dict(__d) = &mut orderParams { std::sync::Arc::make_mut(__d).shift_remove("triggerPrice"); }
}
if (type_var.as_str() == Some("INSTANT")) {
request.insert("amount".into(), self.price_to_precision(symbol.clone().map(Value::from).unwrap_or(Value::Null), self.safe_string_k(order.clone(), "amount", &[])));
} else {
request.insert("quantity".into(), self.amount_to_precision(symbol.clone().map(Value::from).unwrap_or(Value::Null), self.safe_string_k(order.clone(), "amount", &[])));
}
if (type_var.as_str() == Some("LIMIT")) || (type_var.as_str() == Some("STOP_LIMIT")) {
request.insert("price".into(), self.price_to_precision(symbol.map(Value::from).unwrap_or(Value::Null), self.safe_string_k(order, "price", &[])));
}
ordersRequests.push(self.extend(Value::Map(request), &[orderParams]));
}
}
let mut createOrdersRequest: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("data".to_string(), Value::from(ordersRequests));
m
});
let __ws_arg_6 = self.extend(Value::Map(createOrdersRequest), &[params]);
let mut response: Value = self.v3_private_post_orders_batch(&[__ws_arg_6]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_orders(data, &[]);
Value::Null
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.parse_number(id, &[]));
m.insert("type".to_string(), Value::Str("ID".into()));
m
});
let __ws_arg_7 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_put_orders_cancel(&[__ws_arg_7]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut result: Value = self.safe_dict(data, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result, &[]);
Value::Null
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("ALL".into()));
m
});
if (symbol != Value::Null) {
let mut market: indexmap::IndexMap<String, Value> = self.market(symbol).as_map().cloned().unwrap_or_default();
request.insert("type".into(), Value::Str("MARKET".into()));
request.insert("market_symbol".into(), market.get("id").cloned().unwrap_or(Value::Null));
}
let __ws_arg_8 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_put_orders_cancel(&[__ws_arg_8]).await;
return Value::from(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
}), &[])]);
Value::Null
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m
});
let __ws_arg_9 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_orders_by_order_id_id(&[__ws_arg_9]).await;
return self.parse_order(response, &[]);
Value::Null
}
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (symbol != Value::Null) {
market = self.market(symbol);
request.insert("market_symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
}
if (since != Value::Null) {
request.insert("start_time".into(), self.iso8601(since.clone()));
}
if (limit != Value::Null) {
request.insert("page_size".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((100i64) as f64) {
request.insert("page_size".into(), Value::Int(100));
}
}
let __ws_arg_10 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_orders(&[__ws_arg_10]).await;
let mut list: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_orders(list, &[market, since, limit]);
Value::Null
}
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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("market_symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
request.insert("start_time".into(), self.iso8601(since.clone()));
}
if (limit != Value::Null) {
request.insert("page_size".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((100i64) as f64) {
request.insert("page_size".into(), Value::Int(100));
}
}
let __ws_arg_11 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_trades(&[__ws_arg_11]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_trades(data, &[market, since, limit]);
Value::Null
}
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("currency_symbol".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let networkCodeparamsOmitedVariable: Vec<Value> = self.handle_network_code_and_params(params).as_array().cloned().unwrap_or_default();
let mut networkCode: Value = networkCodeparamsOmitedVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsOmited: Value = networkCodeparamsOmitedVariable.get(1).cloned().unwrap_or(Value::Null);
if (networkCode != Value::Null) {
request.insert("network_code".into(), self.network_code_to_id(networkCode, &[code]));
}
let __ws_arg_12 = self.extend(Value::Map(request), &[paramsOmited]);
let mut response: Value = self.v3_private_get_deposits_address(&[__ws_arg_12]).await;
return self.parse_deposit_address(response, &[currency]);
Value::Null
}
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
}
if (limit != Value::Null) {
request.insert("page_size".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((100i64) as f64) {
request.insert("page_size".into(), Value::Int(100));
}
}
if (since != Value::Null) {
request.insert("start_time".into(), self.iso8601(since.clone()));
}
let __ws_arg_13 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_deposits(&[__ws_arg_13]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_transactions(data, &[currency, since, limit]);
Value::Null
}
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
}
if (limit != Value::Null) {
request.insert("page_size".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((100i64) as f64) {
request.insert("page_size".into(), Value::Int(100));
}
}
if (since != Value::Null) {
request.insert("start_time".into(), self.iso8601(since.clone()));
}
let __ws_arg_14 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_withdrawals(&[__ws_arg_14]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_transactions(data, &[currency, since, limit]);
Value::Null
}
pub async fn fetch_transactions(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut withdrawals: Value = self.fetch_withdrawals(&[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
let mut deposits: Value = self.fetch_deposits(&[code, since, limit, params]).await;
let mut allTransactions: Value = self.array_concat(withdrawals, deposits);
let mut result: Value = self.sort_by(allTransactions, Value::Str("timestamp".into()), &[]);
return result;
Value::Null
}
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.status_public_get_status(&[params]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut attributes: Value = self.safe_dict_k(data, "attributes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut statusRaw: Option<String> = self.safe_string_k_opt(attributes.clone(), "status", &[]);
let mut statusMap: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("NORMAL".to_string(), Value::Str("ok".into()));
m.insert("UNDER_MAINTENANCE".to_string(), Value::Str("maintenance".into()));
m
});
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), self.safe_string(Value::Map(statusMap), statusRaw.clone().map(Value::from).unwrap_or(Value::Null), &[statusRaw.map(Value::from).unwrap_or(Value::Null)]));
m.insert("updated".to_string(), self.parse8601(self.safe_string_k(attributes, "updatedAt", &[])));
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response);
m
});
Value::Null
}
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
}));
self.check_required_argument(Value::Str("editOrder".into()), symbol.clone(), Value::Str("symbol".into()), &[]);
let mut typeValue: Value = (if let Some(__s) = type_var.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null });
if (typeValue.as_str() != Some("LIMIT")) && (typeValue.as_str() != Some("MARKET")) && (typeValue.as_str() != Some("STOP_MARKET")) && (typeValue.as_str() != Some("INSTANT")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", Value::Str(format!("{}{}", Value::Str("Invalid order type: ".into()), typeValue).into()), Value::Str(". Must be one of: LIMIT, MARKET, STOP_MARKET, INSTANT.".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
self.check_required_argument(Value::Str("editOrder".into()), side.clone(), Value::Str("side".into()), &[]);
let mut createRequest: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), typeValue.clone());
m.insert("side".to_string(), (if let Some(__s) = side.as_str() { Value::Str(__s.to_uppercase().into()) } else { Value::Null }));
m.insert("market_symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (typeValue.as_str() == Some("LIMIT")) || (typeValue.as_str() == Some("MARKET")) {
createRequest.insert("quantity".into(), self.amount_to_precision(symbol.clone(), amount.clone()));
if (typeValue.as_str() == Some("LIMIT")) {
createRequest.insert("price".into(), self.price_to_precision(symbol.clone(), price.clone()));
}
}
if (typeValue.as_str() == Some("STOP_MARKET")) {
createRequest.insert("stop_price".into(), self.price_to_precision(symbol.clone(), price));
createRequest.insert("quantity".into(), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if (typeValue.as_str() == Some("INSTANT")) {
createRequest.insert("amount".into(), self.price_to_precision(symbol, amount));
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("mode".to_string(), Value::Str("ALLOW_FAILURE".into()));
m.insert("cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("ID".into()));
m.insert("id".to_string(), self.parse_number(id, &[]));
m
}));
m.insert("create".to_string(), Value::Map(createRequest));
m
});
let __ws_arg_15 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_post_orders_cancel_replace(&[__ws_arg_15]).await;
let mut created: Value = self.safe_dict_k(response, "create", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(created, &[market]);
Value::Null
}
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let tagWithdrawTagparamsWithdrawTagVariable: Vec<Value> = self.handle_param_string(params, Value::Str("tag".into()), &[]).as_array().cloned().unwrap_or_default();
let mut tagWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagWithdrawTagparamsWithdrawTagVariable.get(1).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone(), code.clone(), tagWithdrawTag.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: indexmap::IndexMap<String, Value> = self.currency(code.clone()).as_map().cloned().unwrap_or_default();
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("currency_symbol".to_string(), currency.get("id").cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), self.number_to_string(amount));
m.insert("destination_address".to_string(), address);
m
});
if (tagWithdrawTag != Value::Null) {
request.insert("destination_tag".into(), tagWithdrawTag);
}
let networkCodeparamsNetworkCodeVariable: Vec<Value> = self.handle_network_code_and_params(paramsWithdrawTag).as_array().cloned().unwrap_or_default();
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.get(0).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.get(1).cloned().unwrap_or(Value::Null);
if (networkCode != Value::Null) {
request.insert("network_code".into(), self.network_code_to_id(networkCode, &[code]));
}
let __ws_arg_16 = self.extend(Value::Map(request), &[paramsNetworkCode]);
let mut response: Value = self.v3_private_post_withdrawals(&[__ws_arg_16]).await;
return self.parse_transaction(response, &[]);
Value::Null
}
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m
});
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchLedger() requires a code argument".into()))));
}
if (limit != Value::Null) {
request.insert("page_size".into(), limit.clone());
if limit.as_f64().unwrap_or(f64::NAN) > ((100i64) as f64) {
request.insert("page_size".into(), Value::Int(100));
}
}
if (since != Value::Null) {
request.insert("start_time".into(), self.iso8601(since.clone()));
}
let mut currency: Value = self.currency(code);
request.insert("symbol".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_17 = self.extend(Value::Map(request), &[params]);
let mut response: Value = self.v3_private_get_accounts_symbol_transactions(&[__ws_arg_17]).await;
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
return self.parse_ledger(data, &[currency, since, limit]);
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut id: Option<String> = self.safe_string_k_opt(market.clone(), "symbol", &[]);
let mut baseAssets: Value = self.safe_dict_k(market.clone(), "base", &[]);
let mut baseId: Option<String> = self.safe_string_k_opt(baseAssets, "symbol", &[]);
let mut quoteAssets: Value = self.safe_dict_k(market.clone(), "quote", &[]);
let mut quoteId: Option<String> = self.safe_string_k_opt(quoteAssets, "symbol", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone().map(Value::from).unwrap_or(Value::Null), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut fees: Value = self.safe_dict_k(market.clone(), "default_fees", &[]);
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("baseId".to_string(), baseId.map(Value::from).unwrap_or(Value::Null));
m.insert("quoteId".to_string(), quoteId.map(Value::from).unwrap_or(Value::Null));
m.insert("active".to_string(), Value::Bool(true));
m.insert("type".to_string(), Value::Str("spot".into()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("settle".to_string(), Value::Null);
m.insert("settleId".to_string(), Value::Null);
m.insert("contractSize".to_string(), Value::Null);
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".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("taker".to_string(), self.safe_number_k(fees.clone(), "taker", &[]));
m.insert("maker".to_string(), self.safe_number_k(fees, "maker", &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(false));
m.insert("feeSide".to_string(), Value::Str("get".into()));
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("price".to_string(), self.safe_number_k(market.clone(), "price_increment", &[]));
m.insert("amount".to_string(), self.safe_number_k(market.clone(), "quantity_increment", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "quantity_min", &[]));
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(), self.safe_number_k(market.clone(), "price_min", &[]));
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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
pub fn parse_trading_fee(&self, mut entry: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), self.safe_string_k(market, "symbol", &[]));
m.insert("maker".to_string(), self.safe_number_k(entry.clone(), "maker", &[]));
m.insert("taker".to_string(), self.safe_number_k(entry, "taker", &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Option<String> = self.safe_string_k_opt(ticker.clone(), "market_symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.map(Value::from).unwrap_or(Value::Null), &[market.clone(), Value::Null, Value::Str("spot".into())]);
let mut rolling_24h: Value = self.safe_dict_k(ticker.clone(), "rolling_24h", &[]);
let mut best: Value = self.safe_dict_k(ticker.clone(), "best", &[]);
let mut bestAsk: Value = self.safe_dict_k(best.clone(), "ask", &[]);
let mut bestBid: Value = self.safe_dict_k(best, "bid", &[]);
let mut lastTrade: Value = self.safe_dict_k(ticker.clone(), "last_trade", &[]);
let mut lastPrice: Option<String> = self.safe_string_k_opt(lastTrade.clone(), "price", &[]);
let mut change: Option<String> = self.safe_string_k_opt(rolling_24h.clone(), "price_change", &[]);
let mut percentage: Option<String> = self.safe_string_k_opt(rolling_24h.clone(), "price_change_percent", &[]);
if crate::precise::Precise::stringEq(&lastPrice.clone().map(Value::from).unwrap_or(Value::Null), &Value::Str("0".into())).as_bool() == Some(true) {
lastPrice = None;
change = None;
percentage = None;
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), self.parse_date(self.safe_string_k(lastTrade.clone(), "date", &[]), &[]));
m.insert("datetime".to_string(), self.iso8601(self.parse_date(self.safe_string_k(lastTrade, "date", &[]), &[])));
m.insert("high".to_string(), self.safe_number_k(rolling_24h.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_number_k(rolling_24h.clone(), "low", &[]));
m.insert("bid".to_string(), self.safe_number_k(bestBid.clone(), "price", &[]));
m.insert("bidVolume".to_string(), self.safe_number_k(bestBid, "volume", &[]));
m.insert("ask".to_string(), self.safe_number_k(bestAsk.clone(), "price", &[]));
m.insert("askVolume".to_string(), self.safe_number_k(bestAsk, "volume", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_number_k(rolling_24h.clone(), "open", &[]));
m.insert("close".to_string(), lastPrice.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("last".to_string(), lastPrice.map(Value::from).unwrap_or(Value::Null));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), change.map(Value::from).unwrap_or(Value::Null));
m.insert("percentage".to_string(), percentage.map(Value::from).unwrap_or(Value::Null));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(rolling_24h.clone(), "volume", &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(rolling_24h, "quote_volume", &[]));
m.insert("info".to_string(), ticker);
m
}), &[market]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_integer(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv, Value::Int(6), &[])]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut timestamp: Value = self.parse_date(self.safe_string_k(trade.clone(), "created_at", &[]), &[]);
let mut price: Option<String> = self.safe_string_k_opt(trade.clone(), "price", &[]);
let mut amount: Value = self.safe_string_k(trade.clone(), "volume", &[self.safe_string(trade.clone(), Value::Str("quantity".into()), &[])]);
let mut privateSideField: Option<String> = self.safe_string_lower_k_opt(trade.clone(), "side", &[]);
let mut side: Value = self.safe_string_lower_k(trade.clone(), "taker_side", &[privateSideField.map(Value::from).unwrap_or(Value::Null)]);
let mut cost: Value = crate::precise::Precise::stringMul(&price.clone().map(Value::from).unwrap_or(Value::Null), &amount);
let mut fee: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_symbol(self.safe_string_k(trade.clone(), "fee_currency_symbol", &[]), &[]));
m.insert("cost".to_string(), self.safe_number_k(trade.clone(), "fee", &[]));
m.insert("rate".to_string(), Value::Null);
m
});
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(trade.clone(), "id", &[]));
m.insert("info".to_string(), trade);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("order".to_string(), Value::Null);
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side);
m.insert("takerOrMaker".to_string(), Value::Null);
m.insert("price".to_string(), price.map(Value::from).unwrap_or(Value::Null));
m.insert("amount".to_string(), amount);
m.insert("cost".to_string(), cost);
m.insert("fee".to_string(), Value::Map(fee));
m
}), &[market]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("PARTIALLY_CANCELED".to_string(), Value::Str("open".into()));
m.insert("ACTIVE".to_string(), Value::Str("open".into()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".into()));
m.insert("FILLED".to_string(), Value::Str("closed".into()));
m.insert("PENDING_CANCEL".to_string(), Value::Str("canceled".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut symbol: Option<String> = self.safe_string_k_opt(order.clone(), "market_symbol", &[]);
let mut marketResolved: Value = market.clone();
if (market != Value::Null) {
symbol = self.safe_string_k_opt(market.clone(), "symbol", &[]);
} else if (symbol.is_some()) {
marketResolved = self.market(symbol.clone().map(Value::from).unwrap_or(Value::Null));
symbol = self.safe_string_k_opt(marketResolved.clone(), "symbol", &[]);
}
let mut timestamp: Value = self.parse_date(self.safe_string_k(order.clone(), "created_at", &[]), &[]);
let mut price: Option<String> = self.safe_string_k_opt(order.clone(), "price", &[]);
let mut filled: Option<String> = self.safe_string_k_opt(order.clone(), "quantity_executed", &[]);
let mut remaining: Option<String> = self.safe_string_k_opt(order.clone(), "quantity", &[]);
let mut amount: Value = Value::Null;
if (remaining.is_some()) && (filled.is_some()) {
amount = crate::precise::Precise::stringAdd(&remaining.clone().map(Value::from).unwrap_or(Value::Null), &filled.clone().map(Value::from).unwrap_or(Value::Null));
}
let mut cost: Value = self.safe_string_k(order.clone(), "funds_received", &[]);
if (cost == Value::Null) || (cost.as_str() == Some("")) {
let mut priceAverage: Option<String> = self.safe_string_k_opt(order.clone(), "price_avg", &[]);
let mut priceToCalculate: Value = self.safe_string_k(order.clone(), "price", &[priceAverage.map(Value::from).unwrap_or(Value::Null)]);
cost = crate::precise::Precise::stringMul(&priceToCalculate, &amount);
}
let mut side: Option<String> = self.safe_string_lower_k_opt(order.clone(), "side", &[]);
let mut feeCurrency: Option<String> = self.safe_string_upper_k_opt(marketResolved.clone(), "quoteId", &[]);
if (side.as_deref() == Some("buy")) {
feeCurrency = self.safe_string_upper_k_opt(marketResolved.clone(), "baseId", &[]);
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(order.clone(), "id", &[]));
m.insert("info".to_string(), order.clone());
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "client_order_id", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_order_status(self.safe_string_k(order.clone(), "state", &[])).map(Value::from).unwrap_or(Value::Null));
m.insert("symbol".to_string(), self.safe_string_k(marketResolved, "symbol", &[]));
m.insert("type".to_string(), self.safe_string_k(order.clone(), "type", &[]));
m.insert("timeInForce".to_string(), self.safe_string_k(order.clone(), "time_in_force", &[]));
m.insert("postOnly".to_string(), self.safe_bool_k(order.clone(), "post_only", &[]));
m.insert("reduceOnly".to_string(), Value::Null);
m.insert("side".to_string(), side.map(Value::from).unwrap_or(Value::Null));
m.insert("price".to_string(), self.parse_number(price.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("triggerPrice".to_string(), self.safe_number_k(order.clone(), "stop_price", &[]));
m.insert("takeProfitPrice".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("cost".to_string(), self.parse_number(cost, &[]));
m.insert("average".to_string(), self.safe_number_k(order.clone(), "price_avg", &[]));
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("filled".to_string(), self.parse_number(filled.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("remaining".to_string(), self.parse_number(remaining.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), feeCurrency.map(Value::from).unwrap_or(Value::Null));
m.insert("cost".to_string(), self.safe_number_k(order, "fee_paid", &[]));
m
}));
m
}), &[]);
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut network: Value = self.safe_dict_k(depositAddress.clone(), "network", &[]);
let mut networkId: Option<String> = self.safe_string_k_opt(network, "code", &[]);
let mut currencyCode: Value = self.safe_currency_code(Value::Null, &[currency]);
let mut unifiedNetwork: Value = self.network_id_to_code(&[networkId.map(Value::from).unwrap_or(Value::Null), currencyCode.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("address".to_string(), self.safe_string_k(depositAddress.clone(), "address", &[]));
m.insert("tag".to_string(), self.safe_string_k(depositAddress.clone(), "tag", &[]));
m.insert("currency".to_string(), currencyCode);
m.insert("network".to_string(), unifiedNetwork);
m.insert("info".to_string(), depositAddress);
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Option<String> {
let mut statuses: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("SUBMITTING".to_string(), Value::Str("pending".into()));
m.insert("SUBMITTED".to_string(), Value::Str("pending".into()));
m.insert("REJECTED".to_string(), Value::Str("failed".into()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".into()));
m.insert("ACCEPTED".to_string(), Value::Str("ok".into()));
m.insert("WARNING".to_string(), Value::Str("pending".into()));
m.insert("UNBLOCKED".to_string(), Value::Str("pending".into()));
m.insert("BLOCKED".to_string(), Value::Str("pending".into()));
m.insert("PROCESSING".to_string(), Value::Str("pending".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("FAILED".to_string(), Value::Str("failed".into()));
m.insert("DONE".to_string(), Value::Str("ok".into()));
m
});
return self.safe_string(Value::Map(statuses), status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = 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 cryptoDetails: Value = self.safe_dict_k(transaction.clone(), "details_crypto", &[]);
let mut address: Option<String> = self.safe_string2_opt(cryptoDetails.clone(), Value::Str("receiving_address".into()), Value::Str("destination_address".into()), &[]);
let mut sn: Option<String> = self.safe_string_k_opt(transaction.clone(), "sn", &[]);
let mut type_var: String = "withdrawal".to_string();
if (sn.is_some()) && (sn.as_deref().unwrap_or("").starts_with("D")) {
type_var = "deposit".to_string();
}
let mut fee: Value = self.safe_string_k(transaction.clone(), "fee", &[Value::Str("0".into())]);
let mut amount: Option<String> = self.safe_string_k_opt(transaction.clone(), "amount", &[]);
let mut currencySymbol: Option<String> = self.safe_string_k_opt(transaction.clone(), "currency_symbol", &[]);
let mut actualAmount: Value = amount.clone().map(Value::from).unwrap_or(Value::Null);
let mut currencyCode: Value = self.safe_currency_code(currencySymbol.map(Value::from).unwrap_or(Value::Null), &[]);
let mut status: Value = self.parse_transaction_status(self.safe_string_k(transaction.clone(), "state", &[])).map(Value::from).unwrap_or(Value::Null);
let mut created_at: Option<String> = self.safe_string_k_opt(transaction.clone(), "created_at", &[]);
let mut timestamp: Value = self.parse_date(created_at.map(Value::from).unwrap_or(Value::Null), &[]);
let mut datetime: Value = self.iso8601(timestamp.clone());
if (fee != Value::Null) && (amount.is_some()) {
actualAmount = crate::precise::Precise::stringSub(&amount.clone().map(Value::from).unwrap_or(Value::Null), &fee);
}
let mut feeRate: Value = crate::precise::Precise::stringDiv(&fee, &actualAmount);
let mut feeObj: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(fee, &[]));
m.insert("currency".to_string(), currencyCode.clone());
m.insert("rate".to_string(), self.parse_number(feeRate, &[]));
m
});
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string_k(transaction.clone(), "sn", &[]));
m.insert("txid".to_string(), self.safe_string_k(cryptoDetails, "transaction_id", &[]));
m.insert("timestamp".to_string(), timestamp);
m.insert("datetime".to_string(), datetime);
m.insert("network".to_string(), self.network_id_to_code(&[self.safe_string_k(transaction.clone(), "network_code", &[]), currencyCode.clone()]));
m.insert("address".to_string(), address.clone().map(Value::from).unwrap_or(Value::Null));
m.insert("addressTo".to_string(), address.map(Value::from).unwrap_or(Value::Null));
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), self.safe_string_k(transaction.clone(), "destination_tag", &[]));
m.insert("tagTo".to_string(), self.safe_string_k(transaction, "destination_tag", &[]));
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), Value::from(type_var));
m.insert("amount".to_string(), self.parse_number(amount.map(Value::from).unwrap_or(Value::Null), &[]));
m.insert("currency".to_string(), currencyCode);
m.insert("status".to_string(), status);
m.insert("updated".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map(feeObj));
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Option<String> {
let mut types: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("DEPOSITING".to_string(), Value::Str("transaction".into()));
m.insert("WITHDRAWING".to_string(), Value::Str("transaction".into()));
m.insert("TRADING".to_string(), Value::Str("trade".into()));
m.insert("INTERNAL_TRANSFERING".to_string(), Value::Str("transfer".into()));
m.insert("OTHERS".to_string(), Value::Str("transaction".into()));
m
});
return self.safe_string(Value::Map(types), type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut id: Option<String> = self.safe_string_k_opt(item.clone(), "uuid", &[]);
let mut createdAt: Option<String> = self.safe_string_k_opt(item.clone(), "created_at", &[]);
let mut timestamp: Value = self.parse8601(createdAt.map(Value::from).unwrap_or(Value::Null));
let mut reasonType: Option<String> = self.safe_string_k_opt(item.clone(), "reason_type", &[]);
let mut type_var: Value = self.parse_ledger_entry_type(reasonType.map(Value::from).unwrap_or(Value::Null)).map(Value::from).unwrap_or(Value::Null);
let mut exchangeSymbol: Option<String> = self.safe_string_k_opt(item.clone(), "currency_symbol", &[]);
let mut currencySymbol: Value = self.safe_currency_code(exchangeSymbol.map(Value::from).unwrap_or(Value::Null), &[]);
let mut direction: String = "in".to_string();
let mut amount: Value = self.safe_number_k(item.clone(), "amount", &[]);
let mut realAmount: Value = amount.clone();
let mut balance: Value = self.safe_number_k(item.clone(), "balance", &[]);
let mut fee: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.safe_number_k(item.clone(), "fee", &[]));
m.insert("currency".to_string(), currencySymbol.clone());
m
});
if (amount == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" parseLedgerEntry() requires a amount argument".into()))));
}
if (balance == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" parseLedgerEntry() missing balance".into()))));
}
let mut before: Value = Value::Null;
if (amount != Value::Null) && (balance != Value::Null) {
before = (match (&(balance), &(amount)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
if ((0i64) as f64) > amount.as_f64().unwrap_or(f64::NAN) {
direction = "out".to_string();
realAmount = (match &(amount) { Value::Int(x) => Value::Int(-x), Value::Float(x) => Value::Float(-x), _ => Value::Null });
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.map(Value::from).unwrap_or(Value::Null));
m.insert("info".to_string(), item);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("direction".to_string(), Value::from(direction));
m.insert("account".to_string(), Value::Null);
m.insert("referenceId".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), currencySymbol);
m.insert("amount".to_string(), realAmount);
m.insert("before".to_string(), before);
m.insert("after".to_string(), balance);
m.insert("status".to_string(), Value::Str("ok".into()));
m.insert("fee".to_string(), Value::Map(fee));
m
});
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __api_empty = Vec::new();
let api = api.as_array().unwrap_or(&__api_empty);
let mut version: Value = api.get(0).cloned().unwrap_or(Value::Null);
let mut urlPath: Value = api.get(1).cloned().unwrap_or(Value::Null);
let mut fullPath: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("/rest/".into()), version).into()), Value::Str("/".into())).into()), self.implode_params(path.clone(), params.clone())).into());
if (version.as_str() == Some("status")) {
fullPath = Value::Str("/status".into());
urlPath = Value::Str("status".into());
}
let mut apiUrl: Option<String> = self.safe_string_opt(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), urlPath.clone(), &[]);
if (apiUrl.is_none()) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", apiUrl.clone().map(Value::from).unwrap_or(Value::Null), fullPath).into());
let mut paramsOmitted: Value = self.omit(params, self.extract_params(path), &[]);
let mut timestamp: Value = self.milliseconds();
let mut query: Value = Value::Str("".into());
let mut signatureQuery: Value = Value::Str("".into());
if (method.as_str() == Some("GET")) {
let mut paramKeys: Vec<Value> = Value::Array(paramsOmitted.as_map().map(|__m| __m.keys().map(|__k| Value::Str(__k.clone().into())).collect()).unwrap_or_default()).as_array().cloned().unwrap_or_default();
let mut paramKeysLength: Value = Value::Int(paramKeys.len() as i64);
let mut lastKeyIndex: Value = (match (&(paramKeysLength), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
if paramKeysLength.as_f64().unwrap_or(f64::NAN) > ((0i64) as f64) {
query = self.urlencode(paramsOmitted.clone(), &[]);
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), query).into())).into());
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_680: bool = true;
while { if !__for_first_680 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_680 = false; i.as_f64().unwrap_or(f64::NAN) < ((paramKeys.len() as i64) as f64) } {
let mut key: Value = paramKeys.get(i.as_i64().unwrap_or(-1) as usize).cloned().unwrap_or(Value::Null);
let mut value: Option<String> = self.safe_string_opt(paramsOmitted.clone(), key.clone(), &[]);
if (value.is_some()) {
signatureQuery = Value::Str(format!("{}{}", signatureQuery, Value::Str(format!("{}{}", Value::Str(format!("{}{}", key, Value::Str("=".into())).into()), value.map(Value::from).unwrap_or(Value::Null)).into())).into());
}
if i.as_f64().unwrap_or(f64::NAN) < lastKeyIndex.as_f64().unwrap_or(f64::NAN) {
signatureQuery = Value::Str(format!("{}{}", signatureQuery, Value::Str("&".into())).into());
}
}
}
}
let mut requestBody: Value = Value::Null;
if (method.as_str() == Some("POST")) || (method.as_str() == Some("PUT")) {
requestBody = json_stringify(¶msOmitted);
}
let mut bodyToSignature: Value = Value::Str("".into());
if (requestBody != Value::Null) {
bodyToSignature = requestBody.clone();
}
let mut headersValue: indexmap::IndexMap<String, Value> = ({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m.insert("X-FB-CLIENT".to_string(), Value::Str("ccxt".into()));
m.insert("X-FB-CLIENT-VERSION".to_string(), self.get_ccxt_version());
m
});
if (urlPath.as_str() == Some("private")) {
self.check_required_credentials(&[]);
let mut preHash: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}", timestamp).into()), method).into()), fullPath).into()), signatureQuery).into()), bodyToSignature).into());
let mut signature: Value = self.hmac(self.encode(preHash), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[Value::Str("hex".into())]);
headersValue.insert("X-FB-ACCESS-KEY".into(), self.apiKey.clone());
headersValue.insert("X-FB-ACCESS-TIMESTAMP".into(), Value::Str(format!("{}", timestamp).into()));
headersValue.insert("X-FB-ACCESS-SIGNATURE".into(), signature);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), requestBody);
m.insert("headers".to_string(), Value::Map(headersValue));
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
let mut error: Value = self.safe_dict_k(response, "error", &[]);
let mut codeError: Option<String> = self.safe_string_k_opt(error.clone(), "code", &[]);
let mut details: Value = self.safe_list_k(error.clone(), "details", &[]);
let mut message: Value = self.safe_string_k(error.clone(), "message", &[Value::Str("".into())]);
let mut detailsString: Value = Value::Str("".into());
if (details != Value::Null) {
{
let mut i: i64 = 0;
let mut __for_first_681: bool = true;
while { if !__for_first_681 { i += 1; } __for_first_681 = false; i < (details.len() as i64) } {
detailsString = Value::Str(format!("{}{}", Value::Str(format!("{}{}", detailsString, self.safe_string(details.clone(), Value::Int(i), &[Value::Str("".into())])).into()), Value::Str(" ".into())).into());
}
}
}
if (error != Value::Null) {
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message).into()), Value::Str(" details: ".into())).into()), detailsString).into());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), detailsString, feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), codeError.clone().map(Value::from).unwrap_or(Value::Null), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}