// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
pub struct 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);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for 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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
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.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on BitfinexCore.
BitfinexCore::sign(self, path, &[api.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on 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.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"convert_derivatives_id" => self.convert_derivatives_id(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"create_deposit_address" => self.create_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_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.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_order" => self.fetch_closed_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_liquidations" => self.fetch_liquidations(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_interests" => self.fetch_open_interests(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_order" => self.fetch_open_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_status" => self.fetch_status(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_liquidation" => self.parse_liquidation(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_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.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_time_in_force" => self.parse_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer_status" => self.parse_transfer_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for 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".to_string()));
m.insert("name".to_string(), Value::Str("Bitfinex".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("VG".to_string())]));
m.insert("version".to_string(), Value::Str("v2".to_string()));
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".to_string()));
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".to_string()));
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".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("3h".to_string(), Value::Str("3h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1D".to_string()));
m.insert("1w".to_string(), Value::Str("7D".to_string()));
m.insert("2w".to_string(), Value::Str("14D".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
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".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Str("https://api.bitfinex.com".to_string()));
m.insert("public".to_string(), Value::Str("https://api-pub.bitfinex.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api.bitfinex.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.bitfinex.com".to_string()));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://docs.bitfinex.com/v2/docs/".to_string()), Value::Str("https://github.com/bitfinexcom/bitfinex-api-node".to_string())]));
m.insert("fees".to_string(), Value::Str("https://www.bitfinex.com/fees".to_string()));
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/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/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/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/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/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
}));
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".to_string()));
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".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.002".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("7500000".to_string()), &[]), self.parse_number(Value::Str("0.002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.0018".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000000".to_string()), &[]), self.parse_number(Value::Str("0.0016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000000".to_string()), &[]), self.parse_number(Value::Str("0.0014".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0.0012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])])]));
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.001".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.0008".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.0006".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2500000".to_string()), &[]), self.parse_number(Value::Str("0.0004".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.0002".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("7500000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("15000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("20000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])])]));
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".to_string()));
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".to_string()));
m.insert("EXCHANGE MARKET".to_string(), Value::Str("market".to_string()));
m.insert("LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("EXCHANGE LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("EXCHANGE STOP".to_string(), Value::Str("market".to_string()));
m.insert("EXCHANGE FOK".to_string(), Value::Str("limit".to_string()));
m.insert("EXCHANGE STOP LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("EXCHANGE IOC".to_string(), Value::Str("limit".to_string()));
m
}));
m.insert("orderTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), Value::Str("EXCHANGE MARKET".to_string()));
m.insert("limit".to_string(), Value::Str("EXCHANGE LIMIT".to_string()));
m
}));
m.insert("fiat".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USD".to_string(), Value::Str("USD".to_string()));
m.insert("EUR".to_string(), Value::Str("EUR".to_string()));
m.insert("JPY".to_string(), Value::Str("JPY".to_string()));
m.insert("GBP".to_string(), Value::Str("GBP".to_string()));
m.insert("CHN".to_string(), Value::Str("CHN".to_string()));
m
}));
m.insert("v2AccountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("exchange".to_string()));
m.insert("exchange".to_string(), Value::Str("exchange".to_string()));
m.insert("funding".to_string(), Value::Str("funding".to_string()));
m.insert("margin".to_string(), Value::Str("margin".to_string()));
m.insert("derivatives".to_string(), Value::Str("margin".to_string()));
m.insert("future".to_string(), Value::Str("margin".to_string()));
m.insert("swap".to_string(), Value::Str("margin".to_string()));
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".to_string()));
m.insert("LTC".to_string(), Value::Str("LITECOIN".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETHEREUM".to_string()));
m.insert("OMNI".to_string(), Value::Str("TETHERUSO".to_string()));
m.insert("LIQUID".to_string(), Value::Str("TETHERUSL".to_string()));
m.insert("TRC20".to_string(), Value::Str("TETHERUSX".to_string()));
m.insert("EOS".to_string(), Value::Str("TETHERUSS".to_string()));
m.insert("AVAX".to_string(), Value::Str("TETHERUSDTAVAX".to_string()));
m.insert("SOL".to_string(), Value::Str("TETHERUSDTSOL".to_string()));
m.insert("ALGO".to_string(), Value::Str("TETHERUSDTALG".to_string()));
m.insert("BCH".to_string(), Value::Str("TETHERUSDTBCH".to_string()));
m.insert("KSM".to_string(), Value::Str("TETHERUSDTKSM".to_string()));
m.insert("DVF".to_string(), Value::Str("TETHERUSDTDVF".to_string()));
m.insert("OMG".to_string(), Value::Str("TETHERUSDTOMG".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TETHERUSE".to_string(), Value::Str("ERC20".to_string()));
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".to_string()));
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".to_string()));
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".to_string()).clone());
m.insert("10001".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10020".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10100".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("10114".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("20060".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("temporarily_unavailable".to_string(), Value::Str("ExchangeNotAvailable".to_string()).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".to_string()).clone());
m.insert("not enough exchange balance".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("Order not found".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("symbol: invalid".to_string(), Value::Str("BadSymbol".to_string()).clone());
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("UST".to_string(), Value::Str("USDT".to_string()));
m.insert("EUTF0".to_string(), Value::Str("EURT".to_string()));
m.insert("USTF0".to_string(), Value::Str("USDT".to_string()));
m.insert("ALG".to_string(), Value::Str("ALGO".to_string()));
m.insert("AMP".to_string(), Value::Str("AMPL".to_string()));
m.insert("ATO".to_string(), Value::Str("ATOM".to_string()));
m.insert("BCHABC".to_string(), Value::Str("XEC".to_string()));
m.insert("BCHN".to_string(), Value::Str("BCH".to_string()));
m.insert("DAT".to_string(), Value::Str("DATA".to_string()));
m.insert("DOG".to_string(), Value::Str("MDOGE".to_string()));
m.insert("DSH".to_string(), Value::Str("DASH".to_string()));
m.insert("EDO".to_string(), Value::Str("PNT".to_string()));
m.insert("EUS".to_string(), Value::Str("EURS".to_string()));
m.insert("EUT".to_string(), Value::Str("EURT".to_string()));
m.insert("HTX".to_string(), Value::Str("HT".to_string()));
m.insert("IDX".to_string(), Value::Str("ID".to_string()));
m.insert("IOT".to_string(), Value::Str("IOTA".to_string()));
m.insert("IQX".to_string(), Value::Str("IQ".to_string()));
m.insert("LUNA".to_string(), Value::Str("LUNC".to_string()));
m.insert("LUNA2".to_string(), Value::Str("LUNA".to_string()));
m.insert("MNA".to_string(), Value::Str("MANA".to_string()));
m.insert("ORS".to_string(), Value::Str("ORS Group".to_string()));
m.insert("PAS".to_string(), Value::Str("PASS".to_string()));
m.insert("QSH".to_string(), Value::Str("QASH".to_string()));
m.insert("QTM".to_string(), Value::Str("QTUM".to_string()));
m.insert("RBT".to_string(), Value::Str("RBTC".to_string()));
m.insert("SNG".to_string(), Value::Str("SNGLS".to_string()));
m.insert("STJ".to_string(), Value::Str("STORJ".to_string()));
m.insert("TERRAUST".to_string(), Value::Str("USTC".to_string()));
m.insert("TSD".to_string(), Value::Str("TUSD".to_string()));
m.insert("YGG".to_string(), Value::Str("YEED".to_string()));
m.insert("YYW".to_string(), Value::Str("YOYOW".to_string()));
m.insert("UDC".to_string(), Value::Str("USDC".to_string()));
m.insert("VSY".to_string(), Value::Str("VSYS".to_string()));
m.insert("WAX".to_string(), Value::Str("WAXP".to_string()));
m.insert("XCH".to_string(), Value::Str("XCHF".to_string()));
m.insert("ZBT".to_string(), Value::Str("ZB".to_string()));
m
}));
m
})]);
Value::Null
}
pub fn is_fiat(&self, mut code: Value) -> Value {
return (Value::Bool(in_op(&get_value(&self.options, &Value::Str("fiat".to_string())), &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 is_true(&Value::Bool(in_op(&get_value(&self.options, &Value::Str("currencyNames".to_string())), &code))) {
return get_value(&get_value(&self.options, &Value::Str("currencyNames".to_string())), &code);
}
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &code), &Value::Str(" not supported for withdrawal".to_string()))));
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.
symbol = self.safe_symbol(symbol.clone(), &[]);
let mut market: Value = self.market(symbol.clone());
return self.decimal_to_precision(amount.clone(), Value::Int(crate::runtime::TRUNCATE), get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("amount".to_string())), &[Value::Int(crate::runtime::DECIMAL_PLACES)]);
Value::Null
}
pub fn price_to_precision(&self, mut symbol: Value, mut price: Value) -> Value {
symbol = self.safe_symbol(symbol.clone(), &[]);
let mut market: Value = self.market(symbol.clone());
price = self.decimal_to_precision(price.clone(), Value::Int(crate::runtime::ROUND), get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("price".to_string())), &[self.precisionMode.clone()]);
return self.decimal_to_precision(price.clone(), 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.clone()]).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".to_string()));
m.insert("1".to_string(), Value::Str("ok".to_string()));
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.clone());
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::List(vec![Value::Str("pub:info:pair".to_string()), Value::Str("pub:info:pair:futures".to_string()), Value::Str("pub:list:pair:securities".to_string()), Value::Str("pub:list:pair:margin".to_string())]);
let mut config: Value = join(&labels, &Value::Str(",".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("config".to_string(), config.clone());
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
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::List(vec![])]);
let mut futuresMarketsInfo: Value = self.safe_list(response.clone(), Value::Int(1), &[Value::List(vec![])]);
let mut securitiesMarketsIds: Value = self.safe_list(response.clone(), Value::Int(2), &[Value::List(vec![])]);
let mut marginIds: Value = self.safe_list(response.clone(), Value::Int(3), &[Value::List(vec![])]);
let mut markets: Value = self.array_concat(spotMarketsInfo.clone(), futuresMarketsInfo.clone());
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_313: bool = true;
while { if !__for_first_313 { i = add(&i, &Value::Int(1)); } __for_first_313 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut pairObj: Value = get_value(&markets, &i);
let mut pairObj: Value = get_value(&markets, &i);
let mut id: Value = self.safe_string_upper(pairObj.clone(), Value::Int(0), &[]);
let mut market: Value = self.safe_value(pairObj.clone(), 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 is_greater_than_or_equal(&get_index_of(&id, &Value::Str("F0".to_string())), &Value::Int(0)) {
spot = Value::Bool(false);
type_var = Value::Str("swap".to_string());
} else {
type_var = Value::Str("spot".to_string());
}
let mut swap: Value = Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string())));
let mut baseId: Value = Value::Null;
let mut quoteId: Value = Value::Null;
if is_greater_than_or_equal(&get_index_of(&id, &Value::Str(":".to_string())), &Value::Int(0)) {
let mut parts: Value = split(&id, &Value::Str(":".to_string()));
baseId = get_value(&parts, &Value::Int(0));
quoteId = get_value(&parts, &Value::Int(1));
} else {
baseId = slice(&id, &Value::Int(0), &Value::Int(3));
quoteId = slice(&id, &Value::Int(3), &Value::Int(6));
}
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".to_string()));
let mut splitQuote: Value = split("e, &Value::Str("F0".to_string()));
base = self.safe_string(splitBase.clone(), Value::Int(0), &[]);
quote = self.safe_string(splitQuote.clone(), Value::Int(0), &[]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
// baseId = 'f' + baseId;
// quoteId = 'f' + quoteId;
let mut settle: Value = Value::Null;
let mut settleId: Value = Value::Null;
if is_true(&swap) {
settle = quote.clone();
settleId = quote.clone();
symbol = add(&add(&symbol, &Value::Str(":".to_string())), &settle);
}
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(), add(&Value::Str("t".to_string()), &id));
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), spot.clone());
m.insert("tradfi".to_string(), self.in_array(id.clone(), securitiesMarketsIds.clone()));
m.insert("margin".to_string(), Value::Bool((is_true(&spot) && is_true(&self.in_array(id.clone(), marginIds.clone())))));
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(!is_true(&spot)));
m.insert("linear".to_string(), ternary(is_true(&swap), Value::Bool(true), Value::Null));
m.insert("inverse".to_string(), ternary(is_true(&swap), Value::Bool(false), Value::Null));
m.insert("contractSize".to_string(), ternary(is_true(&swap), self.parse_number(Value::Str("1".to_string()), &[]), Value::Null));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), crate::runtime::parse_int(&Value::Str("8".to_string())));
m.insert("price".to_string(), crate::runtime::parse_int(&Value::Str("5".to_string())));
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.clone(), &[]));
m.insert("max".to_string(), self.parse_number(maxOrderSizeString.clone(), &[]));
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".to_string()), &[]));
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.clone());
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::List(vec![Value::Str("pub:list:currency".to_string()), Value::Str("pub:map:currency:sym".to_string()), Value::Str("pub:map:currency:label".to_string()), Value::Str("pub:map:currency:unit".to_string()), Value::Str("pub:map:currency:undl".to_string()), Value::Str("pub:map:currency:pool".to_string()), Value::Str("pub:map:currency:explorer".to_string()), Value::Str("pub:map:currency:tx:fee".to_string()), Value::Str("pub:map:tx:method".to_string()), Value::Str("pub:info:tx:status".to_string()), Value::Str("pub:list:currency:margin".to_string())]);
let mut config: Value = join(&labels, &Value::Str(",".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("config".to_string(), config.clone());
m
});
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
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::List(vec![])]), Value::Int(0)));
m.insert("label".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(2), &[Value::List(vec![])]), Value::Int(0)));
m.insert("unit".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(3), &[Value::List(vec![])]), Value::Int(0)));
m.insert("undl".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(4), &[Value::List(vec![])]), Value::Int(0)));
m.insert("pool".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(5), &[Value::List(vec![])]), Value::Int(0)));
m.insert("explorer".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(6), &[Value::List(vec![])]), Value::Int(0)));
m.insert("fees".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(7), &[Value::List(vec![])]), Value::Int(0)));
m.insert("networks".to_string(), self.safe_list(response.clone(), Value::Int(8), &[Value::List(vec![])]));
m.insert("statuses".to_string(), self.index_by(self.safe_list(response.clone(), Value::Int(9), &[Value::List(vec![])]), Value::Int(0)));
m.insert("marginables".to_string(), self.safe_list(response.clone(), Value::Int(10), &[Value::List(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_314: bool = true;
while { if !__for_first_314 { i = add(&i, &Value::Int(1)); } __for_first_314 = false; is_less_than(&i, &get_array_length(&get_value(&indexed, &Value::Str("networks".to_string())))) } {
let mut networkObj: Value = get_value(&get_value(&indexed, &Value::Str("networks".to_string())), &i);
let mut networkId: Value = self.safe_string(networkObj.clone(), Value::Int(0), &[]);
let mut valuesList: Value = self.safe_list(networkObj.clone(), Value::Int(1), &[]);
let mut networkName: Value = self.safe_string(valuesList.clone(), Value::Int(0), &[]);
// for GOlang transpiler, do with "safe" method
let mut networksList: Value = self.safe_list(indexedNetworks.clone(), networkName.clone(), &[Value::List(vec![])]);
append_to_array(&mut networksList, networkId.clone());
add_element_to_object(&mut indexedNetworks, &networkName, networksList.clone());
}
}
let mut ids: Value = self.safe_list(response.clone(), Value::Int(0), &[Value::List(vec![])]);
return self.parse_currencies_custom(ids.clone(), indexed.clone(), indexedNetworks.clone());
Value::Null
}
pub fn parse_currencies_custom(&self, mut ids: Value, mut indexed: Value, mut indexedNetworks: Value) -> Value {
let mut allowedIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_315: bool = true;
while { if !__for_first_315 { i = add(&i, &Value::Int(1)); } __for_first_315 = false; is_less_than(&i, &get_array_length(&ids)) } {
let mut id: Value = get_value(&ids, &i);
let mut id: Value = get_value(&ids, &i);
if is_true(&Value::Bool(ends_with(&id, &Value::Str("F0".to_string())))) {
continue;
}
append_to_array(&mut allowedIds, id.clone());
}
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut arr: Value = self.to_array(allowedIds.clone());
{
let mut i: Value = Value::Int(0);
let mut __for_first_316: bool = true;
while { if !__for_first_316 { i = add(&i, &Value::Int(1)); } __for_first_316 = false; is_less_than(&i, &get_array_length(&arr)) } {
let mut parsed: Value = self.parse_currency_custom(get_value(&arr, &i), indexed.clone(), indexedNetworks.clone());
let mut code: Value = get_value(&parsed, &Value::Str("code".to_string()));
add_element_to_object(&mut result, &code, parsed.clone());
}
}
return result;
Value::Null
}
pub fn parse_currency_custom(&self, mut id: Value, mut indexed: Value, mut indexedNetworks: Value) -> Value {
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut label: Value = self.safe_list(get_value(&indexed, &Value::Str("label".to_string())), id.clone(), &[Value::List(vec![])]);
let mut name: Value = self.safe_string(label.clone(), Value::Int(1), &[]);
let mut pool: Value = self.safe_list(get_value(&indexed, &Value::Str("pool".to_string())), id.clone(), &[Value::List(vec![])]);
let mut rawType: Value = self.safe_string(pool.clone(), Value::Int(1), &[]);
let mut isCryptoCoin: bool = is_true(&(!is_equal(&rawType, &Value::Null))) || is_true(&(Value::Bool(in_op(&get_value(&indexed, &Value::Str("explorer".to_string())), &id)))); // "hacky" solution
let mut type_var: Value = ternary(is_true(&isCryptoCoin), Value::Str("crypto".to_string()), Value::Null);
let mut feeValues: Value = self.safe_list(get_value(&indexed, &Value::Str("fees".to_string())), id.clone(), &[Value::List(vec![])]);
let mut fees: Value = self.safe_list(feeValues.clone(), Value::Int(1), &[Value::List(vec![])]);
let mut fee: Value = self.safe_number(fees.clone(), Value::Int(1), &[]);
let mut undl: Value = self.safe_list(get_value(&indexed, &Value::Str("undl".to_string())), id.clone(), &[Value::List(vec![])]);
let mut defaultCurrencyPrecision: Value = self.safe_string_k(self.options.clone(), "defaultCurrencyPrecision", &[Value::Str("8".to_string())]); // 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".to_string()), Value::Str("defaultPrecision".to_string()), &[defaultCurrencyPrecision.clone()]));
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut networkIds: Value = self.safe_list(indexedNetworks.clone(), id.clone(), &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_317: bool = true;
while { if !__for_first_317 { j = add(&j, &Value::Int(1)); } __for_first_317 = false; is_less_than(&j, &get_array_length(&networkIds)) } {
// 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 is_equal(&networkId, &Value::Null) {
continue;
}
let mut network: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
let mut dwStatuses: Value = self.safe_list(get_value(&indexed, &Value::Str("statuses".to_string())), networkId.clone(), &[Value::List(vec![])]);
if !is_equal(&network, &Value::Null) {
add_element_to_object(&mut networks, &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.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool(is_equal(&self.safe_integer(dwStatuses.clone(), Value::Int(1), &[]), &Value::Int(1))));
m.insert("withdraw".to_string(), Value::Bool(is_equal(&self.safe_integer(dwStatuses.clone(), Value::Int(2), &[]), &Value::Int(1))));
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.clone());
m.insert("info".to_string(), Value::List(vec![id.clone(), label.clone(), pool.clone(), feeValues.clone(), undl.clone()]));
m.insert("type".to_string(), type_var.clone());
m.insert("name".to_string(), name.clone());
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.clone(), &[]));
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.clone());
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), networks.clone());
m.insert("margin".to_string(), self.in_array(id.clone(), get_value(&indexed, &Value::Str("marginables".to_string()))));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountsByType: Value = self.safe_value_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".to_string())]);
let mut accountType: Value = self.safe_string(accountsByType.clone(), requestedType.clone(), &[requestedType.clone()]);
if is_equal(&accountType, &Value::Null) {
let mut keys: Value = object_keys(&accountsByType);
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" fetchBalance() type parameter must be one of ".to_string())), &join(&keys, &Value::Str(", ".to_string())))));
}
let mut isDerivative: bool = is_equal(&requestedType, &Value::Str("derivatives".to_string()));
let mut query: Value = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
let mut response: Value = self.private_post_auth_r_wallets(&[query.clone()]).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.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_318: bool = true;
while { if !__for_first_318 { i = add(&i, &Value::Int(1)); } __for_first_318 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut balance: Value = get_value(&balances, &i);
let mut balance: Value = get_value(&balances, &i);
let mut account: Value = self.account();
let mut interest: Value = self.safe_string(balance.clone(), Value::Int(3), &[]);
if !is_equal(&interest, &Value::Str("0".to_string())) {
add_element_to_object(&mut account, &Value::Str("debt".to_string()), interest.clone());
}
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("".to_string())]);
let mut start: Value = subtract(&get_array_length(¤cyId), &Value::Int(2));
let mut isDerivativeCode: bool = is_equal(&slice(¤cyId, &start, &Value::Null), &Value::Str("f0".to_string()));
// this will only filter the derivative codes if the requestedType is 'derivatives'
let mut derivativeCondition: bool = !is_true(&isDerivative) || is_true(&isDerivativeCode);
if is_true(&(is_equal(&accountType, &type_var))) && is_true(&derivativeCondition) {
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string(balance.clone(), Value::Int(2), &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string(balance.clone(), Value::Int(4), &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountsByType: Value = self.safe_value_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 is_equal(&fromId, &Value::Null) {
let mut keys: Value = object_keys(&accountsByType);
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&self.id, &Value::Str(" transfer() fromAccount must be one of ".to_string())), &join(&keys, &Value::Str(", ".to_string())))));
}
let mut toId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[]);
if is_equal(&toId, &Value::Null) {
let mut keys: Value = object_keys(&accountsByType);
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&self.id, &Value::Str(" transfer() toAccount must be one of ".to_string())), &join(&keys, &Value::Str(", ".to_string())))));
}
let mut currency: Value = self.currency(code.clone());
let mut fromCurrencyId: Value = self.convert_derivatives_id(currency.clone(), fromAccount.clone());
let mut toCurrencyId: Value = self.convert_derivatives_id(currency.clone(), toAccount.clone());
let mut requestedAmount: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
// 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.clone());
m.insert("currency".to_string(), fromCurrencyId.clone());
m.insert("currency_to".to_string(), toCurrencyId.clone());
m.insert("from".to_string(), fromId.clone());
m.insert("to".to_string(), toId.clone());
m
});
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
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: Value = self.safe_string(response.clone(), Value::Int(0), &[]);
if is_equal(&error, &Value::Str("error".to_string())) {
let mut message: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".to_string())]);
// same message as in v1
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), add(&add(&self.id, &Value::Str(" ".to_string())), &message));
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" ".to_string())), &message)));
}
return self.parse_transfer(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), response.clone());
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// transfer
//
// [
// 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 = self.safe_list_k(transfer.clone(), "result", &[]);
let mut timestamp: Value = self.safe_integer(result.clone(), Value::Int(0), &[]);
let mut info: Value = self.safe_value(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.clone()));
m.insert("status".to_string(), self.parse_transfer_status(status.clone()));
m.insert("amount".to_string(), self.safe_number(info.clone(), Value::Int(7), &[]));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("fromAccount".to_string(), fromAccount.clone());
m.insert("toAccount".to_string(), toAccount.clone());
m.insert("info".to_string(), result.clone());
m
});
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SUCCESS".to_string(), Value::Str("ok".to_string()));
m.insert("ERROR".to_string(), Value::Str("failed".to_string()));
m.insert("FAILURE".to_string(), Value::Str("failed".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn convert_derivatives_id(&self, mut currency: Value, mut type_var: Value) -> Value {
// 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 = self.safe_value_k(currency.clone(), "info", &[]);
let mut transferId: Value = self.safe_string(info.clone(), Value::Int(0), &[]);
let mut underlying: Value = self.safe_value(info.clone(), Value::Int(4), &[Value::List(vec![])]);
let mut currencyId: Value = Value::Null;
if is_equal(&type_var, &Value::Str("derivatives".to_string())) {
currencyId = self.safe_string(underlying.clone(), Value::Int(0), &[transferId.clone()]);
let mut start: Value = subtract(&get_array_length(¤cyId), &Value::Int(2));
let mut isDerivativeCode: bool = is_equal(&slice(¤cyId, &start, &Value::Null), &Value::Str("F0".to_string()));
if !is_true(&isDerivativeCode) {
currencyId = add(¤cyId, &Value::Str("F0".to_string()));
}
} else if !is_equal(&type_var, &Value::Str("margin".to_string())) {
currencyId = self.safe_string(underlying.clone(), Value::Int(1), &[transferId.clone()]);
} else {
currencyId = transferId.clone();
}
return currencyId;
Value::Null
}
/*
* @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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut precision: Value = self.handle_option(Value::Str("fetchOrderBook".to_string()), Value::Str("precision".to_string()), &[Value::Str("R0".to_string())]);
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("precision".to_string(), precision.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("len".to_string()), limit.clone());
}
let mut fullRequest: Value = self.extend(request.clone(), &[params.clone()]);
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(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("bids".to_string(), Value::List(vec![]));
m.insert("asks".to_string(), Value::List(vec![]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("nonce".to_string(), Value::Null);
m
});
let mut priceIndex: Value = ternary(is_true(&(is_equal(&get_value(&fullRequest, &Value::Str("precision".to_string())), &Value::Str("R0".to_string())))), Value::Int(1), Value::Int(0));
let mut orders: Value = self.to_array(orderbook.clone());
{
let mut i: Value = Value::Int(0);
let mut __for_first_319: bool = true;
while { if !__for_first_319 { i = add(&i, &Value::Int(1)); } __for_first_319 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = get_value(&orders, &i);
let mut order: Value = get_value(&orders, &i);
let mut price: Value = self.safe_number(order.clone(), priceIndex.clone(), &[]);
let mut signedAmount: Value = self.safe_string(order.clone(), Value::Int(2), &[]);
let mut amount: Value = crate::precise::Precise::stringAbs(&signedAmount);
let mut side: Value = ternary(is_true(&crate::precise::Precise::stringGt(&signedAmount, &Value::Str("0".to_string()))), Value::Str("bids".to_string()), Value::Str("asks".to_string()));
crate::runtime::append_to_object_array(&mut result, &side, Value::List(vec![price.clone(), self.parse_number(amount.clone(), &[])]));
}
}
{ let __be_tmp = self.sort_by(get_value(&result, &Value::Str("bids".to_string())), Value::Int(0), &[Value::Bool(true)]); add_element_to_object(&mut result, &Value::Str("bids".to_string()), __be_tmp); };
{ let __be_tmp = self.sort_by(get_value(&result, &Value::Str("asks".to_string())), Value::Int(0), &[]); add_element_to_object(&mut result, &Value::Str("asks".to_string()), __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: Value = get_array_length(&ticker);
let mut firstValue: Value = self.safe_number(ticker.clone(), Value::Int(0), &[]);
let mut isFetchTicker: bool = !is_equal(&firstValue, &Value::Null); // if it's Nan, then it's string (symbol)
let mut symbol: Value = Value::Null;
let mut minusIndex: Value = Value::Int(0);
if is_true(&isFetchTicker) {
minusIndex = Value::Int(1);
} else {
let mut marketId: Value = self.safe_string(ticker.clone(), Value::Int(0), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
}
let mut isFundingCurrency: bool = is_greater_than_or_equal(&length, &Value::Int(17));
symbol = self.safe_symbol(Value::Null, &[market.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 is_true(&isFundingCurrency) {
// per api docs, they are different array type
last = self.safe_string(ticker.clone(), subtract(&Value::Int(10), &minusIndex), &[]);
bid = self.safe_string(ticker.clone(), subtract(&Value::Int(2), &minusIndex), &[]);
ask = self.safe_string(ticker.clone(), subtract(&Value::Int(5), &minusIndex), &[]);
change = self.safe_string(ticker.clone(), subtract(&Value::Int(8), &minusIndex), &[]);
percentage = self.safe_string(ticker.clone(), subtract(&Value::Int(9), &minusIndex), &[]);
volume = self.safe_string(ticker.clone(), subtract(&Value::Int(11), &minusIndex), &[]);
high = self.safe_string(ticker.clone(), subtract(&Value::Int(12), &minusIndex), &[]);
low = self.safe_string(ticker.clone(), subtract(&Value::Int(13), &minusIndex), &[]);
} else {
// on trading pairs (ex. tBTCUSD or tHMSTR:USD)
last = self.safe_string(ticker.clone(), subtract(&Value::Int(7), &minusIndex), &[]);
bid = self.safe_string(ticker.clone(), subtract(&Value::Int(1), &minusIndex), &[]);
ask = self.safe_string(ticker.clone(), subtract(&Value::Int(3), &minusIndex), &[]);
change = self.safe_string(ticker.clone(), subtract(&Value::Int(5), &minusIndex), &[]);
percentage = self.safe_string(ticker.clone(), subtract(&Value::Int(6), &minusIndex), &[]);
percentage = crate::precise::Precise::stringMul(&percentage, &Value::Str("100".to_string()));
volume = self.safe_string(ticker.clone(), subtract(&Value::Int(8), &minusIndex), &[]);
high = self.safe_string(ticker.clone(), subtract(&Value::Int(9), &minusIndex), &[]);
low = self.safe_string(ticker.clone(), subtract(&Value::Int(10), &minusIndex), &[]);
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("high".to_string(), high.clone());
m.insert("low".to_string(), low.clone());
m.insert("bid".to_string(), bid.clone());
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), ask.clone());
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.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), change.clone());
m.insert("percentage".to_string(), percentage.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), volume.clone());
m.insert("quoteVolume".to_string(), Value::Null);
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut ids: Value = self.market_ids(&[symbols.clone()]);
add_element_to_object(&mut request, &Value::Str("symbols".to_string()), join(&ids, &Value::Str(",".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("symbols".to_string()), Value::Str("ALL".to_string()));
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut tickers: Value = self.public_get_tickers(&[__ws_arg_3]).await;
return self.parse_tickers(tickers.clone(), &[symbols.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut ticker: Value = self.public_get_ticker_symbol(&[__ws_arg_4]).await;
return self.parse_ticker(ticker.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// 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 = self.safe_list_k(trade.clone(), "result", &[Value::List(vec![])]);
let mut tradeLength: Value = get_array_length(&tradeList);
let mut isPrivate: bool = is_greater_than(&tradeLength, &Value::Int(5));
let mut id: Value = self.safe_string(tradeList.clone(), Value::Int(0), &[]);
let mut amountIndex: Value = ternary(is_true(&isPrivate), Value::Int(4), Value::Int(2));
let mut side: Value = Value::Null;
let mut amountString: Value = self.safe_string(tradeList.clone(), amountIndex.clone(), &[]);
let mut priceIndex: Value = ternary(is_true(&isPrivate), Value::Int(5), Value::Int(3));
let mut priceString: Value = self.safe_string(tradeList.clone(), priceIndex.clone(), &[]);
if is_equal(&get_value(&amountString, &Value::Int(0)), &Value::Str("-".to_string())) {
side = Value::Str("sell".to_string());
amountString = crate::precise::Precise::stringAbs(&amountString);
} else {
side = Value::Str("buy".to_string());
}
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 = ternary(is_true(&isPrivate), Value::Int(2), Value::Int(1));
let mut timestamp: Value = self.safe_integer(tradeList.clone(), timestampIndex.clone(), &[]);
if is_true(&isPrivate) {
let mut marketId: Value = get_value(&tradeList, &Value::Int(1));
symbol = self.safe_symbol(marketId.clone(), &[]);
orderId = self.safe_string(tradeList.clone(), Value::Int(3), &[]);
let mut maker: Value = self.safe_integer(tradeList.clone(), Value::Int(8), &[]);
takerOrMaker = ternary(is_true(&(is_equal(&maker, &Value::Int(1)))), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
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.clone(), &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString.clone());
m.insert("currency".to_string(), feeCurrency.clone());
m
});
let mut orderType: Value = get_value(&tradeList, &Value::Int(6));
type_var = self.safe_string(get_value(&self.options, &Value::Str("exchangeTypes".to_string())), orderType.clone(), &[]);
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("order".to_string(), orderId.clone());
m.insert("side".to_string(), side.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m.insert("info".to_string(), tradeList.clone());
m
}), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Int(10000)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut sort: Value = Value::Str("-1".to_string());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
sort = Value::Str("1".to_string());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(10000))); // default 120, max 10000
}
add_element_to_object(&mut request, &Value::Str("sort".to_string()), sort.clone());
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
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.clone());
let mut trades: Value = self.sort_by(rawTrades.clone(), Value::Int(1), &[]);
let mut tradesList: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_320: bool = true;
while { if !__for_first_320 { i = add(&i, &Value::Int(1)); } __for_first_320 = false; is_less_than(&i, &get_array_length(&trades)) } {
append_to_array(&mut tradesList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&trades, &i));
m
})); // convert to array of dicts to match parseOrder signature
}
}
return self.parse_trades(tradesList.clone(), &[market.clone(), Value::Null, limit.clone()]);
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".to_string()));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(10000)]).await;
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&limit, &Value::Null) {
limit = Value::Int(10000);
} else {
limit = 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(), get_value(&market, &Value::Str("id".to_string())));
m.insert("timeframe".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m.insert("limit".to_string(), limit.clone());
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
add_element_to_object(&mut request, &Value::Str("sort".to_string()), Value::Int(1));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
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.clone()), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_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.clone(), Value::Int(5), &[])]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
if is_equal(&status, &Value::Null) {
return status;
}
let mut parts: Value = split(&status, &Value::Str(" ".to_string()));
let mut state: Value = self.safe_string(parts.clone(), Value::Int(0), &[]);
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ACTIVE".to_string(), Value::Str("open".to_string()));
m.insert("PARTIALLY".to_string(), Value::Str("open".to_string()));
m.insert("EXECUTED".to_string(), Value::Str("closed".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("INSUFFICIENT".to_string(), Value::Str("canceled".to_string()));
m.insert("POSTONLY CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("RSN_DUST".to_string(), Value::Str("rejected".to_string()));
m.insert("RSN_PAUSE".to_string(), Value::Str("rejected".to_string()));
m.insert("IOC CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("FILLORKILL CANCELED".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), state.clone(), &[status.clone()]);
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::List(vec![Value::Str("reduceOnly".to_string())]));
m.insert("4096".to_string(), Value::List(vec![Value::Str("postOnly".to_string())]));
m.insert("5120".to_string(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("postOnly".to_string())]));
m
});
return self.safe_value(flagValues.clone(), flags.clone(), &[Value::Null]);
Value::Null
}
pub fn parse_time_in_force(&self, mut orderType: Value) -> Value {
let mut orderTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("EXCHANGE IOC".to_string(), Value::Str("IOC".to_string()));
m.insert("EXCHANGE FOK".to_string(), Value::Str("FOK".to_string()));
m.insert("IOC".to_string(), Value::Str("IOC".to_string()));
m.insert("FOK".to_string(), Value::Str("FOK".to_string()));
m
});
return self.safe_string(orderTypes.clone(), orderType.clone(), &[Value::Str("GTC".to_string())]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut orderList: Value = self.safe_list_k(order.clone(), "result", &[]);
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.clone(), &[]);
// 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 = ternary(is_true(&crate::precise::Precise::stringLt(&signedAmount, &Value::Str("0".to_string()))), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
let mut orderType: Value = self.safe_string(orderList.clone(), Value::Int(8), &[]);
let mut type_var: Value = self.safe_string(self.safe_value_k(self.options.clone(), "exchangeTypes", &[]), orderType.clone(), &[]);
let mut timeInForce: Value = self.parse_time_in_force(orderType.clone());
let mut rawFlags: Value = self.safe_string(orderList.clone(), Value::Int(12), &[]);
let mut flags: Value = self.parse_order_flags(rawFlags.clone());
let mut postOnly: Value = Value::Bool(false);
if !is_equal(&flags, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_321: bool = true;
while { if !__for_first_321 { i = add(&i, &Value::Int(1)); } __for_first_321 = false; is_less_than(&i, &get_array_length(&flags)) } {
if is_equal(&get_value(&flags, &i), &Value::Str("postOnly".to_string())) {
postOnly = Value::Bool(true);
}
}
}
}
let mut price: Value = self.safe_string(orderList.clone(), Value::Int(16), &[]);
let mut triggerPrice: Value = Value::Null;
if is_true(&(is_equal(&orderType, &Value::Str("EXCHANGE STOP".to_string())))) || is_true(&(is_equal(&orderType, &Value::Str("EXCHANGE STOP LIMIT".to_string())))) {
price = Value::Null;
triggerPrice = self.safe_string(orderList.clone(), Value::Int(16), &[]);
if is_equal(&orderType, &Value::Str("EXCHANGE STOP LIMIT".to_string())) {
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 !is_equal(&statusString, &Value::Null) {
let mut parts: Value = split(&statusString, &Value::Str(" @ ".to_string()));
status = self.parse_order_status(self.safe_string(parts.clone(), 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.clone());
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("postOnly".to_string(), postOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), average.clone());
m.insert("filled".to_string(), Value::Null);
m.insert("remaining".to_string(), remaining.clone());
m.insert("status".to_string(), status.clone());
m.insert("fee".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
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 is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
/*
* @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.clone());
amountString = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), amountString.clone(), crate::precise::Precise::stringNeg(&amountString));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("amount".to_string(), amountString.clone());
m
});
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut timeInForce: Value = self.safe_string_k(params.clone(), "timeInForce", &[]);
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".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut orderType: Value = to_upper(&type_var);
if !is_equal(&trailingAmount, &Value::Null) {
orderType = Value::Str("TRAILING STOP".to_string());
add_element_to_object(&mut request, &Value::Str("price_trailing".to_string()), trailingAmount.clone());
} else if !is_equal(&triggerPrice, &Value::Null) {
// request['price'] is taken as triggerPrice for stop orders
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
if is_equal(&type_var, &Value::Str("limit".to_string())) {
orderType = Value::Str("STOP LIMIT".to_string());
add_element_to_object(&mut request, &Value::Str("price_aux_limit".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
} else {
orderType = Value::Str("STOP".to_string());
}
}
let mut ioc: bool = is_equal(&timeInForce, &Value::Str("IOC".to_string()));
let mut fok: bool = is_equal(&timeInForce, &Value::Str("FOK".to_string()));
let mut postOnly: bool = is_true(&(is_equal(&postOnlyParam, &Value::Bool(true)))) || is_true(&(is_equal(&timeInForce, &Value::Str("PO".to_string()))));
if is_true(&(is_true(&ioc) || is_true(&fok))) && is_true(&(is_equal(&price, &Value::Null))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires a price argument with IOC and FOK orders".to_string()))));
}
if is_true(&(is_true(&ioc) || is_true(&fok))) && is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() does not allow market IOC and FOK orders".to_string()))));
}
if is_true(&(!is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_equal(&triggerPrice, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
if is_true(&ioc) {
orderType = Value::Str("IOC".to_string());
} else if is_true(&fok) {
orderType = Value::Str("FOK".to_string());
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("createOrder".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&(is_equal(&marginMode, &Value::Null))) {
// The EXCHANGE prefix is only required for non margin spot markets
orderType = add(&Value::Str("EXCHANGE ".to_string()), &orderType);
}
add_element_to_object(&mut request, &Value::Str("type".to_string()), orderType.clone());
// flag values may be summed to combine flags
let mut flags: Value = Value::Int(0);
if is_true(&postOnly) {
flags = self.sum(&[flags.clone(), Value::Int(4096)]);
}
if is_equal(&reduceOnly, &Value::Bool(true)) {
flags = self.sum(&[flags.clone(), Value::Int(1024)]);
}
if !is_equal(&flags, &Value::Int(0)) {
add_element_to_object(&mut request, &Value::Str("flags".to_string()), flags.clone());
}
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cid".to_string()), clientOrderId.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("timeInForce".to_string()), Value::Str("postOnly".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = self.private_post_auth_w_order_submit(&[request.clone()]).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 !is_equal(&status, &Value::Str("SUCCESS".to_string())) {
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(add(&add(&add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &status), &Value::Str(": ".to_string())), &errorText), &Value::Str(" (#".to_string())), &errorCode), &Value::Str(")".to_string()))));
}
let mut orders: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::List(vec![])]);
let mut order: Value = self.safe_list(orders.clone(), Value::Int(0), &[]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order.clone());
m
});
return self.parse_order(newOrder.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_322: bool = true;
while { if !__for_first_322 { i = add(&i, &Value::Int(1)); } __for_first_322 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut symbol: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
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.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, Value::List(vec![Value::Str("on".to_string()), orderRequest.clone()]));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ops".to_string(), ordersRequests.clone());
m
});
let mut response: Value = self.private_post_auth_w_order_multi(&[request.clone()]).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::List(vec![]);
let mut data: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_323: bool = true;
while { if !__for_first_323 { i = add(&i, &Value::Int(1)); } __for_first_323 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
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.clone(), &[]);
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 is_equal(&self.markets, &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.clone(), &[params.clone()]);
let mut response: Value = self.private_post_auth_w_order_cancel_multi(&[__ws_arg_7]).await;
let mut orders: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::List(vec![])]);
let mut ordersList: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_324: bool = true;
while { if !__for_first_324 { i = add(&i, &Value::Int(1)); } __for_first_324 = false; is_less_than(&i, &get_array_length(&orders)) } {
append_to_array(&mut ordersList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&orders, &i));
m
}));
}
}
return self.parse_orders(ordersList.clone(), &[]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut cid: Value = self.safe_value2(params.clone(), Value::Str("cid".to_string()), Value::Str("clientOrderId".to_string()), &[]); // client order id
let mut request: Value = Value::Null;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
if !is_equal(&cid, &Value::Null) {
let mut cidDate: Value = self.safe_value_k(params.clone(), "cidDate", &[]); // client order id date
if is_equal(&cidDate, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" canceling an order by clientOrderId ('cid') requires both 'cid' and 'cid_date' ('YYYY-MM-DD')".to_string()))));
}
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cid".to_string(), cid.clone());
m.insert("cid_date".to_string(), cidDate.clone());
m
});
params = self.omit(params.clone(), Value::List(vec![Value::Str("cid".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
} else {
request = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), crate::runtime::parse_int(&id));
m
});
}
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_auth_w_order_cancel(&[__ws_arg_8]).await;
let mut order: Value = self.safe_value(response.clone(), Value::Int(4), &[]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order.clone());
m
});
return self.parse_order(newOrder.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut numericIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_325: bool = true;
while { if !__for_first_325 { i = add(&i, &Value::Int(1)); } __for_first_325 = false; is_less_than(&i, &get_array_length(&ids)) } {
// numericIds[i] = this.parseToNumeric (ids[i]);
append_to_array(&mut numericIds, self.parse_to_numeric(get_value(&ids, &i)));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), numericIds.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
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.clone(), Value::Int(4), &[Value::List(vec![])]);
let mut ordersList: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_326: bool = true;
while { if !__for_first_326 { i = add(&i, &Value::Int(1)); } __for_first_326 = false; is_less_than(&i, &get_array_length(&orders)) } {
append_to_array(&mut ordersList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&orders, &i));
m
}));
}
}
return self.parse_orders(ordersList.clone(), &[market.clone()]);
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::List(vec![crate::runtime::parse_int(&id)]));
m
});
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut orders: Value = self.fetch_open_orders(&[symbol.clone(), Value::Null, Value::Null, __ws_arg_10]).await;
let mut order: Value = self.safe_value(orders.clone(), Value::Int(0), &[]);
if is_equal(&order, &Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&add(&self.id, &Value::Str(" order ".to_string())), &id), &Value::Str(" not found".to_string()))));
}
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::List(vec![crate::runtime::parse_int(&id)]));
m
});
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut orders: Value = self.fetch_closed_orders(&[symbol.clone(), Value::Null, Value::Null, __ws_arg_11]).await;
let mut order: Value = self.safe_value(orders.clone(), Value::Int(0), &[]);
if is_equal(&order, &Value::Null) {
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&add(&self.id, &Value::Str(" order ".to_string())), &id), &Value::Str(" not found".to_string()))));
}
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if is_equal(&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.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_327: bool = true;
while { if !__for_first_327 { i = add(&i, &Value::Int(1)); } __for_first_327 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchClosedOrders".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchClosedOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 25, max 2500
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if is_equal(&symbol, &Value::Null) {
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_auth_r_orders_hist(&[__ws_arg_14]).await;
} else {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_328: bool = true;
while { if !__for_first_328 { i = add(&i, &Value::Int(1)); } __for_first_328 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrderTrades() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut orderId: Value = crate::runtime::parse_int(&id);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
// valid for trades up to 10 days old
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
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.clone());
let mut tradesList: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_329: bool = true;
while { if !__for_first_329 { i = add(&i, &Value::Int(1)); } __for_first_329 = false; is_less_than(&i, &get_array_length(&rawTrades)) } {
append_to_array(&mut tradesList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&rawTrades, &i));
m
})); // convert to array of dicts to match parseOrder signature
}
}
return self.parse_trades(tradesList.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &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 !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 25, max 1000
}
let mut response: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __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.clone(), &[params.clone()]);
response = self.private_post_auth_r_trades_hist(&[__ws_arg_18]).await;
}
let mut tradesList: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_330: bool = true;
while { if !__for_first_330 { i = add(&i, &Value::Int(1)); } __for_first_330 = false; is_less_than(&i, &get_array_length(&response)) } {
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.clone(), &[market.clone(), since.clone(), limit.clone()]);
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 is_equal(&self.markets, &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.clone(), &[params.clone()]);
return self.fetch_deposit_address(code.clone(), &[__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 is_equal(&self.markets, &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_value_k(currency.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyNetwork: Value = self.safe_value(currencyNetworks.clone(), network.clone(), &[]);
let mut networkId: Value = self.safe_string_k(currencyNetwork.clone(), "id", &[]);
if is_equal(&networkId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" fetchDepositAddress() could not find a network for '".to_string())), &code), &Value::Str("'. You can specify it by providing the 'network' value inside params".to_string()))));
}
let mut wallet: Value = self.safe_string_k(params.clone(), "wallet", &[Value::Str("exchange".to_string())]); // 'exchange', 'margin', 'funding' and also old labels 'exchange', 'trading', 'deposit', respectively
params = self.omit(params.clone(), Value::Str("network".to_string()), &[Value::Str("wallet".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), networkId.clone());
m.insert("wallet".to_string(), wallet.clone());
m.insert("op_renew".to_string(), Value::Int(0));
m
});
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
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_value(response.clone(), Value::Int(4), &[Value::List(vec![])]);
let mut poolAddress: Value = self.safe_string(result.clone(), Value::Int(5), &[]);
let mut address: Value = ternary(is_true(&(is_equal(&poolAddress, &Value::Null))), self.safe_string(result.clone(), Value::Int(4), &[]), poolAddress.clone());
let mut tag: Value = ternary(is_true(&(is_equal(&poolAddress, &Value::Null))), Value::Null, self.safe_string(result.clone(), Value::Int(4), &[]));
self.check_address(&[address.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m.insert("network".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
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".to_string()));
m.insert("COMPLETED".to_string(), Value::Str("ok".to_string()));
m.insert("ERROR".to_string(), Value::Str("failed".to_string()));
m.insert("FAILURE".to_string(), Value::Str("failed".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("PENDING APPROVAL".to_string(), Value::Str("pending".to_string()));
m.insert("PENDING".to_string(), Value::Str("pending".to_string()));
m.insert("PENDING REVIEW".to_string(), Value::Str("pending".to_string()));
m.insert("PENDING CANCELLATION".to_string(), Value::Str("pending".to_string()));
m.insert("SENDING".to_string(), Value::Str("pending".to_string()));
m.insert("USER APPROVED".to_string(), Value::Str("pending".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// 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: Value = get_array_length(&transaction);
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 is_equal(&transactionLength, &Value::Int(8)) {
let mut data: Value = self.safe_value(transaction.clone(), Value::Int(4), &[Value::List(vec![])]);
timestamp = self.safe_integer(transaction.clone(), Value::Int(0), &[]);
if !is_equal(¤cy, &Value::Null) {
code = get_value(¤cy, &Value::Str("code".to_string()));
}
feeCost = self.safe_string(data.clone(), Value::Int(8), &[]);
if !is_equal(&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".to_string());
if is_equal(&id, &Value::Int(0)) {
id = Value::Null;
status = Value::Str("failed".to_string());
}
tag = self.safe_string(data.clone(), Value::Int(3), &[]);
type_var = Value::Str("withdrawal".to_string());
let mut networkId: Value = self.safe_string(data.clone(), Value::Int(2), &[]);
network = self.network_id_to_code(&[to_upper(&networkId), code.clone()]); // withdraw returns in lowercase
} else if is_equal(&transactionLength, &Value::Int(22)) {
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.clone(), &[currency.clone()]);
let mut networkId: Value = self.safe_string(transaction.clone(), Value::Int(2), &[]);
network = self.network_id_to_code(&[networkId.clone(), 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 !is_equal(&signedAmount, &Value::Null) {
if is_true(&crate::precise::Precise::stringLt(&signedAmount, &Value::Str("0".to_string()))) {
type_var = Value::Str("withdrawal".to_string());
} else {
type_var = Value::Str("deposit".to_string());
}
}
feeCost = self.safe_string(transaction.clone(), Value::Int(13), &[]);
if !is_equal(&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.clone());
m.insert("id".to_string(), id.clone());
m.insert("txid".to_string(), txid.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), network.clone());
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("status".to_string(), status.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("address".to_string(), addressTo.clone());
m.insert("addressFrom".to_string(), Value::Null);
m.insert("addressTo".to_string(), addressTo.clone());
m.insert("tag".to_string(), tag.clone());
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), tag.clone());
m.insert("updated".to_string(), updated.clone());
m.insert("comment".to_string(), comment.clone());
m.insert("internal".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("cost".to_string(), self.parse_number(feeCost.clone(), &[]));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_post_auth_r_summary(&[params.clone()]).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_value_k(self.options.clone(), "fiat", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut feeData: Value = self.safe_value(response.clone(), Value::Int(4), &[Value::List(vec![])]);
let mut makerData: Value = self.safe_value(feeData.clone(), Value::Int(0), &[Value::List(vec![])]);
let mut takerData: Value = self.safe_value(feeData.clone(), Value::Int(1), &[Value::List(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.clone(), 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.clone(), Value::Int(5), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_331: bool = true;
while { if !__for_first_331 { i = add(&i, &Value::Int(1)); } __for_first_331 = false; is_less_than(&i, &get_array_length(&self.symbols)) } {
let mut symbol: Value = get_value(&self.symbols, &i);
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 is_true(&Value::Bool(in_op(&fiat, &get_value(&market, &Value::Str("quote".to_string()))))) {
add_element_to_object(&mut fee, &Value::Str("maker".to_string()), makerFeeFiat.clone());
add_element_to_object(&mut fee, &Value::Str("taker".to_string()), takerFeeFiat.clone());
} else if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut fee, &Value::Str("maker".to_string()), makerFeeDeriv.clone());
add_element_to_object(&mut fee, &Value::Str("taker".to_string()), takerFeeDeriv.clone());
} else {
add_element_to_object(&mut fee, &Value::Str("maker".to_string()), makerFee.clone());
add_element_to_object(&mut fee, &Value::Str("taker".to_string()), takerFee.clone());
}
add_element_to_object(&mut result, &symbol, fee.clone());
}
}
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 is_equal(&self.markets, &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 !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // max 1000
}
let mut response: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
let __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.clone());
} else {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
let mut movements: Value = self.private_post_auth_r_movements_hist(&[__ws_arg_22]).await;
response = self.to_array(movements.clone());
}
return self.parse_transactions(response.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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 {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.check_address(&[address.clone()]);
if is_equal(&self.markets, &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()]);
params = self.omit(params.clone(), Value::Str("network".to_string()), &[]);
let mut currencyNetworks: Value = self.safe_value_k(currency.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyNetwork: Value = self.safe_value(currencyNetworks.clone(), network.clone(), &[]);
let mut networkId: Value = self.safe_string_k(currencyNetwork.clone(), "id", &[]);
if is_equal(&networkId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" withdraw() could not find a network for '".to_string())), &code), &Value::Str("'. You can specify it by providing the 'network' value inside params".to_string()))));
}
let mut wallet: Value = self.safe_string_k(params.clone(), "wallet", &[Value::Str("exchange".to_string())]); // 'exchange', 'margin', 'funding' and also old labels 'exchange', 'trading', 'deposit', respectively
params = self.omit(params.clone(), Value::Str("network".to_string()), &[Value::Str("wallet".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), networkId.clone());
m.insert("wallet".to_string(), wallet.clone());
m.insert("amount".to_string(), self.number_to_string(amount.clone()));
m.insert("address".to_string(), address.clone());
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("payment_id".to_string()), tag.clone());
}
let mut withdrawOptions: Value = self.safe_value_k(self.options.clone(), "withdraw", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut includeFee: Value = self.safe_bool_k(withdrawOptions.clone(), "includeFee", &[Value::Bool(false)]);
if is_equal(&includeFee, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("fee_deduct".to_string()), Value::Int(1));
}
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
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: Value = self.safe_string(response.clone(), Value::Int(0), &[]);
if is_equal(&statusMessage, &Value::Str("error".to_string())) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &response);
let mut message: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".to_string())]);
// same message as in v1
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut text: Value = self.safe_string(response.clone(), Value::Int(7), &[]);
if !is_equal(&text, &Value::Str("success".to_string())) {
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), text.clone(), text.clone());
}
return self.parse_transaction(response.clone(), &[currency.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.private_post_auth_r_positions(&[params.clone()]).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.clone());
let mut positionsList: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_332: bool = true;
while { if !__for_first_332 { i = add(&i, &Value::Int(1)); } __for_first_332 = false; is_less_than(&i, &get_array_length(&rawPositions)) } {
append_to_array(&mut positionsList, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), get_value(&rawPositions, &i));
m
}));
}
}
return self.parse_positions(positionsList.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// "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 = self.safe_list_k(position.clone(), "result", &[]);
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.clone(), "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.clone(), &[market.clone()]));
m.insert("notional".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
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(), ternary(is_true(&crate::precise::Precise::stringGt(&amount, &Value::Str("0".to_string()))), Value::Str("long".to_string()), Value::Str("short".to_string())));
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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.clone(), 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(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut request: Value = add(&Value::Str("/".to_string()), &self.implode_params(path.clone(), params.clone()));
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
if is_equal(&api, &Value::Str("v1".to_string())) {
request = add(&api, &request);
} else {
request = add(&self.version, &request);
}
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &request);
if is_equal(&api, &Value::Str("public".to_string())) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
}
if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut nonce: Value = to_string_val(&self.nonce());
body = self.json(query.clone());
let mut auth: Value = add(&add(&add(&Value::Str("/api/".to_string()), &request), &nonce), &body);
let mut signature: Value = self.hmac(self.encode(auth.clone()), self.encode(self.secret.clone()), Value::Str("sha384".to_string()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bfx-nonce".to_string(), nonce.clone());
m.insert("bfx-apikey".to_string(), self.apiKey.clone());
m.insert("bfx-signature".to_string(), signature.clone());
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut 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 !is_equal(&response, &Value::Null) {
if !is_true(&Value::Bool(is_array(&response))) {
let mut message: Value = self.safe_string2(response.clone(), Value::Str("message".to_string()), Value::Str("error".to_string()), &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" ".to_string())), &body)));
}
} else if is_equal(&response, &Value::Str("".to_string())) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" returned empty response".to_string()))));
}
if is_equal(&statusCode, &Value::Int(429)) {
panic!("{}", crate::exchange_errors::rate_limit_exceeded(add(&add(&self.id, &Value::Str(" ".to_string())), &body)));
}
if is_equal(&statusCode, &Value::Int(500)) {
// 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("".to_string())]);
let mut errorText: Value = self.safe_string(response.clone(), Value::Int(2), &[Value::Str("".to_string())]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &errorText);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), errorText.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorText.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &errorText), &Value::Str(" (#".to_string())), &errorCode), &Value::Str(")".to_string()))));
}
return response;
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
if is_equal(&type_var, &Value::Null) {
return Value::Null;
} else if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("fee".to_string())), &Value::Int(0)) || is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("charged".to_string())), &Value::Int(0)) {
return Value::Str("fee".to_string());
} else if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("rebate".to_string())), &Value::Int(0)) {
return Value::Str("rebate".to_string());
} else if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("deposit".to_string())), &Value::Int(0)) || is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("withdrawal".to_string())), &Value::Int(0)) {
return Value::Str("transaction".to_string());
} else if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("transfer".to_string())), &Value::Int(0)) {
return Value::Str("transfer".to_string());
} else if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("payment".to_string())), &Value::Int(0)) {
return Value::Str("payout".to_string());
} else if is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("exchange".to_string())), &Value::Int(0)) || is_greater_than_or_equal(&get_index_of(&type_var, &Value::Str("position".to_string())), &Value::Int(0)) {
return Value::Str("trade".to_string());
} 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::List(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()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
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.clone(), Value::Int(8), &[]);
if !is_equal(&description, &Value::Null) {
let mut parts: Value = split(&description, &Value::Str(" @ ".to_string()));
let mut first: Value = self.safe_string_lower(parts.clone(), Value::Int(0), &[]);
type_var = self.parse_ledger_entry_type(first.clone());
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), id.clone());
m.insert("direction".to_string(), Value::Null);
m.insert("account".to_string(), Value::Null);
m.insert("referenceId".to_string(), id.clone());
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), after.clone());
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
}), &[currency.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLedger".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchLedger".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Int(2500)]).await;
}
let mut currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_auth_r_ledgers_currency_hist(&[__ws_arg_24]).await;
} else {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
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::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_333: bool = true;
while { if !__for_first_333 { i = add(&i, &Value::Int(1)); } __for_first_333 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut item: Value = get_value(&response, &i);
let mut item: Value = get_value(&response, &i);
append_to_array(&mut ledgerObjects, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), item.clone());
m
}));
}
}
return self.parse_ledger(ledgerObjects.clone(), &[currency.clone(), since.clone(), limit.clone()]);
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 is_equal(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRates() requires a symbols argument".to_string()))));
}
if is_equal(&self.markets, &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(",".to_string())));
m
});
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_26]).await;
return self.parse_funding_rates(response.clone(), &[symbols.clone()]);
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 is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
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.clone());
let mut rates: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_334: bool = true;
while { if !__for_first_334 { i = add(&i, &Value::Int(1)); } __for_first_334 = false; is_less_than(&i, &get_array_length(&rawRatesData)) } {
let mut fr: Value = get_value(&rawRatesData, &i);
let mut fr: Value = get_value(&rawRatesData, &i);
let mut rate: Value = self.parse_funding_rate_history(fr.clone(), &[market.clone()]);
append_to_array(&mut rates, rate.clone());
}
}
let mut reversedArray: Value = Value::List(vec![]);
let mut rawRates: Value = self.filter_by_symbol_since_limit(rates.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
let mut ratesLength: Value = get_array_length(&rawRates);
{
let mut i: Value = Value::Int(0);
let mut __for_first_335: bool = true;
while { if !__for_first_335 { i = add(&i, &Value::Int(1)); } __for_first_335 = false; is_less_than(&i, &ratesLength) } {
let mut index: Value = subtract(&subtract(&ratesLength, &i), &Value::Int(1));
let mut valueAtIndex: Value = get_value(&rawRates, &index);
let mut valueAtIndex: Value = get_value(&rawRates, &index);
append_to_array(&mut reversedArray, valueAtIndex.clone());
}
}
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.clone(), &[market.clone()]));
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.clone()));
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.clone(), Value::Int(9), &[]));
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), 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), &[]);
let mut nextFundingTimestamp: Value = self.safe_integer(contract.clone(), Value::Int(7), &[]);
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.clone()]));
m.insert("markPrice".to_string(), self.safe_number(contract.clone(), Value::Int(14), &[]));
m.insert("indexPrice".to_string(), self.safe_number(contract.clone(), Value::Int(2), &[]));
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.clone()));
m.insert("fundingRate".to_string(), self.safe_number(contract.clone(), Value::Int(11), &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), self.safe_number(contract.clone(), Value::Int(8), &[]));
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut marketIds: Value = Value::List(vec![Value::Str("ALL".to_string())]);
if !is_equal(&symbols, &Value::Null) {
marketIds = 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(",".to_string())));
m
});
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_status_deriv(&[__ws_arg_28]).await;
return self.parse_open_interests(response.clone(), &[symbols.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("keys".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
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.clone(), Value::Int(0), &[]);
return self.parse_open_interest(oi.clone(), &[market.clone()]);
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".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOpenInterestHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOpenInterestHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.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(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_status_deriv_symbol_hist(&[__ws_arg_30]).await;
return self.parse_open_interests_history(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// 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 = ternary(is_true(&(is_equal(&interestLength, &Value::Int(23)))), Value::Int(17), 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.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
m.insert("openInterestAmount".to_string(), self.safe_number(interest.clone(), openInterestIndex.clone(), &[]));
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name 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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLiquidations".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchLiquidations".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.clone(), Value::Int(500)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_liquidations_hist(&[__ws_arg_31]).await;
return self.parse_liquidations(self.to_array(response.clone()), &[market.clone(), since.clone(), limit.clone()]);
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 = get_value(&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: Value = self.safe_integer(entry.clone(), Value::Int(8), &[]);
let mut side: Value = ternary(is_true(&(is_equal(&sideFlag, &Value::Int(1)))), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("contracts".to_string(), self.parse_number(contracts.clone(), &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSize.clone(), &[]));
m.insert("price".to_string(), self.parse_number(price.clone(), &[]));
m.insert("side".to_string(), side.clone());
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.clone()));
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setMargin() only support swap markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("collateral".to_string(), self.parse_to_numeric(amount.clone()));
m
});
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
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.clone(), Value::Int(0), &[]);
return self.parse_margin_modification(data.clone(), &[market.clone()]);
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 = get_value(&data, &Value::Int(0));
let mut marginStatus: Value = ternary(is_true(&(is_equal(&marginStatusRaw, &Value::Int(1)))), Value::Str("ok".to_string()), Value::Str("failed".to_string()));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
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.clone());
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::List(vec![self.parse_to_numeric(id.clone())]));
m
});
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if is_equal(&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.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
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.clone(), Value::Int(0), &[]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order.clone());
m
});
return self.parse_order(newOrder.clone(), &[market.clone()]);
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 is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.parse_to_numeric(id.clone()));
m
});
if !is_equal(&amount, &Value::Null) {
let mut amountString: Value = self.amount_to_precision(symbol.clone(), amount.clone());
amountString = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), amountString.clone(), crate::precise::Precise::stringNeg(&amountString));
add_element_to_object(&mut request, &Value::Str("amount".to_string()), amountString.clone());
}
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut timeInForce: Value = self.safe_string_k(params.clone(), "timeInForce", &[]);
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".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&trailingAmount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price_trailing".to_string()), trailingAmount.clone());
} else if !is_equal(&triggerPrice, &Value::Null) {
// request['price'] is taken as triggerPrice for stop orders
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
if is_equal(&type_var, &Value::Str("limit".to_string())) {
add_element_to_object(&mut request, &Value::Str("price_aux_limit".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
}
let mut postOnly: bool = is_true(&(is_equal(&postOnlyParam, &Value::Bool(true)))) || is_true(&(is_equal(&timeInForce, &Value::Str("PO".to_string()))));
if is_true(&(!is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_equal(&triggerPrice, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
// flag values may be summed to combine flags
let mut flags: Value = Value::Int(0);
if is_true(&postOnly) {
flags = self.sum(&[flags.clone(), Value::Int(4096)]);
}
if is_equal(&reduceOnly, &Value::Bool(true)) {
flags = self.sum(&[flags.clone(), Value::Int(1024)]);
}
if !is_equal(&flags, &Value::Int(0)) {
add_element_to_object(&mut request, &Value::Str("flags".to_string()), flags.clone());
}
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cid".to_string()), clientOrderId.clone());
}
let mut leverage: Value = self.safe_integer2(params.clone(), Value::Str("leverage".to_string()), Value::Str("lev".to_string()), &[]);
if !is_equal(&leverage, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("lev".to_string()), leverage.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("timeInForce".to_string()), Value::Str("postOnly".to_string()), Value::Str("reduceOnly".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("leverage".to_string())]), &[]);
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
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 !is_equal(&status, &Value::Str("SUCCESS".to_string())) {
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(add(&add(&add(&add(&add(&add(&add(&self.id, &Value::Str(" ".to_string())), &status), &Value::Str(": ".to_string())), &errorText), &Value::Str(" (#".to_string())), &errorCode), &Value::Str(")".to_string()))));
}
let mut order: Value = self.safe_list(response.clone(), Value::Int(4), &[Value::List(vec![])]);
let mut newOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("result".to_string(), order.clone());
m
});
return self.parse_order(newOrder.clone(), &[market.clone()]);
Value::Null
}
}