// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct BitfinexCore {
pub exchange: crate::exchange::Exchange,
}
impl BitfinexCore {
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 = BitfinexCore::describe(self);
self.initialize_properties(described);
// compatibility for sandbox/testnet options in userConfig
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for BitfinexCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_order(self, order, &[market])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_position(self, position, &[market])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_funding_rate(self, rate, &[market])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_transfer(self, transfer, &[currency])
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_open_interest(self, interest, &[market])
}
fn parse_liquidation(&self, liquidation: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_liquidation(self, liquidation, &[market])
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_funding_rate_history(self, entry, &[market])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::parse_margin_modification(self, data, &[market])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::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 {
// Forward to the inherent method on BitfinexCore.
#[allow(invalid_reference_casting)]
let me = unsafe { &mut *(self as *const BitfinexCore as *mut BitfinexCore) };
BitfinexCore::sign(me, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BitfinexCore {
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 {
"amount_to_precision" => self.amount_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_deposit_address" => self.create_deposit_address(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_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"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_closed_order" => self.fetch_closed_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).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_withdrawals" => self.fetch_deposits_withdrawals(&args[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_liquidations" => self.fetch_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).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_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interests" => self.fetch_open_interests(&args[..]).await,
"fetch_open_order" => self.fetch_open_order(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_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).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,
"get_currency_name" => self.get_currency_name(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"is_fiat" => self.is_fiat(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"parse_currencies_custom" => self.parse_currencies_custom(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)),
"parse_currency_custom" => self.parse_currency_custom(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)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(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_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_liquidation" => self.parse_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_flags" => self.parse_order_flags(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(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_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"price_to_precision" => self.price_to_precision(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"set_margin" => self.set_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args[2.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BitfinexCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BitfinexCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BitfinexCore {
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("bitfinex".into()));
m.insert("name".to_string(), Value::Str("Bitfinex".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("VG".into())]));
m.insert("version".to_string(), Value::Str("v2".into()));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(true));
m.insert("createLimitOrder".to_string(), Value::Bool(true));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(true));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchClosedOrder".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Str("emulated".into()));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(true));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(true));
m.insert("fetchOpenInterests".to_string(), Value::Bool(true));
m.insert("fetchOpenOrder".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(false));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactionFees".to_string(), Value::Null);
m.insert("fetchTransactions".to_string(), Value::Str("emulated".into()));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(true));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("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("3h".to_string(), Value::Str("3h".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("7D".into()));
m.insert("2w".to_string(), Value::Str("14D".into()));
m.insert("1M".to_string(), Value::Str("1M".into()));
m
}));
m.insert("rateLimit".to_string(), Value::Int(250));
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/4a8e947f-ab46-481a-a8ae-8b20e9b03178".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Str("https://api.bitfinex.com".into()));
m.insert("public".to_string(), Value::Str("https://api-pub.bitfinex.com".into()));
m.insert("private".to_string(), Value::Str("https://api.bitfinex.com".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.bitfinex.com".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://docs.bitfinex.com/v2/docs/".into()), Value::Str("https://github.com/bitfinexcom/bitfinex-api-node".into())]));
m.insert("fees".to_string(), Value::Str("https://www.bitfinex.com/fees".into()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("conf/{config}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:{action}:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:{action}:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:sym".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:label".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:unit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:undl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:pool".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:explorer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:currency:tx:fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:map:tx:method".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:pair:exchange".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:pair:margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:pair:futures".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:list:competitions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:{object}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:{object}:{detail}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:pair".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:pair:futures".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:info:tx:status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("conf/pub:fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("platform/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(8));
m
}));
m.insert("tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("ticker/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("tickers/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("trades/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("book/{symbol}/{precision}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P0".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/P3".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book/{symbol}/R0".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:{side}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:{side}/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:{side}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:long/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:long/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:short/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("stats1/{key}:{size}:{symbol}:short/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}:{period}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}/last".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("candles/trade:{timeframe}:{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("status/{type}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("status/deriv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("status/deriv/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("liquidations/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(80));
m
}));
m.insert("rankings/{key}:{timeframe}:{symbol}/{section}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("rankings/{key}:{timeframe}:{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("pulse/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("pulse/profile/{nickname}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("funding/stats/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("ext/vasps".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("calc/trade/avg".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("calc/fx".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("auth/r/wallets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/wallets/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/submit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/update".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/multi".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/order/cancel/multi".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/orders/otc/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/order/{symbol}:{id}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/trades/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/trades/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/ledgers/{currency}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/ledgers/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/margin/{key}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/margin/base".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/margin/sym_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/position/claim".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/position/increase:".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/position/increase/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions/audit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/positions/snap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/position/update/funding/type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/deriv/collateral/set".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/deriv/collateral/limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/offer/submit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/offer/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/offer/cancel/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/auto".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/funding/keep".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/offers/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/loans/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/credits/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/trades/{symbol}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/funding/trades/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/funding/{key}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/info/user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/logins/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/permissions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/token".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/audit/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/r/deposit/address/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/w/deposit/invoice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/r/ext/invoice/payments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(24));
m
}));
m.insert("auth/r/movements/{currency}/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/movements/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/movements/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/alerts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(5.34));
m
}));
m.insert("auth/w/alert/set".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/alert/price:{symbol}:{price}/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/alert/{type}:{symbol}:{price}/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/calc/order/avail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/settings/set".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/settings/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/pulse/hist".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/pulse/add".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(16));
m
}));
m.insert("auth/w/pulse/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/ext/wallets/deposits/request".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/w/ext/wallets/withdrawals/request".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
m
}));
m.insert("auth/r/ext/wallets/transfers/free/count".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.7));
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("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.001".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.002".into()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("7500000".into()), &[]), self.parse_number(Value::Str("0.002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0.0018".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0.0016".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000000".into()), &[]), self.parse_number(Value::Str("0.0014".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25000000".into()), &[]), self.parse_number(Value::Str("0.0012".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("30000000".into()), &[]), self.parse_number(Value::Str("0.001".into()), &[])])]));
m.insert("maker".to_string(), Value::from(vec![Value::from(vec![self.parse_number(Value::Str("0".into()), &[]), self.parse_number(Value::Str("0.001".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("500000".into()), &[]), self.parse_number(Value::Str("0.0008".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("1000000".into()), &[]), self.parse_number(Value::Str("0.0006".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("2500000".into()), &[]), self.parse_number(Value::Str("0.0004".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("5000000".into()), &[]), self.parse_number(Value::Str("0.0002".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("7500000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("10000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("15000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("20000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("25000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])]), Value::from(vec![self.parse_number(Value::Str("30000000".into()), &[]), self.parse_number(Value::Str("0".into()), &[])])]));
m
}));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::SIGNIFICANT_DIGITS));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fetchOrderBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("precision".to_string(), Value::Str("R0".into()));
m
}));
m.insert("fetchCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultPrecision".to_string(), Value::Int(8));
m
}));
m.insert("exchangeTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".into()));
m.insert("EXCHANGE MARKET".to_string(), Value::Str("market".into()));
m.insert("LIMIT".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE LIMIT".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE STOP".to_string(), Value::Str("market".into()));
m.insert("EXCHANGE FOK".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE STOP LIMIT".to_string(), Value::Str("limit".into()));
m.insert("EXCHANGE IOC".to_string(), Value::Str("limit".into()));
m
}));
m.insert("orderTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), Value::Str("EXCHANGE MARKET".into()));
m.insert("limit".to_string(), Value::Str("EXCHANGE LIMIT".into()));
m
}));
m.insert("fiat".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USD".to_string(), Value::Str("USD".into()));
m.insert("EUR".to_string(), Value::Str("EUR".into()));
m.insert("JPY".to_string(), Value::Str("JPY".into()));
m.insert("GBP".to_string(), Value::Str("GBP".into()));
m.insert("CHN".to_string(), Value::Str("CHN".into()));
m
}));
m.insert("v2AccountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("exchange".into()));
m.insert("exchange".to_string(), Value::Str("exchange".into()));
m.insert("funding".to_string(), Value::Str("funding".into()));
m.insert("margin".to_string(), Value::Str("margin".into()));
m.insert("derivatives".to_string(), Value::Str("margin".into()));
m.insert("future".to_string(), Value::Str("margin".into()));
m.insert("swap".to_string(), Value::Str("margin".into()));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("includeFee".to_string(), Value::Bool(false));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BITCOIN".into()));
m.insert("LTC".to_string(), Value::Str("LITECOIN".into()));
m.insert("ERC20".to_string(), Value::Str("ETHEREUM".into()));
m.insert("OMNI".to_string(), Value::Str("TETHERUSO".into()));
m.insert("LIQUID".to_string(), Value::Str("TETHERUSL".into()));
m.insert("TRC20".to_string(), Value::Str("TETHERUSX".into()));
m.insert("EOS".to_string(), Value::Str("TETHERUSS".into()));
m.insert("AVAX".to_string(), Value::Str("TETHERUSDTAVAX".into()));
m.insert("SOL".to_string(), Value::Str("TETHERUSDTSOL".into()));
m.insert("ALGO".to_string(), Value::Str("TETHERUSDTALG".into()));
m.insert("BCH".to_string(), Value::Str("TETHERUSDTBCH".into()));
m.insert("KSM".to_string(), Value::Str("TETHERUSDTKSM".into()));
m.insert("DVF".to_string(), Value::Str("TETHERUSDTDVF".into()));
m.insert("OMG".to_string(), Value::Str("TETHERUSDTOMG".into()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TETHERUSE".to_string(), Value::Str("ERC20".into()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("leverage".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(75));
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(2500));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("daysBack".to_string(), Value::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(10000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("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("11010".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("10001".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("10020".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("10100".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("10114".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("20060".to_string(), Value::Str("OnMaintenance".into()).clone());
m.insert("temporarily_unavailable".to_string(), Value::Str("ExchangeNotAvailable".into()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("available balance is only".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("not enough exchange balance".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("Order not found".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("symbol: invalid".to_string(), Value::Str("BadSymbol".into()).clone());
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("UST".to_string(), Value::Str("USDT".into()));
m.insert("EUTF0".to_string(), Value::Str("EURT".into()));
m.insert("USTF0".to_string(), Value::Str("USDT".into()));
m.insert("ALG".to_string(), Value::Str("ALGO".into()));
m.insert("AMP".to_string(), Value::Str("AMPL".into()));
m.insert("ATO".to_string(), Value::Str("ATOM".into()));
m.insert("BCHABC".to_string(), Value::Str("XEC".into()));
m.insert("BCHN".to_string(), Value::Str("BCH".into()));
m.insert("DAT".to_string(), Value::Str("DATA".into()));
m.insert("DOG".to_string(), Value::Str("MDOGE".into()));
m.insert("DSH".to_string(), Value::Str("DASH".into()));
m.insert("EDO".to_string(), Value::Str("PNT".into()));
m.insert("EUS".to_string(), Value::Str("EURS".into()));
m.insert("EUT".to_string(), Value::Str("EURT".into()));
m.insert("HTX".to_string(), Value::Str("HT".into()));
m.insert("IDX".to_string(), Value::Str("ID".into()));
m.insert("IOT".to_string(), Value::Str("IOTA".into()));
m.insert("IQX".to_string(), Value::Str("IQ".into()));
m.insert("LUNA".to_string(), Value::Str("LUNC".into()));
m.insert("LUNA2".to_string(), Value::Str("LUNA".into()));
m.insert("MNA".to_string(), Value::Str("MANA".into()));
m.insert("ORS".to_string(), Value::Str("ORS Group".into()));
m.insert("PAS".to_string(), Value::Str("PASS".into()));
m.insert("QSH".to_string(), Value::Str("QASH".into()));
m.insert("QTM".to_string(), Value::Str("QTUM".into()));
m.insert("RBT".to_string(), Value::Str("RBTC".into()));
m.insert("SNG".to_string(), Value::Str("SNGLS".into()));
m.insert("STJ".to_string(), Value::Str("STORJ".into()));
m.insert("TERRAUST".to_string(), Value::Str("USTC".into()));
m.insert("TSD".to_string(), Value::Str("TUSD".into()));
m.insert("YGG".to_string(), Value::Str("YEED".into()));
m.insert("YYW".to_string(), Value::Str("YOYOW".into()));
m.insert("UDC".to_string(), Value::Str("USDC".into()));
m.insert("VSY".to_string(), Value::Str("VSYS".into()));
m.insert("WAX".to_string(), Value::Str("WAXP".into()));
m.insert("XCH".to_string(), Value::Str("XCHF".into()));
m.insert("ZBT".to_string(), Value::Str("ZB".into()));
m
}));
m
})]);
Value::Null
}
pub fn is_fiat(&self, mut code: Value) -> Value {
return (Value::Bool(in_op(&self.options.as_map().and_then(|__m| __m.get("fiat")).cloned().unwrap_or(Value::Null), &code)));
Value::Null
}
pub fn get_currency_name(&self, mut code: Value) -> Value {
// temporary fix for transpiler recognition, even though this is in parent class
if (in_op(&self.options.as_map().and_then(|__m| __m.get("currencyNames")).cloned().unwrap_or(Value::Null), &code)) {
return get_value(&self.options.as_map().and_then(|__m| __m.get("currencyNames")).cloned().unwrap_or(Value::Null), &code);
}
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), code).into()), Value::Str(" not supported for withdrawal".into()))));
Value::Null
}
pub fn amount_to_precision(&self, mut symbol: Value, mut amount: Value) -> Value {
// https://docs.bitfinex.com/docs/introduction#amount-precision
// The amount field allows up to 8 decimals.
// Anything exceeding this will be rounded to the 8th decimal.
let mut symbolValue: Value = self.safe_symbol(symbol, &[]);
let mut market: Value = self.market(symbolValue);
return self.decimal_to_precision(amount, Value::Int(crate::runtime::TRUNCATE), market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("amount")).cloned().unwrap_or(Value::Null), &[Value::Int(crate::runtime::DECIMAL_PLACES)]);
Value::Null
}
pub fn price_to_precision(&self, mut symbol: Value, mut price: Value) -> Value {
let mut symbolValue: Value = self.safe_symbol(symbol, &[]);
let mut market: Value = self.market(symbolValue);
let mut priceValue: Value = self.decimal_to_precision(price, Value::Int(crate::runtime::ROUND), market.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("price")).cloned().unwrap_or(Value::Null), &[self.precisionMode.clone()]);
return self.decimal_to_precision(priceValue, Value::Int(crate::runtime::TRUNCATE), Value::Int(8), &[Value::Int(crate::runtime::DECIMAL_PLACES)]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://docs.bitfinex.com/reference/rest-public-platform-status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
//
// [1] // operative
// [0] // maintenance
//
let mut response: Value = self.public_get_platform_status(&[params]).await;
let mut statusRaw: Value = self.safe_string(response.clone(), Value::Int(0), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), self.safe_string(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("maintenance".into()));
m.insert("1".to_string(), Value::Str("ok".into()));
m
}), statusRaw.clone(), &[statusRaw.clone()]));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response);
m
});
Value::Null
}
/*
* @method
* @name bitfinex#fetchMarkets
* @description retrieves data on all markets for bitfinex
* @see https://docs.bitfinex.com/reference/rest-public-conf
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut labels: Value = Value::from(vec![Value::Str("pub:info:pair".into()), Value::Str("pub:info:pair:futures".into()), Value::Str("pub:list:pair:securities".into()), Value::Str("pub:list:pair:margin".into())]);
let mut config: Value = join(&labels, &Value::Str(",".into()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("config".to_string(), config);
m
});
let __ws_arg_0 = self.extend(request, &[params]);
let mut response: Value = self.public_get_conf_config(&[__ws_arg_0]).await;
let mut spotMarketsInfo: Value = self.safe_list(response.clone(), Value::Int(0), &[Value::from(vec![])]);
let mut futuresMarketsInfo: Value = self.safe_list(response.clone(), Value::Int(1), &[Value::from(vec![])]);
let mut marginIds: Value = self.safe_list(response, Value::Int(3), &[Value::from(vec![])]);
let mut markets: Value = self.array_concat(spotMarketsInfo, futuresMarketsInfo);
let mut result: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_317: bool = true;
while { if !__for_first_317 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_317 = false; i.as_f64().unwrap_or(f64::NAN) < ((markets.len() as i64) as f64) } {
let mut pairObj: Value = self.safe_list(markets.clone(), i.clone(), &[]);
let mut id: Value = self.safe_string_upper(pairObj.clone(), Value::Int(0), &[]);
let mut market: Value = self.safe_value(pairObj, Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spot: Value = Value::Bool(true);
let mut type_var: Value = Value::Null;
if Value::Int(id.as_str().and_then(|__s| __s.find("F0")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
spot = Value::Bool(false);
type_var = Value::Str("swap".into());
} else {
type_var = Value::Str("spot".into());
}
let mut swap: Value = Value::Bool(type_var.as_str() == Some("swap"));
let mut baseId: Value = Value::Null;
let mut quoteId: Value = Value::Null;
if Value::Int(id.as_str().and_then(|__s| __s.find(":")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
let mut parts: Value = split(&id, &Value::Str(":".into()));
baseId = parts.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
quoteId = parts.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
} else {
baseId = id.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(0); let __j = __l.min(3); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
quoteId = id.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(3); let __j = __l.min(6); if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
}
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut splitBase: Value = split(&base, &Value::Str("F0".into()));
let mut splitQuote: Value = split("e, &Value::Str("F0".into()));
base = self.safe_string(splitBase, Value::Int(0), &[]);
quote = self.safe_string(splitQuote, Value::Int(0), &[]);
if (base == Value::Null) || (quote == Value::Null) {
continue;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
// baseId = 'f' + baseId;
// quoteId = 'f' + quoteId;
let mut settle: Value = Value::Null;
let mut settleId: Value = Value::Null;
if matches!(&swap, Value::Bool(true)) {
settle = quote.clone();
settleId = quote.clone();
symbol = Value::Str(format!("{}{}", Value::Str(format!("{}{}", symbol, Value::Str(":".into())).into()), settle).into());
}
let mut minOrderSizeString: Value = self.safe_string(market.clone(), Value::Int(3), &[]);
let mut maxOrderSizeString: Value = self.safe_string(market.clone(), Value::Int(4), &[]);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str(format!("{}{}", Value::Str("t".into()), id).into()));
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), settle);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), type_var);
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), Value::Bool((spot.as_bool() == Some(true) && self.in_array(id, marginIds.clone()).as_bool() == Some(true))));
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool(true));
m.insert("contract".to_string(), Value::Bool(!(spot.as_bool() == Some(true))));
m.insert("linear".to_string(), (if matches!(&swap, Value::Bool(true)) { Value::Bool(true) } else { Value::Null }));
m.insert("inverse".to_string(), (if matches!(&swap, Value::Bool(true)) { Value::Bool(false) } else { Value::Null }));
m.insert("contractSize".to_string(), (if matches!(&swap, Value::Bool(true)) { self.parse_number(Value::Str("1".into()), &[]) } else { Value::Null }));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Int(8));
m.insert("price".to_string(), Value::Int(5));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minOrderSizeString, &[]));
m.insert("max".to_string(), self.parse_number(maxOrderSizeString, &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(Value::Str("1e-8".into()), &[]));
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
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
}));
}
}
return result;
Value::Null
}
/*
* @method
* @name bitfinex#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://docs.bitfinex.com/reference/rest-public-conf
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut labels: Value = Value::from(vec![Value::Str("pub:list:currency".into()), Value::Str("pub:map:currency:sym".into()), Value::Str("pub:map:currency:label".into()), Value::Str("pub:map:currency:unit".into()), Value::Str("pub:map:currency:undl".into()), Value::Str("pub:map:currency:pool".into()), Value::Str("pub:map:currency:explorer".into()), Value::Str("pub:map:currency:tx:fee".into()), Value::Str("pub:map:tx:method".into()), Value::Str("pub:info:tx:status".into()), Value::Str("pub:list:currency:margin".into())]);
let mut config: Value = join(&labels, &Value::Str(",".into()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("config".to_string(), config);
m
});
let __ws_arg_1 = self.extend(request, &[params]);
let mut response: Value = self.public_get_conf_config(&[__ws_arg_1]).await;
//
// [
//
// a list of symbols
// ["AAA","ABS","ADA"],
//
// // sym
// // maps symbols to their API symbols, BAB > BCH
// [
// [ "BAB", "BCH" ],
// [ "CNHT", "CNHt" ],
// [ "DSH", "DASH" ],
// [ "IOT", "IOTA" ],
// [ "LES", "LEO-EOS" ],
// [ "LET", "LEO-ERC20" ],
// [ "STJ", "STORJ" ],
// [ "TSD", "TUSD" ],
// [ "UDC", "USDC" ],
// [ "USK", "USDK" ],
// [ "UST", "USDt" ],
// [ "USTF0", "USDt0" ],
// [ "XCH", "XCHF" ],
// [ "YYW", "YOYOW" ],
// // ...
// ],
// // label
// // verbose friendly names, BNT > Bancor
// [
// [ "BAB", "Bitcoin Cash" ],
// [ "BCH", "Bitcoin Cash" ],
// [ "LEO", "Unus Sed LEO" ],
// [ "LES", "Unus Sed LEO (EOS)" ],
// [ "LET", "Unus Sed LEO (ERC20)" ],
// // ...
// ],
// // unit
// // maps symbols to unit of measure where applicable
// [
// [ "IOT", "Mi|MegaIOTA" ],
// ],
// // undl
// // maps derivatives symbols to their underlying currency
// [
// [ "USTF0", "UST" ],
// [ "BTCF0", "BTC" ],
// [ "ETHF0", "ETH" ],
// ],
// // pool
// // maps symbols to underlying network/protocol they operate on
// [
// [ 'SAN', 'ETH' ], [ 'OMG', 'ETH' ], [ 'AVT', 'ETH' ], [ "EDO", "ETH" ],
// [ 'ESS', 'ETH' ], [ 'ATD', 'EOS' ], [ 'ADD', 'EOS' ], [ "MTO", "EOS" ],
// [ 'PNK', 'ETH' ], [ 'BAB', 'BCH' ], [ 'WLO', 'XLM' ], [ "VLD", "ETH" ],
// [ 'BTT', 'TRX' ], [ 'IMP', 'ETH' ], [ 'SCR', 'ETH' ], [ "GNO", "ETH" ],
// // ...
// ],
// // explorer
// // maps symbols to their recognised block explorer URLs
// [
// [
// "AIO",
// [
// "https://mainnet.aion.network",
// "https://mainnet.aion.network/#/account/VAL",
// "https://mainnet.aion.network/#/transaction/VAL"
// ]
// ],
// // ...
// ],
// // fee
// // maps currencies to their withdrawal fees
// [
// ["AAA",[0,0]],
// ["ABS",[0,131.3]],
// ["ADA",[0,0.3]],
// ],
// // deposit/withdrawal data
// [
// ["BITCOIN", 1, 1, null, null, null, null, 0, 0, null, null, 3],
// ...
// ]
// ]
//
let mut indexed: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sym".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(1), &[Value::from(vec![])]), Value::Int(0)));
m.insert("label".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(2), &[Value::from(vec![])]), Value::Int(0)));
m.insert("unit".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(3), &[Value::from(vec![])]), Value::Int(0)));
m.insert("undl".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(4), &[Value::from(vec![])]), Value::Int(0)));
m.insert("pool".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(5), &[Value::from(vec![])]), Value::Int(0)));
m.insert("explorer".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(6), &[Value::from(vec![])]), Value::Int(0)));
m.insert("fees".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(7), &[Value::from(vec![])]), Value::Int(0)));
m.insert("networks".to_string(), self.safe_list(response.clone(), Value::Int(8), &[Value::from(vec![])]));
m.insert("statuses".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(9), &[Value::from(vec![])]), Value::Int(0)));
m.insert("marginables".to_string(), self.safe_list(response.clone(), Value::Int(10), &[Value::from(vec![])]));
m
});
let mut indexedNetworks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_318: bool = true;
while { if !__for_first_318 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_318 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&get_value(&indexed, &Value::Str("networks".into()))).as_f64().unwrap_or(f64::NAN) } {
let mut networkObj: Value = self.safe_list(match &indexed { Value::Dict(__m15) => __m15.get("networks").cloned().unwrap_or(Value::Null), _ => Value::Null }, i.clone(), &[]);
let mut networkId: Value = self.safe_string(networkObj.clone(), Value::Int(0), &[]);
let mut valuesList: Value = self.safe_list(networkObj, Value::Int(1), &[]);
let mut networkName: Value = self.safe_string(valuesList, Value::Int(0), &[]);
// for GOlang transpiler, do with "safe" method
let mut networksList: Value = self.safe_list(indexedNetworks.clone(), networkName.clone(), &[Value::from(vec![])]);
append_to_array(&mut networksList, networkId);
if let Value::Dict(__d) = &mut indexedNetworks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&networkName), networksList); }
}
}
let mut ids: Value = self.safe_list(response, Value::Int(0), &[Value::from(vec![])]);
return self.parse_currencies_custom(ids, indexed, indexedNetworks);
Value::Null
}
pub fn parse_currencies_custom(&self, mut ids: Value, mut indexed: Value, mut indexedNetworks: Value) -> Value {
let mut allowedIds: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_319: bool = true;
while { if !__for_first_319 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_319 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
let mut id: Value = ids.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if (ends_with(&id, &Value::Str("F0".into()))) {
continue;
}
append_to_array(&mut allowedIds, id);
}
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut arr: Value = self.to_array(allowedIds);
{
let mut i: Value = Value::Int(0);
let mut __for_first_320: bool = true;
while { if !__for_first_320 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_320 = false; i.as_f64().unwrap_or(f64::NAN) < ((arr.len() as i64) as f64) } {
let mut parsed: Value = self.parse_currency_custom(arr.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), indexed.clone(), indexedNetworks.clone());
let mut code: Value = parsed.as_map().and_then(|__m| __m.get("code")).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), parsed); }
}
}
return result;
Value::Null
}
pub fn parse_currency_custom(&self, mut id: Value, mut indexed: Value, mut indexedNetworks: Value) -> Value {
let __indexed_empty = indexmap::IndexMap::new();
let indexed = indexed.as_map().unwrap_or(&__indexed_empty);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut label: Value = self.safe_list(indexed.get("label").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut name: Value = self.safe_string(label.clone(), Value::Int(1), &[]);
let mut pool: Value = self.safe_list(indexed.get("pool").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut rawType: Option<String> = self.safe_string(pool.clone(), Value::Int(1), &[]).as_str().map(str::to_owned);
let mut isCryptoCoin: bool = (rawType.is_some()) || (in_op(&indexed.get("explorer").cloned().unwrap_or(Value::Null), &id)); // "hacky" solution
let mut type_var: Value = (if isCryptoCoin { Value::Str("crypto".into()) } else { Value::Null });
let mut feeValues: Value = self.safe_list(indexed.get("fees").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut fees: Value = self.safe_list(feeValues.clone(), Value::Int(1), &[Value::from(vec![])]);
let mut fee: Value = self.safe_number(fees, Value::Int(1), &[]);
let mut undl: Value = self.safe_list(indexed.get("undl").cloned().unwrap_or(Value::Null), id.clone(), &[Value::from(vec![])]);
let mut defaultCurrencyPrecision: Value = self.safe_string_k(self.options.clone(), "defaultCurrencyPrecision", &[Value::Str("8".into())]); // kept here for backward-compatibility
// numberToString instead of an `as string` cast: the describe() default for this option is the
// NUMBER 8 (and users may override with numbers too), and the hard cast makes the C# build throw
// InvalidCastException Int32 to String here, breaking bitfinex loadMarkets entirely in C#
let mut precision: Value = self.number_to_string(self.handle_option(Value::Str("fetchCurrencies".into()), Value::Str("defaultPrecision".into()), &[defaultCurrencyPrecision]));
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut networkIds: Value = self.safe_list(indexedNetworks, id.clone(), &[Value::from(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_321: bool = true;
while { if !__for_first_321 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_321 = false; j.as_f64().unwrap_or(f64::NAN) < ((networkIds.len() as i64) as f64) } {
// safeString instead of raw access: the venue config payload can carry numeric
// network ids, and the raw value flows into toLowerCase and a dictionary key,
// which hard-casts to string in the C# build and throws InvalidCastException
let mut networkId: Value = self.safe_string(networkIds.clone(), j.clone(), &[]);
if (networkId == Value::Null) {
continue;
}
let mut network: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
let mut dwStatuses: Value = self.safe_list(indexed.get("statuses").cloned().unwrap_or(Value::Null), networkId.clone(), &[Value::from(vec![])]);
if (network != Value::Null) {
if let Value::Dict(__d) = &mut networks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&network), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), networkId.clone());
m.insert("id".to_string(), to_lower(&networkId));
m.insert("network".to_string(), networkId);
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool(self.safe_integer(dwStatuses.clone(), Value::Int(1), &[]).as_f64() == Some(1.0)));
m.insert("withdraw".to_string(), Value::Bool(self.safe_integer(dwStatuses, Value::Int(2), &[]).as_f64() == Some(1.0)));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
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(), id.clone());
m.insert("code".to_string(), code);
m.insert("info".to_string(), Value::from(vec![id.clone(), label, pool, feeValues, undl]));
m.insert("type".to_string(), type_var);
m.insert("name".to_string(), name);
m.insert("active".to_string(), Value::Bool(true));
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m.insert("precision".to_string(), self.parse_number(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("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), fee);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), networks);
m.insert("margin".to_string(), self.in_array(id, indexed.get("marginables").cloned().unwrap_or(Value::Null)));
m
}));
Value::Null
}
/*
* @method
* @name bitfinex#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.bitfinex.com/reference/rest-auth-wallets
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// this api call does not return the 'used' amount - use the v1 version instead (which also returns zero balances)
// there is a difference between this and the v1 api, namely trading wallet is called margin in v2
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "v2AccountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut requestedType: Value = self.safe_string_k(params.clone(), "type", &[Value::Str("exchange".into())]);
let mut accountType: Value = self.safe_string(accountsByType.clone(), requestedType.clone(), &[requestedType.clone()]);
if (accountType == Value::Null) {
let mut keys: Value = object_keys(&accountsByType);
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchBalance() type parameter must be one of ".into())).into()), join(&keys, &Value::Str(", ".into())))));
}
let mut isDerivative: bool = requestedType.as_str() == Some("derivatives");
let mut query: Value = self.omit(params, Value::Str("type".into()), &[]);
let mut response: Value = self.private_post_auth_r_wallets(&[query]).await;
let mut balances: Value = self.to_array(response.clone());
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_322: bool = true;
while { if !__for_first_322 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_322 = false; i.as_f64().unwrap_or(f64::NAN) < ((balances.len() as i64) as f64) } {
let mut balance: Value = self.safe_list(balances.clone(), i.clone(), &[]);
let mut account: Value = self.account();
let mut interest: Value = self.safe_string(balance.clone(), Value::Int(3), &[]);
if (interest.as_str() != Some("0")) {
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("debt".into(), interest); }
}
let mut type_var: Value = self.safe_string(balance.clone(), Value::Int(0), &[]);
let mut currencyId: Value = self.safe_string_lower(balance.clone(), Value::Int(1), &[Value::Str("".into())]);
let mut start: Value = (match (&(Value::Int(currencyId.len() as i64)), &(Value::Int(2))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
let mut isDerivativeCode: bool = slice(¤cyId, &start, &Value::Null).as_str() == Some("f0");
// this will only filter the derivative codes if the requestedType is 'derivatives'
let mut derivativeCondition: bool = !isDerivative || isDerivativeCode;
if (accountType.as_str() == type_var.as_str()) && derivativeCondition {
let mut code: Value = self.safe_currency_code(currencyId, &[]);
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string(balance.clone(), Value::Int(2), &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string(balance, Value::Int(4), &[])); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name bitfinex#transfer
* @description transfer currency internally between wallets on the same account
* @see https://docs.bitfinex.com/reference/rest-auth-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// transferring between derivatives wallet and regular wallet is not documented in their API
// however we support it in CCXT (from just looking at web inspector)
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "v2AccountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[]);
if (fromId == Value::Null) {
let mut keys: Value = object_keys(&accountsByType);
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" transfer() fromAccount must be one of ".into())).into()), join(&keys, &Value::Str(", ".into())))));
}
let mut toId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[]);
if (toId == Value::Null) {
let mut keys: Value = object_keys(&accountsByType);
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" transfer() toAccount must be one of ".into())).into()), join(&keys, &Value::Str(", ".into())))));
}
let mut currency: Value = self.currency(code.clone());
let mut fromCurrencyId: Value = self.convert_derivatives_id(currency.clone(), fromAccount).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut toCurrencyId: Value = self.convert_derivatives_id(currency.clone(), toAccount).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut requestedAmount: Value = self.currency_to_precision(code, amount, &[]);
// this request is slightly different from v1 fromAccount -> from
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), requestedAmount);
m.insert("currency".to_string(), fromCurrencyId);
m.insert("currency_to".to_string(), toCurrencyId);
m.insert("from".to_string(), fromId);
m.insert("to".to_string(), toId);
m
});
let __ws_arg_2 = self.extend(request, &[params]);
let mut response: Value = self.private_post_auth_w_transfer(&[__ws_arg_2]).await;
//
// [
// 1616451183763,
// "acc_tf",
// null,
// null,
// [
// 1616451183763,
// "exchange",
// "margin",
// null,
// "UST",
// "UST",
// null,
// 1
// ],
// null,
// "SUCCESS",
// "1.0 Tether USDt transfered from Exchange to Margin"
// ]
//
let mut error: Option<String> = self.safe_string(response.clone(), Value::Int(0), &[]).as_str().map(str::to_owned);
if (error.as_deref() == Some("error")) {
let mut message: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".into())]);
// same message as in v1
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), message.clone(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message).into()));
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message)));
}
return self.parse_transfer(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), response);
m
}), &[currency]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let __transfer_empty = indexmap::IndexMap::new();
let transfer = transfer.as_map().unwrap_or(&__transfer_empty);
//
// transfer
//
// [
// 1616451183763,
// "acc_tf",
// null,
// null,
// [
// 1616451183763,
// "exchange",
// "margin",
// null,
// "UST",
// "UST",
// null,
// 1
// ],
// null,
// "SUCCESS",
// "1.0 Tether USDt transfered from Exchange to Margin"
// ]
//
let mut result: Value = (match transfer.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut timestamp: Value = self.safe_integer(result.clone(), Value::Int(0), &[]);
let mut info: Value = self.safe_list(result.clone(), Value::Int(4), &[]);
let mut fromAccount: Value = self.safe_string(info.clone(), Value::Int(1), &[]);
let mut toAccount: Value = self.safe_string(info.clone(), Value::Int(2), &[]);
let mut currencyId: Value = self.safe_string(info.clone(), Value::Int(5), &[]);
let mut status: Value = self.safe_string(result.clone(), Value::Int(6), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("status".to_string(), self.parse_transfer_status(status).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("amount".to_string(), self.safe_number(info, Value::Int(7), &[]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("fromAccount".to_string(), fromAccount);
m.insert("toAccount".to_string(), toAccount);
m.insert("info".to_string(), result);
m
});
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SUCCESS".to_string(), Value::Str("ok".into()));
m.insert("ERROR".to_string(), Value::Str("failed".into()));
m.insert("FAILURE".to_string(), Value::Str("failed".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn convert_derivatives_id(&self, mut currency: Value, mut type_var: Value) -> Option<String> {
let __currency_empty = indexmap::IndexMap::new();
let currency = currency.as_map().unwrap_or(&__currency_empty);
// there is a difference between this and the v1 api, namely trading wallet is called margin in v2
// {
// "id": "fUSTF0",
// "code": "USTF0",
// "info": [ 'USTF0', [], [], [], [ "USTF0", "UST" ] ],
let mut info: Value = (match currency.get("info") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut transferId: Value = self.safe_string(info.clone(), Value::Int(0), &[]);
let mut underlying: Value = self.safe_list(info, Value::Int(4), &[Value::from(vec![])]);
let mut currencyId: Value = Value::Null;
if (type_var.as_str() == Some("derivatives")) {
currencyId = self.safe_string(underlying.clone(), Value::Int(0), &[transferId.clone()]);
let mut start: Value = (match (&(Value::Int(currencyId.len() as i64)), &(Value::Int(2))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
let mut isDerivativeCode: bool = slice(¤cyId, &start, &Value::Null).as_str() == Some("F0");
if !isDerivativeCode {
currencyId = Value::Str(format!("{}{}", currencyId, Value::Str("F0".into())).into());
}
} else if (type_var.as_str() != Some("margin")) {
currencyId = self.safe_string(underlying, Value::Int(1), &[transferId.clone()]);
} else {
currencyId = transferId;
}
return currencyId.as_str().map(str::to_owned);
}
/*
* @method
* @name bitfinex#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.bitfinex.com/reference/rest-public-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return, bitfinex only allows 1, 25, or 100
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut precision: Value = self.handle_option(Value::Str("fetchOrderBook".into()), Value::Str("precision".into()), &[Value::Str("R0".into())]);
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("precision".to_string(), precision);
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("len".into(), limit); }
}
let mut fullRequest: Value = self.extend(request, &[params]);
let mut orderbook: Value = self.public_get_book_symbol_precision(&[fullRequest.clone()]).await;
let mut timestamp: Value = self.milliseconds();
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("bids".to_string(), Value::from(vec![]));
m.insert("asks".to_string(), Value::from(vec![]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("nonce".to_string(), Value::Null);
m
});
let mut priceIndex: Value = (if (fullRequest.as_map().and_then(|__m| __m.get("precision")).cloned().unwrap_or(Value::Null).as_str() == Some("R0")) { Value::Int(1) } else { Value::Int(0) });
let mut orders: Value = self.to_array(orderbook);
{
let mut i: Value = Value::Int(0);
let mut __for_first_323: bool = true;
while { if !__for_first_323 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_323 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut order: Value = orders.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut price: Value = self.safe_number(order.clone(), priceIndex.clone(), &[]);
let mut signedAmount: Value = self.safe_string(order, Value::Int(2), &[]);
let mut amount: Value = crate::precise::Precise::stringAbs(&signedAmount);
let mut side: Value = Value::Str("asks".into());
if is_true(&crate::precise::Precise::stringGt(&signedAmount, &Value::Str("0".into()))) {
side = Value::Str("bids".into());
}
crate::runtime::append_to_object_array(&mut result, &side, Value::from(vec![price, self.parse_number(amount, &[])]));
}
}
{ let __be_tmp = self.sort_by(crate::value::get_value_k(&result, "bids"), Value::Int(0), &[Value::Bool(true)]); if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("bids".into(), __be_tmp); } }
{ let __be_tmp = self.sort_by(crate::value::get_value_k(&result, "asks"), Value::Int(0), &[]); if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert("asks".into(), __be_tmp); } }
return result;
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// on trading pairs (ex. tBTCUSD)
//
// [
// SYMBOL, // this index is not present in singular-ticker
// BID,
// BID_SIZE,
// ASK,
// ASK_SIZE,
// DAILY_CHANGE,
// DAILY_CHANGE_RELATIVE,
// LAST_PRICE,
// VOLUME,
// HIGH,
// LOW
// ]
//
//
// on funding currencies (ex. fUSD)
//
// [
// SYMBOL, // this index is not present in singular-ticker
// FRR,
// BID,
// BID_PERIOD,
// BID_SIZE,
// ASK,
// ASK_PERIOD,
// ASK_SIZE,
// DAILY_CHANGE,
// DAILY_CHANGE_RELATIVE,
// LAST_PRICE,
// VOLUME,
// HIGH,
// LOW,
// _PLACEHOLDER,
// _PLACEHOLDER,
// FRR_AMOUNT_AVAILABLE
// ]
//
let mut length: f64 = ((ticker.len() as i64) as f64);
// the list shapes (fetchTickers) carry the market id in slot 0, the singular
// shapes (fetchTicker) do not. safeNumber is not a portable discriminator here:
// in PHP a non numeric string casts to 0.0 instead of undefined, so 'fUSD' would
// look like a number and the whole array would be read off by one.
let mut firstValue: Value = self.safe_string(ticker.clone(), Value::Int(0), &[]);
let mut hasMarketId: bool = (firstValue != Value::Null) && ((starts_with(&firstValue, &Value::Str("t".into()))) || (starts_with(&firstValue, &Value::Str("f".into()))));
let mut isFetchTicker: bool = !hasMarketId;
let mut symbol: Value = Value::Null;
let mut minusIndex: Value = Value::Int(0);
if isFetchTicker {
minusIndex = Value::Int(1);
}
let mut marketId: Value = self.safe_string(ticker.clone(), Value::Int(0), &[]);
let mut marketResolved: Value = Value::Null;
if isFetchTicker {
marketResolved = market.clone();
} else {
marketResolved = self.safe_market(&[marketId, market]);
}
let mut isFundingCurrency: bool = length >= ((17i64) as f64);
symbol = self.safe_symbol(Value::Null, &[marketResolved.clone()]);
let mut last: Value = Value::Null;
let mut bid: Value = Value::Null;
let mut ask: Value = Value::Null;
let mut change: Value = Value::Null;
let mut percentage: Value = Value::Null;
let mut volume: Value = Value::Null;
let mut high: Value = Value::Null;
let mut low: Value = Value::Null;
if isFundingCurrency {
// per api docs, they are different array type
last = self.safe_string(ticker.clone(), (match (&(Value::Int(10)), &(minusIndex)) { (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 }), &[]);
bid = self.safe_string(ticker.clone(), (match (&(Value::Int(2)), &(minusIndex)) { (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 }), &[]);
ask = self.safe_string(ticker.clone(), (match (&(Value::Int(5)), &(minusIndex)) { (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 }), &[]);
change = self.safe_string(ticker.clone(), (match (&(Value::Int(8)), &(minusIndex)) { (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 }), &[]);
// DAILY_CHANGE_RELATIVE, per the array above: the same field the trading
// branch reads at index 6 and scales
percentage = crate::precise::Precise::stringMul(&self.safe_string(ticker.clone(), (match (&(Value::Int(9)), &(minusIndex)) { (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 }), &[]), &Value::Str("100".into()));
volume = self.safe_string(ticker.clone(), (match (&(Value::Int(11)), &(minusIndex)) { (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 }), &[]);
high = self.safe_string(ticker.clone(), (match (&(Value::Int(12)), &(minusIndex)) { (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 }), &[]);
low = self.safe_string(ticker.clone(), (match (&(Value::Int(13)), &(minusIndex)) { (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 }), &[]);
} else {
// on trading pairs (ex. tBTCUSD or tHMSTR:USD)
last = self.safe_string(ticker.clone(), (match (&(Value::Int(7)), &(minusIndex)) { (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 }), &[]);
bid = self.safe_string(ticker.clone(), (match (&(Value::Int(1)), &(minusIndex)) { (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 }), &[]);
ask = self.safe_string(ticker.clone(), (match (&(Value::Int(3)), &(minusIndex)) { (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 }), &[]);
change = self.safe_string(ticker.clone(), (match (&(Value::Int(5)), &(minusIndex)) { (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 }), &[]);
percentage = self.safe_string(ticker.clone(), (match (&(Value::Int(6)), &(minusIndex)) { (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 }), &[]);
percentage = crate::precise::Precise::stringMul(&percentage, &Value::Str("100".into()));
volume = self.safe_string(ticker.clone(), (match (&(Value::Int(8)), &(minusIndex)) { (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 }), &[]);
high = self.safe_string(ticker.clone(), (match (&(Value::Int(9)), &(minusIndex)) { (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 }), &[]);
low = self.safe_string(ticker.clone(), (match (&(Value::Int(10)), &(minusIndex)) { (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 }), &[]);
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), high);
m.insert("low".to_string(), low);
m.insert("bid".to_string(), bid);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), ask);
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), Value::Null);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), change);
m.insert("percentage".to_string(), percentage);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), volume);
m.insert("quoteVolume".to_string(), Value::Null);
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://docs.bitfinex.com/reference/rest-public-tickers
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (symbolsNormalized != Value::Null) {
let mut ids: Value = self.market_ids(&[symbolsNormalized.clone()]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbols".into(), join(&ids, &Value::Str(",".into()))); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbols".into(), Value::Str("ALL".into())); }
}
let __ws_arg_3 = self.extend(request, &[params]);
let mut tickers: Value = self.public_get_tickers(&[__ws_arg_3]).await;
return self.parse_tickers(tickers, &[symbolsNormalized]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://docs.bitfinex.com/reference/rest-public-ticker
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_4 = self.extend(request, &[params]);
let mut ticker: Value = self.public_get_ticker_symbol(&[__ws_arg_4]).await;
return self.parse_ticker(ticker, &[market]);
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 __trade_empty = indexmap::IndexMap::new();
let trade = trade.as_map().unwrap_or(&__trade_empty);
//
// fetchTrades (public)
//
// [
// ID,
// MTS, // timestamp
// AMOUNT,
// PRICE
// ]
//
// fetchMyTrades (private)
//
// [
// ID,
// PAIR,
// MTS_CREATE,
// ORDER_ID,
// EXEC_AMOUNT,
// EXEC_PRICE,
// ORDER_TYPE,
// ORDER_PRICE,
// MAKER,
// FEE,
// FEE_CURRENCY,
// ...
// ]
//
let mut tradeList: Value = (match trade.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::from(vec![]) });
let mut tradeLength: f64 = ((tradeList.len() as i64) as f64);
let mut isPrivate: bool = tradeLength > ((5i64) as f64);
let mut id: Value = self.safe_string(tradeList.clone(), Value::Int(0), &[]);
let mut amountIndex: Value = (if isPrivate { Value::Int(4) } else { Value::Int(2) });
let mut side: Value = Value::Null;
let mut amountString: Value = self.safe_string(tradeList.clone(), amountIndex, &[]);
let mut priceIndex: Value = (if isPrivate { Value::Int(5) } else { Value::Int(3) });
let mut priceString: Value = self.safe_string(tradeList.clone(), priceIndex, &[]);
if (get_value(&amountString, &Value::Int(0)).as_str() == Some("-")) {
side = Value::Str("sell".into());
amountString = crate::precise::Precise::stringAbs(&amountString);
} else {
side = Value::Str("buy".into());
}
let mut orderId: Value = Value::Null;
let mut takerOrMaker: Value = Value::Null;
let mut type_var: Value = Value::Null;
let mut fee: Value = Value::Null;
let mut symbol: Value = self.safe_symbol(Value::Null, &[market.clone()]);
let mut timestampIndex: Value = (if isPrivate { Value::Int(2) } else { Value::Int(1) });
let mut timestamp: Value = self.safe_integer(tradeList.clone(), timestampIndex, &[]);
if isPrivate {
let mut marketId: Value = tradeList.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
symbol = self.safe_symbol(marketId, &[]);
orderId = self.safe_string(tradeList.clone(), Value::Int(3), &[]);
let mut maker: Option<i64> = self.safe_integer(tradeList.clone(), Value::Int(8), &[]).as_i64();
takerOrMaker = (if (maker == Some(1)) { Value::Str("maker".into()) } else { Value::Str("taker".into()) });
let mut feeCostString: Value = self.safe_string(tradeList.clone(), Value::Int(9), &[]);
feeCostString = crate::precise::Precise::stringNeg(&feeCostString);
let mut feeCurrencyId: Value = self.safe_string(tradeList.clone(), Value::Int(10), &[]);
let mut feeCurrency: Value = self.safe_currency_code(feeCurrencyId, &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString);
m.insert("currency".to_string(), feeCurrency);
m
});
let mut orderType: Value = tradeList.as_array().and_then(|__arr| __arr.get(6)).cloned().unwrap_or(Value::Null);
type_var = self.safe_string(self.options.as_map().and_then(|__m| __m.get("exchangeTypes")).cloned().unwrap_or(Value::Null), orderType, &[]);
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), symbol);
m.insert("order".to_string(), orderId);
m.insert("side".to_string(), side);
m.insert("type".to_string(), type_var);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("price".to_string(), priceString);
m.insert("amount".to_string(), amountString);
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("info".to_string(), tradeList);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://docs.bitfinex.com/reference/rest-public-trades
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch, default 120, max 10000
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @param {int} [params.until] the latest time in ms to fetch entries for
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Int(10000)]).await;
}
let mut market: Value = self.market(symbol);
let mut sort: Value = Value::Str("-1".into());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since); }
sort = Value::Str("1".into());
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), crate::runtime::Math::min(&limit, &Value::Int(10000))); }; // default 120, max 10000
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("sort".into(), sort); }
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("end".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_5 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_trades_symbol_hist(&[__ws_arg_5]).await;
//
// [
// [
// ID,
// MTS, // timestamp
// AMOUNT,
// PRICE
// ]
// ]
//
let mut rawTrades: Value = self.to_array(response);
let mut trades: Value = self.sort_by(rawTrades, Value::Int(1), &[]);
let mut tradesList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_324: bool = true;
while { if !__for_first_324 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_324 = false; i.as_f64().unwrap_or(f64::NAN) < ((trades.len() as i64) as f64) } {
append_to_array(&mut tradesList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), trades.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
m
})); // convert to array of dicts to match parseOrder signature
}
}
return self.parse_trades(tradesList, &[market, Value::Null, limit]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://docs.bitfinex.com/reference/rest-public-candles
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch, default 100 max 10000
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
*/
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::Int(100));
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 paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), Value::Int(10000)]).await;
}
let mut market: Value = self.market(symbol);
let mut limitResolved: Value = (if (limit == Value::Null) { Value::Int(10000) } else { crate::runtime::Math::min(&limit, &Value::Int(10000)) });
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("timeframe".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m.insert("limit".to_string(), limitResolved.clone());
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("sort".into(), Value::Int(1)); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("end".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_6 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_candles_trade_timeframe_symbol_hist(&[__ws_arg_6]).await;
return self.parse_ohlc_vs(self.to_array(response), &[market, timeframe, since, limitResolved]);
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(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv, Value::Int(5), &[])]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
if (status == Value::Null) {
return Value::Null;
}
let mut parts: Value = split(&status, &Value::Str(" ".into()));
let mut state: Value = self.safe_string(parts, Value::Int(0), &[]);
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ACTIVE".to_string(), Value::Str("open".into()));
m.insert("PARTIALLY".to_string(), Value::Str("open".into()));
m.insert("EXECUTED".to_string(), Value::Str("closed".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("INSUFFICIENT".to_string(), Value::Str("canceled".into()));
m.insert("POSTONLY CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("RSN_DUST".to_string(), Value::Str("rejected".into()));
m.insert("RSN_PAUSE".to_string(), Value::Str("rejected".into()));
m.insert("IOC CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("FILLORKILL CANCELED".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(statuses, state, &[status]);
Value::Null
}
pub fn parse_order_flags(&self, mut flags: Value) -> Value {
// flags can be added to each other...
let mut flagValues: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1024".to_string(), Value::from(vec![Value::Str("reduceOnly".into())]));
m.insert("4096".to_string(), Value::from(vec![Value::Str("postOnly".into())]));
m.insert("5120".to_string(), Value::from(vec![Value::Str("reduceOnly".into()), Value::Str("postOnly".into())]));
m
});
return self.safe_list(flagValues, flags, &[Value::Null]);
Value::Null
}
pub fn parse_time_in_force(&self, mut orderType: Value) -> Option<String> {
let mut orderTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("EXCHANGE IOC".to_string(), Value::Str("IOC".into()));
m.insert("EXCHANGE FOK".to_string(), Value::Str("FOK".into()));
m.insert("IOC".to_string(), Value::Str("IOC".into()));
m.insert("FOK".to_string(), Value::Str("FOK".into()));
m
});
return self.safe_string(orderTypes, orderType, &[Value::Str("GTC".into())]).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 __order_empty = indexmap::IndexMap::new();
let order = order.as_map().unwrap_or(&__order_empty);
let mut orderList: Value = (match order.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut id: Value = self.safe_string(orderList.clone(), Value::Int(0), &[]);
let mut marketId: Value = self.safe_string(orderList.clone(), Value::Int(3), &[]);
let mut symbol: Value = self.safe_symbol(marketId, &[]);
// https://github.com/ccxt/ccxt/issues/6686
// const timestamp = this.safeTimestamp (orderObject, 5);
let mut timestamp: Value = self.safe_integer(orderList.clone(), Value::Int(5), &[]);
let mut remaining: Value = crate::precise::Precise::stringAbs(&self.safe_string(orderList.clone(), Value::Int(6), &[]));
let mut signedAmount: Value = self.safe_string(orderList.clone(), Value::Int(7), &[]);
let mut amount: Value = crate::precise::Precise::stringAbs(&signedAmount);
let mut side: Value = Value::Str("buy".into());
if is_true(&crate::precise::Precise::stringLt(&signedAmount, &Value::Str("0".into()))) {
side = Value::Str("sell".into());
}
let mut orderType: Value = self.safe_string(orderList.clone(), Value::Int(8), &[]);
let mut type_var: Value = self.safe_string(self.safe_dict_k(self.options.clone(), "exchangeTypes", &[]), orderType.clone(), &[]);
let mut timeInForce: Value = self.parse_time_in_force(orderType.clone()).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut rawFlags: Value = self.safe_string(orderList.clone(), Value::Int(12), &[]);
let mut flags: Value = self.parse_order_flags(rawFlags);
let mut postOnly: Value = Value::Bool(false);
if (flags != Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_325: bool = true;
while { if !__for_first_325 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_325 = false; i.as_f64().unwrap_or(f64::NAN) < ((flags.len() as i64) as f64) } {
if (flags.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null).as_str() == Some("postOnly")) {
postOnly = Value::Bool(true);
}
}
}
}
let mut price: Value = self.safe_string(orderList.clone(), Value::Int(16), &[]);
let mut triggerPrice: Value = Value::Null;
if (orderType.as_str() == Some("EXCHANGE STOP")) || (orderType.as_str() == Some("EXCHANGE STOP LIMIT")) {
price = Value::Null;
triggerPrice = self.safe_string(orderList.clone(), Value::Int(16), &[]);
if (orderType.as_str() == Some("EXCHANGE STOP LIMIT")) {
price = self.safe_string(orderList.clone(), Value::Int(19), &[]);
}
}
let mut status: Value = Value::Null;
let mut statusString: Value = self.safe_string(orderList.clone(), Value::Int(13), &[]);
if (statusString != Value::Null) {
let mut parts: Value = split(&statusString, &Value::Str(" @ ".into()));
status = self.parse_order_status(self.safe_string(parts, Value::Int(0), &[]));
}
let mut average: Value = self.safe_string(orderList.clone(), Value::Int(17), &[]);
let mut clientOrderId: Value = self.safe_string(orderList.clone(), Value::Int(2), &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), orderList);
m.insert("id".to_string(), id);
m.insert("clientOrderId".to_string(), clientOrderId);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), type_var);
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), postOnly);
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("triggerPrice".to_string(), triggerPrice);
m.insert("amount".to_string(), amount);
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), average);
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), remaining);
m.insert("status".to_string(), status);
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m
}), &[market]);
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (type_var == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a type argument".into()))));
}
if (side == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" requires a side argument".into()))));
}
/*
* @method
* @ignore
* @name bitfinex#createOrderRequest
* @description helper function to build an order request
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price of the order, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
* @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
* @param {bool} [params.postOnly]
* @param {bool} [params.reduceOnly] Ensures that the executed order does not flip the opened position.
* @param {int} [params.flags] additional order parameters: 4096 (Post Only), 1024 (Reduce Only), 16384 (OCO), 64 (Hidden), 512 (Close), 524288 (No Var Rates)
* @param {int} [params.lev] leverage for a derivative order, supported by derivative symbol orders only. The value should be between 1 and 100 inclusive.
* @param {string} [params.price_traling] The trailing price for a trailing stop order
* @param {string} [params.price_aux_limit] Order price for stop limit orders
* @param {string} [params.price_oco_stop] OCO stop price
* @returns {object} an [order structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-structure}
*/
let mut market: Value = self.market(symbol.clone());
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount);
amountString = (if (side.as_str() == Some("buy")) { amountString.clone() } else { crate::precise::Precise::stringNeg(&amountString) });
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), amountString);
m
});
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]);
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut timeInForce: Option<String> = self.safe_string_k(params.clone(), "timeInForce", &[]).as_str().map(str::to_owned);
let mut postOnlyParam: Value = self.safe_bool_k(params.clone(), "postOnly", &[Value::Bool(false)]);
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut clientOrderId: Value = self.safe_value2(params.clone(), Value::Str("cid".into()), Value::Str("clientOrderId".into()), &[]);
let mut orderType: Value = to_upper(&type_var);
if (trailingAmount != Value::Null) {
orderType = Value::Str("TRAILING STOP".into());
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price_trailing".into(), trailingAmount); }
} else if (triggerPrice != Value::Null) {
// request['price'] is taken as triggerPrice for stop orders
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone())); }
if (type_var.as_str() == Some("limit")) {
orderType = Value::Str("STOP LIMIT".into());
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price_aux_limit".into(), self.price_to_precision(symbol.clone(), price.clone())); }
} else {
orderType = Value::Str("STOP".into());
}
}
let mut ioc: bool = timeInForce.as_deref() == Some("IOC");
let mut fok: bool = timeInForce.as_deref() == Some("FOK");
let mut postOnly: bool = (postOnlyParam.as_bool() == Some(true)) || (timeInForce.as_deref() == Some("PO"));
if (ioc || fok) && (price == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() requires a price argument with IOC and FOK orders".into()))));
}
if (ioc || fok) && (type_var.as_str() == Some("market")) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" createOrder() does not allow market IOC and FOK orders".into()))));
}
if (type_var.as_str() != Some("market")) && (triggerPrice == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol, price)); }
}
if ioc {
orderType = Value::Str("IOC".into());
} else if fok {
orderType = Value::Str("FOK".into());
}
let mut marginModeparamsMarginModeVariable = self.handle_margin_mode_and_params(Value::Str("createOrder".into()), &[params]);
let mut marginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMarginMode: Value = marginModeparamsMarginModeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (market.as_map().and_then(|__m| __m.get("spot")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) && (marginMode == Value::Null) {
// The EXCHANGE prefix is only required for non margin spot markets
orderType = Value::Str(format!("{}{}", Value::Str("EXCHANGE ".into()), orderType).into());
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), orderType); }
// flag values may be summed to combine flags
let mut flags: Value = Value::Int(0);
if postOnly {
flags = self.sum(&[flags.clone(), Value::Int(4096)]);
}
if (reduceOnly.as_bool() == Some(true)) {
flags = self.sum(&[flags.clone(), Value::Int(1024)]);
}
if (flags.as_f64() != Some(0.0)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("flags".into(), flags); }
}
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("cid".into(), clientOrderId); }
}
let mut paramsOmitted: Value = self.omit(paramsMarginMode, Value::from(vec![Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), Value::Str("timeInForce".into()), Value::Str("postOnly".into()), Value::Str("reduceOnly".into()), Value::Str("trailingAmount".into()), Value::Str("clientOrderId".into())]), &[]);
return self.extend(request, &[paramsOmitted]);
Value::Null
}
/*
* @method
* @name bitfinex#createOrder
* @description create an order on the exchange
* @see https://docs.bitfinex.com/reference/rest-auth-submit-order
* @param {string} symbol unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] price of the order
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] the price that triggers a trigger order
* @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
* @param {boolean} [params.postOnly] set to true if you want to make a post only order
* @param {boolean} [params.reduceOnly] indicates that the order is to reduce the size of a position
* @param {int} [params.flags] additional order parameters: 4096 (Post Only), 1024 (Reduce Only), 16384 (OCO), 64 (Hidden), 512 (Close), 524288 (No Var Rates)
* @param {int} [params.lev] leverage for a derivative order, supported by derivative symbol orders only. The value should be between 1 and 100 inclusive.
* @param {string} [params.price_aux_limit] order price for stop limit orders
* @param {string} [params.price_oco_stop] OCO stop price
* @param {string} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_order_request(symbol, type_var, side, amount, &[price, params]);
let mut response: Value = self.private_post_auth_w_order_submit(&[request]).await;
//
// [
// 1653325121, // Timestamp in milliseconds
// "on-req", // Purpose of notification ('on-req', 'oc-req', "uca", 'fon-req', "foc-req")
// null, // unique ID of the message
// null,
// [
// [
// 95412102131, // Order ID
// null, // Group ID
// 1653325121798, // Client Order ID
// "tDOGE:UST", // Market ID
// 1653325121798, // Millisecond timestamp of creation
// 1653325121798, // Millisecond timestamp of update
// -10, // Amount (Positive means buy, negative means sell)
// -10, // Original amount
// "EXCHANGE LIMIT", // Type of the order: LIMIT, EXCHANGE LIMIT, MARKET, EXCHANGE MARKET, STOP, EXCHANGE STOP, STOP LIMIT, EXCHANGE STOP LIMIT, TRAILING STOP, EXCHANGE TRAILING STOP, FOK, EXCHANGE FOK, IOC, EXCHANGE IOC.
// null, // Previous order type (stop-limit orders are converted to limit orders so for them previous type is always STOP)
// null, // Millisecond timestamp of Time-In-Force: automatic order cancellation
// null, // _PLACEHOLDER
// 4096, // Flags, see parseOrderFlags()
// "ACTIVE", // Order Status, see parseOrderStatus()
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// 0.071, // Price (Stop Price for stop-limit orders, Limit Price for limit orders)
// 0, // Average Price
// 0, // Trailing Price
// 0, // Auxiliary Limit price (for STOP LIMIT)
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// 0, // Hidden (0 if false, 1 if true)
// 0, // Placed ID (If another order caused this order to be placed (OCO) this will be that other order's ID)
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// "API>BFX", // Routing, indicates origin of action: BFX, ETHFX, API>BFX, API>ETHFX
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// {"$F7":1} // additional meta information about the order ( $F7 = IS_POST_ONLY (0 if false, 1 if true), $F33 = Leverage (int))
// ]
// ],
// null, // CODE (work in progress)
// "SUCCESS", // Status of the request
// "Submitting 1 orders." // Message
// ]
//
let mut status: Value = self.safe_string(response.clone(), Value::Int(6), &[]);
if (status.as_str() != Some("SUCCESS")) {
let mut errorCode: Value = self.safe_string(response.clone(), Value::Int(5), &[]);
let mut errorText: Value = self.safe_string(response.clone(), Value::Int(7), &[]);
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), status).into()), Value::Str(": ".into())).into()), errorText).into()), Value::Str(" (#".into())).into()), errorCode).into()), Value::Str(")".into()))));
}
let mut orders: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut order: Value = self.safe_list(orders, Value::Int(0), &[]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(newOrder, &[market]);
Value::Null
}
/*
* @method
* @name bitfinex#createOrders
* @description create a list of trade orders
* @see https://docs.bitfinex.com/reference/rest-auth-order-multi
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_326: bool = true;
while { if !__for_first_326 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_326 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
let mut rawOrder: Value = self.safe_dict(orders.clone(), i.clone(), &[]);
let mut symbol: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_number_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_number_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder, "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_order_request(symbol, type_var, side, amount, &[price, orderParams]);
append_to_array(&mut ordersRequests, Value::from(vec![Value::Str("on".into()), orderRequest]));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ops".to_string(), ordersRequests);
m
});
let mut response: Value = self.private_post_auth_w_order_multi(&[request]).await;
//
// [
// 1706762515553,
// "ox_multi-req",
// null,
// null,
// [
// [
// 1706762515,
// "on-req",
// null,
// null,
// [
// [139567428547,null,1706762515551,"tBTCUST",1706762515551,1706762515551,0.0001,0.0001,"EXCHANGE LIMIT",null,null,null,0,"ACTIVE",null,null,35000,0,0,0,null,null,null,0,0,null,null,null,"API>BFX",null,null,{}]
// ],
// null,
// "SUCCESS",
// "Submitting 1 orders."
// ],
// ],
// null,
// "SUCCESS",
// "Submitting 2 order operations."
// ]
//
let mut results: Value = Value::from(vec![]);
let mut data: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_327: bool = true;
while { if !__for_first_327 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_327 = false; i.as_f64().unwrap_or(f64::NAN) < ((data.len() as i64) as f64) } {
let mut entry: Value = data.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut individualOrder: Value = get_value(&entry, &Value::Int(4));
append_to_array(&mut results, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&individualOrder, &Value::Int(0)));
m
}));
}
}
return self.parse_orders(results, &[]);
Value::Null
}
/*
* @method
* @name bitfinex#cancelAllOrders
* @description cancel all open orders
* @see https://docs.bitfinex.com/reference/rest-auth-cancel-orders-multiple
* @param {string} [symbol] unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("all".to_string(), Value::Int(1));
m
});
let __ws_arg_7 = self.extend(request, &[params]);
let mut response: Value = self.private_post_auth_w_order_cancel_multi(&[__ws_arg_7]).await;
let mut orders: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut ordersList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_328: bool = true;
while { if !__for_first_328 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_328 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
append_to_array(&mut ordersList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), orders.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
m
}));
}
}
return self.parse_orders(ordersList, &[]);
Value::Null
}
/*
* @method
* @name bitfinex#cancelOrder
* @description cancels an open order
* @see https://docs.bitfinex.com/reference/rest-auth-cancel-order
* @param {string} id order id
* @param {string} symbol Not used by bitfinex cancelOrder ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn 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 cid: Value = self.safe_value2(params.clone(), Value::Str("cid".into()), Value::Str("clientOrderId".into()), &[]); // client order id
let mut request: Value = Value::Null;
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
if (cid != Value::Null) {
let mut cidDate: Value = self.safe_value_k(params.clone(), "cidDate", &[]); // client order id date
if (cidDate == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(format!("{}{}", self.id.clone(), Value::Str(" canceling an order by clientOrderId ('cid') requires both 'cid' and 'cid_date' ('YYYY-MM-DD')".into()))));
}
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cid".to_string(), cid.clone());
m.insert("cid_date".to_string(), cidDate);
m
});
} else {
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), (match &id { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null }));
m
});
}
let mut paramsOmitted: Value = (if (cid != Value::Null) { self.omit(params.clone(), Value::from(vec![Value::Str("cid".into()), Value::Str("clientOrderId".into())]), &[]) } else { params });
let __ws_arg_8 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_post_auth_w_order_cancel(&[__ws_arg_8]).await;
let mut order: Value = self.safe_value(response, Value::Int(4), &[]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(newOrder, &[market]);
Value::Null
}
/*
* @method
* @name bitfinex#cancelOrders
* @description cancel multiple orders at the same time
* @see https://docs.bitfinex.com/reference/rest-auth-cancel-orders-multiple
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an array of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut numericIds: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_329: bool = true;
while { if !__for_first_329 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_329 = false; i.as_f64().unwrap_or(f64::NAN) < ((ids.len() as i64) as f64) } {
// numericIds[i] = this.parseToNumeric (ids[i]);
append_to_array(&mut numericIds, self.parse_to_numeric(ids.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null)));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), numericIds);
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let __ws_arg_9 = self.extend(request, &[params]);
let mut response: Value = self.private_post_auth_w_order_cancel_multi(&[__ws_arg_9]).await;
//
// [
// 1706740198811,
// "oc_multi-req",
// null,
// null,
// [
// [
// 139530205057,
// null,
// 1706740132275,
// "tBTCF0:USTF0",
// 1706740132276,
// 1706740132276,
// 0.0001,
// 0.0001,
// "LIMIT",
// null,
// null,
// null,
// 0,
// "ACTIVE",
// null,
// null,
// 39000,
// 0,
// 0,
// 0,
// null,
// null,
// null,
// 0,
// 0,
// null,
// null,
// null,
// "API>BFX",
// null,
// null,
// {
// "lev": 10,
// "$F33": 10
// }
// ],
// ],
// null,
// "SUCCESS",
// "Submitting 2 order cancellations."
// ]
//
let mut orders: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut ordersList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_330: bool = true;
while { if !__for_first_330 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_330 = false; i.as_f64().unwrap_or(f64::NAN) < ((orders.len() as i64) as f64) } {
append_to_array(&mut ordersList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), orders.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
m
}));
}
}
return self.parse_orders(ordersList, &[market]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchOpenOrder
* @description fetch an open order by it's id
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol
* @param {string} id order id
* @param {string} symbol unified market symbol, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::from(vec![(match &id { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null })]));
m
});
let __ws_arg_10 = self.extend(request, &[params]);
let mut orders: Value = self.fetch_open_orders(&[symbol, Value::Null, Value::Null, __ws_arg_10]).await;
let mut order: Value = self.safe_value(orders, Value::Int(0), &[]);
if (order == Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" order ".into())).into()), id).into()), Value::Str(" not found".into()))));
}
return order;
Value::Null
}
/*
* @method
* @name bitfinex#fetchClosedOrder
* @description fetch an open order by it's id
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol
* @param {string} id order id
* @param {string} symbol unified market symbol, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::from(vec![(match &id { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null })]));
m
});
let __ws_arg_11 = self.extend(request, &[params]);
let mut orders: Value = self.fetch_closed_orders(&[symbol, Value::Null, Value::Null, __ws_arg_11]).await;
let mut order: Value = self.safe_value(orders, Value::Int(0), &[]);
if (order == Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" order ".into())).into()), id).into()), Value::Str(" not found".into()))));
}
return order;
Value::Null
}
/*
* @method
* @name bitfinex#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if (symbol == Value::Null) {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_auth_r_orders(&[__ws_arg_12]).await;
} else {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_13 = self.extend(request, &[params]);
response = self.private_post_auth_r_orders_symbol(&[__ws_arg_13]).await;
}
//
// [
// [
// 95408916206, // Order ID
// null, // Group Order ID
// 1653322349926, // Client Order ID
// "tDOGE:UST", // Market ID
// 1653322349926, // Created Timestamp in milliseconds
// 1653322349927, // Updated Timestamp in milliseconds
// -10, // Amount remaining (Positive means buy, negative means sell)
// -10, // Original amount
// "EXCHANGE LIMIT", // Order type
// null, // Previous Order Type
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// 0, // Flags, see parseOrderFlags()
// "ACTIVE", // Order Status, see parseOrderStatus()
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// 0.11, // Price
// 0, // Average Price
// 0, // Trailing Price
// 0, // Auxiliary Limit price (for STOP LIMIT)
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// 0, // Hidden (0 if false, 1 if true)
// 0, // Placed ID (If another order caused this order to be placed (OCO) this will be that other order's ID)
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// "API>BFX", // Routing, indicates origin of action: BFX, ETHFX, API>BFX, API>ETHFX
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// {"$F7":1} // additional meta information about the order ( $F7 = IS_POST_ONLY (0 if false, 1 if true), $F33 = Leverage (int))
// ],
// ]
//
let mut ordersList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_331: bool = true;
while { if !__for_first_331 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_331 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
append_to_array(&mut ordersList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&response, &i));
m
}));
}
}
return self.parse_orders(ordersList, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// returns the most recent closed or canceled orders up to circa two weeks ago
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchClosedOrders".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchClosedOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPaginate.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // default 25, max 2500
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("end".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if (symbol == Value::Null) {
let __ws_arg_14 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_post_auth_r_orders_hist(&[__ws_arg_14]).await;
} else {
market = self.market(symbol);
add_element_to_object(&mut requestUntil, &Value::Str("symbol".into()), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_15 = self.extend(requestUntil, &[paramsUntil]);
response = self.private_post_auth_r_orders_symbol_hist(&[__ws_arg_15]).await;
}
//
// [
// [
// 95412102131, // Order ID
// null, // Group Order ID
// 1653325121798, // Client Order ID
// "tDOGE:UST", // Market ID
// 1653325122000, // Created Timestamp in milliseconds
// 1653325122000, // Updated Timestamp in milliseconds
// -10, // Amount remaining (Positive means buy, negative means sell)
// -10, // Original amount
// "EXCHANGE LIMIT", // Order type
// null, // Previous Order Type
// null, // Millisecond timestamp of Time-In-Force: automatic order cancellation
// null, // _PLACEHOLDER
// "4096", // Flags, see parseOrderFlags()
// "POSTONLY CANCELED", // Order Status, see parseOrderStatus()
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// 0.071, // Price
// 0, // Average Price
// 0, // Trailing Price
// 0, // Auxiliary Limit price (for STOP LIMIT)
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// 0, // Notify (0 if false, 1 if true)
// 0, // Hidden (0 if false, 1 if true)
// null, // Placed ID (If another order caused this order to be placed (OCO) this will be that other order's ID)
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// "API>BFX", // Routing, indicates origin of action: BFX, ETHFX, API>BFX, API>ETHFX
// null, // _PLACEHOLDER
// null, // _PLACEHOLDER
// {"_$F7":1} // additional meta information about the order ( _$F7 = IS_POST_ONLY (0 if false, 1 if true), _$F33 = Leverage (int))
// ]
// ]
//
let mut ordersList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_332: bool = true;
while { if !__for_first_332 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_332 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
append_to_array(&mut ordersList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&response, &i));
m
}));
}
}
return self.parse_orders(ordersList, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://docs.bitfinex.com/reference/rest-auth-order-trades
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchOrderTrades() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut orderId: Value = (match &id { Value::Str(__parse_s) => __parse_s.trim().parse::<i64>().map(Value::Int).unwrap_or(Value::Null), Value::Int(__parse_n) => Value::Int(*__parse_n), Value::Float(__parse_f) => Value::Int(*__parse_f as i64), _ => Value::Null });
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId);
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
// valid for trades up to 10 days old
let __ws_arg_16 = self.extend(request, &[params]);
let mut response: Value = self.private_post_auth_r_order_symbol_id_trades(&[__ws_arg_16]).await;
let mut rawTrades: Value = self.to_array(response);
let mut tradesList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_333: bool = true;
while { if !__for_first_333 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_333 = false; i.as_f64().unwrap_or(f64::NAN) < ((rawTrades.len() as i64) as f64) } {
append_to_array(&mut tradesList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), rawTrades.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
m
})); // convert to array of dicts to match parseOrder signature
}
}
return self.parse_trades(tradesList, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.bitfinex.com/reference/rest-auth-trades
* @see https://docs.bitfinex.com/reference/rest-auth-trades-by-symbol
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("end".to_string(), self.milliseconds());
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // default 25, max 1000
}
let mut response: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_auth_r_trades_symbol_hist(&[__ws_arg_17]).await;
} else {
let __ws_arg_18 = self.extend(request, &[params]);
response = self.private_post_auth_r_trades_hist(&[__ws_arg_18]).await;
}
let mut tradesList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_334: bool = true;
while { if !__for_first_334 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_334 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
append_to_array(&mut tradesList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&response, &i));
m
})); // convert to array of dicts to match parseOrder signature
}
}
return self.parse_trades(tradesList, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name bitfinex#createDepositAddress
* @description create a currency deposit address
* @see https://docs.bitfinex.com/reference/rest-auth-deposit-address
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("op_renew".to_string(), Value::Int(1));
m
});
let __ws_arg_19 = self.extend(request, &[params]);
return self.fetch_deposit_address(code, &[__ws_arg_19]).await;
Value::Null
}
/*
* @method
* @name bitfinex#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://docs.bitfinex.com/reference/rest-auth-deposit-address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_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());
// if not provided explicitly we will try to match using the currency name
let mut network: Value = self.safe_string_k(params.clone(), "network", &[code.clone()]);
let mut currencyNetworks: Value = self.safe_dict_k(currency, "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyNetwork: Value = self.safe_dict(currencyNetworks, network, &[]);
let mut networkId: Value = self.safe_string_k(currencyNetwork, "id", &[]);
if (networkId == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositAddress() could not find a network for '".into())).into()), code).into()), Value::Str("'. You can specify it by providing the 'network' value inside params".into()))));
}
let mut wallet: Value = self.safe_string_k(params.clone(), "wallet", &[Value::Str("exchange".into())]); // 'exchange', 'margin', 'funding' and also old labels 'exchange', 'trading', 'deposit', respectively
let mut paramsOmitted: Value = self.omit(params, Value::Str("network".into()), &[Value::Str("wallet".into())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), networkId);
m.insert("wallet".to_string(), wallet);
m.insert("op_renew".to_string(), Value::Int(0));
m
});
let __ws_arg_20 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_post_auth_w_deposit_address(&[__ws_arg_20]).await;
//
// [
// 1582269616687, // MTS Millisecond Time Stamp of the update
// "acc_dep", // TYPE Purpose of notification "acc_dep" for account deposit
// null, // MESSAGE_ID unique ID of the message
// null, // not documented
// [
// null, // PLACEHOLDER
// "BITCOIN", // METHOD Method of deposit
// "BTC", // CURRENCY_CODE Currency code of new address
// null, // PLACEHOLDER
// "1BC9PZqpUmjyEB54uggn8TFKj49zSDYzqG", // ADDRESS
// null, // POOL_ADDRESS
// ],
// null, // CODE null or integer work in progress
// "SUCCESS", // STATUS Status of the notification, SUCCESS, ERROR, FAILURE
// "success", // TEXT Text of the notification
// ]
//
let mut result: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::from(vec![])]);
let mut poolAddress: Value = self.safe_string(result.clone(), Value::Int(5), &[]);
let mut address: Value = (if (poolAddress == Value::Null) { self.safe_string(result.clone(), Value::Int(4), &[]) } else { poolAddress.clone() });
let mut tag: Value = (if (poolAddress == Value::Null) { Value::Null } else { self.safe_string(result, Value::Int(4), &[]) });
self.check_address(&[address.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("address".to_string(), address);
m.insert("tag".to_string(), tag);
m.insert("network".to_string(), Value::Null);
m.insert("info".to_string(), response);
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SUCCESS".to_string(), Value::Str("ok".into()));
m.insert("COMPLETED".to_string(), Value::Str("ok".into()));
m.insert("ERROR".to_string(), Value::Str("failed".into()));
m.insert("FAILURE".to_string(), Value::Str("failed".into()));
m.insert("CANCELED".to_string(), Value::Str("canceled".into()));
m.insert("PENDING APPROVAL".to_string(), Value::Str("pending".into()));
m.insert("PENDING".to_string(), Value::Str("pending".into()));
m.insert("PENDING REVIEW".to_string(), Value::Str("pending".into()));
m.insert("PENDING CANCELLATION".to_string(), Value::Str("pending".into()));
m.insert("SENDING".to_string(), Value::Str("pending".into()));
m.insert("USER APPROVED".to_string(), Value::Str("pending".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// withdraw
//
// [
// 1582271520931, // MTS Millisecond Time Stamp of the update
// "acc_wd-req", // TYPE Purpose of notification "acc_wd-req" account withdrawal request
// null, // MESSAGE_ID unique ID of the message
// null, // not documented
// [
// 0, // WITHDRAWAL_ID Unique Withdrawal ID
// null, // PLACEHOLDER
// "bitcoin", // METHOD Method of withdrawal
// null, // PAYMENT_ID Payment ID if relevant
// "exchange", // WALLET Sending wallet
// 1, // AMOUNT Amount of Withdrawal less fee
// null, // PLACEHOLDER
// null, // PLACEHOLDER
// 0.0004, // WITHDRAWAL_FEE Fee on withdrawal
// ],
// null, // CODE null or integer Work in progress
// "SUCCESS", // STATUS Status of the notification, it may vary over time SUCCESS, ERROR, FAILURE
// "Invalid bitcoin address (abcdef)", // TEXT Text of the notification
// ]
//
// fetchDepositsWithdrawals
//
// [
// 13293039, // ID
// "ETH", // CURRENCY
// "ETHEREUM", // CURRENCY_NAME
// null,
// null,
// 1574175052000, // MTS_STARTED
// 1574181326000, // MTS_UPDATED
// null,
// null,
// "CANCELED", // STATUS
// null,
// null,
// -0.24, // AMOUNT, negative for withdrawals
// -0.00135, // FEES
// null,
// null,
// "0x38110e0Fc932CB2BE...........", // DESTINATION_ADDRESS
// null,
// null,
// null,
// "0x523ec8945500.....................................", // TRANSACTION_ID
// "Purchase of 100 pizzas", // WITHDRAW_TRANSACTION_NOTE, might also be: null
// ]
//
let mut transactionLength: f64 = ((transaction.len() as i64) as f64);
let mut timestamp: Value = Value::Null;
let mut updated: Value = Value::Null;
let mut code: Value = Value::Null;
let mut amount: Value = Value::Null;
let mut id: Value = Value::Null;
let mut status: Value = Value::Null;
let mut tag: Value = Value::Null;
let mut type_var: Value = Value::Null;
let mut feeCost: Value = Value::Null;
let mut txid: Value = Value::Null;
let mut addressTo: Value = Value::Null;
let mut network: Value = Value::Null;
let mut comment: Value = Value::Null;
if (transactionLength == 8.0) {
let mut data: Value = self.safe_list(transaction.clone(), Value::Int(4), &[Value::from(vec![])]);
timestamp = self.safe_integer(transaction.clone(), Value::Int(0), &[]);
if (currency != Value::Null) {
code = self.safe_string_k(currency.clone(), "code", &[]);
}
feeCost = self.safe_string(data.clone(), Value::Int(8), &[]);
if (feeCost != Value::Null) {
feeCost = crate::precise::Precise::stringAbs(&feeCost);
}
amount = self.safe_number(data.clone(), Value::Int(5), &[]);
id = self.safe_integer(data.clone(), Value::Int(0), &[]);
status = Value::Str("ok".into());
if (id.as_f64() == Some(0.0)) {
id = Value::Null;
status = Value::Str("failed".into());
}
tag = self.safe_string(data.clone(), Value::Int(3), &[]);
type_var = Value::Str("withdrawal".into());
let mut networkId: Value = self.safe_string(data, Value::Int(2), &[]);
network = self.network_id_to_code(&[to_upper(&networkId), code.clone()]); // withdraw returns in lowercase
} else if (transactionLength == 22.0) {
id = self.safe_string(transaction.clone(), Value::Int(0), &[]);
let mut currencyId: Value = self.safe_string(transaction.clone(), Value::Int(1), &[]);
code = self.safe_currency_code(currencyId, &[currency]);
let mut networkId: Value = self.safe_string(transaction.clone(), Value::Int(2), &[]);
network = self.network_id_to_code(&[networkId, code.clone()]);
timestamp = self.safe_integer(transaction.clone(), Value::Int(5), &[]);
updated = self.safe_integer(transaction.clone(), Value::Int(6), &[]);
status = self.parse_transaction_status(self.safe_string(transaction.clone(), Value::Int(9), &[]));
let mut signedAmount: Value = self.safe_string(transaction.clone(), Value::Int(12), &[]);
amount = crate::precise::Precise::stringAbs(&signedAmount);
if (signedAmount != Value::Null) {
if is_true(&crate::precise::Precise::stringLt(&signedAmount, &Value::Str("0".into()))) {
type_var = Value::Str("withdrawal".into());
} else {
type_var = Value::Str("deposit".into());
}
}
feeCost = self.safe_string(transaction.clone(), Value::Int(13), &[]);
if (feeCost != Value::Null) {
feeCost = crate::precise::Precise::stringAbs(&feeCost);
}
addressTo = self.safe_string(transaction.clone(), Value::Int(16), &[]);
txid = self.safe_string(transaction.clone(), Value::Int(20), &[]);
comment = self.safe_string(transaction.clone(), Value::Int(21), &[]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction);
m.insert("id".to_string(), id);
m.insert("txid".to_string(), txid);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), network);
m.insert("amount".to_string(), self.parse_number(amount, &[]));
m.insert("status".to_string(), status);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("address".to_string(), addressTo.clone());
m.insert("addressFrom".to_string(), Value::Null);
m.insert("addressTo".to_string(), addressTo);
m.insert("tag".to_string(), tag.clone());
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), tag);
m.insert("updated".to_string(), updated);
m.insert("comment".to_string(), comment);
m.insert("internal".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("cost".to_string(), self.parse_number(feeCost, &[]));
m.insert("rate".to_string(), Value::Null);
m
}));
m
});
Value::Null
}
/*
* @method
* @name bitfinex#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://docs.bitfinex.com/reference/rest-auth-summary
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_post_auth_r_summary(&[params]).await;
//
// Response Spec:
// [
// PLACEHOLDER,
// PLACEHOLDER,
// PLACEHOLDER,
// PLACEHOLDER,
// [
// [
// MAKER_FEE,
// MAKER_FEE,
// MAKER_FEE,
// PLACEHOLDER,
// PLACEHOLDER,
// DERIV_REBATE
// ],
// [
// TAKER_FEE_TO_CRYPTO,
// TAKER_FEE_TO_STABLE,
// TAKER_FEE_TO_FIAT,
// PLACEHOLDER,
// PLACEHOLDER,
// DERIV_TAKER_FEE
// ]
// ],
// PLACEHOLDER,
// PLACEHOLDER,
// PLACEHOLDER,
// PLACEHOLDER,
// {
// LEO_LEV,
// LEO_AMOUNT_AVG
// }
// ]
//
// Example response:
//
// [
// null,
// null,
// null,
// null,
// [
// [ 0.001, 0.001, 0.001, null, null, 0.0002 ],
// [ 0.002, 0.002, 0.002, null, null, 0.00065 ]
// ],
// [
// [
// {
// "curr": "Total (USD)",
// "vol": "0",
// "vol_safe": "0",
// "vol_maker": "0",
// "vol_BFX": "0",
// "vol_BFX_safe": "0",
// "vol_BFX_maker": "0"
// }
// ],
// {},
// 0
// ],
// [ null, {}, 0 ],
// null,
// null,
// { leo_lev: "0", leo_amount_avg: "0" }
// ]
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut fiat: Value = self.safe_dict_k(self.options.clone(), "fiat", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut feeData: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::from(vec![])]);
let mut makerData: Value = self.safe_list(feeData.clone(), Value::Int(0), &[Value::from(vec![])]);
let mut takerData: Value = self.safe_list(feeData, Value::Int(1), &[Value::from(vec![])]);
let mut makerFee: Value = self.safe_number(makerData.clone(), Value::Int(0), &[]);
let mut makerFeeFiat: Value = self.safe_number(makerData.clone(), Value::Int(2), &[]);
let mut makerFeeDeriv: Value = self.safe_number(makerData, Value::Int(5), &[]);
let mut takerFee: Value = self.safe_number(takerData.clone(), Value::Int(0), &[]);
let mut takerFeeFiat: Value = self.safe_number(takerData.clone(), Value::Int(2), &[]);
let mut takerFeeDeriv: Value = self.safe_number(takerData, Value::Int(5), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_335: bool = true;
while { if !__for_first_335 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_335 = false; i.as_f64().unwrap_or(f64::NAN) < ((self.symbols.len() as i64) as f64) } {
let mut symbol: Value = self.symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut market: Value = self.market(symbol.clone());
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
if (in_op(&fiat, &market.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null))) {
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("maker".into(), makerFeeFiat.clone()); }
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("taker".into(), takerFeeFiat.clone()); }
} else if (market.as_map().and_then(|__m| __m.get("contract")).cloned().unwrap_or(Value::Null).as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("maker".into(), makerFeeDeriv.clone()); }
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("taker".into(), takerFeeDeriv.clone()); }
} else {
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("maker".into(), makerFee.clone()); }
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("taker".into(), takerFee.clone()); }
}
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), fee); }
}
}
return result;
Value::Null
}
/*
* @method
* @name bitfinex#fetchDepositsWithdrawals
* @description fetch history of deposits and withdrawals
* @see https://docs.bitfinex.com/reference/movement-info
* @see https://docs.bitfinex.com/reference/rest-auth-movements
* @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
* @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
* @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits_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 currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // max 1000
}
let mut response: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("currency".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
let mut currencyMovements: Value = self.private_post_auth_r_movements_currency_hist(&[__ws_arg_21]).await;
response = self.to_array(currencyMovements);
} else {
let __ws_arg_22 = self.extend(request, &[params]);
let mut movements: Value = self.private_post_auth_r_movements_hist(&[__ws_arg_22]).await;
response = self.to_array(movements);
}
return self.parse_transactions(response, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name bitfinex#withdraw
* @description make a withdrawal
* @see https://docs.bitfinex.com/reference/rest-auth-withdraw
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tag] memo / destination tag, required for currencies in options['withdrawTagRequiredCurrencies']
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut tagparamsWithdrawTagVariable = self.handle_param_string(params, Value::Str("tag".into()), &[]);
let mut tag: Value = tagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsWithdrawTag: Value = tagparamsWithdrawTagVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
self.check_address(&[address.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
// if not provided explicitly we will try to match using the currency name
let mut network: Value = self.safe_string_k(paramsWithdrawTag.clone(), "network", &[code.clone()]);
let mut paramsOmitted: Value = self.omit(paramsWithdrawTag, Value::Str("network".into()), &[]);
let mut currencyNetworks: Value = self.safe_dict_k(currency.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyNetwork: Value = self.safe_dict(currencyNetworks, network, &[]);
let mut networkId: Value = self.safe_string_k(currencyNetwork, "id", &[]);
if (networkId == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" withdraw() could not find a network for '".into())).into()), code).into()), Value::Str("'. You can specify it by providing the 'network' value inside params".into()))));
}
let mut wallet: Value = self.safe_string_k(paramsOmitted.clone(), "wallet", &[Value::Str("exchange".into())]); // 'exchange', 'margin', 'funding' and also old labels 'exchange', 'trading', 'deposit', respectively
let mut paramsOmitted2: Value = self.omit(paramsOmitted, Value::Str("network".into()), &[Value::Str("wallet".into())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), networkId);
m.insert("wallet".to_string(), wallet);
m.insert("amount".to_string(), self.number_to_string(amount));
m.insert("address".to_string(), address);
m
});
if (tag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("payment_id".into(), tag); }
}
let mut withdrawOptions: Value = self.safe_dict_k(self.options.clone(), "withdraw", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut includeFee: Value = self.safe_bool_k(withdrawOptions, "includeFee", &[Value::Bool(false)]);
if (includeFee.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("fee_deduct".into(), Value::Int(1)); }
}
let __ws_arg_23 = self.extend(request, &[paramsOmitted2]);
let mut response: Value = self.private_post_auth_w_withdraw(&[__ws_arg_23]).await;
//
// [
// 1582271520931, // MTS Millisecond Time Stamp of the update
// "acc_wd-req", // TYPE Purpose of notification "acc_wd-req" account withdrawal request
// null, // MESSAGE_ID unique ID of the message
// null, // not documented
// [
// 0, // WITHDRAWAL_ID Unique Withdrawal ID
// null, // PLACEHOLDER
// "bitcoin", // METHOD Method of withdrawal
// null, // PAYMENT_ID Payment ID if relevant
// "exchange", // WALLET Sending wallet
// 1, // AMOUNT Amount of Withdrawal less fee
// null, // PLACEHOLDER
// null, // PLACEHOLDER
// 0.0004, // WITHDRAWAL_FEE Fee on withdrawal
// ],
// null, // CODE null or integer Work in progress
// "SUCCESS", // STATUS Status of the notification, it may vary over time SUCCESS, ERROR, FAILURE
// "Invalid bitcoin address (abcdef)", // TEXT Text of the notification
// ]
//
// in case of failure:
//
// [
// "error",
// 10001,
// "Momentary balance check. Please wait few seconds and try the transfer again."
// ]
//
let mut statusMessage: Option<String> = self.safe_string(response.clone(), Value::Int(0), &[]).as_str().map(str::to_owned);
if (statusMessage.as_deref() == Some("error")) {
let mut feedback: Value = add(&Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), &response);
let mut message: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".into())]);
// same message as in v1
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut text: Value = self.safe_string(response.clone(), Value::Int(7), &[]);
if (text.as_str() != Some("success")) {
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), text.clone(), text.clone());
}
return self.parse_transaction(response, &[currency]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchPositions
* @description fetch all open positions
* @see https://docs.bitfinex.com/reference/rest-auth-positions
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut response: Value = self.private_post_auth_r_positions(&[params]).await;
//
// [
// [
// "tBTCUSD", // SYMBOL
// "ACTIVE", // STATUS
// 0.0195, // AMOUNT
// 8565.0267019, // BASE_PRICE
// 0, // MARGIN_FUNDING
// 0, // MARGIN_FUNDING_TYPE
// -0.33455568705000516, // PL
// -0.0003117550117425625, // PL_PERC
// 7045.876419249083, // PRICE_LIQ
// 3.0673001895895604, // LEVERAGE
// null, // _PLACEHOLDER
// 142355652, // POSITION_ID
// 1574002216000, // MTS_CREATE
// 1574002216000, // MTS_UPDATE
// null, // _PLACEHOLDER
// 0, // TYPE
// null, // _PLACEHOLDER
// 0, // COLLATERAL
// 0, // COLLATERAL_MIN
// // META
// {
// "reason":"TRADE",
// "order_id":34271018124,
// "liq_stage":null,
// "trade_price":"8565.0267019",
// "trade_amount":"0.0195",
// "order_id_oppo":34277498022
// }
// ]
// ]
//
let mut rawPositions: Value = self.to_array(response);
let mut positionsList: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_336: bool = true;
while { if !__for_first_336 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_336 = false; i.as_f64().unwrap_or(f64::NAN) < ((rawPositions.len() as i64) as f64) } {
append_to_array(&mut positionsList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), rawPositions.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null));
m
}));
}
}
return self.parse_positions(positionsList, &[symbolsNormalized]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let __position_empty = indexmap::IndexMap::new();
let position = position.as_map().unwrap_or(&__position_empty);
//
// [
// "tBTCUSD", // SYMBOL
// "ACTIVE", // STATUS
// 0.0195, // AMOUNT
// 8565.0267019, // BASE_PRICE
// 0, // MARGIN_FUNDING
// 0, // MARGIN_FUNDING_TYPE
// -0.33455568705000516, // PL
// -0.0003117550117425625, // PL_PERC
// 7045.876419249083, // PRICE_LIQ
// 3.0673001895895604, // LEVERAGE
// null, // _PLACEHOLDER
// 142355652, // POSITION_ID
// 1574002216000, // MTS_CREATE
// 1574002216000, // MTS_UPDATE
// null, // _PLACEHOLDER
// 0, // TYPE
// null, // _PLACEHOLDER
// 0, // COLLATERAL
// 0, // COLLATERAL_MIN
// // META
// {
// "reason": "TRADE",
// "order_id": 34271018124,
// "liq_stage": null,
// "trade_price": "8565.0267019",
// "trade_amount": "0.0195",
// "order_id_oppo": 34277498022
// }
// ]
//
let mut positionList: Value = (match position.get("result") { Some(__v) if matches!(__v, Value::Arr(_)) => __v.clone(), _ => Value::Null });
let mut marketId: Value = self.safe_string(positionList.clone(), Value::Int(0), &[]);
let mut amount: Value = self.safe_string(positionList.clone(), Value::Int(2), &[]);
let mut timestamp: Value = self.safe_integer(positionList.clone(), Value::Int(12), &[]);
let mut meta: Value = self.safe_string(positionList.clone(), Value::Int(19), &[]);
let mut tradePrice: Value = self.safe_string_k(meta.clone(), "trade_price", &[]);
let mut tradeAmount: Value = self.safe_string_k(meta, "trade_amount", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), positionList.clone());
m.insert("id".to_string(), self.safe_string(positionList.clone(), Value::Int(11), &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("notional".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("liquidationPrice".to_string(), self.safe_number(positionList.clone(), Value::Int(8), &[]));
m.insert("entryPrice".to_string(), self.safe_number(positionList.clone(), Value::Int(3), &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number(positionList.clone(), Value::Int(6), &[]));
m.insert("percentage".to_string(), self.safe_number(positionList.clone(), Value::Int(7), &[]));
m.insert("contracts".to_string(), Value::Null);
m.insert("contractSize".to_string(), Value::Null);
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), (if is_true(&crate::precise::Precise::stringGt(&amount, &Value::Str("0".into()))) { Value::Str("long".into()) } else { Value::Str("short".into()) }));
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer(positionList.clone(), Value::Int(13), &[]));
m.insert("maintenanceMargin".to_string(), self.safe_number(positionList.clone(), Value::Int(18), &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("collateral".to_string(), self.safe_number(positionList.clone(), Value::Int(17), &[]));
m.insert("initialMargin".to_string(), self.parse_number(crate::precise::Precise::stringMul(&tradeAmount, &tradePrice), &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number(positionList, Value::Int(9), &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn nonce(&self) -> Value {
return self.milliseconds();
Value::Null
}
pub fn sign(&mut self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".into()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut request: Value = Value::Str(format!("{}{}", Value::Str("/".into()), self.implode_params(path.clone(), params.clone())).into());
let mut query: Value = self.omit(params, self.extract_params(path), &[]);
if (api.as_str() == Some("v1")) {
request = Value::Str(format!("{}{}", api, request).into());
} else {
request = Value::Str(format!("{}{}", self.version.clone(), request).into());
}
let mut apiUrl: Value = self.safe_string(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), api.clone(), &[]);
if (apiUrl == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", apiUrl, Value::Str("/".into())).into()), request).into());
let mut requestBody: Value = Value::Null;
let mut requestHeaders: Value = Value::Null;
if (api.as_str() == Some("public")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into())).into());
}
}
if (api.as_str() == Some("private")) {
self.check_required_credentials(&[]);
// bitfinex rejects a nonce that is not greater than the previous one for the key (error 10114)
let mut nonce: Value = to_string_val(&self.incrementing_nonce());
requestBody = json_stringify(&query);
let mut auth: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("/api/".into()), request).into()), nonce).into()), requestBody).into());
let mut signature: Value = self.hmac(self.encode(auth), self.encode(self.secret.clone()), Value::Str("sha384".into()), &[]);
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bfx-nonce".to_string(), nonce);
m.insert("bfx-apikey".to_string(), self.apiKey.clone());
m.insert("bfx-signature".to_string(), signature);
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
}
let mut bodyResolved: Value = (if (requestBody == Value::Null) { body } else { requestBody });
let mut headersResolved: Value = (if (requestHeaders == Value::Null) { headers } else { requestHeaders });
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(), bodyResolved);
m.insert("headers".to_string(), headersResolved);
m
});
Value::Null
}
pub fn handle_errors(&self, mut statusCode: Value, mut statusText: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
// ["error", 11010, "ratelimit: error"]
if (response != Value::Null) {
if !(matches!(&response, Value::Arr(_))) {
let mut message: Value = self.safe_string2(response.clone(), Value::Str("message".into()), Value::Str("error".into()), &[]);
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body)));
}
} else if (response.as_str() == Some("")) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" returned empty response".into()))));
}
if (statusCode.as_f64() == Some(429.0)) {
panic!("{}", crate::exchange_errors::rate_limit_exceeded(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body)));
}
if (statusCode.as_f64() == Some(500.0)) {
// See https://docs.bitfinex.com/docs/abbreviations-glossary#section-errorinfo-codes
let mut errorCode: Value = self.safe_string(response.clone(), Value::Int(1), &[Value::Str("".into())]);
let mut errorText: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".into())]);
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), errorText).into());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), errorText.clone(), feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorCode.clone(), feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), errorText.clone(), feedback);
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), errorText).into()), Value::Str(" (#".into())).into()), errorCode).into()), Value::Str(")".into()))));
}
return response;
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
if (type_var == Value::Null) {
return Value::Null;
} else if Value::Int(type_var.as_str().and_then(|__s| __s.find("fee")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) || Value::Int(type_var.as_str().and_then(|__s| __s.find("charged")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return Value::Str("fee".into());
} else if Value::Int(type_var.as_str().and_then(|__s| __s.find("rebate")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return Value::Str("rebate".into());
} else if Value::Int(type_var.as_str().and_then(|__s| __s.find("deposit")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) || Value::Int(type_var.as_str().and_then(|__s| __s.find("withdrawal")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return Value::Str("transaction".into());
} else if Value::Int(type_var.as_str().and_then(|__s| __s.find("transfer")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return Value::Str("transfer".into());
} else if Value::Int(type_var.as_str().and_then(|__s| __s.find("payment")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return Value::Str("payout".into());
} else if Value::Int(type_var.as_str().and_then(|__s| __s.find("exchange")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) || Value::Int(type_var.as_str().and_then(|__s| __s.find("position")).map(|__i| __i as i64).unwrap_or(-1)).as_f64().unwrap_or(f64::NAN) >= ((0i64) as f64) {
return Value::Str("trade".into());
} else {
return type_var;
}
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// [
// [
// 2531822314, // ID: Ledger identifier
// "USD", // CURRENCY: The symbol of the currency (ex. "BTC")
// null, // PLACEHOLDER
// 1573521810000, // MTS: Timestamp in milliseconds
// null, // PLACEHOLDER
// 0.01644445, // AMOUNT: Amount of funds moved
// 0, // BALANCE: New balance
// null, // PLACEHOLDER
// "Settlement @ 185.79 on wallet margin" // DESCRIPTION: Description of ledger transaction
// ]
// ]
//
let mut itemList: Value = self.safe_list_k(item.clone(), "result", &[Value::from(vec![])]);
let mut type_var: Value = Value::Null;
let mut id: Value = self.safe_string(itemList.clone(), Value::Int(0), &[]);
let mut currencyId: Value = self.safe_string(itemList.clone(), Value::Int(1), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut currencyResolved: Value = self.safe_currency(currencyId, &[currency]);
let mut timestamp: Value = self.safe_integer(itemList.clone(), Value::Int(3), &[]);
let mut amount: Value = self.safe_number(itemList.clone(), Value::Int(5), &[]);
let mut after: Value = self.safe_number(itemList.clone(), Value::Int(6), &[]);
let mut description: Value = self.safe_string(itemList, Value::Int(8), &[]);
if (description != Value::Null) {
let mut parts: Value = split(&description, &Value::Str(" @ ".into()));
let mut first: Value = self.safe_string_lower(parts, Value::Int(0), &[]);
type_var = self.parse_ledger_entry_type(first);
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item);
m.insert("id".to_string(), id.clone());
m.insert("direction".to_string(), Value::Null);
m.insert("account".to_string(), Value::Null);
m.insert("referenceId".to_string(), id);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code);
m.insert("amount".to_string(), amount);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), after);
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currencyResolved]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://docs.bitfinex.com/reference/rest-auth-ledgers
* @param {string} [code] unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined, max is 2500
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest ledger entry
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchLedger".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchLedger".into()), &[code.clone(), since.clone(), limit.clone(), paramsPaginate.clone(), Value::Int(2500)]).await;
}
let mut currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("end".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut response: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
add_element_to_object(&mut requestUntil, &Value::Str("currency".into()), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
let __ws_arg_24 = self.extend(requestUntil.clone(), &[paramsUntil.clone()]);
response = self.private_post_auth_r_ledgers_currency_hist(&[__ws_arg_24]).await;
} else {
let __ws_arg_25 = self.extend(requestUntil, &[paramsUntil]);
response = self.private_post_auth_r_ledgers_hist(&[__ws_arg_25]).await;
}
//
// [
// [
// 2531822314, // ID: Ledger identifier
// "USD", // CURRENCY: The symbol of the currency (ex. "BTC")
// null, // PLACEHOLDER
// 1573521810000, // MTS: Timestamp in milliseconds
// null, // PLACEHOLDER
// 0.01644445, // AMOUNT: Amount of funds moved
// 0, // BALANCE: New balance
// null, // PLACEHOLDER
// "Settlement @ 185.79 on wallet margin" // DESCRIPTION: Description of ledger transaction
// ]
// ]
//
let mut ledgerObjects: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_337: bool = true;
while { if !__for_first_337 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_337 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut item: Value = get_value(&response, &i);
let mut item: Value = get_value(&response, &i);
append_to_array(&mut ledgerObjects, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), item);
m
}));
}
}
return self.parse_ledger(ledgerObjects, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchFundingRates
* @description fetch the current funding rate for multiple symbols
* @see https://docs.bitfinex.com/reference/rest-public-derivatives-status
* @param {string[]} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbols == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRates() requires a symbols argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("keys".to_string(), join(&marketIds, &Value::Str(",".into())));
m
});
let __ws_arg_26 = self.extend(request, &[params]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_26]).await;
return self.parse_funding_rates(response, &[symbols]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://docs.bitfinex.com/reference/rest-public-derivatives-status-history
* @param {string} symbol unified market symbol
* @param {int} [since] timestamp in ms of the earliest funding rate entry
* @param {int} [limit] max number of funding rate entrys to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest funding rate
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone(), Value::Int(5000)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("end".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_27 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_status_deriv_symbol_hist(&[__ws_arg_27]).await;
//
// [
// [
// "tBTCF0:USTF0",
// 1691165059000,
// null,
// 29297.851276225,
// 29277.5,
// null,
// 36950860.76010306,
// null,
// 1691193600000,
// 0.00000527,
// 82,
// null,
// 0.00014548,
// null,
// null,
// 29278.8925,
// null,
// null,
// 9636.07644994,
// null,
// null,
// null,
// 0.0005,
// 0.0025
// ]
// ]
//
let mut rawRatesData: Value = self.to_array(response);
let mut rates: Value = Value::from(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_338: bool = true;
while { if !__for_first_338 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_338 = false; i.as_f64().unwrap_or(f64::NAN) < ((rawRatesData.len() as i64) as f64) } {
let mut fr: Value = rawRatesData.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut rate: Value = self.parse_funding_rate_history(fr, &[market.clone()]);
append_to_array(&mut rates, rate);
}
}
let mut reversedArray: Value = Value::from(vec![]);
let mut rawRates: Value = self.filter_by_symbol_since_limit(rates, &[symbol, since, limit]);
let mut ratesLength: Value = Value::Int(rawRates.len() as i64);
{
let mut i: Value = Value::Int(0);
let mut __for_first_339: bool = true;
while { if !__for_first_339 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_339 = false; i.as_f64().unwrap_or(f64::NAN) < ratesLength.as_f64().unwrap_or(f64::NAN) } {
let mut index: Value = (match (&((match (&(ratesLength), &(i)) { (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 })), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
let mut valueAtIndex: Value = get_value(&rawRates, &index);
let mut valueAtIndex: Value = get_value(&rawRates, &index);
append_to_array(&mut reversedArray, valueAtIndex);
}
}
return reversedArray;
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// "tBTCF0:USTF0",
// 1691165059000,
// null,
// 29297.851276225,
// 29277.5,
// null,
// 36950860.76010306,
// null,
// 1691193600000,
// 0.00000527,
// 82,
// null,
// 0.00014548,
// null,
// null,
// 29278.8925,
// null,
// null,
// 9636.07644994,
// null,
// null,
// null,
// 0.0005,
// 0.0025
// ]
//
let mut marketId: Value = self.safe_string(contract.clone(), Value::Int(0), &[]);
let mut timestamp: Value = self.safe_integer(contract.clone(), Value::Int(1), &[]);
let mut nextFundingTimestamp: Value = self.safe_integer(contract.clone(), Value::Int(8), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market]));
m.insert("markPrice".to_string(), self.safe_number(contract.clone(), Value::Int(15), &[]));
m.insert("indexPrice".to_string(), self.safe_number(contract.clone(), Value::Int(3), &[]));
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("fundingRate".to_string(), self.safe_number(contract.clone(), Value::Int(12), &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), self.safe_number(contract, Value::Int(9), &[]));
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_funding_rate_history(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// 1691165494000,
// null,
// 29278.95838065,
// 29260.5,
// null,
// 36950860.76010305,
// null,
// 1691193600000,
// 0.00001449,
// 222,
// null,
// 0.00014548,
// null,
// null,
// 29260.005,
// null,
// null,
// 9635.86484562,
// null,
// null,
// null,
// 0.0005,
// 0.0025
// ]
//
let mut timestamp: Value = self.safe_integer(contract.clone(), Value::Int(0), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(Value::Null, &[market]));
m.insert("fundingRate".to_string(), self.safe_number(contract, Value::Int(11), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
});
Value::Null
}
/*
* @method
* @name bitfinex#fetchOpenInterests
* @description Retrieves the open interest for a list of symbols
* @see https://docs.bitfinex.com/reference/rest-public-derivatives-status
* @param {string[]} [symbols] a list of unified CCXT market symbols
* @param {object} [params] exchange specific parameters
* @returns {object[]} a list of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interests(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut symbolsNormalized: Value = self.market_symbols(&[symbols]);
let mut marketIds: Value = Value::from(vec![Value::Str("ALL".into())]);
if (symbolsNormalized != Value::Null) {
marketIds = self.market_ids(&[symbolsNormalized.clone()]);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("keys".to_string(), join(&marketIds, &Value::Str(",".into())));
m
});
let __ws_arg_28 = self.extend(request, &[params]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_28]).await;
return self.parse_open_interests(response, &[symbolsNormalized]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchOpenInterest
* @description retrieves the open interest of a contract trading pair
* @see https://docs.bitfinex.com/reference/rest-public-derivatives-status
* @param {string} symbol unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @returns {object} an [open interest structure]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("keys".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_29 = self.extend(request, &[params]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_29]).await;
//
// [
// [
// "tXRPF0:USTF0", // market id
// 1706256986000, // millisecond timestamp
// null,
// 0.512705, // derivative mid price
// 0.512395, // underlying spot mid price
// null,
// 37671483.04, // insurance fund balance
// null,
// 1706284800000, // timestamp of next funding
// 0.00002353, // accrued funding for next period
// 317, // next funding step
// null,
// 0, // current funding
// null,
// null,
// 0.5123016, // mark price
// null,
// null,
// 2233562.03115, // open interest in contracts
// null,
// null,
// null,
// 0.0005, // average spread without funding payment
// 0.0025 // funding payment cap
// ]
// ]
//
let mut oi: Value = self.safe_list(response, Value::Int(0), &[]);
return self.parse_open_interest(oi, &[market]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchOpenInterestHistory
* @description retrieves the open interest history of a currency
* @see https://docs.bitfinex.com/reference/rest-public-derivatives-status-history
* @param {string} symbol unified CCXT market symbol
* @param {string} timeframe the time period of each row of data, not used by bitfinex
* @param {int} [since] the time in ms of the earliest record to retrieve as a unix timestamp
* @param {int} [limit] the number of records in the response
* @param {object} [params] exchange specific parameters
* @param {int} [params.until] the time in ms of the latest record to retrieve as a unix timestamp
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns An array of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("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 paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOpenInterestHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOpenInterestHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone(), Value::Int(5000)]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("end".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_30 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_status_deriv_symbol_hist(&[__ws_arg_30]).await;
return self.parse_open_interests_history(response, &[market, since, limit]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchOpenInterest:
//
// [
// "tXRPF0:USTF0", // market id
// 1706256986000, // millisecond timestamp
// null,
// 0.512705, // derivative mid price
// 0.512395, // underlying spot mid price
// null,
// 37671483.04, // insurance fund balance
// null,
// 1706284800000, // timestamp of next funding
// 0.00002353, // accrued funding for next period
// 317, // next funding step
// null,
// 0, // current funding
// null,
// null,
// 0.5123016, // mark price
// null,
// null,
// 2233562.03115, // open interest in contracts
// null,
// null,
// null,
// 0.0005, // average spread without funding payment
// 0.0025 // funding payment cap
// ]
//
// fetchOpenInterestHistory:
//
// [
// 1706295191000, // timestamp
// null,
// 42152.425382, // derivative mid price
// 42133, // spot mid price
// null,
// 37671589.7853521, // insurance fund balance
// null,
// 1706313600000, // timestamp of next funding
// 0.00018734, // accrued funding for next period
// 3343, // next funding step
// null,
// 0.00007587, // current funding
// null,
// null,
// 42134.1, // mark price
// null,
// null,
// 5775.20348804, // open interest number of contracts
// null,
// null,
// null,
// 0.0005, // average spread without funding payment
// 0.0025 // funding payment cap
// ]
//
let mut interestLength: Value = get_array_length(&interest);
let mut openInterestIndex: Value = (if (is_equal(&interestLength, &Value::Int(23))) { Value::Int(17) } else { Value::Int(18) });
let mut timestamp: Value = self.safe_integer(interest.clone(), Value::Int(1), &[]);
let mut marketId: Value = self.safe_string(interest.clone(), Value::Int(0), &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market.clone(), Value::Null, Value::Str("swap".into())]));
m.insert("openInterestAmount".to_string(), self.safe_number(interest.clone(), openInterestIndex, &[]));
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("info".to_string(), interest);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name bitfinex#fetchLiquidations
* @description retrieves the public liquidations of a trading pair
* @see https://docs.bitfinex.com/reference/rest-public-liquidations
* @param {string} symbol unified CCXT market symbol
* @param {int} [since] the earliest time in ms to fetch liquidations for
* @param {int} [limit] the maximum number of liquidation structures to retrieve
* @param {object} [params] exchange specific parameters
* @param {int} [params.until] timestamp in ms of the latest liquidation
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/?id=liquidation-structure}
*/
pub async fn fetch_liquidations(&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 paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchLiquidations".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchLiquidations".into()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".into()), paramsPaginate.clone(), Value::Int(500)]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), since.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("end".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let __ws_arg_31 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_liquidations_hist(&[__ws_arg_31]).await;
return self.parse_liquidations(self.to_array(response), &[market, since, limit]);
Value::Null
}
pub fn parse_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// [
// "pos",
// 171085137, // position id
// 1706395919788, // timestamp
// null,
// "tAVAXF0:USTF0", // market id
// -8, // amount in contracts
// 32.868, // base price
// null,
// 1,
// 1,
// null,
// 33.255 // acquired price
// ]
// ]
//
let mut entry: Value = self.safe_list(liquidation, Value::Int(0), &[]);
let mut timestamp: Value = self.safe_integer(entry.clone(), Value::Int(2), &[]);
let mut marketId: Value = self.safe_string(entry.clone(), Value::Int(4), &[]);
let mut contracts: Value = crate::precise::Precise::stringAbs(&self.safe_string(entry.clone(), Value::Int(5), &[]));
let mut contractSize: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
let mut baseValue: Value = crate::precise::Precise::stringMul(&contracts, &contractSize);
let mut price: Value = self.safe_string(entry.clone(), Value::Int(11), &[]);
let mut sideFlag: Option<i64> = self.safe_integer(entry.clone(), Value::Int(8), &[]).as_i64();
let mut side: Value = Value::Str("sell".into());
if (sideFlag == Some(1)) {
side = Value::Str("buy".into());
}
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry);
m.insert("symbol".to_string(), self.safe_symbol(marketId, &[market, Value::Null, Value::Str("contract".into())]));
m.insert("contracts".to_string(), self.parse_number(contracts, &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSize, &[]));
m.insert("price".to_string(), self.parse_number(price.clone(), &[]));
m.insert("side".to_string(), side);
m.insert("baseValue".to_string(), self.parse_number(baseValue.clone(), &[]));
m.insert("quoteValue".to_string(), self.parse_number(crate::precise::Precise::stringMul(&baseValue, &price), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m
}), &[]);
Value::Null
}
/*
* @method
* @name bitfinex#setMargin
* @description either adds or reduces margin in a swap position in order to set the margin to a specific value
* @see https://docs.bitfinex.com/reference/rest-auth-deriv-pos-collateral-set
* @param {string} symbol unified market symbol of the market to set margin in
* @param {float} amount the amount to set the margin to
* @param {object} [params] parameters specific to the exchange API endpoint
* @returns {object} A [margin structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#add-margin-structure}
*/
pub async fn set_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" setMargin() only support swap markets".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("collateral".to_string(), self.parse_to_numeric(amount));
m
});
let __ws_arg_32 = self.extend(request, &[params]);
let mut response: Value = self.private_post_auth_w_deriv_collateral_set(&[__ws_arg_32]).await;
//
// [
// [
// 1
// ]
// ]
//
let mut data: Value = self.safe_value(response, Value::Int(0), &[]);
return self.parse_margin_modification(data, &[market]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// setMargin
//
// [
// [
// 1
// ]
// ]
//
let mut marginStatusRaw: Value = data.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut marginStatus: Value = Value::Str("failed".into());
if is_equal(&marginStatusRaw, &Value::Int(1)) {
marginStatus = Value::Str("ok".into());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data);
m.insert("symbol".to_string(), self.safe_string_k(market, "symbol", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".into()));
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("status".to_string(), marginStatus);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bitfinex#fetchOrder
* @description fetches information on an order made by the user
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders
* @see https://docs.bitfinex.com/reference/rest-auth-retrieve-orders-by-symbol
* @param {string} id the order id
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::from(vec![self.parse_to_numeric(id)]));
m
});
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if (symbol == Value::Null) {
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_auth_r_orders(&[__ws_arg_33]).await;
} else {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_34 = self.extend(request, &[params]);
response = self.private_post_auth_r_orders_symbol(&[__ws_arg_34]).await;
}
//
// [
// [
// 139658969116,
// null,
// 1706843908637,
// "tBTCUST",
// 1706843908637,
// 1706843908638,
// 0.0001,
// 0.0001,
// "EXCHANGE LIMIT",
// null,
// null,
// null,
// 0,
// "ACTIVE",
// null,
// null,
// 35000,
// 0,
// 0,
// 0,
// null,
// null,
// null,
// 0,
// 0,
// null,
// null,
// null,
// "API>BFX",
// null,
// null,
// {}
// ]
// ]
//
let mut order: Value = self.safe_list(response, Value::Int(0), &[]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(newOrder, &[market]);
Value::Null
}
/*
* @method
* @name bitfinex#editOrder
* @description edit a trade order
* @see https://docs.bitfinex.com/reference/rest-auth-update-order
* @param {string} id edit order id
* @param {string} symbol unified symbol of the market to edit an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] the price that triggers a trigger order
* @param {boolean} [params.postOnly] set to true if you want to make a post only order
* @param {boolean} [params.reduceOnly] indicates that the order is to reduce the size of a position
* @param {int} [params.flags] additional order parameters: 4096 (Post Only), 1024 (Reduce Only), 16384 (OCO), 64 (Hidden), 512 (Close), 524288 (No Var Rates)
* @param {int} [params.leverage] leverage for a derivative order, supported by derivative symbol orders only, the value should be between 1 and 100 inclusive
* @param {int} [params.clientOrderId] a unique client order id for the order
* @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.parse_to_numeric(id.clone()));
m
});
if (amount != Value::Null) {
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount);
amountString = (if (side.as_str() == Some("buy")) { amountString.clone() } else { crate::precise::Precise::stringNeg(&amountString) });
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("amount".into(), amountString); }
}
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".into()), Value::Str("triggerPrice".into()), &[]);
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut timeInForce: Option<String> = self.safe_string_k(params.clone(), "timeInForce", &[]).as_str().map(str::to_owned);
let mut postOnlyParam: Value = self.safe_bool_k(params.clone(), "postOnly", &[Value::Bool(false)]);
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
let mut clientOrderId: Value = self.safe_integer2(params.clone(), Value::Str("cid".into()), Value::Str("clientOrderId".into()), &[]);
if (trailingAmount != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price_trailing".into(), trailingAmount); }
} else if (triggerPrice != Value::Null) {
// request['price'] is taken as triggerPrice for stop orders
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), triggerPrice.clone())); }
if (type_var.as_str() == Some("limit")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price_aux_limit".into(), self.price_to_precision(symbol.clone(), price.clone())); }
}
}
let mut postOnly: bool = (postOnlyParam.as_bool() == Some(true)) || (timeInForce.as_deref() == Some("PO"));
if (type_var.as_str() != Some("market")) && (triggerPrice == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol, price)); }
}
// flag values may be summed to combine flags
let mut flags: Value = Value::Int(0);
if postOnly {
flags = self.sum(&[flags.clone(), Value::Int(4096)]);
}
if (reduceOnly.as_bool() == Some(true)) {
flags = self.sum(&[flags.clone(), Value::Int(1024)]);
}
if (flags.as_f64() != Some(0.0)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("flags".into(), flags); }
}
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("cid".into(), clientOrderId); }
}
let mut leverage: Value = self.safe_integer2(params.clone(), Value::Str("leverage".into()), Value::Str("lev".into()), &[]);
if (leverage != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("lev".into(), leverage); }
}
let mut paramsOmitted: Value = self.omit(params, Value::from(vec![Value::Str("triggerPrice".into()), Value::Str("stopPrice".into()), Value::Str("timeInForce".into()), Value::Str("postOnly".into()), Value::Str("reduceOnly".into()), Value::Str("trailingAmount".into()), Value::Str("clientOrderId".into()), Value::Str("leverage".into())]), &[]);
let __ws_arg_35 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_post_auth_w_order_update(&[__ws_arg_35]).await;
//
// [
// 1706845376402,
// "ou-req",
// null,
// null,
// [
// 139658969116,
// null,
// 1706843908637,
// "tBTCUST",
// 1706843908637,
// 1706843908638,
// 0.0002,
// 0.0002,
// "EXCHANGE LIMIT",
// null,
// null,
// null,
// 0,
// "ACTIVE",
// null,
// null,
// 35000,
// 0,
// 0,
// 0,
// null,
// null,
// null,
// 0,
// 0,
// null,
// null,
// null,
// "API>BFX",
// null,
// null,
// {}
// ],
// null,
// "SUCCESS",
// "Submitting update to exchange limit buy order for 0.0002 BTC."
// ]
//
let mut status: Value = self.safe_string(response.clone(), Value::Int(6), &[]);
if (status.as_str() != Some("SUCCESS")) {
let mut errorCode: Value = self.safe_string(response.clone(), Value::Int(5), &[]);
let mut errorText: Value = self.safe_string(response.clone(), Value::Int(7), &[]);
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), status).into()), Value::Str(": ".into())).into()), errorText).into()), Value::Str(" (#".into())).into()), errorCode).into()), Value::Str(")".into()))));
}
let mut order: Value = self.safe_list(response, Value::Int(4), &[Value::from(vec![])]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order);
m
});
return self.parse_order(newOrder, &[market]);
Value::Null
}
}