// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct CoinbaseexchangeCore {
pub exchange: crate::exchange::Exchange,
}
impl CoinbaseexchangeCore {
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 = CoinbaseexchangeCore::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 CoinbaseexchangeCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_order(self, order, &[market])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_balance(self, response)
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_ledger_entry(self, entry, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_currency(self, currency)
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_account(self, account)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::parse_transaction(self, transaction, &[currency])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::sign(self, path, &[api, method, params, headers, body])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on CoinbaseexchangeCore.
CoinbaseexchangeCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for CoinbaseexchangeCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_all_orders" => self.cancel_all_orders(&args[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_deposit_address" => self.create_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"fetch_accounts" => self.fetch_accounts(&args[..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposits" => self.fetch_deposits(&args[..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args[..]).await,
"fetch_ledger" => self.fetch_ledger(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_payment_methods" => self.fetch_payment_methods(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_tickers" => self.fetch_tickers(&args[..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"parse_account" => self.parse_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"request" => self.request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for CoinbaseexchangeCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for CoinbaseexchangeCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl CoinbaseexchangeCore {
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("coinbaseexchange".into()));
m.insert("name".to_string(), Value::Str("Coinbase Exchange".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("US".into())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("userAgent".to_string(), self.userAgents.as_map().and_then(|__m| __m.get("chrome")).cloned().unwrap_or(Value::Null));
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::Bool(true));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createDepositAddress".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(false));
m.insert("createOrderWithTakeProfitAndStopLossWs".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
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("fetchAccounts".to_string(), Value::Bool(true));
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("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(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("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("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarginModes".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("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".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(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
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("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(false));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(false));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactions".to_string(), Value::Str("emulated".into()));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
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("repayMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Int(60));
m.insert("5m".to_string(), Value::Int(300));
m.insert("15m".to_string(), Value::Int(900));
m.insert("1h".to_string(), Value::Int(3600));
m.insert("6h".to_string(), Value::Int(21600));
m.insert("1d".to_string(), Value::Int(86400));
m
}));
m.insert("hostname".to_string(), Value::Str("exchange.coinbase.com".into()));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api-public.sandbox.exchange.coinbase.com".into()));
m.insert("private".to_string(), Value::Str("https://api-public.sandbox.exchange.coinbase.com".into()));
m
}));
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/a99ef849-a4b2-4dd4-87fe-458ef17db7fd".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.{hostname}".into()));
m.insert("private".to_string(), Value::Str("https://api.{hostname}".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://coinbase.com/".into()));
m.insert("doc".to_string(), Value::Str("https://docs.cloud.coinbase.com/exchange/docs/".into()));
m.insert("fees".to_string(), Value::from(vec![Value::Str("https://docs.pro.coinbase.com/#fees".into()), Value::Str("https://support.pro.coinbase.com/customer/en/portal/articles/2945310-fees".into())]));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m.insert("password".to_string(), Value::Bool(true));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/{id}/book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/{id}/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/{id}/stats".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/{id}/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/{id}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/spark-lines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("products/volume-summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/{wrapped_asset_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/{wrapped_asset_id}/conversion-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("address-book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("address-book/counterparty".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accounts/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accounts/{id}/holds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accounts/{id}/ledger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("accounts/{id}/transfers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("coinbase-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/profile_information".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/buying_power".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/withdrawal_power".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/withdrawal_power_all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/exit_plan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/liquidation_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/position_refresh_amounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("margin/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("oracle".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders/client:{client_oid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("otc/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("payment-methods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("profiles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("profiles/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("reports/{report_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfers/{transfer_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("travel-rules".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/self/exchange-limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/self/hold-balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/self/trailing-volume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/{user_id}/trading-volumes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawals/fee-estimate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("conversions/{conversion_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("conversions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("conversions/fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/lending-overview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/lending-overview-xm".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/loan-preview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/loan-preview-xm".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/repayment-preview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/repayment-preview-xm".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/interest/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/interest/history/{loan_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/redeem/{redeem_id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/stake-wrap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/stake-wrap/{stake_wrap_id}".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("conversions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposits/coinbase-account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("deposits/payment-method".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("coinbase-accounts/{id}/addresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("address-book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("funding/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("position/close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("profiles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("profiles/margin-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("profiles/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("reports".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawals/coinbase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawals/coinbase-account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawals/counterparty".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawals/crypto".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("withdrawals/payment-method".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("transfers/{transfer_id}/travel-rules".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("travel-rules".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/{user_id}/settlement-preferences".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("wrapped-assets/stake-wrap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/open".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/repay-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("loans/repay-principal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders/client:{client_oid}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("address-book/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("travel-rules/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("profiles/{id}/deactivate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("profiles/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("address-book/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CGLD".to_string(), Value::Str("CELO".into()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.004".into()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.006".into()), &[]));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(false));
m.insert("percentage".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BCH".to_string(), Value::Int(0));
m.insert("BTC".to_string(), Value::Int(0));
m.insert("LTC".to_string(), Value::Int(0));
m.insert("ETH".to_string(), Value::Int(0));
m.insert("EUR".to_string(), Value::Float(0.15));
m.insert("USD".to_string(), Value::Int(25));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BCH".to_string(), Value::Int(0));
m.insert("BTC".to_string(), Value::Int(0));
m.insert("LTC".to_string(), Value::Int(0));
m.insert("ETH".to_string(), Value::Int(0));
m.insert("EUR".to_string(), Value::Float(0.15));
m.insert("USD".to_string(), Value::Int(10));
m
}));
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(true));
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(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(true));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(true));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
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("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("daysBackCanceled".to_string(), Value::Int(1));
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(300));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("bitcoin".into()));
m.insert("ETH".to_string(), Value::Str("ethereum".into()));
m.insert("SOL".to_string(), Value::Str("solana".into()));
m.insert("ARBITRUM".to_string(), Value::Str("arbitrum".into()));
m.insert("AVAXC".to_string(), Value::Str("avacchain".into()));
m.insert("MATIC".to_string(), Value::Str("polygon".into()));
m.insert("BASE".to_string(), Value::Str("base".into()));
m.insert("SUI".to_string(), Value::Str("sui".into()));
m.insert("OP".to_string(), Value::Str("optimism".into()));
m.insert("NEAR".to_string(), Value::Str("near".into()));
m.insert("APT".to_string(), Value::Str("aptos".into()));
m.insert("KAVA".to_string(), Value::Str("kava".into()));
m.insert("BLAST".to_string(), Value::Str("blast".into()));
m.insert("XLM".to_string(), Value::Str("stellar".into()));
m.insert("SEI".to_string(), Value::Str("sei".into()));
m.insert("ADA".to_string(), Value::Str("cardano".into()));
m.insert("CORE".to_string(), Value::Str("coredao".into()));
m.insert("ALGO".to_string(), Value::Str("algorand".into()));
m.insert("OSMO".to_string(), Value::Str("osmosis".into()));
m.insert("CELO".to_string(), Value::Str("celo".into()));
m.insert("HBAR".to_string(), Value::Str("hedera".into()));
m.insert("ZKSYNC".to_string(), Value::Str("zksync".into()));
m.insert("STX".to_string(), Value::Str("stacks".into()));
m.insert("XTZ".to_string(), Value::Str("tezos".into()));
m.insert("EGLD".to_string(), Value::Str("elrond".into()));
m.insert("LTC".to_string(), Value::Str("litecoin".into()));
m.insert("ATOM".to_string(), Value::Str("cosmos".into()));
m.insert("FIL".to_string(), Value::Str("filecoin".into()));
m.insert("DOT".to_string(), Value::Str("polkadot".into()));
m.insert("DOGE".to_string(), Value::Str("dogecoin".into()));
m.insert("XRP".to_string(), Value::Str("ripple".into()));
m.insert("DASH".to_string(), Value::Str("dash".into()));
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("Insufficient funds".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("NotFound".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("Invalid API Key".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("invalid signature".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("Invalid Passphrase".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("Invalid order id".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("Private rate limit exceeded".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("Trading pair not available".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("Product not found".to_string(), Value::Str("InvalidOrder".into()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Order already done".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("order not found".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("price too small".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("price too precise".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("under maintenance".to_string(), Value::Str("OnMaintenance".into()).clone());
m.insert("size is too small".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("Cancel only mode".to_string(), Value::Str("OnMaintenance".into()).clone());
m
}));
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getcurrencies
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_currencies(&[params]).await;
return self.parse_currencies(response);
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut id: Value = self.safe_string_k(rawCurrency.clone(), "id", &[]);
let mut name: Value = self.safe_string_k(rawCurrency.clone(), "name", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut details: Value = self.safe_dict_k(rawCurrency.clone(), "details", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut supportedNetworks: Value = self.safe_list_k(rawCurrency.clone(), "supported_networks", &[Value::from(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_527: bool = true;
while { if !__for_first_527 { j = (match (&(j), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_527 = false; j.as_f64().unwrap_or(f64::NAN) < ((supportedNetworks.len() as i64) as f64) } {
let mut network: Value = supportedNetworks.as_array().and_then(|__arr| match &j { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut networkId: Value = self.safe_string_k(network.clone(), "id", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut networks { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&networkCode), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), networkId);
m.insert("name".to_string(), self.safe_string_k(network.clone(), "name", &[]));
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Bool(self.safe_string_k(network.clone(), "status", &[]).as_str() == Some("online")));
m.insert("withdraw".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
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(), self.safe_number_k(network.clone(), "min_withdrawal_amount", &[]));
m.insert("max".to_string(), self.safe_number_k(network.clone(), "max_withdrawal_amount", &[]));
m
}));
m
}));
m.insert("contract".to_string(), self.safe_string_k(network.clone(), "contract_address", &[]));
m.insert("info".to_string(), network);
m
})); }
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("code".to_string(), code);
m.insert("info".to_string(), rawCurrency.clone());
m.insert("type".to_string(), self.safe_string_k(details.clone(), "type", &[]));
m.insert("name".to_string(), name);
m.insert("active".to_string(), Value::Bool(self.safe_string_k(rawCurrency.clone(), "status", &[]).as_str() == Some("online")));
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), self.safe_number_k(rawCurrency, "max_precision", &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(details.clone(), "min_size", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(details.clone(), "min_withdrawal_amount", &[]));
m.insert("max".to_string(), self.safe_number_k(details, "max_withdrawal_amount", &[]));
m
}));
m
}));
m.insert("networks".to_string(), networks);
m
}));
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchMarkets
* @description retrieves data on all markets for coinbaseexchange
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducts
* @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 response: Value = self.public_get_products(&[params]).await;
//
// [
// {
// "id": "BTCAUCTION-USD",
// "base_currency": "BTC",
// "quote_currency": "USD",
// "base_min_size": "0.000016",
// "base_max_size": "1500",
// "quote_increment": "0.01",
// "base_increment": "0.00000001",
// "display_name": "BTCAUCTION/USD",
// "min_market_funds": "1",
// "max_market_funds": "20000000",
// "margin_enabled": false,
// "fx_stablecoin": false,
// "max_slippage_percentage": "0.02000000",
// "post_only": false,
// "limit_only": false,
// "cancel_only": true,
// "trading_disabled": false,
// "status": "online",
// "status_message": '',
// "auction_mode": false
// },
// {
// "id": "BTC-USD",
// "base_currency": "BTC",
// "quote_currency": "USD",
// "base_min_size": "0.000016",
// "base_max_size": "1500",
// "quote_increment": "0.01",
// "base_increment": "0.00000001",
// "display_name": "BTC/USD",
// "min_market_funds": "1",
// "max_market_funds": "20000000",
// "margin_enabled": false,
// "fx_stablecoin": false,
// "max_slippage_percentage": "0.02000000",
// "post_only": false,
// "limit_only": false,
// "cancel_only": false,
// "trading_disabled": false,
// "status": "online",
// "status_message": '',
// "auction_mode": false
// }
// ]
//
let mut result: Value = Value::from(vec![]);
let mut rawMarkets: Value = self.to_array(response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_528: bool = true;
while { if !__for_first_528 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_528 = false; i.as_f64().unwrap_or(f64::NAN) < ((rawMarkets.len() as i64) as f64) } {
let mut market: Value = rawMarkets.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut id: Value = self.safe_string_k(market.clone(), "id", &[]);
let mut baseIdquoteIdVariable = split(&id, &Value::Str("-".into()));
let mut baseId: Value = baseIdquoteIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut quoteId: Value = baseIdquoteIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
// BTCAUCTION-USD vs BTC-USD conflict workaround, see the output sample above
// const baseId = this.safeString (market, 'base_currency');
// const quoteId = this.safeString (market, 'quote_currency');
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut status: Option<String> = self.safe_string_k(market.clone(), "status", &[]).as_str().map(str::to_owned);
let __ws_arg_4 = crate::value::get_value_k(&self.fees, "trading");
let __ws_arg_0 = self.safe_bool_k(market.clone(), "margin_enabled", &[]);
let __ws_arg_1 = self.safe_number_k(market.clone(), "base_increment", &[]);
let __ws_arg_2 = self.safe_number_k(market.clone(), "quote_increment", &[]);
let __ws_arg_3 = self.safe_number_k(market.clone(), "min_market_funds", &[]);
append_to_array(&mut result, self.extend(__ws_arg_4, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("symbol".to_string(), Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into()));
m.insert("base".to_string(), base);
m.insert("quote".to_string(), quote);
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId);
m.insert("quoteId".to_string(), quoteId);
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".into()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), __ws_arg_0);
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), (Value::Bool(status.as_deref() == Some("online"))));
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("contractSize".to_string(), Value::Null);
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), __ws_arg_1);
m.insert("price".to_string(), __ws_arg_2);
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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), __ws_arg_3);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
})]));
}
}
return result;
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/?id=account-structure} indexed by the account type
*/
pub async fn fetch_accounts(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_accounts(&[params.clone()]).await;
//
// [
// {
// "id": "4aac9c60-cbda-4396-9da4-4aa71e95fba0",
// "currency": "BTC",
// "balance": "0.0000000000000000",
// "available": "0",
// "hold": "0.0000000000000000",
// "profile_id": "b709263e-f42a-4c7d-949a-a95c83d065da"
// },
// {
// "id": "f75fa69a-1ad1-4a80-bd61-ee7faa6135a3",
// "currency": "USDC",
// "balance": "0.0000000000000000",
// "available": "0",
// "hold": "0.0000000000000000",
// "profile_id": "b709263e-f42a-4c7d-949a-a95c83d065da"
// },
// ]
//
let mut accounts: Value = self.to_array(response);
return self.parse_accounts(accounts, &[params]);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
//
// {
// "id": "4aac9c60-cbda-4396-9da4-4aa71e95fba0",
// "currency": "BTC",
// "balance": "0.0000000000000000",
// "available": "0",
// "hold": "0.0000000000000000",
// "profile_id": "b709263e-f42a-4c7d-949a-a95c83d065da"
// }
//
let mut currencyId: Value = self.safe_string_k(account.clone(), "currency", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(account.clone(), "id", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("code".to_string(), self.safe_currency_code(currencyId, &[]));
m.insert("info".to_string(), account);
m
});
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
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_529: bool = true;
while { if !__for_first_529 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_529 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut balance: Value = get_value(&response, &i);
let mut balance: Value = get_value(&response, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(balance.clone(), "available", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(balance.clone(), "hold", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string_k(balance, "balance", &[])); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounts
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_accounts(&[params]).await;
return self.parse_balance(response);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchOrderBook
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductbook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
// level 1 - only the best bid and ask
// level 2 - top 50 bids and asks (aggregated)
// level 3 - full order book (non aggregated)
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.market_id(symbol.clone()));
m.insert("level".to_string(), Value::Int(2));
m
});
let __ws_arg_5 = self.extend(request, &[params]);
let mut response: Value = self.public_get_products_id_book(&[__ws_arg_5]).await;
//
// {
// "sequence":1924393896,
// "bids":[
// ["0.01825","24.34811287",2],
// ["0.01824","72.5463",3],
// ["0.01823","424.54298049",6],
// ],
// "asks":[
// ["0.01826","171.10414904",4],
// ["0.01827","22.60427028",1],
// ["0.01828","397.46018784",7],
// ]
// }
//
let mut orderbook: Value = self.parse_order_book(response.clone(), symbol, &[]);
add_element_to_object(&mut orderbook, &Value::Str("nonce".into()), self.safe_integer_k(response, "sequence", &[]));
return orderbook;
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTickers
//
// [
// 1639472400, // timestamp
// 4.26, // low
// 4.38, // high
// 4.35, // open
// 4.27 // close
// ]
//
// fetchTicker
//
// publicGetProductsIdTicker
//
// {
// "trade_id":843439,
// "price":"0.997999",
// "size":"80.29769",
// "time":"2020-01-28T02:13:33.012523Z",
// "bid":"0.997094",
// "ask":"0.998",
// "volume":"1903188.03750000"
// }
//
// publicGetProductsIdStats
//
// {
// "open": "34.19000000",
// "high": "95.70000000",
// "low": "7.06000000",
// "volume": "2.41000000"
// }
//
let mut timestamp: Value = Value::Null;
let mut bid: Value = Value::Null;
let mut ask: Value = Value::Null;
let mut last: Value = Value::Null;
let mut high: Value = Value::Null;
let mut low: Value = Value::Null;
let mut open: Value = Value::Null;
let mut volume: Value = Value::Null;
let mut symbol: Value = (if (market == Value::Null) { Value::Null } else { market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null) });
if (matches!(&ticker, Value::Arr(_))) {
last = self.safe_string(ticker.clone(), Value::Int(4), &[]);
} else {
timestamp = self.parse8601(self.safe_string_k(ticker.clone(), "time", &[]));
bid = self.safe_string_k(ticker.clone(), "bid", &[]);
ask = self.safe_string_k(ticker.clone(), "ask", &[]);
high = self.safe_string_k(ticker.clone(), "high", &[]);
low = self.safe_string_k(ticker.clone(), "low", &[]);
open = self.safe_string_k(ticker.clone(), "open", &[]);
last = self.safe_string2(ticker.clone(), Value::Str("price".into()), Value::Str("last".into()), &[]);
volume = self.safe_string_k(ticker.clone(), "volume", &[]);
}
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), high);
m.insert("low".to_string(), low);
m.insert("bid".to_string(), bid);
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), ask);
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), open);
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), volume);
m.insert("quoteVolume".to_string(), Value::Null);
m.insert("info".to_string(), ticker);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproduct
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let __ws_arg_6 = self.extend(request, &[params]);
let mut response: Value = self.public_get_products_spark_lines(&[__ws_arg_6]).await;
//
// {
// YYY-USD: [
// [
// 1639472400, // timestamp
// 4.26, // low
// 4.38, // high
// 4.35, // open
// 4.27 // close
// ],
// [
// 1639468800,
// 4.31,
// 4.45,
// 4.35,
// 4.35
// ],
// ]
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut marketIds: Value = object_keys(&response);
let mut delimiter: Value = Value::Str("-".into());
{
let mut i: Value = Value::Int(0);
let mut __for_first_530: bool = true;
while { if !__for_first_530 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_530 = false; i.as_f64().unwrap_or(f64::NAN) < ((marketIds.len() as i64) as f64) } {
let mut marketId: Value = marketIds.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut entry: Value = self.safe_list(response.clone(), marketId.clone(), &[Value::from(vec![])]);
let mut first: Value = self.safe_list(entry, Value::Int(0), &[Value::from(vec![])]);
let mut market: Value = self.safe_market(&[marketId, Value::Null, delimiter.clone()]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), self.parse_ticker(first, &[market])); }
}
}
return self.filter_by_array_tickers(result, Value::Str("symbol".into()), &[symbols]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchTicker
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductticker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
// publicGetProductsIdTicker or publicGetProductsIdStats
let mut method: Option<String> = self.safe_string_k(self.options.clone(), "fetchTickerMethod", &[Value::Str("publicGetProductsIdTicker".into())]).as_str().map(str::to_owned);
let mut response: Value = Value::Null;
if (method.as_deref() == Some("publicGetProductsIdStats")) {
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_products_id_stats(&[__ws_arg_7]).await;
} else {
let __ws_arg_8 = self.extend(request, &[params]);
response = self.public_get_products_id_ticker(&[__ws_arg_8]).await;
}
return self.parse_ticker(response, &[market]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "type": "match",
// "trade_id": 82047307,
// "maker_order_id": "0f358725-2134-435e-be11-753912a326e0",
// "taker_order_id": "252b7002-87a3-425c-ac73-f5b9e23f3caf",
// "order_id": "d50ec984-77a8-460a-b958-66f114b0de9b",
// "side": "sell",
// "size": "0.00513192",
// "price": "9314.78",
// "product_id": "BTC-USD",
// "profile_id": "6244401d-c078-40d9-b305-7ad3551bc3b0",
// "sequence": 12038915443,
// "time": "2020-01-31T20:03:41.158814Z"
// "created_at": "2014-11-07T22:19:28.578544Z",
// "liquidity": "T",
// "fee": "0.00025",
// "settled": true,
// "usd_volume": "0.0924556000000000",
// "user_id": "595eb864313c2b02ddf2937d"
// }
//
let mut timestamp: Value = self.parse8601(self.safe_string2(trade.clone(), Value::Str("time".into()), Value::Str("created_at".into()), &[]));
let mut marketId: Value = self.safe_string_k(trade.clone(), "product_id", &[]);
market = self.safe_market(&[marketId, market.clone(), Value::Str("-".into())]);
let mut feeRate: Value = Value::Null;
let mut takerOrMaker: Value = Value::Null;
let mut cost: Value = Value::Null;
let mut feeCurrencyId: Value = self.safe_string_lower_k(market.clone(), "quoteId", &[]);
if (feeCurrencyId != Value::Null) {
let mut costField: Value = Value::Str(format!("{}{}", feeCurrencyId, Value::Str("_value".into())).into());
cost = self.safe_string(trade.clone(), costField, &[]);
let mut liquidity: Option<String> = self.safe_string_k(trade.clone(), "liquidity", &[]).as_str().map(str::to_owned);
if (liquidity.is_some()) {
takerOrMaker = (if (liquidity.as_deref() == Some("T")) { Value::Str("taker".into()) } else { Value::Str("maker".into()) });
feeRate = self.safe_string(market.clone(), takerOrMaker.clone(), &[]);
}
}
let mut feeCost: Value = self.safe_string2(trade.clone(), Value::Str("fill_fees".into()), Value::Str("fee".into()), &[]);
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost);
m.insert("currency".to_string(), market.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null));
m.insert("rate".to_string(), feeRate);
m
});
let mut id: Value = self.safe_string_k(trade.clone(), "trade_id", &[]);
let mut side: Value = (if (trade.as_map().and_then(|__m| __m.get("side")).cloned().unwrap_or(Value::Null).as_str() == Some("buy")) { Value::Str("sell".into()) } else { Value::Str("buy".into()) });
let mut orderId: Value = self.safe_string_k(trade.clone(), "order_id", &[]);
// Coinbase Pro returns inverted side to fetchMyTrades vs fetchTrades
let mut makerOrderId: Option<String> = self.safe_string_k(trade.clone(), "maker_order_id", &[]).as_str().map(str::to_owned);
let mut takerOrderId: Option<String> = self.safe_string_k(trade.clone(), "taker_order_id", &[]).as_str().map(str::to_owned);
if (orderId != Value::Null) || ((makerOrderId.is_some()) && (takerOrderId.is_some())) {
side = (if (trade.as_map().and_then(|__m| __m.get("side")).cloned().unwrap_or(Value::Null).as_str() == Some("buy")) { Value::Str("buy".into()) } else { Value::Str("sell".into()) });
}
let mut price: Value = self.safe_string_k(trade.clone(), "price", &[]);
let mut amount: Value = self.safe_string_k(trade.clone(), "size", &[]);
let mut symbol: Value = market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("order".to_string(), orderId);
m.insert("info".to_string(), trade);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("amount".to_string(), amount);
m.insert("fee".to_string(), fee);
m.insert("cost".to_string(), cost);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchMyTrades
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfills
* @description fetch all trades made by the user
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades 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 {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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchMyTrades() requires a symbol argument".into()))));
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".into()), Value::Str("paginate".into()), &[]); paginate = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Int(100)]).await;
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("product_id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_date".into(), self.iso8601(since.clone())); }
}
let mut until: Value = self.safe_value2(params.clone(), Value::Str("until".into()), Value::Str("end_date".into()), &[]);
if (until != Value::Null) {
params = self.omit(params.clone(), Value::from(vec![Value::Str("until".into())]), &[]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_date".into(), self.iso8601(until)); }
}
let __ws_arg_9 = self.extend(request, &[params]);
let mut response: Value = self.private_get_fills(&[__ws_arg_9]).await;
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchTrades
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproducttrades
* @description get the list of most recent trades for a particular symbol
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // default 100
}
let __ws_arg_10 = self.extend(request, &[params]);
let mut response: Value = self.public_get_products_id_trades(&[__ws_arg_10]).await;
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getfees
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_fees(&[params]).await;
//
// {
// "maker_fee_rate": "0.0050",
// "taker_fee_rate": "0.0050",
// "usd_volume": "43806.92"
// }
//
let mut maker: Value = self.safe_number_k(response.clone(), "maker_fee_rate", &[]);
let mut taker: Value = self.safe_number_k(response.clone(), "taker_fee_rate", &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_531: bool = true;
while { if !__for_first_531 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_531 = false; i.as_f64().unwrap_or(f64::NAN) < ((self.symbols.len() as i64) as f64) } {
let mut symbol: Value = self.symbols.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&symbol), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), maker.clone());
m.insert("taker".to_string(), taker.clone());
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
})); }
}
}
return result;
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::from(vec![self.safe_timestamp(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv, Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchOHLCV
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getproductcandles
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades 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 {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]); paginate = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(300)]).await;
}
let mut market: Value = self.market(symbol);
let mut parsedTimeframe: Value = self.safe_integer(self.timeframes.clone(), timeframe.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (parsedTimeframe != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("granularity".into(), parsedTimeframe.clone()); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("granularity".into(), timeframe.clone()); }
}
let mut until: Value = self.safe_value2(params.clone(), Value::Str("until".into()), Value::Str("end".into()), &[]);
params = self.omit(params.clone(), Value::from(vec![Value::Str("until".into())]), &[]);
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start".into(), self.iso8601(since.clone())); }
if (limit == Value::Null) {
// https://docs.pro.coinbase.com/#get-historic-rates
limit = Value::Int(300); // max = 300
} else {
limit = crate::runtime::Math::min(&Value::Int(300), &limit);
}
if (until == Value::Null) {
let mut parsedTimeframeMilliseconds: Value = (match (&(parsedTimeframe), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
if self.is_round_number(mod_val(&since, &parsedTimeframeMilliseconds)).as_bool() == Some(true) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end".into(), self.iso8601(self.sum(&[(match (&(((match (&(limit), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null }))), &(parsedTimeframeMilliseconds)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }), since.clone()]))); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end".into(), self.iso8601(self.sum(&[(match (&(limit), &(parsedTimeframeMilliseconds)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }), since.clone()]))); }
}
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end".into(), self.iso8601(until)); }
}
}
let __ws_arg_11 = self.extend(request, &[params]);
let mut response: Value = self.public_get_products_id_candles(&[__ws_arg_11]).await;
return self.parse_ohlc_vs(self.to_array(response), &[market, timeframe, since, limit]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_time(&[params]).await;
return self.safe_timestamp_k(response, "epoch", &[]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pending".to_string(), Value::Str("open".into()));
m.insert("active".to_string(), Value::Str("open".into()));
m.insert("open".to_string(), Value::Str("open".into()));
m.insert("done".to_string(), Value::Str("closed".into()));
m.insert("canceled".to_string(), Value::Str("canceled".into()));
m.insert("canceling".to_string(), Value::Str("open".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder
//
// {
// "id": "d0c5340b-6d6c-49d9-b567-48c4bfca13d2",
// "price": "0.10000000",
// "size": "0.01000000",
// "product_id": "BTC-USD",
// "side": "buy",
// "stp": "dc",
// "type": "limit",
// "time_in_force": "GTC",
// "post_only": false,
// "created_at": "2016-12-08T20:02:28.53864Z",
// "fill_fees": "0.0000000000000000",
// "filled_size": "0.00000000",
// "executed_value": "0.0000000000000000",
// "status": "pending",
// "settled": false
// }
//
let mut timestamp: Value = self.parse8601(self.safe_string_k(order.clone(), "created_at", &[]));
let mut marketId: Value = self.safe_string_k(order.clone(), "product_id", &[]);
market = self.safe_market(&[marketId, market.clone(), Value::Str("-".into())]);
let mut status: Value = self.parse_order_status(self.safe_string_k(order.clone(), "status", &[]));
let mut doneReason: Option<String> = self.safe_string_k(order.clone(), "done_reason", &[]).as_str().map(str::to_owned);
if (status.as_str() == Some("closed")) && (doneReason.as_deref() == Some("canceled")) {
status = Value::Str("canceled".into());
}
let mut price: Value = self.safe_string_k(order.clone(), "price", &[]);
let mut filled: Value = self.safe_string_k(order.clone(), "filled_size", &[]);
let mut amount: Value = self.safe_string_k(order.clone(), "size", &[filled.clone()]);
let mut cost: Value = self.safe_string_k(order.clone(), "executed_value", &[]);
let mut feeCost: Value = self.safe_number_k(order.clone(), "fill_fees", &[]);
let mut fee: Value = Value::Null;
if (feeCost != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost);
m.insert("currency".to_string(), market.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null));
m.insert("rate".to_string(), Value::Null);
m
});
}
let mut id: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(order.clone(), "side", &[]);
let mut timeInForce: Value = self.safe_string_k(order.clone(), "time_in_force", &[]);
let mut postOnly: Value = self.safe_bool_k(order.clone(), "post_only", &[]);
let mut triggerPrice: Value = self.safe_number_k(order.clone(), "stop_price", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "client_oid", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("clientOrderId".to_string(), clientOrderId);
m.insert("info".to_string(), order);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("status".to_string(), status);
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("type".to_string(), type_var);
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), postOnly);
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("triggerPrice".to_string(), triggerPrice);
m.insert("cost".to_string(), cost);
m.insert("amount".to_string(), amount);
m.insert("filled".to_string(), filled);
m.insert("remaining".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("average".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m
}), &[market]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchOrder
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorder
* @description fetches information on an order made by the user
* @param {string} id the order id
* @param {string} symbol not used by coinbaseexchange fetchOrder
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".into()), Value::Str("client_oid".into()), &[]);
let mut response: Value = Value::Null;
if (clientOrderId == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("id".into(), id); }
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_orders_id(&[__ws_arg_12]).await;
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_oid".into(), clientOrderId); }
params = self.omit(params.clone(), Value::from(vec![Value::Str("clientOrderId".into()), Value::Str("client_oid".into())]), &[]);
let __ws_arg_13 = self.extend(request, &[params]);
response = self.private_get_orders_client_client_oid(&[__ws_arg_13]).await;
}
return self.parse_order(response, &[]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchOrderTrades
* @description fetch all the trades made from a single order
* @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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("order_id".to_string(), id);
m
});
let __ws_arg_14 = self.extend(request, &[params]);
let mut response: Value = self.private_get_fills(&[__ws_arg_14]).await;
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchOrders
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders
* @description fetches information on multiple orders made by the user
* @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 open orders for
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("all".into()));
m
});
let __ws_arg_15 = self.extend(request, &[params]);
return self.fetch_open_orders(&[symbol, since, limit, __ws_arg_15]).await;
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchOpenOrders
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders
* @description fetch all unfilled currently open orders
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch open orders 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_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOpenOrders".into()), Value::Str("paginate".into()), &[]); paginate = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchOpenOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Int(100)]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("product_id".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // default 100
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_date".into(), self.iso8601(since.clone())); }
}
let mut until: Value = self.safe_value2(params.clone(), Value::Str("until".into()), Value::Str("end_date".into()), &[]);
if (until != Value::Null) {
params = self.omit(params.clone(), Value::from(vec![Value::Str("until".into())]), &[]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_date".into(), self.iso8601(until)); }
}
let __ws_arg_16 = self.extend(request, &[params]);
let mut response: Value = self.private_get_orders(&[__ws_arg_16]).await;
return self.parse_orders(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchClosedOrders
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getorders
* @description fetches information on multiple closed orders made by the user
* @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 open orders for
* @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
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("done".into()));
m
});
let __ws_arg_17 = self.extend(request, &[params]);
return self.fetch_open_orders(&[symbol, since, limit, __ws_arg_17]).await;
Value::Null
}
/*
* @method
* @name coinbaseexchange#createOrder
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postorders
* @description create a trade order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), type_var.clone());
m.insert("side".to_string(), side);
m.insert("product_id".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".into()), Value::Str("client_oid".into()), &[]);
if (clientOrderId != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_oid".into(), clientOrderId); }
}
let mut triggerPrice: Value = self.safe_number_n(params.clone(), Value::from(vec![Value::Str("stopPrice".into()), Value::Str("stop_price".into()), Value::Str("triggerPrice".into())]), &[]);
if (triggerPrice != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stop_price".into(), self.price_to_precision(symbol.clone(), triggerPrice)); }
}
let mut timeInForce: Value = self.safe_string2(params.clone(), Value::Str("timeInForce".into()), Value::Str("time_in_force".into()), &[]);
if (timeInForce != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("time_in_force".into(), timeInForce); }
}
let mut postOnly: Value = self.safe_bool2(params.clone(), Value::Str("postOnly".into()), Value::Str("post_only".into()), &[Value::Bool(false)]);
if (postOnly.as_bool() == Some(true)) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("post_only".into(), Value::Bool(true)); }
}
params = self.omit(params.clone(), Value::from(vec![Value::Str("timeInForce".into()), Value::Str("time_in_force".into()), Value::Str("stopPrice".into()), Value::Str("stop_price".into()), Value::Str("clientOrderId".into()), Value::Str("client_oid".into()), Value::Str("postOnly".into()), Value::Str("post_only".into()), Value::Str("triggerPrice".into())]), &[]);
if (type_var.as_str() == Some("limit")) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price.clone())); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("size".into(), self.amount_to_precision(symbol.clone(), amount.clone())); }
} else if (type_var.as_str() == Some("market")) {
let mut cost: Value = self.safe_number2(params.clone(), Value::Str("cost".into()), Value::Str("funds".into()), &[]);
if (cost == Value::Null) {
if (price != Value::Null) {
cost = (match (&(amount), &(price)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
}
} else {
params = self.omit(params.clone(), Value::from(vec![Value::Str("cost".into()), Value::Str("funds".into())]), &[]);
}
if (cost != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("funds".into(), self.cost_to_precision(symbol.clone(), cost)); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("size".into(), self.amount_to_precision(symbol, amount)); }
}
}
let __ws_arg_18 = self.extend(request, &[params]);
let mut response: Value = self.private_post_orders(&[__ws_arg_18]).await;
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#cancelOrder
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorder
* @description cancels an open order
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".into()), Value::Str("client_oid".into()), &[]);
if (clientOrderId == Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("id".into(), id); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("client_oid".into(), clientOrderId.clone()); }
params = self.omit(params.clone(), Value::from(vec![Value::Str("clientOrderId".into()), Value::Str("client_oid".into())]), &[]);
}
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("product_id".into(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)); }; // the request will be more performant if you include it
}
let mut response: Value = Value::Null;
if (clientOrderId == Value::Null) {
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_orders_id(&[__ws_arg_19]).await;
} else {
let __ws_arg_20 = self.extend(request, &[params]);
response = self.private_delete_orders_client_client_oid(&[__ws_arg_20]).await;
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
}), &[]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#cancelAllOrders
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_deleteorders
* @description cancel all open orders
* @param {string} [symbol] unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("product_id".into(), market.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null)); }; // the request will be more performant if you include it
}
let __ws_arg_21 = self.extend(request, &[params]);
let mut response: Value = self.private_delete_orders(&[__ws_arg_21]).await;
return Value::from(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response);
m
}), &[])]);
Value::Null
}
pub async fn fetch_payment_methods(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.private_get_payment_methods(&[params]).await;
Value::Null
}
/*
* @method
* @name coinbaseexchange#withdraw
* @description make a withdrawal
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawpaymentmethod
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postwithdrawcoinbaseaccount
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
{ let __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); params = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
self.check_address(&[address.clone()]);
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("amount".to_string(), amount);
m
});
let mut response: Value = Value::Null;
if (matches!(¶ms, Value::Dict(__d) if __d.contains_key("payment_method_id"))) {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_withdrawals_payment_method(&[__ws_arg_22]).await;
} else if (matches!(¶ms, Value::Dict(__d) if __d.contains_key("coinbase_account_id"))) {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_withdrawals_coinbase_account(&[__ws_arg_23]).await;
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("crypto_address".into(), address); }
if (tag != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("destination_tag".into(), tag); }
}
let __ws_arg_24 = self.extend(request, &[params]);
response = self.private_post_withdrawals_crypto(&[__ws_arg_24]).await;
}
if (response == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" withdraw() error: ".into())).into()), json_stringify(&response))));
}
return self.parse_transaction(response, &[currency]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("transfer".to_string(), Value::Str("transfer".into()));
m.insert("match".to_string(), Value::Str("trade".into()));
m.insert("fee".to_string(), Value::Str("fee".into()));
m.insert("rebate".to_string(), Value::Str("rebate".into()));
m.insert("conversion".to_string(), Value::Str("trade".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
// {
// "id": "12087495079",
// "amount": "-0.0100000000000000",
// "balance": "0.0645419900000000",
// "created_at": "2021-10-28T17:14:32.593168Z",
// "type": "transfer",
// "details": {
// "from": "2f74edf7-1440-4586-86dc-ae58c5693691",
// "profile_transfer_id": "3ef093ad-2482-40d1-8ede-2f89cff5099e",
// "to": "dda99503-4980-4b60-9549-0b770ee51336"
// }
// },
// {
// "id": "11740725774",
// "amount": "-1.7565669701255000",
// "balance": "0.0016490047745000",
// "created_at": "2021-10-22T03:47:34.764122Z",
// "type": "fee",
// "details": {
// "order_id": "ad06abf4-95ab-432a-a1d8-059ef572e296",
// "product_id": "ETH-DAI",
// "trade_id": "1740617"
// }
// }
let mut id: Value = self.safe_string_k(item.clone(), "id", &[]);
let mut amountString: Value = self.safe_string_k(item.clone(), "amount", &[]);
let mut direction: Value = Value::Null;
let mut afterString: Value = self.safe_string_k(item.clone(), "balance", &[]);
let mut beforeString: Value = crate::precise::Precise::stringSub(&afterString, &amountString);
if is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".into()))) {
direction = Value::Str("out".into());
amountString = crate::precise::Precise::stringAbs(&amountString);
} else {
direction = Value::Str("in".into());
}
let mut amount: Value = self.parse_number(amountString, &[]);
let mut after: Value = self.parse_number(afterString, &[]);
let mut before: Value = self.parse_number(beforeString, &[]);
let mut timestamp: Value = self.parse8601(self.safe_string_k(item.clone(), "created_at", &[]));
let mut type_var: Value = self.parse_ledger_entry_type(self.safe_string_k(item.clone(), "type", &[])).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut code: Value = self.safe_currency_code(Value::Null, &[currency.clone()]);
let mut details: Value = self.safe_dict_k(item.clone(), "details", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut account: Value = Value::Null;
let mut referenceAccount: Value = Value::Null;
let mut referenceId: Value = Value::Null;
if (type_var.as_str() == Some("transfer")) {
account = self.safe_string_k(details.clone(), "from", &[]);
referenceAccount = self.safe_string_k(details.clone(), "to", &[]);
referenceId = self.safe_string_k(details.clone(), "profile_transfer_id", &[]);
} else {
referenceId = self.safe_string_k(details, "order_id", &[]);
}
let mut status: Value = Value::Str("ok".into());
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item);
m.insert("id".to_string(), id);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("direction".to_string(), direction);
m.insert("account".to_string(), account);
m.insert("referenceAccount".to_string(), referenceAccount);
m.insert("referenceId".to_string(), referenceId);
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code);
m.insert("amount".to_string(), amount);
m.insert("before".to_string(), before);
m.insert("after".to_string(), after);
m.insert("status".to_string(), status);
m.insert("fee".to_string(), Value::Null);
m
}), &[currency]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountledger
* @param {string} code unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch trades for
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccountledger
if (code == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchLedger() requires a code param".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_accounts(&[]).await;
let mut currency: Value = self.currency(code.clone());
let mut accountsByCurrencyCode: Value = self.index_by(self.accounts.clone(), Value::Str("code".into()));
let mut account: Value = self.safe_dict(accountsByCurrencyCode, code.clone(), &[]);
if (account == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchLedger() could not find account id for ".into())).into()), code)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), account.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (since != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("start_date".into(), self.iso8601(since.clone())); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }; // default 100
}
let mut until: Value = self.safe_value2(params.clone(), Value::Str("until".into()), Value::Str("end_date".into()), &[]);
if (until != Value::Null) {
params = self.omit(params.clone(), Value::from(vec![Value::Str("until".into())]), &[]);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("end_date".into(), self.iso8601(until)); }
}
let __ws_arg_25 = self.extend(request, &[params]);
let mut response: Value = self.private_get_accounts_id_ledger(&[__ws_arg_25]).await;
let mut entries: Value = self.to_array(response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_532: bool = true;
while { if !__for_first_532 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_532 = false; i.as_f64().unwrap_or(f64::NAN) < ((entries.len() as i64) as f64) } {
add_element_to_object(get_value_mut(&mut entries, &i), &Value::Str("currency".into()), code.clone());
}
}
return self.parse_ledger(entries, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchDepositsWithdrawals
* @description fetch history of deposits and withdrawals
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers
* @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
* @param {string} [params.id] account id, when defined, the endpoint used is '/accounts/{account_id}/transfers/' instead of '/transfers/'
* @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
self.load_accounts(&[]).await;
let mut currency: Value = Value::Null;
let mut id: Value = self.safe_string_k(params.clone(), "id", &[]); // account id
if (id == Value::Null) {
if (code != Value::Null) {
currency = self.currency(code.clone());
let mut accountsByCurrencyCode: Value = self.index_by(self.accounts.clone(), Value::Str("code".into()));
let mut account: Value = self.safe_dict(accountsByCurrencyCode, code.clone(), &[]);
if (account == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" fetchDepositsWithdrawals() could not find account id for ".into())).into()), code)));
}
id = account.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if (id != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("id".into(), id.clone()); }
}
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("limit".into(), limit.clone()); }
}
let mut response: Value = Value::Null;
if (id == Value::Null) {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
let mut transfers: Value = self.private_get_transfers(&[__ws_arg_26]).await;
//
// [
// {
// "id": "bee6fd7c-afb2-4e47-8298-671d09997d16",
// "type": "deposit",
// "created_at": "2022-12-21 00:48:45.477503+00",
// "completed_at": null,
// "account_id": "sal3802-36bd-46be-a7b8-alsjf383sldak",
// "user_id": "6382048209f92as392039dlks2",
// "amount": "0.01000000",
// "details": {
// "network": "litecoin",
// "crypto_address": "MKemtnCFUYKsNWaf5EMYMpwSszcXWFDtTY",
// "coinbase_account_id": "fl2b6925-f6ba-403n-jj03-40fl435n430f",
// "coinbase_transaction_id": "63a25bb13cb5cf0001d2cf17", // withdrawals only
// "crypto_transaction_hash": "752f35570736341e2a253f7041a34cf1e196fc56128c900fd03d99da899d94c1",
// "tx_service_transaction_id": "1873249104",
// "coinbase_payment_method_id": ""
// },
// "canceled_at": null,
// "processed_at": null,
// "user_nonce": null,
// "idem": "5e3201b0-e390-5k3k-a913-c32932049242",
// "profile_id": "k3k302a8-c4dk-4f49-9d39-3203923wpk39",
// "currency": "LTC"
// }
// ]
//
response = self.to_array(transfers);
{
let mut i: Value = Value::Int(0);
let mut __for_first_533: bool = true;
while { if !__for_first_533 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_533 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
let mut account_id: Value = self.safe_string(response.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null), Value::Str("account_id".into()), &[]);
let mut account: Value = self.safe_dict(self.accountsById.clone(), account_id, &[]);
let mut codeInner: Value = self.safe_string_k(account, "code", &[]);
add_element_to_object(get_value_mut(&mut response, &i), &Value::Str("currency".into()), codeInner);
}
}
} else {
let __ws_arg_27 = self.extend(request, &[params]);
let mut accountTransfers: Value = self.private_get_accounts_id_transfers(&[__ws_arg_27]).await;
//
// [
// {
// "id": "bee6fd7c-afb2-4e47-8298-671d09997d16",
// "type": "deposit",
// "created_at": "2022-12-21 00:48:45.477503+00",
// "completed_at": null,
// "amount": "0.01000000",
// "details": {
// "network": "litecoin",
// "crypto_address": "MKemtnCFUYKsNWaf5EMYMpwSszcXWFDtTY",
// "coinbase_account_id": "fl2b6925-f6ba-403n-jj03-40fl435n430f",
// "coinbase_transaction_id": "63a25bb13cb5cf0001d2cf17", // withdrawals only
// "crypto_transaction_hash": "752f35570736341e2a253f7041a34cf1e196fc56128c900fd03d99da899d94c1",
// "tx_service_transaction_id": "1873249104",
// "coinbase_payment_method_id": ""
// },
// "canceled_at": null,
// "processed_at": null,
// "user_nonce": null,
// "idem": "5e3201b0-e390-5k3k-a913-c32932049242",
// "profile_id": "k3k302a8-c4dk-4f49-9d39-3203923wpk39",
// "currency": "LTC"
// }
// ]
//
response = self.to_array(accountTransfers);
{
let mut i: Value = Value::Int(0);
let mut __for_first_534: bool = true;
while { if !__for_first_534 { i = (match (&(i), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null }); } __for_first_534 = false; i.as_f64().unwrap_or(f64::NAN) < ((response.len() as i64) as f64) } {
add_element_to_object(get_value_mut(&mut response, &i), &Value::Str("currency".into()), code.clone());
}
}
}
return self.parse_transactions(response, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchDeposits
* @description fetch all deposits made to an account
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __ws_arg_28 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("deposit".into()));
m
}), &[params]);
return self.fetch_deposits_withdrawals(&[code, since, limit, __ws_arg_28]).await;
Value::Null
}
/*
* @method
* @name coinbaseexchange#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_gettransfers
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_getaccounttransfers
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_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
}));
let __ws_arg_29 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("withdraw".into()));
m
}), &[params]);
return self.fetch_deposits_withdrawals(&[code, since, limit, __ws_arg_29]).await;
Value::Null
}
pub fn parse_transaction_status(&self, mut transaction: Value) -> Value {
let __transaction_empty = indexmap::IndexMap::new();
let transaction = transaction.as_map().unwrap_or(&__transaction_empty);
let mut canceled: Value = (match transaction.get("canceled_at") { Some(__v) if !matches!(__v, Value::Null) && !matches!(__v, Value::Str(__s) if __s.is_empty()) => __v.clone(), _ => Value::Null });
if (canceled != Value::Null) && (canceled != Value::Null) {
return Value::Str("canceled".into());
}
let mut processed: Value = (match transaction.get("processed_at") { Some(__v) if !matches!(__v, Value::Null) && !matches!(__v, Value::Str(__s) if __s.is_empty()) => __v.clone(), _ => Value::Null });
let mut completed: Value = (match transaction.get("completed_at") { Some(__v) if !matches!(__v, Value::Null) && !matches!(__v, Value::Str(__s) if __s.is_empty()) => __v.clone(), _ => Value::Null });
if (completed != Value::Null) && (completed != Value::Null) {
return Value::Str("ok".into());
} else if (processed != Value::Null) && (processed != Value::Null) {
return Value::Str("failed".into());
} else {
return Value::Str("pending".into());
}
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// privateGetTransfers
//
// [
// {
// "id": "bee6fd7c-afb2-4e47-8298-671d09997d16",
// "type": "deposit",
// "created_at": "2022-12-21 00:48:45.477503+00",
// "completed_at": null,
// "account_id": "sal3802-36bd-46be-a7b8-alsjf383sldak", // only from privateGetTransfers
// "user_id": "6382048209f92as392039dlks2", // only from privateGetTransfers
// "amount": "0.01000000",
// "details": {
// "network": "litecoin",
// "crypto_address": "MKemtnCFUYKsNWaf5EMYMpwSszcXWFDtTY",
// "coinbase_account_id": "fl2b6925-f6ba-403n-jj03-40fl435n430f",
// "coinbase_transaction_id": "63a25bb13cb5cf0001d2cf17", // withdrawals only
// "crypto_transaction_hash": "752f35570736341e2a253f7041a34cf1e196fc56128c900fd03d99da899d94c1",
// "tx_service_transaction_id": "1873249104",
// "coinbase_payment_method_id": ""
// },
// "canceled_at": null,
// "processed_at": null,
// "user_nonce": null,
// "idem": "5e3201b0-e390-5k3k-a913-c32932049242",
// "profile_id": "k3k302a8-c4dk-4f49-9d39-3203923wpk39",
// "currency": "LTC"
// }
// ]
//
let mut details: Value = self.safe_dict_k(transaction.clone(), "details", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.parse8601(self.safe_string_k(transaction.clone(), "created_at", &[]));
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency]);
let mut amount: Value = self.safe_number_k(transaction.clone(), "amount", &[]);
let mut type_var: Value = self.safe_string_k(transaction.clone(), "type", &[]);
let mut address: Value = self.safe_string_k(details.clone(), "crypto_address", &[]);
address = self.safe_string_k(transaction.clone(), "crypto_address", &[address.clone()]);
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("rate".to_string(), Value::Null);
m
});
if (type_var.as_str() == Some("withdraw")) {
type_var = Value::Str("withdrawal".into());
address = self.safe_string_k(details.clone(), "sent_to_address", &[address.clone()]);
let mut feeCost: Value = self.safe_number_k(details.clone(), "fee", &[]);
if (feeCost != Value::Null) {
if (amount != Value::Null) {
amount = (match (&(amount), &(feeCost)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
}
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("cost".into(), feeCost); }
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("currency".into(), code.clone()); }
}
}
let mut networkId: Value = self.safe_string_k(details.clone(), "network", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string_k(transaction.clone(), "id", &[]));
m.insert("txid".to_string(), self.safe_string_k(details.clone(), "crypto_transaction_hash", &[]));
m.insert("type".to_string(), type_var);
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), self.network_id_to_code(&[networkId, code]));
m.insert("amount".to_string(), amount);
m.insert("status".to_string(), self.parse_transaction_status(transaction.clone()));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("address".to_string(), address);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("addressTo".to_string(), self.safe_string_k(details.clone(), "crypto_address", &[]));
m.insert("tag".to_string(), self.safe_string_k(details, "destination_tag", &[]));
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("updated".to_string(), self.parse8601(self.safe_string_k(transaction, "processed_at", &[])));
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Bool(false));
m.insert("fee".to_string(), fee);
m
});
Value::Null
}
/*
* @method
* @name coinbaseexchange#createDepositAddress
* @description create a currency deposit address
* @see https://docs.cloud.coinbase.com/exchange/reference/exchangerestapi_postcoinbaseaccountaddresses
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut accounts: Value = self.safe_value_k(self.options.clone(), "coinbaseAccounts", &[]);
if (accounts == Value::Null) {
accounts = self.private_get_coinbase_accounts(&[]).await;
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("coinbaseAccounts".into(), accounts.clone()); }; // cache it
{ let __be_tmp = self.index_by(accounts, Value::Str("currency".into())); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("coinbaseAccountsByCurrencyId".into(), __be_tmp); } }
}
let mut currencyId: Value = currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null);
let mut account: Value = self.safe_dict(self.options.as_map().and_then(|__m| __m.get("coinbaseAccountsByCurrencyId")).cloned().unwrap_or(Value::Null), currencyId.clone(), &[]);
if (account == Value::Null) {
panic!("{}", crate::exchange_errors::invalid_address(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" createDepositAddress() could not find currency code ".into())).into()), code).into()), Value::Str(" with id = ".into())).into()), currencyId).into()), Value::Str(" in this.options['coinbaseAccountsByCurrencyId']".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), account.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_30 = self.extend(request, &[params]);
let mut response: Value = self.private_post_coinbase_accounts_id_addresses(&[__ws_arg_30]).await;
let mut address: Value = self.safe_string_k(response.clone(), "address", &[]);
let mut tag: Value = self.safe_string_k(response.clone(), "destination_tag", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("address".to_string(), self.check_address(&[address]));
m.insert("network".to_string(), Value::Null);
m.insert("tag".to_string(), tag);
m.insert("info".to_string(), response);
m
});
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".into()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut request: Value = Value::Str(format!("{}{}", Value::Str("/".into()), self.implode_params(path.clone(), params.clone())).into());
let mut query: Value = self.omit(params, self.extract_params(path), &[]);
if (method.as_str() == Some("GET")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
request = Value::Str(format!("{}{}", request, Value::Str(format!("{}{}", Value::Str("?".into()), self.urlencode(query.clone(), &[])).into())).into());
}
}
let mut url: Value = Value::Str(format!("{}{}", self.implode_hostname(get_value(&self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), &api)), request).into());
if (api.as_str() == Some("private")) {
self.check_required_credentials(&[]);
let mut nonce: Value = to_string_val(&self.nonce());
let mut payload: Value = Value::Str("".into());
if (method.as_str() != Some("GET")) {
if ((object_keys(&query).len() as i64) as f64) > ((0i64) as f64) {
body = json_stringify(&query);
payload = body.clone();
}
}
let mut what: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", nonce, method).into()), request).into()), payload).into());
let mut secret: Value = Value::Null;
let _try_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
secret = self.base64_to_binary(self.secret.clone(), &[]);
#[allow(unreachable_code)] { Value::Null }}));
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
panic!("{}", crate::exchange_errors::authentication_error(format!("{}{}", self.id.clone(), Value::Str(" sign() invalid base64 secret".into()))));
}
let mut signature: Value = self.hmac(self.encode(what), secret.clone(), Value::Str("sha256".into()), &[Value::Str("base64".into())]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CB-ACCESS-KEY".to_string(), self.apiKey.clone());
m.insert("CB-ACCESS-SIGN".to_string(), signature);
m.insert("CB-ACCESS-TIMESTAMP".to_string(), nonce);
m.insert("CB-ACCESS-PASSPHRASE".to_string(), self.password.clone());
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), body);
m.insert("headers".to_string(), headers);
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (code.as_f64() == Some(400.0)) || (code.as_f64() == Some(404.0)) {
if (get_value(&body, &Value::Int(0)).as_str() == Some("{")) {
let mut message: Value = self.safe_string_k(response, "message", &[]);
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), message).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body)));
}
return Value::Null;
Value::Null
}
pub async fn request(&mut self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".into()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut config = get_arg(optional_args, 5, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.fetch2(path, &[api, method, params, headers, body, config]).await;
if !matches!(&response, Value::Str(_)) {
if (in_op(&response, &Value::Str("message".into()))) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), json_stringify(&response))));
}
}
return response;
Value::Null
}
}