// PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
// https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
#![allow(unused, non_snake_case, clippy::all)]
use crate::Value;
use crate::get_value;
use crate::runtime::*;
// Base methods are now trait methods (review #1: static dispatch). Bring the
// traits into scope so `self.market(...)`, `self.safe_market(...)`,
// `self.load_markets(...)`, … on this Core resolve to the base defaults.
use crate::exchange_generated::ExchangeBase;
use crate::exchange::ExchangeRuntime;
pub struct PoloniexCore {
pub exchange: crate::exchange::Exchange,
}
impl PoloniexCore {
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 = PoloniexCore::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 PoloniexCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_position(self, position, &[market.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_currency(self, currency)
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_leverage(self, leverage, &[market.clone()])
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::parse_deposit_withdraw_fee(self, fee, &[currency.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::sign(self, path, &[api.clone(), method.clone(), params.clone(), headers.clone(), body.clone()])
}
fn handle_errors(&self, code: crate::Value, reason: crate::Value, url: crate::Value, method: crate::Value, headers: crate::Value, body: crate::Value, response: crate::Value, request_headers: crate::Value, request_body: crate::Value) -> crate::Value {
// Forward to the inherent method on PoloniexCore.
PoloniexCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for PoloniexCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_deposit_address" => self.create_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_status" => self.fetch_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position_mode" => self.fetch_position_mode(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_swap_markets" => self.fetch_swap_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transactions_helper" => self.fetch_transactions_helper(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).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)),
"load_markets" => self.load_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"modify_margin_helper" => self.modify_margin_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"nonce" => self.nonce(),
"order_request" => self.order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), &args.get(5..).unwrap_or(&[]).to_vec()[..]),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address_special" => self.parse_deposit_address_special(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_deposit_withdraw_fees" => self.parse_deposit_withdraw_fees(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_orders" => self.parse_open_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null)),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type" => self.parse_order_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_spot_market" => self.parse_spot_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_swap_market" => self.parse_swap_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"prepare_request_for_deposit_address" => self.prepare_request_for_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for PoloniexCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for PoloniexCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl PoloniexCore {
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("poloniex".to_string()));
m.insert("name".to_string(), Value::Str("Poloniex".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("US".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(5));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(true));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Null);
m.insert("createDepositAddress".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Null);
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchDepositWithdrawFees".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::Null);
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Null);
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLiquidations".to_string(), Value::Null);
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenOrder".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("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactions".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("MINUTE_1".to_string()));
m.insert("5m".to_string(), Value::Str("MINUTE_5".to_string()));
m.insert("10m".to_string(), Value::Str("MINUTE_10".to_string()));
m.insert("15m".to_string(), Value::Str("MINUTE_15".to_string()));
m.insert("30m".to_string(), Value::Str("MINUTE_30".to_string()));
m.insert("1h".to_string(), Value::Str("HOUR_1".to_string()));
m.insert("2h".to_string(), Value::Str("HOUR_2".to_string()));
m.insert("4h".to_string(), Value::Str("HOUR_4".to_string()));
m.insert("6h".to_string(), Value::Str("HOUR_6".to_string()));
m.insert("12h".to_string(), Value::Str("HOUR_12".to_string()));
m.insert("1d".to_string(), Value::Str("DAY_1".to_string()));
m.insert("3d".to_string(), Value::Str("DAY_3".to_string()));
m.insert("1w".to_string(), Value::Str("WEEK_1".to_string()));
m.insert("1M".to_string(), Value::Str("MONTH_1".to_string()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/1294454/27766817-e9456312-5ee6-11e7-9b3c-b628ca5626a5.jpg".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("https://api.poloniex.com".to_string()));
m.insert("swap".to_string(), Value::Str("https://api.poloniex.com".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("https://sand-spot-api-gateway.poloniex.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.poloniex.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://api-docs.poloniex.com/spot/".to_string()));
m.insert("fees".to_string(), Value::Str("https://poloniex.com/fees".to_string()));
m.insert("referral".to_string(), Value::Str("https://poloniex.com/signup?c=UBFZJRPJ".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("markets/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v2/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v2/currencies/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("timestamp".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/{symbol}/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/markPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/{symbol}/markPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/{symbol}/markPriceComponents".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/{symbol}/orderBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/{symbol}/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/{symbol}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("markets/ticker24h".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("markets/{symbol}/ticker24h".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("markets/collateralInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/{currency}/collateralInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("markets/borrowRatesInfo".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("accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("accounts/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("accounts/{id}/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("accounts/activity".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("accounts/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("accounts/transfer/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("feeinfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("accounts/interest/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("subaccounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("subaccounts/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("subaccounts/{id}/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("subaccounts/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("subaccounts/transfer/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("wallets/addresses".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("wallets/addresses/{currency}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("wallets/activity".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("margin/accountMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("margin/borrowStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("margin/maxSize".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("orders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("orders/killSwitchStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("smartorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("smartorders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("orders/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("smartorders/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("orders/{id}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accounts/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("subaccounts/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("wallets/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("wallets/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v2/wallets/withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("orders/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("orders/killSwitch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("smartorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("orders/cancelByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("smartorders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("smartorders/cancelByIds".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("smartorders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("smartorders/{id}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m
}));
m.insert("swapPublic".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("v3/market/allInstruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/orderBook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v3/market/indexPriceCandlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v3/market/premiumIndexCandlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v3/market/markPriceCandlesticks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v3/market/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/liquidationOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/markPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/indexPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/indexPriceComponents".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/fundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/openInterest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/insurance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("v3/market/riskLimit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m
}));
m
}));
m.insert("swapPrivate".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("v3/account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("v3/account/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/order/opens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/order/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/position/opens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/position/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/position/leverages".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/position/mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v3/trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("v3/trade/position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/positionAll".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("v3/position/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/position/mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/position/margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v3/trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("v3/trade/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("v3/trade/allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("get".to_string()));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0009".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0009".to_string()), &[]));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("AIR".to_string(), Value::Str("AirCoin".to_string()));
m.insert("APH".to_string(), Value::Str("AphroditeCoin".to_string()));
m.insert("BCC".to_string(), Value::Str("BTCtalkcoin".to_string()));
m.insert("BCHABC".to_string(), Value::Str("BCHABC".to_string()));
m.insert("BDG".to_string(), Value::Str("Badgercoin".to_string()));
m.insert("BTM".to_string(), Value::Str("Bitmark".to_string()));
m.insert("CON".to_string(), Value::Str("Coino".to_string()));
m.insert("ETHTRON".to_string(), Value::Str("ETH".to_string()));
m.insert("GOLD".to_string(), Value::Str("GoldEagles".to_string()));
m.insert("GPUC".to_string(), Value::Str("GPU".to_string()));
m.insert("HOT".to_string(), Value::Str("Hotcoin".to_string()));
m.insert("ITC".to_string(), Value::Str("Information Coin".to_string()));
m.insert("KEY".to_string(), Value::Str("KEYCoin".to_string()));
m.insert("MASK".to_string(), Value::Str("NFTX Hashmasks Index".to_string()));
m.insert("MEME".to_string(), Value::Str("Degenerator Meme".to_string()));
m.insert("PLX".to_string(), Value::Str("ParallaxCoin".to_string()));
m.insert("REPV2".to_string(), Value::Str("REP".to_string()));
m.insert("STR".to_string(), Value::Str("XLM".to_string()));
m.insert("SOC".to_string(), Value::Str("SOCC".to_string()));
m.insert("TRADE".to_string(), Value::Str("Unitrade".to_string()));
m.insert("TRXETH".to_string(), Value::Str("TRX".to_string()));
m.insert("XAP".to_string(), Value::Str("API Coin".to_string()));
m.insert("USDTBSC".to_string(), Value::Str("USDT".to_string()));
m.insert("USDTTRON".to_string(), Value::Str("USDT".to_string()));
m.insert("USDTETH".to_string(), Value::Str("USDT".to_string()));
m.insert("UST".to_string(), Value::Str("USTC".to_string()));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("spot".to_string()));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(true));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRX".to_string()));
m.insert("TRX".to_string(), Value::Str("TRX".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("TRX".to_string(), Value::Str("TRC20".to_string()));
m.insert("TRON".to_string(), Value::Str("TRC20".to_string()));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Float(0.0001));
m.insert("ETH".to_string(), Value::Float(0.0001));
m.insert("USDT".to_string(), Value::Int(1));
m.insert("TRX".to_string(), Value::Int(100));
m.insert("BNB".to_string(), Value::Float(0.06));
m.insert("USDC".to_string(), Value::Int(1));
m.insert("USDJ".to_string(), Value::Int(1));
m.insert("TUSD".to_string(), Value::Float(0.0001));
m.insert("DAI".to_string(), Value::Int(1));
m.insert("PAX".to_string(), Value::Int(1));
m.insert("BUSD".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("spot".to_string()));
m.insert("future".to_string(), Value::Str("futures".to_string()));
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exchange".to_string(), Value::Str("spot".to_string()));
m.insert("futures".to_string(), Value::Str("future".to_string()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(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(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(20));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(2000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(500));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m.insert("forContracts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
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(false));
m.insert("hedged".to_string(), Value::Bool(true));
m.insert("stpMode".to_string(), Value::Bool(true));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(10));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(100));
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::Null);
m.insert("daysBackCanceled".to_string(), divide(&Value::Int(1), &Value::Int(6)));
m.insert("untilDays".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(100));
m.insert("untilDays".to_string(), Value::Int(90));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forContracts".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forContracts".to_string()));
m
}));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forContracts".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("forContracts".to_string()));
m
}));
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("500".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("603".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("601".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("415".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("602".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("21604".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("21600".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("21605".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("21102".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21100".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("21704".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("21700".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("21705".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("21707".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21708".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("21601".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("21711".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21709".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("250000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("250001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("250002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("250003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("250004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("250005".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("250008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("250012".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21110".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10040".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("10060".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("10020".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("10041".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("21340".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("21341".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21342".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21343".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21351".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("21352".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("21353".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("21354".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("21359".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("21360".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("24106".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("24201".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("21301".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("21302".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21304".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21305".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("21307".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21309".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21310".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21311".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21312".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21314".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21315".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21317".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21319".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21320".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21321".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21322".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21324".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("21327".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21328".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21330".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21335".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21336".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21337".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21344".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21345".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21346".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21348".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21347".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21349".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21350".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("21355".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("21356".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("21721".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("24101".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("24102".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("24103".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("24104".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("24105".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("25020".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25003".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("25004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25005".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("25006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25009".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("25010".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("25011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("25012".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("25013".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("25014".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("25015".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("25016".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("25017".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("25018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("25019".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("820181".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("820201".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("830111".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("250".to_string(), Value::Str("DuplicateOrderId".to_string()).clone());
m.insert("400".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("403".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("404".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("429".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("503".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("1000".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("1002".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("1003".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("10000".to_string(), Value::Str("MarketClosed".to_string()).clone());
m.insert("10001".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("10002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10005".to_string(), Value::Str("MarketClosed".to_string()).clone());
m.insert("10006".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("10007".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("10008".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("10009".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("10010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10012".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10013".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10015".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("10016".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10018".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("10019".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("11003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("11004".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("11008".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("12004".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("21001".to_string(), Value::Str("OperationRejected".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
})]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// spot:
//
// [
// [
// "22814.01",
// "22937.42",
// "22832.57",
// "22937.42",
// "3916.58764051",
// "0.171199",
// "2982.64647063",
// "0.130295",
// 33,
// 0,
// "22877.449915304470460711",
// "MINUTE_5",
// 1659664800000,
// 1659665099999
// ]
// ]
//
// contract:
//
// [
// "84207.02",
// "84320.85",
// "84207.02",
// "84253.83",
// "3707.5395",
// "44",
// "14",
// "1740770040000",
// "1740770099999",
// ],
//
let mut ohlcvLength: Value = get_array_length(&ohlcv);
let mut isContract: bool = is_equal(&ohlcvLength, &Value::Int(9));
if is_true(&isContract) {
return Value::List(vec![self.safe_integer(ohlcv.clone(), Value::Int(7), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
}
return Value::List(vec![self.safe_integer(ohlcv.clone(), Value::Int(12), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name poloniex#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://api-docs.poloniex.com/spot/api/public/market-data#candles
* @see https://api-docs.poloniex.com/v3/futures/api/market/get-kline-data
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(500)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut keyStart: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("startTime".to_string()), Value::Str("sTime".to_string()));
let mut keyEnd: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("endTime".to_string()), Value::Str("eTime".to_string()));
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &keyStart, since.clone());
}
if !is_equal(&limit, &Value::Null) {
// limit should in between 100 and 500
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(keyEnd.clone(), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut responseRaw: Value = self.swap_public_get_v3_market_candles(&[__ws_arg_0]).await;
//
// {
// code: "200",
// msg: "Success",
// data: [
// [
// "84207.02",
// "84320.85",
// "84207.02",
// "84253.83",
// "3707.5395",
// "44",
// "14",
// "1740770040000",
// "1740770099999",
// ],
//
let mut data: Value = self.safe_list_k(responseRaw.clone(), "data", &[]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_markets_symbol_candles(&[__ws_arg_1]).await;
//
// [
// [
// "22814.01",
// "22937.42",
// "22832.57",
// "22937.42",
// "3916.58764051",
// "0.171199",
// "2982.64647063",
// "0.130295",
// 33,
// 0,
// "22877.449915304470460711",
// "MINUTE_5",
// 1659664800000,
// 1659665099999
// ]
// ]
//
let mut candles: Value = Value::List(vec![]);
if is_true(&Value::Bool(is_array(&response))) {
candles = response.clone();
}
return self.parse_ohlc_vs(candles.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub async fn load_markets(&mut self, optional_args: &[Value]) -> Value {
let mut reload = get_arg(optional_args, 0, Value::Bool(false));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut markets: Value = self.super_load_markets(reload.clone(), params.clone()).await;
let mut currenciesByNumericId: Value = self.safe_value_k(self.options.clone(), "currenciesByNumericId", &[]);
if is_true(&(is_equal(¤ciesByNumericId, &Value::Null))) || is_true(&reload) {
{ let __be_tmp = self.index_by(self.currencies.clone(), Value::Str("numericId".to_string())); add_element_to_object(&mut self.options, &Value::Str("currenciesByNumericId".to_string()), __be_tmp); };
}
return markets;
Value::Null
}
/*
* @method
* @name poloniex#fetchMarkets
* @description retrieves data on all markets for poloniex
* @see https://api-docs.poloniex.com/spot/api/public/reference-data#symbol-information
* @see https://api-docs.poloniex.com/v3/futures/api/market/get-all-product-info
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut promises: Value = Value::List(vec![self.fetch_spot_markets(&[params.clone()]).await, self.fetch_swap_markets(&[params.clone()]).await]);
let mut results: Value = promise_all(&promises).await;
return self.array_concat(get_value(&results, &Value::Int(0)), get_value(&results, &Value::Int(1)));
Value::Null
}
pub async fn fetch_spot_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 markets: Value = self.public_get_markets(&[params.clone()]).await;
return self.parse_markets(markets.clone());
Value::Null
}
pub async fn fetch_swap_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// do similar as spot per https://api-docs.poloniex.com/v3/futures/api/market/get-product-info
let mut response: Value = self.swap_public_get_v3_market_all_instruments(&[params.clone()]).await;
//
// {
// "code": "200",
// "msg": "Success",
// "data": [
// {
// "symbol": "BNB_USDT_PERP",
// "bAsset": ".PBNBUSDT",
// "bCcy": "BNB",
// "qCcy": "USDT",
// "visibleStartTime": "1620390600000",
// "tradableStartTime": "1620390600000",
// "sCcy": "USDT",
// "tSz": "0.001",
// "pxScale": "0.001,0.01,0.1,1,10",
// "lotSz": "1",
// "minSz": "1",
// "ctVal": "0.1",
// "status": "OPEN",
// "oDate": "1620287590000",
// "maxPx": "1000000",
// "minPx": "0.001",
// "maxQty": "1000000",
// "minQty": "1",
// "maxLever": "50",
// "lever": "10",
// "ctType": "LINEAR",
// "alias": "",
// "iM": "0.02",
// "mM": "0.0115",
// "mR": "2000",
// "buyLmt": "",
// "sellLmt": "",
// "ordPxRange": "0.05",
// "marketMaxQty": "2800",
// "limitMaxQty": "1000000"
// },
//
let mut markets: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_markets(markets.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
if is_true(&Value::Bool(in_op(&market, &Value::Str("ctType".to_string())))) {
return self.parse_swap_market(market.clone());
} else {
return self.parse_spot_market(market.clone());
}
Value::Null
}
pub fn parse_spot_market(&self, mut market: Value) -> Value {
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCurrencyName", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCurrencyName", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut state: Value = self.safe_string_k(market.clone(), "state", &[]);
let mut active: Value = Value::Bool(is_equal(&state, &Value::Str("NORMAL".to_string())));
let mut symbolTradeLimit: Value = self.safe_value_k(market.clone(), "symbolTradeLimit", &[]);
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), add(&add(&base, &Value::Str("/".to_string())), "e));
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), Value::Null);
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".to_string()));
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("active".to_string(), active.clone());
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("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(), self.parse_number(self.parse_precision(&[self.safe_string_k(symbolTradeLimit.clone(), "quantityScale", &[])]), &[]));
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(symbolTradeLimit.clone(), "priceScale", &[])]), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(symbolTradeLimit.clone(), "minQuantity", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(symbolTradeLimit.clone(), "minAmount", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer_k(market.clone(), "tradableStartTime", &[]));
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
pub fn parse_swap_market(&self, mut market: Value) -> Value {
//
// {
// "symbol": "BNB_USDT_PERP",
// "bAsset": ".PBNBUSDT",
// "bCcy": "BNB",
// "qCcy": "USDT",
// "visibleStartTime": "1620390600000",
// "tradableStartTime": "1620390600000",
// "sCcy": "USDT",
// "tSz": "0.001",
// "pxScale": "0.001,0.01,0.1,1,10",
// "lotSz": "1",
// "minSz": "1",
// "ctVal": "0.1",
// "status": "OPEN",
// "oDate": "1620287590000",
// "maxPx": "1000000",
// "minPx": "0.001",
// "maxQty": "1000000",
// "minQty": "1",
// "maxLever": "50",
// "lever": "10",
// "ctType": "LINEAR",
// "alias": "",
// "iM": "0.02",
// "mM": "0.0115",
// "mR": "2000",
// "buyLmt": "",
// "sellLmt": "",
// "ordPxRange": "0.05",
// "marketMaxQty": "2800",
// "limitMaxQty": "1000000"
// },
//
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "bCcy", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "qCcy", &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "sCcy", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut active: Value = Value::Bool(is_equal(&status, &Value::Str("OPEN".to_string())));
let mut linear: Value = Value::Bool(is_equal(&get_value(&market, &Value::Str("ctType".to_string())), &Value::Str("LINEAR".to_string())));
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
if is_true(&linear) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &settle));
} else {
// actually, exchange does not have any inverse future now
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &base));
}
let mut alias: Value = self.safe_string_k(market.clone(), "alias", &[]);
let mut type_var: Value = Value::Str("swap".to_string());
if !is_equal(&alias, &Value::Null) {
type_var = Value::Str("future".to_string());
}
let mut marketType: Value = ternary(is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))), Value::Str("future".to_string()), Value::Str("swap".to_string()));
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), marketType.clone());
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string()))));
m.insert("future".to_string(), Value::Bool(is_equal(&type_var, &Value::Str("future".to_string()))));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active.clone());
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), linear.clone());
m.insert("inverse".to_string(), Value::Bool(!is_true(&linear)));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "ctVal", &[]));
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "tFee", &[]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "mFee", &[]));
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(market.clone(), "lotSz", &[]));
m.insert("price".to_string(), self.safe_number_k(market.clone(), "tSz", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minSz", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "limitMaxQty", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(market.clone(), "minPx", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxPx", &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxLever", &[]));
m.insert("min".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer_k(market.clone(), "oDate", &[]));
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name poloniex#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://api-docs.poloniex.com/spot/api/public/reference-data#system-timestamp
* @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_timestamp(&[params.clone()]).await;
return self.safe_integer_k(response.clone(), "serverTime", &[]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// spot:
//
// {
// "symbol" : "BTC_USDT",
// "open" : "26053.33",
// "low" : "26053.33",
// "high" : "26798.02",
// "close" : "26447.58",
// "quantity" : "6116.210188",
// "amount" : "161082122.88450926",
// "tradeCount" : "134709",
// "startTime" : "1692784440000",
// "closeTime" : "1692870839630",
// "displayName" : "BTC/USDT",
// "dailyChange" : "0.0151",
// "bid" : "26447.57",
// "bidQuantity" : "0.016313",
// "ask" : "26447.58",
// "askQuantity" : "0.068307",
// "ts" : "1692870845446",
// "markPrice" : "26444.11"
// }
//
// swap:
//
// {
// "s": "XRP_USDT_PERP",
// "o": "2.0503",
// "l": "2.0066",
// "h": "2.216",
// "c": "2.1798",
// "qty": "21090",
// "amt": "451339.65",
// "tC": "3267",
// "sT": "1740736380000",
// "cT": "1740822777559",
// "dN": "XRP/USDT/PERP",
// "dC": "0.0632",
// "bPx": "2.175",
// "bSz": "3",
// "aPx": "2.1831",
// "aSz": "111",
// "mPx": "2.1798",
// "iPx": "2.1834"
// },
//
let mut timestamp: Value = self.safe_integer2(ticker.clone(), Value::Str("ts".to_string()), Value::Str("cT".to_string()), &[]);
let mut marketId: Value = self.safe_string2(ticker.clone(), Value::Str("symbol".to_string()), Value::Str("s".to_string()), &[]);
market = self.safe_market(&[marketId.clone()]);
let mut baseVolume: Value = self.safe_string2(ticker.clone(), Value::Str("quantity".to_string()), Value::Str("qty".to_string()), &[]);
if is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))) && is_true(&(!is_equal(&get_value(&market, &Value::Str("contractSize".to_string())), &Value::Null))) {
// 'quantity' counts contracts, and a ticker reports base volume
baseVolume = crate::precise::Precise::stringMul(&baseVolume, &self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string()))));
}
let mut relativeChange: Value = self.safe_string2(ticker.clone(), Value::Str("dailyChange".to_string()), Value::Str("dc".to_string()), &[]);
let mut percentage: Value = crate::precise::Precise::stringMul(&relativeChange, &Value::Str("100".to_string()));
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string2(ticker.clone(), Value::Str("high".to_string()), Value::Str("h".to_string()), &[]));
m.insert("low".to_string(), self.safe_string2(ticker.clone(), Value::Str("low".to_string()), Value::Str("l".to_string()), &[]));
m.insert("bid".to_string(), self.safe_string2(ticker.clone(), Value::Str("bid".to_string()), Value::Str("bPx".to_string()), &[]));
m.insert("bidVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("bidQuantity".to_string()), Value::Str("bSz".to_string()), &[]));
m.insert("ask".to_string(), self.safe_string2(ticker.clone(), Value::Str("ask".to_string()), Value::Str("aPx".to_string()), &[]));
m.insert("askVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("askQuantity".to_string()), Value::Str("aSz".to_string()), &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string2(ticker.clone(), Value::Str("open".to_string()), Value::Str("o".to_string()), &[]));
m.insert("close".to_string(), self.safe_string2(ticker.clone(), Value::Str("close".to_string()), Value::Str("c".to_string()), &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), percentage.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("amount".to_string()), Value::Str("amt".to_string()), &[]));
m.insert("markPrice".to_string(), self.safe_string2(ticker.clone(), Value::Str("markPrice".to_string()), Value::Str("mPx".to_string()), &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "iPx", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://api-docs.poloniex.com/spot/api/public/market-data#ticker
* @see https://api-docs.poloniex.com/v3/futures/api/market/get-market-info
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(false)]);
let mut symbolsLength: Value = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(0)) {
market = self.market(get_value(&symbols, &Value::Int(0)));
if is_equal(&symbolsLength, &Value::Int(1)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("swap".to_string())) {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut responseRaw: Value = self.swap_public_get_v3_market_tickers(&[__ws_arg_2]).await;
//
// {
// "code": "200",
// "msg": "Success",
// "data": [
// {
// "s": "XRP_USDT_PERP",
// "o": "2.0503",
// "l": "2.0066",
// "h": "2.216",
// "c": "2.1798",
// "qty": "21090",
// "amt": "451339.65",
// "tC": "3267",
// "sT": "1740736380000",
// "cT": "1740822777559",
// "dN": "XRP/USDT/PERP",
// "dC": "0.0632",
// "bPx": "2.175",
// "bSz": "3",
// "aPx": "2.1831",
// "aSz": "111",
// "mPx": "2.1798",
// "iPx": "2.1834"
// },
//
let mut data: Value = self.safe_list_k(responseRaw.clone(), "data", &[]);
return self.parse_tickers(data.clone(), &[symbols.clone()]);
}
let mut response: Value = self.public_get_markets_ticker24h(&[params.clone()]).await;
return self.parse_tickers(response.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://api-docs.poloniex.com/spot/api/public/reference-data#currencyv2-information
* @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_v2_currencies(&[params.clone()]).await;
return self.parse_currencies(response.clone());
Value::Null
}
pub fn parse_currency(&self, mut currency: Value) -> Value {
let mut entry: Value = currency.clone();
let mut id: Value = self.safe_string_k(entry.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut chains: Value = self.safe_list_k(entry.clone(), "networkList", &[Value::List(vec![])]);
let mut chainsLength: Value = get_array_length(&chains);
{
let mut j: Value = Value::Int(0);
let mut __for_first_1054: bool = true;
while { if !__for_first_1054 { j = add(&j, &Value::Int(1)); } __for_first_1054 = false; is_less_than(&j, &chainsLength) } {
let mut chain: Value = get_value(&chains, &j);
let mut chain: Value = get_value(&chains, &j);
let mut chainId: Value = self.safe_string_k(chain.clone(), "blockchain", &[]);
let mut networkCode: Value = self.network_id_to_code(&[chainId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), chainId.clone());
m.insert("name".to_string(), Value::Null);
m.insert("code".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), self.safe_number_k(chain.clone(), "withdrawFee", &[]));
m.insert("deposit".to_string(), self.safe_bool_k(chain.clone(), "depositEnable", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(chain.clone(), "withdrawalEnable", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(chain.clone(), "decimals", &[])]), &[]));
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(chain.clone(), "withdrawMin", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("name".to_string(), self.safe_string_k(entry.clone(), "name", &[]));
m.insert("code".to_string(), code.clone());
m.insert("type".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("info".to_string(), entry.clone());
m.insert("networks".to_string(), networks.clone());
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("active".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Null);
m.insert("margin".to_string(), self.safe_bool_k(entry.clone(), "supportBorrow", &[]));
m
}));
Value::Null
}
/*
* @method
* @name poloniex#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://api-docs.poloniex.com/spot/api/public/market-data#ticker
* @see https://api-docs.poloniex.com/v3/futures/api/market/get-market-info
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let mut tickers: Value = self.fetch_tickers(&[Value::List(vec![get_value(&market, &Value::Str("symbol".to_string()))]), params.clone()]).await;
return self.safe_dict(tickers.clone(), symbol.clone(), &[]);
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_markets_symbol_ticker24h(&[__ws_arg_3]).await;
return self.parse_ticker(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades
//
// spot:
//
// {
// "id" : "60014521",
// "price" : "23162.94",
// "quantity" : "0.00009",
// "amount" : "2.0846646",
// "takerSide" : "SELL",
// "ts" : 1659684602042,
// "createTime" : 1659684602036
// }
//
// swap:
//
// {
// "id": "105807376",
// "side": "buy",
// "px": "84410.57",
// "qty": "1",
// "amt": "84.41057",
// "cT": "1740777563557",
// }
//
// fetchMyTrades
//
// spot:
//
// {
// "id": "32164924331503616",
// "symbol": "LINK_USDT",
// "accountType": "SPOT",
// "orderId": "32164923987566592",
// "side": "SELL",
// "type": "MARKET",
// "matchRole": "TAKER",
// "createTime": 1648635115525,
// "price": "11",
// "quantity": "0.5",
// "amount": "5.5",
// "feeCurrency": "USDT",
// "feeAmount": "0.007975",
// "pageId": "32164924331503616",
// "clientOrderId": "myOwnId-321"
// }
//
// swap:
//
// {
// "symbol": "BTC_USDT_PERP",
// "trdId": "105813553",
// "side": "SELL",
// "type": "TRADE",
// "mgnMode": "CROSS",
// "ordType": "MARKET",
// "clOrdId": "polo418912106147315112",
// "role": "TAKER",
// "px": "84704.9",
// "qty": "1",
// "cTime": "1740842829430",
// "uTime": "1740842829450",
// "feeCcy": "USDT",
// "feeAmt": "0.04235245",
// "deductCcy": "",
// "deductAmt": "0",
// "feeRate": "0.0005",
// "id": "418912106342654592",
// "posSide": "BOTH",
// "ordId": "418912106147315112",
// "qCcy": "USDT",
// "value": "84.7049",
// "actType": "TRADING"
// },
//
// fetchOrderTrades (taker trades)
//
// {
// "id": "30341456333942784",
// "symbol": "LINK_USDT",
// "accountType": "SPOT",
// "orderId": "30249408733945856",
// "side": "BUY",
// "type": "LIMIT",
// "matchRole": "MAKER",
// "createTime": 1648200366864,
// "price": "3.1",
// "quantity": "1",
// "amount": "3.1",
// "feeCurrency": "LINK",
// "feeAmount": "0.00145",
// "pageId": "30341456333942784",
// "clientOrderId": ""
// }
//
let mut id: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("id".to_string()), Value::Str("tradeID".to_string()), Value::Str("trdId".to_string())]), &[]);
let mut orderId: Value = self.safe_string2(trade.clone(), Value::Str("orderId".to_string()), Value::Str("ordId".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_n(trade.clone(), Value::List(vec![Value::Str("ts".to_string()), Value::Str("createTime".to_string()), Value::Str("cT".to_string()), Value::Str("cTime".to_string())]), &[]);
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut side: Value = self.safe_string_lower2(trade.clone(), Value::Str("side".to_string()), Value::Str("takerSide".to_string()), &[]);
let mut fee: Value = Value::Null;
let mut priceString: Value = self.safe_string2(trade.clone(), Value::Str("price".to_string()), Value::Str("px".to_string()), &[]);
let mut amountString: Value = self.safe_string2(trade.clone(), Value::Str("quantity".to_string()), Value::Str("qty".to_string()), &[]);
let mut costString: Value = self.safe_string2(trade.clone(), Value::Str("amount".to_string()), Value::Str("amt".to_string()), &[]);
let mut feeCurrencyId: Value = self.safe_string2(trade.clone(), Value::Str("feeCurrency".to_string()), Value::Str("feeCcy".to_string()), &[]);
let mut feeCostString: Value = self.safe_string2(trade.clone(), Value::Str("feeAmount".to_string()), Value::Str("feeAmt".to_string()), &[]);
if !is_equal(&feeCostString, &Value::Null) {
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString.clone());
m.insert("currency".to_string(), feeCurrencyCode.clone());
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("order".to_string(), orderId.clone());
m.insert("type".to_string(), self.safe_string_lower2(trade.clone(), Value::Str("ordType".to_string()), Value::Str("type".to_string()), &[]));
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), self.safe_string_lower2(trade.clone(), Value::Str("matchRole".to_string()), Value::Str("role".to_string()), &[]));
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), costString.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://api-docs.poloniex.com/spot/api/public/market-data#trades
* @see https://api-docs.poloniex.com/v3/futures/api/market/get-execution-info
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // max 1000, for spot & swap
}
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_public_get_v3_market_trades(&[__ws_arg_4]).await;
//
// {
// code: "200",
// msg: "Success",
// data: [
// {
// id: "105807320", // descending order
// side: "sell",
// px: "84383.93",
// qty: "1",
// amt: "84.38393",
// cT: "1740777074704",
// },
//
let mut tradesList: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(tradesList.clone(), &[market.clone(), since.clone(), limit.clone()]);
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut trades: Value = self.public_get_markets_symbol_trades(&[__ws_arg_5]).await;
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchMyTrades
* @description fetch all trades made by the user
* @see https://api-docs.poloniex.com/spot/api/private/trade#trade-history
* @see https://api-docs.poloniex.com/v3/futures/api/trade/get-execution-details
* @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 entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {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
}));
self.load_markets(&[]).await;
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isContract: Value = self.in_array(marketType.clone(), Value::List(vec![Value::Str("swap".to_string()), Value::Str("future".to_string())]));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut startKey: Value = ternary(is_true(&isContract), Value::Str("sTime".to_string()), Value::Str("startTime".to_string()));
let mut endKey: Value = ternary(is_true(&isContract), Value::Str("eTime".to_string()), Value::Str("endTime".to_string()));
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &startKey, since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if is_true(&isContract) && !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
{ let __destr_tmp = self.handle_until_option(endKey.clone(), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&isContract) {
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut raw: Value = self.swap_private_get_v3_trade_order_trades(&[__ws_arg_6]).await;
//
// {
// "code": "200",
// "msg": "",
// "data": [
// {
// "symbol": "BTC_USDT_PERP",
// "trdId": "105813553",
// "side": "SELL",
// "type": "TRADE",
// "mgnMode": "CROSS",
// "ordType": "MARKET",
// "clOrdId": "polo418912106147315112",
// "role": "TAKER",
// "px": "84704.9",
// "qty": "1",
// "cTime": "1740842829430",
// "uTime": "1740842829450",
// "feeCcy": "USDT",
// "feeAmt": "0.04235245",
// "deductCcy": "",
// "deductAmt": "0",
// "feeRate": "0.0005",
// "id": "418912106342654592",
// "posSide": "BOTH",
// "ordId": "418912106147315112",
// "qCcy": "USDT",
// "value": "84.7049",
// "actType": "TRADING"
// },
//
let mut data: Value = self.safe_list_k(raw.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
}
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_trades(&[__ws_arg_7]).await;
//
// [
// {
// "id": "32164924331503616",
// "symbol": "LINK_USDT",
// "accountType": "SPOT",
// "orderId": "32164923987566592",
// "side": "SELL",
// "type": "MARKET",
// "matchRole": "TAKER",
// "createTime": 1648635115525,
// "price": "11",
// "quantity": "0.5",
// "amount": "5.5",
// "feeCurrency": "USDT",
// "feeAmount": "0.007975",
// "pageId": "32164924331503616",
// "clientOrderId": "myOwnId-321"
// }
// ]
//
let mut result: Value = self.parse_trades(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
return result;
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("NEW".to_string(), Value::Str("open".to_string()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".to_string()));
m.insert("FILLED".to_string(), Value::Str("closed".to_string()));
m.insert("PENDING_CANCEL".to_string(), Value::Str("canceled".to_string()));
m.insert("PARTIALLY_CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("FAILED".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchOpenOrder
//
// {
// "id" : "7xxxxxxxxxxxxxxx6",
// "clientOrderId" : "",
// "symbol" : "ETH_USDT",
// "state" : "NEW",
// "accountType" : "SPOT",
// "side" : "BUY",
// "type" : "LIMIT",
// "timeInForce" : "GTC",
// "quantity" : "0.001",
// "price" : "1600",
// "avgPrice" : "0",
// "amount" : "0",
// "filledQuantity" : "0",
// "filledAmount" : "0",
// "createTime" : 16xxxxxxxxx26,
// "updateTime" : 16xxxxxxxxx36
// }
//
// fetchOpenOrders (and fetchClosedOrders same for contracts)
//
// spot:
//
// {
// "id": "24993088082542592",
// "clientOrderId": "",
// "symbol": "ELON_USDC",
// "state": "NEW",
// "accountType": "SPOT",
// "side": "SELL",
// "type": "MARKET",
// "timeInForce": "GTC",
// "quantity": "1.00",
// "price": "0.00",
// "avgPrice": "0.00",
// "amount": "0.00",
// "filledQuantity": "0.00",
// "filledAmount": "0.00",
// "createTime": 1646925216548,
// "updateTime": 1646925216548
// }
//
// contract:
//
// {
// "symbol": "BTC_USDT_PERP",
// "side": "BUY",
// "type": "LIMIT",
// "ordId": "418890767248232148",
// "clOrdId": "polo418890767248232148",
// "mgnMode": "CROSS",
// "px": "81130.13",
// "reduceOnly": false,
// "lever": "20",
// "state": "NEW",
// "source": "WEB",
// "timeInForce": "GTC",
// "tpTrgPx": "",
// "tpPx": "",
// "tpTrgPxType": "",
// "slTrgPx": "",
// "slPx": "",
// "slTrgPxType": "",
// "avgPx": "0",
// "execQty": "0",
// "execAmt": "0",
// "feeCcy": "",
// "feeAmt": "0",
// "deductCcy": "0",
// "deductAmt": "0",
// "stpMode": "NONE", // todo: selfTradePrevention
// "cTime": "1740837741523",
// "uTime": "1740840846882",
// "sz": "1",
// "posSide": "BOTH",
// "qCcy": "USDT"
// "cancelReason": "", // this field can only be in closed orders
// },
//
// createOrder, editOrder
//
// spot:
//
// {
// "id": "29772698821328896",
// "clientOrderId": "1234Abc"
// }
//
// contract:
//
// {
// "ordId":"418876147745775616",
// "clOrdId":"polo418876147745775616"
// }
//
let mut timestamp: Value = self.safe_integer_n(order.clone(), Value::List(vec![Value::Str("timestamp".to_string()), Value::Str("createTime".to_string()), Value::Str("cTime".to_string())]), &[]);
if is_equal(×tamp, &Value::Null) {
timestamp = self.parse8601(self.safe_string_k(order.clone(), "date", &[]));
}
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("_".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut resultingTrades: Value = self.safe_value_k(order.clone(), "resultingTrades", &[]);
if !is_equal(&resultingTrades, &Value::Null) {
if !is_true(&Value::Bool(is_array(&resultingTrades))) {
resultingTrades = self.safe_value(resultingTrades.clone(), self.safe_string_k(market.clone(), "id", &[marketId.clone()]), &[]);
}
}
let mut price: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("price".to_string()), Value::Str("rate".to_string()), Value::Str("px".to_string())]), &[]);
let mut amount: Value = self.safe_string2(order.clone(), Value::Str("quantity".to_string()), Value::Str("sz".to_string()), &[]);
let mut filled: Value = self.safe_string2(order.clone(), Value::Str("filledQuantity".to_string()), Value::Str("execQty".to_string()), &[]);
let mut status: Value = self.parse_order_status(self.safe_string_k(order.clone(), "state", &[]));
let mut side: Value = self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]);
let mut rawType: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut type_var: Value = self.parse_order_type(rawType.clone());
let mut id: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("orderNumber".to_string()), Value::Str("id".to_string()), Value::Str("orderId".to_string()), Value::Str("ordId".to_string())]), &[]);
let mut fee: Value = Value::Null;
let mut feeCurrency: Value = self.safe_string2(order.clone(), Value::Str("tokenFeeCurrency".to_string()), Value::Str("feeCcy".to_string()), &[]);
let mut feeCost: Value = Value::Null;
let mut feeCurrencyCode: Value = Value::Null;
let mut rate: Value = self.safe_string_k(order.clone(), "fee", &[]);
if is_equal(&feeCurrency, &Value::Null) {
feeCurrencyCode = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), get_value(&market, &Value::Str("base".to_string())), get_value(&market, &Value::Str("quote".to_string())));
} else {
// poloniex accepts a 30% discount to pay fees in TRX
feeCurrencyCode = self.safe_currency_code(feeCurrency.clone(), &[]);
feeCost = self.safe_string2(order.clone(), Value::Str("tokenFee".to_string()), Value::Str("feeAmt".to_string()), &[]);
}
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("rate".to_string(), rate.clone());
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), feeCurrencyCode.clone());
m
});
}
let mut clientOrderId: Value = self.safe_string2(order.clone(), Value::Str("clientOrderId".to_string()), Value::Str("clOrdId".to_string()), &[]);
let mut marginMode: Value = self.safe_string_lower(order.clone(), Value::Str("mgnMode".to_string()), &[]);
let mut reduceOnly: Value = self.safe_bool_k(order.clone(), "reduceOnly", &[]);
let mut leverage: Value = self.safe_integer_k(order.clone(), "lever", &[]);
let mut hedged: Value = Value::Bool(!is_equal(&self.safe_string_k(order.clone(), "posSide", &[]), &Value::Str("BOTH".to_string())));
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), self.safe_integer_k(order.clone(), "updateTime", &[]));
m.insert("status".to_string(), status.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), self.safe_string_k(order.clone(), "timeInForce", &[]));
m.insert("postOnly".to_string(), Value::Bool(is_equal(&rawType, &Value::Str("LIMIT_MAKER".to_string()))));
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), self.safe_string2(order.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "execAmt", &[]));
m.insert("average".to_string(), self.safe_string2(order.clone(), Value::Str("avgPrice".to_string()), Value::Str("avgPx".to_string()), &[]));
m.insert("amount".to_string(), amount.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), Value::Null);
m.insert("trades".to_string(), resultingTrades.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("reduceOnly".to_string(), reduceOnly.clone());
m.insert("leverage".to_string(), leverage.clone());
m.insert("hedged".to_string(), hedged.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_order_type(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("MARKET".to_string(), Value::Str("market".to_string()));
m.insert("LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("LIMIT_MAKER".to_string(), Value::Str("limit".to_string()));
m.insert("STOP-LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("STOP-MARKET".to_string(), Value::Str("market".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_open_orders(&self, mut orders: Value, mut market: Value, mut result: Value) -> Value {
{
let mut i: Value = Value::Int(0);
let mut __for_first_1055: bool = true;
while { if !__for_first_1055 { i = add(&i, &Value::Int(1)); } __for_first_1055 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = get_value(&orders, &i);
let mut order: Value = get_value(&orders, &i);
let mut extended: Value = self.extend(order.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("open".to_string()));
m.insert("type".to_string(), Value::Str("limit".to_string()));
m.insert("side".to_string(), get_value(&order, &Value::Str("type".to_string())));
m.insert("price".to_string(), get_value(&order, &Value::Str("rate".to_string())));
m
})]);
append_to_array(&mut result, self.parse_order(extended.clone(), &[market.clone()]));
}
}
return result;
Value::Null
}
/*
* @method
* @name poloniex#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://api-docs.poloniex.com/spot/api/private/order#open-orders
* @see https://api-docs.poloniex.com/spot/api/private/smart-order#open-orders // trigger orders
* @see https://api-docs.poloniex.com/v3/futures/api/trade/get-current-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 {boolean} [params.trigger] set true to fetch trigger orders instead of regular orders
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
let mut max: Value = ternary(is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))), Value::Int(2000), Value::Int(100));
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::max(&limit, &max));
}
let mut isTrigger: Value = self.safe_value2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
let mut response: Value = Value::List(vec![]);
if !is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut raw: Value = self.swap_private_get_v3_trade_order_opens(&[__ws_arg_8]).await;
//
// {
// "code": "200",
// "msg": "",
// "data": [
// {
// "symbol": "BTC_USDT_PERP",
// "side": "BUY",
// "type": "LIMIT",
// "ordId": "418890767248232148",
// "clOrdId": "polo418890767248232148",
// "mgnMode": "CROSS",
// "px": "81130.13",
// "reduceOnly": false,
// "lever": "20",
// "state": "NEW",
// "source": "WEB",
// "timeInForce": "GTC",
// "tpTrgPx": "",
// "tpPx": "",
// "tpTrgPxType": "",
// "slTrgPx": "",
// "slPx": "",
// "slTrgPxType": "",
// "avgPx": "0",
// "execQty": "0",
// "execAmt": "0",
// "feeCcy": "",
// "feeAmt": "0",
// "deductCcy": "0",
// "deductAmt": "0",
// "stpMode": "NONE",
// "cTime": "1740837741523",
// "uTime": "1740840846882",
// "sz": "1",
// "posSide": "BOTH",
// "qCcy": "USDT"
// },
//
response = self.safe_list_k(raw.clone(), "data", &[Value::List(vec![])]);
} else if is_equal(&isTrigger, &Value::Bool(true)) {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_smartorders(&[__ws_arg_9]).await;
} else {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_orders(&[__ws_arg_10]).await;
}
//
// [
// {
// "id" : "7xxxxxxxxxxxxxxx6",
// "clientOrderId" : "",
// "symbol" : "ETH_USDT",
// "state" : "NEW",
// "accountType" : "SPOT",
// "side" : "BUY",
// "type" : "LIMIT",
// "timeInForce" : "GTC",
// "quantity" : "0.001",
// "price" : "1600",
// "avgPrice" : "0",
// "amount" : "0",
// "filledQuantity" : "0",
// "filledAmount" : "0",
// "stopPrice": "3750.00", // for trigger orders
// "createTime" : 16xxxxxxxxx26,
// "updateTime" : 16xxxxxxxxx36
// }
// ]
//
let mut extension: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("open".to_string()));
m
});
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone(), extension.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchClosedOrders
* @see https://api-docs.poloniex.com/v3/futures/api/trade/get-order-history
* @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] timestamp in ms of the latest entry
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchClosedOrders".to_string()), &[market.clone(), params.clone(), Value::Str("swap".to_string())]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchClosedOrders() is not supported for spot markets yet".to_string()))));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&Value::Int(200), &limit));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("sTime".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("eTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_private_get_v3_trade_order_history(&[__ws_arg_11]).await;
//
// {
// "code": "200",
// "msg": "",
// "data": [
// {
// "symbol": "BTC_USDT_PERP",
// "side": "SELL",
// "type": "MARKET",
// "ordId": "418912106147315712",
// "clOrdId": "polo418912106147315712",
// "mgnMode": "CROSS",
// "px": "0",
// "sz": "2",
// "lever": "20",
// "state": "FILLED",
// "cancelReason": "",
// "source": "WEB",
// "reduceOnly": "true",
// "timeInForce": "GTC",
// "tpTrgPx": "",
// "tpPx": "",
// "tpTrgPxType": "",
// "slTrgPx": "",
// "slPx": "",
// "slTrgPxType": "",
// "avgPx": "84705.56",
// "execQty": "2",
// "execAmt": "169.41112",
// "feeCcy": "USDT",
// "feeAmt": "0.08470556",
// "deductCcy": "0",
// "deductAmt": "0",
// "stpMode": "NONE",
// "cTime": "1740842829116",
// "uTime": "1740842829130",
// "posSide": "BOTH",
// "qCcy": "USDT"
// },
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#createOrder
* @description create a trade order
* @see https://api-docs.poloniex.com/spot/api/private/order#create-order
* @see https://api-docs.poloniex.com/spot/api/private/smart-order#create-order // trigger orders
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] the price at which a trigger order is triggered at
* @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
* @param {string} [params.clientOrderId] a unique identifier for the order
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), to_upper(&side));
m
});
let mut triggerPrice: Value = self.safe_number2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
{ let __destr_tmp = self.order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), request.clone(), &[price.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)))) {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut responseInitial: Value = self.swap_private_post_v3_trade_order(&[__ws_arg_12]).await;
//
// {"code":200,"msg":"Success","data":{"ordId":"418876147745775616","clOrdId":"polo418876147745775616"}}
//
response = self.safe_dict_k(responseInitial.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else if !is_equal(&triggerPrice, &Value::Null) {
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_smartorders(&[__ws_arg_13]).await;
} else {
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_orders(&[__ws_arg_14]).await;
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
pub fn order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, mut request: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut triggerPrice: Value = self.safe_number2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("marginMode".to_string()), &[]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Null) {
self.check_required_argument(Value::Str("createOrder".to_string()), marginMode.clone(), Value::Str("marginMode".to_string()), &[Value::List(vec![Value::Str("cross".to_string()), Value::Str("isolated".to_string())])]);
add_element_to_object(&mut request, &Value::Str("mgnMode".to_string()), to_upper(&marginMode));
}
let mut hedged: Value = Value::Null;
{ let __destr_tmp = self.handle_param_string(params.clone(), Value::Str("hedged".to_string()), &[]); hedged = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(!is_equal(&hedged, &Value::Null))) && is_true(&(!is_equal(&hedged, &Value::Str("".to_string())))) {
if is_equal(&marginMode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a marginMode parameter \"cross\" or \"isolated\" for hedged orders".to_string()))));
}
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("posSide".to_string()))))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires a posSide parameter \"LONG\" or \"SHORT\" for hedged orders".to_string()))));
}
}
}
let mut upperCaseType: Value = to_upper(&type_var);
let mut isMarket: Value = Value::Bool(is_equal(&upperCaseType, &Value::Str("MARKET".to_string())));
let mut isPostOnly: Value = self.is_post_only(isMarket.clone(), Value::Bool(is_equal(&upperCaseType, &Value::Str("LIMIT_MAKER".to_string()))), &[params.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("postOnly".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string())]), &[]);
if !is_equal(&triggerPrice, &Value::Null) {
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&self.id, &Value::Str(" createOrder() does not support trigger orders for ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" markets".to_string()))));
}
upperCaseType = ternary(is_true(&(is_equal(&price, &Value::Null))), Value::Str("STOP".to_string()), Value::Str("STOP_LIMIT".to_string()));
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), triggerPrice.clone());
} else if is_true(&isPostOnly) {
upperCaseType = Value::Str("LIMIT_MAKER".to_string());
}
add_element_to_object(&mut request, &Value::Str("type".to_string()), upperCaseType.clone());
if is_true(&isMarket) {
if is_equal(&side, &Value::Str("buy".to_string())) {
let mut quoteAmount: Value = Value::Null;
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("createMarketBuyOrderRequiresPrice".to_string()), &[Value::Bool(true)]); createMarketBuyOrderRequiresPrice = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut cost: Value = self.safe_number_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if !is_equal(&cost, &Value::Null) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost.clone());
} else if is_true(&createMarketBuyOrderRequiresPrice) && is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument".to_string()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
let mut costRequest: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
quoteAmount = self.cost_to_precision(symbol.clone(), costRequest.clone());
}
} else {
quoteAmount = self.cost_to_precision(symbol.clone(), amount.clone());
}
let mut amountKey: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("amount".to_string()), Value::Str("sz".to_string()));
add_element_to_object(&mut request, &amountKey, quoteAmount.clone());
} else {
let mut amountKey: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("quantity".to_string()), Value::Str("sz".to_string()));
add_element_to_object(&mut request, &amountKey, self.amount_to_precision(symbol.clone(), amount.clone()));
}
} else {
let mut amountKey: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("quantity".to_string()), Value::Str("sz".to_string()));
add_element_to_object(&mut request, &amountKey, self.amount_to_precision(symbol.clone(), amount.clone()));
let mut priceKey: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("price".to_string()), Value::Str("px".to_string()));
add_element_to_object(&mut request, &priceKey, self.price_to_precision(symbol.clone(), price.clone()));
}
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("clOrdId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
// the futures v3 api silently ignores the spot key and generates its own id
let mut clientOrderIdKey: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("clientOrderId".to_string()), Value::Str("clOrdId".to_string()));
add_element_to_object(&mut request, &clientOrderIdKey, clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("clOrdId".to_string())]), &[]);
}
return Value::List(vec![request.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#editOrder
* @description edit a trade order
* @see https://api-docs.poloniex.com/spot/api/private/order#cancel-replace-order
* @see https://api-docs.poloniex.com/spot/api/private/smart-order#cancel-replace-order
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} [amount] how much of the currency you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
* @param {string} [params.clientOrderId] a unique identifier for the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" editOrder() does not support ".to_string())), &get_value(&market, &Value::Str("type".to_string()))), &Value::Str(" orders, only spot orders are accepted".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
});
let mut triggerPrice: Value = self.safe_number2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
{ let __destr_tmp = self.order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), request.clone(), &[price.clone(), params.clone()]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&triggerPrice, &Value::Null) {
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.private_put_smartorders_id(&[__ws_arg_15]).await;
} else {
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.private_put_orders_id(&[__ws_arg_16]).await;
}
//
// {
// "id" : "78923648051920896",
// "clientOrderId" : ""
// }
//
response = self.extend(response.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("side".to_string(), side.clone());
m.insert("type".to_string(), type_var.clone());
m
})]);
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
//
// @method
// @name poloniex#cancelOrder
// @description cancels an open order
// @see https://api-docs.poloniex.com/spot/api/private/order#cancel-order-by-id
// @see https://api-docs.poloniex.com/spot/api/private/smart-order#cancel-order-by-id // trigger orders
// @param {string} id order id
// @param {string} symbol unified symbol of the market the order was made in
// @param {object} [params] extra parameters specific to the exchange API endpoint
// @param {boolean} [params.trigger] true if canceling a trigger order
// @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
//
self.load_markets(&[]).await;
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
add_element_to_object(&mut request, &Value::Str("ordId".to_string()), id.clone());
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut raw: Value = self.swap_private_delete_v3_trade_order(&[__ws_arg_17]).await;
return self.parse_order(self.safe_dict_k(raw.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), &[]);
}
let mut clientOrderId: Value = self.safe_value_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
id = clientOrderId.clone();
}
add_element_to_object(&mut request, &Value::Str("id".to_string()), id.clone());
let mut isTrigger: Value = self.safe_value2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&isTrigger, &Value::Bool(true)) {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_smartorders_id(&[__ws_arg_18]).await;
} else {
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_orders_id(&[__ws_arg_19]).await;
}
return self.parse_order(response.clone(), &[]);
Value::Null
}
/*
* @method
* @name poloniex#cancelAllOrders
* @description cancel all open orders
* @see https://api-docs.poloniex.com/spot/api/private/order#cancel-all-orders
* @see https://api-docs.poloniex.com/spot/api/private/smart-order#cancel-all-orders // trigger orders
* @see https://api-docs.poloniex.com/v3/futures/api/trade/cancel-all-orders - contract markets
* @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
* @param {boolean} [params.trigger] true if canceling trigger orders
* @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
}));
self.load_markets(&[]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbols".to_string(), Value::List(vec![]));
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbols".to_string()), Value::List(vec![get_value(&market, &Value::Str("id".to_string()))]));
}
let mut response: Value = Value::List(vec![]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("swap".to_string())) || is_equal(&marketType, &Value::Str("future".to_string())) {
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
let mut raw: Value = self.swap_private_delete_v3_trade_all_orders(&[__ws_arg_20]).await;
//
// {
// "code": "200",
// "msg": "Success",
// "data": [
// {
// "code": "200",
// "msg": "Success",
// "ordId": "418885787866388511",
// "clOrdId": "polo418885787866388511"
// }
// ]
// }
//
response = self.safe_list_k(raw.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(response.clone(), &[market.clone()]);
}
let mut isTrigger: Value = self.safe_value2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&isTrigger, &Value::Bool(true)) {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_smartorders(&[__ws_arg_21]).await;
} else {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_orders(&[__ws_arg_22]).await;
}
return self.parse_orders(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchOrder
* @description fetch an order by it's id
* @see https://api-docs.poloniex.com/spot/api/private/order#order-details
* @see https://api-docs.poloniex.com/spot/api/private/smart-order#open-orders // trigger orders
* @param {string} id order id
* @param {string} symbol unified market symbol, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] true if fetching a trigger order
* @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
}));
self.load_markets(&[]).await;
id = to_string_val(&id);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marketType, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" fetchOrder() is not supported for ".to_string())), &marketType), &Value::Str(" markets yet".to_string()))));
}
let mut isTrigger: Value = self.safe_value2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
let mut response: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&isTrigger, &Value::Bool(true)) {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_smartorders_id(&[__ws_arg_23]).await;
response = self.safe_value(response.clone(), Value::Int(0), &[]);
} else {
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_orders_id(&[__ws_arg_24]).await;
}
//
// {
// "id": "21934611974062080",
// "clientOrderId": "123",
// "symbol": "TRX_USDC",
// "state": "NEW",
// "accountType": "SPOT",
// "side": "SELL",
// "type": "LIMIT",
// "timeInForce": "GTC",
// "quantity": "1.00",
// "price": "10.00",
// "avgPrice": "0.00",
// "amount": "0.00",
// "filledQuantity": "0.00",
// "filledAmount": "0.00",
// "stopPrice": "3750.00", // for trigger orders
// "createTime": 1646196019020,
// "updateTime": 1646196019020
// }
//
let mut order: Value = self.parse_order(response.clone(), &[]);
add_element_to_object(&mut order, &Value::Str("id".to_string()), id.clone());
return order;
Value::Null
}
pub async fn fetch_order_status(&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
}));
self.load_markets(&[]).await;
let mut orders: Value = self.fetch_open_orders(&[symbol.clone(), Value::Null, Value::Null, params.clone()]).await;
let mut indexed: Value = self.index_by(orders.clone(), Value::Str("id".to_string()));
return ternary(is_true(&(Value::Bool(in_op(&indexed, &id)))), Value::Str("open".to_string()), Value::Str("closed".to_string()));
Value::Null
}
/*
* @method
* @name poloniex#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://api-docs.poloniex.com/spot/api/private/trade#trades-by-order-id
* @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
}));
self.load_markets(&[]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m
});
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
let mut trades: Value = self.private_get_orders_id_trades(&[__ws_arg_25]).await;
return self.parse_trades(trades.clone(), &[]);
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.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
// for swap
if !is_true(&Value::Bool(is_array(&response))) {
let mut ts: Value = self.safe_integer_k(response.clone(), "uTime", &[]);
add_element_to_object(&mut result, &Value::Str("timestamp".to_string()), ts.clone());
add_element_to_object(&mut result, &Value::Str("datetime".to_string()), self.iso8601(ts.clone()));
let mut details: Value = self.safe_list_k(response.clone(), "details", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1056: bool = true;
while { if !__for_first_1056 { i = add(&i, &Value::Int(1)); } __for_first_1056 = false; is_less_than(&i, &get_array_length(&details)) } {
let mut balance: Value = get_value(&details, &i);
let mut balance: Value = get_value(&details, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "avail", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "im", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_1058: bool = true;
while { if !__for_first_1058 { i = add(&i, &Value::Int(1)); } __for_first_1058 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut account: Value = self.safe_value(response.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut balances: Value = self.safe_value_k(account.clone(), "balances", &[]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_1057: bool = true;
while { if !__for_first_1057 { j = add(&j, &Value::Int(1)); } __for_first_1057 = false; is_less_than(&j, &get_array_length(&balances)) } {
let mut balance: Value = self.safe_value(balances.clone(), j.clone(), &[]);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut newAccount: Value = self.account();
add_element_to_object(&mut newAccount, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "available", &[]));
add_element_to_object(&mut newAccount, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "hold", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, newAccount.clone());
}
}
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name poloniex#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://api-docs.poloniex.com/spot/api/private/account#all-account-balances
* @see https://api-docs.poloniex.com/v3/futures/api/account/balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marketType, &Value::Str("spot".to_string())) {
let mut responseRaw: Value = self.swap_private_get_v3_account_balance(&[params.clone()]).await;
//
// {
// "code": "200",
// "msg": "",
// "data": {
// "state": "NORMAL",
// "eq": "9.98571622",
// "isoEq": "0",
// "im": "0",
// "mm": "0",
// "mmr": "0",
// "upl": "0",
// "availMgn": "9.98571622",
// "cTime": "1738093601775",
// "uTime": "1740829116236",
// "details": [
// {
// "ccy": "USDT",
// "eq": "9.98571622",
// "isoEq": "0",
// "avail": "9.98571622",
// "trdHold": "0",
// "upl": "0",
// "isoAvail": "0",
// "isoHold": "0",
// "isoUpl": "0",
// "im": "0",
// "mm": "0",
// "mmr": "0",
// "imr": "0",
// "cTime": "1740829116236",
// "uTime": "1740829116236"
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(responseRaw.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_balance(data.clone());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("accountType".to_string(), Value::Str("SPOT".to_string()));
m
});
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_accounts_balances(&[__ws_arg_26]).await;
return self.parse_balance(response.clone());
Value::Null
}
/*
* @method
* @name poloniex#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://api-docs.poloniex.com/spot/api/private/account#fee-info
* @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
}));
self.load_markets(&[]).await;
let mut response: Value = self.private_get_feeinfo(&[params.clone()]).await;
//
// {
// "trxDiscount" : false,
// "makerRate" : "0.00145",
// "takerRate" : "0.00155",
// "volume30D" : "0.00"
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut symbols: Value = self.symbols.clone();
{
let mut i: Value = Value::Int(0);
let mut __for_first_1059: bool = true;
while { if !__for_first_1059 { i = add(&i, &Value::Int(1)); } __for_first_1059 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
add_element_to_object(&mut result, &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(), self.safe_number_k(response.clone(), "makerRate", &[]));
m.insert("taker".to_string(), self.safe_number_k(response.clone(), "takerRate", &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
}));
}
}
return result;
Value::Null
}
/*
* @method
* @name poloniex#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://api-docs.poloniex.com/spot/api/public/market-data#order-book
* @see https://api-docs.poloniex.com/v3/futures/api/market/get-order-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // The default value of limit is 10. Valid limit values are: 5, 10, 20, 50, 100, 150.
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), self.find_nearest_ceiling(Value::List(vec![Value::Int(5), Value::Int(10), Value::Int(20), Value::Int(100), Value::Int(150)]), limit.clone()));
}
}
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
let mut responseRaw: Value = self.swap_public_get_v3_market_order_book(&[__ws_arg_27]).await;
//
// {
// "code": 200,
// "data": {
// "asks": [ ["58700", "9934"], ..],
// "bids": [ ["58600", "9952"], ..],
// "s": "100",
// "ts": 1719974138333
// },
// "msg": "Success"
// }
//
let mut data: Value = self.safe_dict_k(responseRaw.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ts: Value = self.safe_integer_k(data.clone(), "ts", &[]);
return self.parse_order_book(data.clone(), symbol.clone(), &[ts.clone()]);
}
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_markets_symbol_order_book(&[__ws_arg_28]).await;
//
// {
// "time" : 1659695219507,
// "scale" : "-1",
// "asks" : [ "23139.82", "0.317981", "23140", "0.191091", "23170.06", "0.01", "23200", "0.107758", "23230.55", "0.01", "23247.2", "0.154", "23254", "0.005121", "23263", "0.038", "23285.4", "0.308", "23300", "0.108896" ],
// "bids" : [ "23139.74", "0.432092", "23139.73", "0.198592", "23123.21", "0.000886", "23123.2", "0.308", "23121.4", "0.154", "23105", "0.000789", "23100", "0.078175", "23069.1", "0.026276", "23068.83", "0.001329", "23051", "0.000048" ],
// "ts" : 1659695219512
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "time", &[]);
let mut asks: Value = self.safe_value_k(response.clone(), "asks", &[]);
let mut bids: Value = self.safe_value_k(response.clone(), "bids", &[]);
let mut asksResult: Value = Value::List(vec![]);
let mut bidsResult: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1060: bool = true;
while { if !__for_first_1060 { i = add(&i, &Value::Int(1)); } __for_first_1060 = false; is_less_than(&i, &get_array_length(&asks)) } {
if is_less_than(&(mod_val(&i, &Value::Int(2))), &Value::Int(1)) {
let mut price: Value = self.safe_number(asks.clone(), i.clone(), &[]);
let mut amount: Value = self.safe_number(asks.clone(), self.sum(&[i.clone(), Value::Int(1)]), &[]);
append_to_array(&mut asksResult, Value::List(vec![price.clone(), amount.clone()]));
}
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_1061: bool = true;
while { if !__for_first_1061 { i = add(&i, &Value::Int(1)); } __for_first_1061 = false; is_less_than(&i, &get_array_length(&bids)) } {
if is_less_than(&(mod_val(&i, &Value::Int(2))), &Value::Int(1)) {
let mut price: Value = self.safe_number(bids.clone(), i.clone(), &[]);
let mut amount: Value = self.safe_number(bids.clone(), self.sum(&[i.clone(), Value::Int(1)]), &[]);
append_to_array(&mut bidsResult, Value::List(vec![price.clone(), amount.clone()]));
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("bids".to_string(), self.sort_by(bidsResult.clone(), Value::Int(0), &[Value::Bool(true)]));
m.insert("asks".to_string(), self.sort_by(asksResult.clone(), Value::Int(0), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("nonce".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name poloniex#createDepositAddress
* @description create a currency deposit address
* @see https://api-docs.poloniex.com/spot/api/private/wallet#deposit-addresses
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn create_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut requestextraParamscurrencynetworkEntryVariable = self.prepare_request_for_deposit_address(code.clone(), &[params.clone()]);
let mut request: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(0));
let mut extraParams: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(1));
let mut currency: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(2));
let mut networkEntry: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(3));
params = extraParams.clone();
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_wallets_address(&[__ws_arg_29]).await;
return self.parse_deposit_address_special(response.clone(), currency.clone(), networkEntry.clone());
Value::Null
}
/*
* @method
* @name poloniex#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://api-docs.poloniex.com/spot/api/private/wallet#deposit-addresses
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut requestextraParamscurrencynetworkEntryVariable = self.prepare_request_for_deposit_address(code.clone(), &[params.clone()]);
let mut request: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(0));
let mut extraParams: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(1));
let mut currency: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(2));
let mut networkEntry: Value = get_value(&requestextraParamscurrencynetworkEntryVariable, &Value::Int(3));
params = extraParams.clone();
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_wallets_addresses(&[__ws_arg_30]).await;
//
// {
// "USDTTRON" : "Txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxp"
// }
//
let mut keys: Value = object_keys(&response);
let mut length: Value = get_array_length(&keys);
if is_less_than(&length, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchDepositAddress() returned an empty response, you might need to try \"createDepositAddress\" at first and then use \"fetchDepositAddress\"".to_string()))));
}
return self.parse_deposit_address_special(response.clone(), currency.clone(), networkEntry.clone());
Value::Null
}
pub fn prepare_request_for_deposit_address(&self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if !is_true(&(Value::Bool(in_op(&self.currencies, &code)))) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&add(&add(&self.id, &Value::Str(" fetchDepositAddress(): can not recognize ".to_string())), &code), &Value::Str(" currency, you might try using unified currency-code and add provide specific \"network\" parameter, like: fetchDepositAddress(\"USDT\", { \"network\": \"TRC20\" })".to_string()))));
}
let mut currency: Value = self.currency(code.clone());
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&networkCode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" fetchDepositAddress requires a network parameter for ".to_string())), &code), &Value::Str(".".to_string()))));
}
let mut exchangeNetworkId: Value = Value::Null;
networkCode = self.network_id_to_code(&[networkCode.clone(), code.clone()]);
let mut networkEntry: Value = ternary(is_true(&(is_equal(&networkCode, &Value::Null))), Value::Null, self.safe_dict(get_value(¤cy, &Value::Str("networks".to_string())), networkCode.clone(), &[]));
if !is_equal(&networkEntry, &Value::Null) {
exchangeNetworkId = get_value(&networkEntry, &Value::Str("id".to_string()));
} else {
exchangeNetworkId = networkCode.clone();
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), exchangeNetworkId.clone());
m
});
return Value::List(vec![request.clone(), params.clone(), currency.clone(), networkEntry.clone()]);
Value::Null
}
pub fn parse_deposit_address_special(&self, mut response: Value, mut currency: Value, mut networkEntry: Value) -> Value {
let mut address: Value = self.safe_string_k(response.clone(), "address", &[]);
if is_equal(&address, &Value::Null) {
address = self.safe_string(response.clone(), get_value(&networkEntry, &Value::Str("id".to_string())), &[]);
}
let mut tag: Value = Value::Null;
self.check_address(&[address.clone()]);
if !is_equal(&networkEntry, &Value::Null) {
let mut depositAddress: Value = self.safe_string(get_value(&networkEntry, &Value::Str("info".to_string())), Value::Str("depositAddress".to_string()), &[]);
if !is_equal(&depositAddress, &Value::Null) {
tag = address.clone();
address = depositAddress.clone();
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("code".to_string())));
m.insert("network".to_string(), self.safe_string_k(networkEntry.clone(), "network", &[]));
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m
});
Value::Null
}
/*
* @method
* @name poloniex#transfer
* @description transfer currency internally between wallets on the same account
* @see https://api-docs.poloniex.com/spot/api/private/account#accounts-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut currency: Value = self.currency(code.clone());
let mut accountsByType: Value = self.safe_value_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[fromAccount.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("fromAccount".to_string(), fromId.clone());
m.insert("toAccount".to_string(), toId.clone());
m
});
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_accounts_transfer(&[__ws_arg_31]).await;
return self.parse_transfer(response.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "transferId", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("currency".to_string(), self.safe_string_k(currency.clone(), "id", &[]));
m.insert("amount".to_string(), Value::Null);
m.insert("fromAccount".to_string(), Value::Null);
m.insert("toAccount".to_string(), Value::Null);
m.insert("status".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name poloniex#withdraw
* @description make a withdrawal
* @see https://api-docs.poloniex.com/spot/api/private/wallet#withdraw-currency
* @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 = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
self.check_address(&[address.clone()]);
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("address".to_string(), address.clone());
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&networkCode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" withdraw requires a network parameter for ".to_string())), &code), &Value::Str(".".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("network".to_string()), self.network_code_to_id(networkCode.clone(), &[code.clone()]));
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("paymentId".to_string()), tag.clone());
}
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v2_wallets_withdraw(&[__ws_arg_32]).await;
return self.parse_transaction(response.clone(), &[currency.clone()]);
Value::Null
}
pub async fn fetch_transactions_helper(&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
}));
self.load_markets(&[]).await;
let mut year: Value = Value::Int(31104000); // 60 * 60 * 24 * 30 * 12 = one year of history, why not
let mut now: Value = self.seconds();
let mut start: Value = ternary(is_true(&(!is_equal(&since, &Value::Null))), self.parse_to_int(divide(&since, &Value::Int(1000))), subtract(&now, &multiply(&Value::Int(10), &year)));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("start".to_string(), start.clone());
m.insert("end".to_string(), now.clone());
m
});
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_wallets_activity(&[__ws_arg_33]).await;
return response;
Value::Null
}
/*
* @method
* @name poloniex#fetchDepositsWithdrawals
* @description fetch history of deposits and withdrawals
* @see https://api-docs.poloniex.com/spot/api/private/wallet#wallets-activity-records
* @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
* @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
* @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut response: Value = self.fetch_transactions_helper(&[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut withdrawals: Value = self.safe_value_k(response.clone(), "withdrawals", &[Value::List(vec![])]);
let mut deposits: Value = self.safe_value_k(response.clone(), "deposits", &[Value::List(vec![])]);
let mut withdrawalTransactions: Value = self.parse_transactions(withdrawals.clone(), &[currency.clone(), since.clone(), limit.clone()]);
let mut depositTransactions: Value = self.parse_transactions(deposits.clone(), &[currency.clone(), since.clone(), limit.clone()]);
let mut transactions: Value = self.array_concat(depositTransactions.clone(), withdrawalTransactions.clone());
return self.filter_by_currency_since_limit(self.sort_by(transactions.clone(), Value::Str("timestamp".to_string()), &[]), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://api-docs.poloniex.com/spot/api/private/wallet#wallets-activity-records
* @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 mut response: Value = self.fetch_transactions_helper(&[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut withdrawals: Value = self.safe_value_k(response.clone(), "withdrawals", &[Value::List(vec![])]);
let mut transactions: Value = self.parse_transactions(withdrawals.clone(), &[currency.clone(), since.clone(), limit.clone()]);
return self.filter_by_currency_since_limit(transactions.clone(), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name poloniex#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees
* @see https://api-docs.poloniex.com/spot/api/public/reference-data#currency-information
* @param {string[]|undefined} codes list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [fees structures]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let __ws_arg_34 = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("includeMultiChainCurrencies".to_string(), Value::Bool(true));
m
})]);
let mut response: Value = self.public_get_currencies(&[__ws_arg_34]).await;
//
// [
// {
// "1CR": {
// "id": 1,
// "name": "1CRedit",
// "description": "BTC Clone",
// "type": "address",
// "withdrawalFee": "0.01000000",
// "minConf": 10000,
// "depositAddress": null,
// "blockchain": "1CR",
// "delisted": false,
// "tradingState": "NORMAL",
// "walletState": "DISABLED",
// "parentChain": null,
// "isMultiChain": false,
// "isChildChain": false,
// "childChains": []
// }
// }
// ]
//
let mut data: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut entries: Value = Value::List(vec![]);
if is_true(&Value::Bool(is_array(&response))) {
entries = response.clone();
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_1062: bool = true;
while { if !__for_first_1062 { i = add(&i, &Value::Int(1)); } __for_first_1062 = false; is_less_than(&i, &get_array_length(&entries)) } {
let mut entry: Value = get_value(&entries, &i);
let mut entry: Value = get_value(&entries, &i);
let mut currencies: Value = object_keys(&entry);
let mut currencyId: Value = self.safe_string(currencies.clone(), Value::Int(0), &[]);
add_element_to_object(&mut data, ¤cyId, get_value(&entry, ¤cyId));
}
}
return self.parse_deposit_withdraw_fees(data.clone(), &[codes.clone()]);
Value::Null
}
pub fn parse_deposit_withdraw_fees(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut currencyIdKey = get_arg(optional_args, 1, Value::Null);
//
// {
// "1CR": {
// "id": 1,
// "name": "1CRedit",
// "description": "BTC Clone",
// "type": "address",
// "withdrawalFee": "0.01000000",
// "minConf": 10000,
// "depositAddress": null,
// "blockchain": "1CR",
// "delisted": false,
// "tradingState": "NORMAL",
// "walletState": "DISABLED",
// "parentChain": null,
// "isMultiChain": false,
// "isChildChain": false,
// "childChains": []
// },
// }
//
let mut depositWithdrawFees: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
codes = self.market_codes(&[codes.clone()]);
let mut responseKeys: Value = object_keys(&response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1064: bool = true;
while { if !__for_first_1064 { i = add(&i, &Value::Int(1)); } __for_first_1064 = false; is_less_than(&i, &get_array_length(&responseKeys)) } {
let mut currencyId: Value = get_value(&responseKeys, &i);
let mut currencyId: Value = get_value(&responseKeys, &i);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut feeInfo: Value = get_value(&response, ¤cyId);
let mut feeInfo: Value = get_value(&response, ¤cyId);
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(is_true(&(is_equal(&codes, &Value::Null))) || is_true(&(self.in_array(code.clone(), codes.clone()))))) {
let mut currency: Value = self.currency(code.clone());
add_element_to_object(&mut depositWithdrawFees, &code, self.parse_deposit_withdraw_fee(feeInfo.clone(), &[currency.clone()]));
let mut childChains: Value = self.safe_value_k(feeInfo.clone(), "childChains", &[]);
let mut chainsLength: Value = get_array_length(&childChains);
if is_greater_than(&chainsLength, &Value::Int(0)) {
{
let mut j: Value = Value::Int(0);
let mut __for_first_1063: bool = true;
while { if !__for_first_1063 { j = add(&j, &Value::Int(1)); } __for_first_1063 = false; is_less_than(&j, &get_array_length(&childChains)) } {
let mut networkId: Value = get_value(&childChains, &j);
let mut networkId: Value = get_value(&childChains, &j);
networkId = replace_str(&networkId, &code, &Value::Str("".to_string()));
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), get_value(¤cy, &Value::Str("code".to_string()))]);
let mut networkInfo: Value = self.safe_value(response.clone(), networkId.clone(), &[]);
let mut networkObject: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut withdrawFee: Value = self.safe_number_k(networkInfo.clone(), "withdrawalFee", &[]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networkObject, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee.clone());
m.insert("percentage".to_string(), ternary(is_true(&(!is_equal(&withdrawFee, &Value::Null))), Value::Bool(false), Value::Null));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m
}));
}
{ let __be_tmp = self.extend(get_value(&get_value(&depositWithdrawFees, &code), &Value::Str("networks".to_string())), &[networkObject.clone()]); add_element_to_object(get_value_mut(&mut depositWithdrawFees, &code), &Value::Str("networks".to_string()), __be_tmp); };
}
}
}
}
}
}
return depositWithdrawFees;
Value::Null
}
pub fn parse_deposit_withdraw_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut depositWithdrawFee: Value = self.deposit_withdraw_fee(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut currencyCode: Value = self.safe_string_k(currency.clone(), "code", &[]);
add_element_to_object(get_value_mut(&mut depositWithdrawFee, &Value::Str("info".to_string())), ¤cyCode, fee.clone());
let mut networkId: Value = self.safe_string_k(fee.clone(), "blockchain", &[]);
let mut withdrawFee: Value = self.safe_number_k(fee.clone(), "withdrawalFee", &[]);
let mut withdrawResult: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee.clone());
m.insert("percentage".to_string(), ternary(is_true(&(!is_equal(&withdrawFee, &Value::Null))), Value::Bool(false), Value::Null));
m
});
let mut depositResult: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
});
add_element_to_object(&mut depositWithdrawFee, &Value::Str("withdraw".to_string()), withdrawResult.clone());
add_element_to_object(&mut depositWithdrawFee, &Value::Str("deposit".to_string()), depositResult.clone());
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), self.safe_string_k(currency.clone(), "code", &[])]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(get_value_mut(&mut depositWithdrawFee, &Value::Str("networks".to_string())), &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), withdrawResult.clone());
m.insert("deposit".to_string(), depositResult.clone());
m
}));
}
return depositWithdrawFee;
Value::Null
}
/*
* @method
* @name poloniex#fetchDeposits
* @description fetch all deposits made to an account
* @see https://api-docs.poloniex.com/spot/api/private/wallet#wallets-activity-records
* @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 mut response: Value = self.fetch_transactions_helper(&[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut deposits: Value = self.safe_value_k(response.clone(), "deposits", &[Value::List(vec![])]);
let mut transactions: Value = self.parse_transactions(deposits.clone(), &[currency.clone(), since.clone(), limit.clone()]);
return self.filter_by_currency_since_limit(transactions.clone(), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("COMPLETE".to_string(), Value::Str("ok".to_string()));
m.insert("COMPLETED".to_string(), Value::Str("ok".to_string()));
m.insert("AWAITING APPROVAL".to_string(), Value::Str("pending".to_string()));
m.insert("AWAITING_APPROVAL".to_string(), Value::Str("pending".to_string()));
m.insert("PENDING".to_string(), Value::Str("pending".to_string()));
m.insert("PROCESSING".to_string(), Value::Str("pending".to_string()));
m.insert("COMPLETE ERROR".to_string(), Value::Str("failed".to_string()));
m.insert("COMPLETE_ERROR".to_string(), Value::Str("failed".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// deposits
//
// {
// "txid": "f49d489616911db44b740612d19464521179c76ebe9021af85b6de1e2f8d68cd",
// "amount": "49798.01987021",
// "status": "COMPLETE",
// "address": "DJVJZ58tJC8UeUv9Tqcdtn6uhWobouxFLT",
// "currency": "DOGE",
// "timestamp": 1524321838,
// "confirmations": 3371,
// "depositNumber": 134587098
// }
//
// withdrawals
//
// {
// "withdrawalRequestsId": 7397527,
// "currency": "ETC",
// "address": "0x26419a62055af459d2cd69bb7392f5100b75e304",
// "amount": "13.19951600",
// "fee": "0.01000000",
// "timestamp": 1506010932,
// "status": "COMPLETED",
// "txid": "343346392f82ac16e8c2604f2a604b7b2382d0e9d8030f673821f8de4b5f5bk",
// "ipAddress": "1.2.3.4",
// "paymentID": null
// }
//
// withdraw
//
// {
// "withdrawalRequestsId": 33485231
// }
//
// if it's being parsed from "withdraw()" method, get the original response
if is_true(&Value::Bool(in_op(&transaction, &Value::Str("withdrawNetworkEntry".to_string())))) {
transaction = get_value(&transaction, &Value::Str("response".to_string()));
}
let mut timestamp: Value = self.safe_timestamp(transaction.clone(), Value::Str("timestamp".to_string()), &[]);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "currency", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut status: Value = self.safe_string_k(transaction.clone(), "status", &[Value::Str("pending".to_string())]);
status = self.parse_transaction_status(status.clone());
let mut txid: Value = self.safe_string_k(transaction.clone(), "txid", &[]);
let mut type_var: Value = ternary(is_true(&(Value::Bool(in_op(&transaction, &Value::Str("withdrawalRequestsId".to_string()))))), Value::Str("withdrawal".to_string()), Value::Str("deposit".to_string()));
let mut id: Value = self.safe_string2(transaction.clone(), Value::Str("withdrawalRequestsId".to_string()), Value::Str("depositNumber".to_string()), &[]);
let mut address: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut tag: Value = self.safe_string_k(transaction.clone(), "paymentID", &[]);
let mut amountString: Value = self.safe_string_k(transaction.clone(), "amount", &[]);
let mut feeCostString: Value = self.safe_string_k(transaction.clone(), "fee", &[]);
if is_equal(&type_var, &Value::Str("withdrawal".to_string())) {
amountString = crate::precise::Precise::stringSub(&amountString, &feeCostString);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.clone());
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.parse_number(amountString.clone(), &[]));
m.insert("network".to_string(), Value::Null);
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), Value::Null);
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), tag.clone());
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("updated".to_string(), Value::Null);
m.insert("txid".to_string(), txid.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("cost".to_string(), self.parse_number(feeCostString.clone(), &[]));
m.insert("rate".to_string(), Value::Null);
m
}));
m
});
Value::Null
}
/*
* @method
* @name poloniex#setLeverage
* @description set the level of leverage for a market
* @see https://api-docs.poloniex.com/v3/futures/api/positions/set-leverage
* @param {int} leverage the rate of leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] 'cross' or 'isolated'
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setLeverage".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a marginMode parameter \"cross\" or \"isolated\"".to_string()))));
}
let mut hedged: Value = Value::Null;
{ let __destr_tmp = self.handle_param_bool(params.clone(), Value::Str("hedged".to_string()), &[Value::Bool(false)]); hedged = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&hedged, &Value::Bool(true)) {
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("posSide".to_string()))))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a posSide parameter for hedged mode: \"LONG\" or \"SHORT\"".to_string()))));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("lever".to_string(), leverage.clone());
m.insert("mgnMode".to_string(), to_upper(&marginMode));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_private_post_v3_position_leverage(&[__ws_arg_35]).await;
return response;
Value::Null
}
/*
* @method
* @name poloniex#fetchLeverage
* @description fetch the set leverage for a market
* @see https://api-docs.poloniex.com/v3/futures/api/positions/get-leverages
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage structure]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverage(&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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchLeverage".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchLeverage() requires a marginMode parameter \"cross\" or \"isolated\"".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("mgnMode".to_string()), to_upper(&marginMode));
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_private_get_v3_position_leverages(&[__ws_arg_36]).await;
return self.parse_leverage(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut shortLeverage: Value = Value::Null;
let mut longLeverage: Value = Value::Null;
let mut marketId: Value = Value::Null;
let mut marginMode: Value = Value::Null;
let mut data: Value = self.safe_list_k(leverage.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1065: bool = true;
while { if !__for_first_1065 { i = add(&i, &Value::Int(1)); } __for_first_1065 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
marketId = self.safe_string_k(entry.clone(), "symbol", &[]);
// mgnMode arrives upper case; parseOrder and parsePosition read the
// same field with safeStringLower
marginMode = self.safe_string_lower(entry.clone(), Value::Str("mgnMode".to_string()), &[]);
let mut lever: Value = self.safe_integer_k(entry.clone(), "lever", &[]);
let mut posSide: Value = self.safe_string_k(entry.clone(), "posSide", &[]);
if is_equal(&posSide, &Value::Str("LONG".to_string())) {
longLeverage = lever.clone();
} else if is_equal(&posSide, &Value::Str("SHORT".to_string())) {
shortLeverage = lever.clone();
} else {
longLeverage = lever.clone();
shortLeverage = lever.clone();
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("longLeverage".to_string(), longLeverage.clone());
m.insert("shortLeverage".to_string(), shortLeverage.clone());
m
});
Value::Null
}
/*
* @method
* @name poloniex#fetchPositionMode
* @description fetches the position mode, hedged or one way, hedged is set identically for all linear markets or all inverse markets
* @see https://api-docs.poloniex.com/v3/futures/api/positions/position-mode-switch
* @param {string} [symbol] unified symbol of the market to fetch the position mode for (not used by fetchPositionMode)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an object detailing whether the market is in hedged or one-way mode
*/
pub async fn fetch_position_mode(&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
}));
let mut response: Value = self.swap_private_get_v3_position_mode(&[params.clone()]).await;
//
// {
// "code": "200",
// "msg": "Success",
// "data": {
// "posMode": "ONE_WAY"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut posMode: Value = self.safe_string_k(data.clone(), "posMode", &[]);
let mut hedged: Value = Value::Bool(is_equal(&posMode, &Value::Str("HEDGE".to_string())));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("hedged".to_string(), hedged.clone());
m
});
Value::Null
}
/*
* @method
* @name poloniex#setPositionMode
* @description set hedged to true or false for a market
* @see https://api-docs.poloniex.com/v3/futures/api/positions/position-mode-switch
* @param {bool} hedged set to true to use the hedged position mode
* @param {string} symbol not used by setPositionMode ()
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut mode: Value = ternary(is_true(&hedged), Value::Str("HEDGE".to_string()), Value::Str("ONE_WAY".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("posMode".to_string(), mode.clone());
m
});
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_private_post_v3_position_mode(&[__ws_arg_37]).await;
return response;
Value::Null
}
/*
* @method
* @name poloniex#fetchPositions
* @description fetch all open positions
* @see https://api-docs.poloniex.com/v3/futures/api/positions/get-current-position
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.standard] whether to fetch standard contract positions
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.swap_private_get_v3_trade_position_opens(&[params.clone()]).await;
//
// {
// "code": "200",
// "msg": "",
// "data": [
// {
// "symbol": "BTC_USDT_PERP",
// "posSide": "LONG",
// "side": "BUY",
// "mgnMode": "CROSS",
// "openAvgPx": "94193.42",
// "qty": "1",
// "availQty": "1",
// "lever": "20",
// "adl": "0.3007",
// "liqPx": "84918.201844064386317906",
// "im": "4.7047795",
// "mm": "0.56457354",
// "upl": "-0.09783",
// "uplRatio": "-0.0207",
// "pnl": "0",
// "markPx": "94095.59",
// "mgnRatio": "0.0582",
// "state": "NORMAL",
// "cTime": "1740950344401",
// "uTime": "1740950344401",
// "mgn": "4.7047795",
// "actType": "TRADING",
// "maxWAmt": "0",
// "tpTrgPx": "",
// "slTrgPx": ""
// }
// ]
// }
//
let mut positions: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_positions(positions.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTC_USDT_PERP",
// "posSide": "LONG",
// "side": "BUY",
// "mgnMode": "CROSS",
// "openAvgPx": "94193.42",
// "qty": "1",
// "availQty": "1",
// "lever": "20",
// "adl": "0.3007",
// "liqPx": "84918.201844064386317906",
// "im": "4.7047795",
// "mm": "0.56457354",
// "upl": "-0.09783",
// "uplRatio": "-0.0207",
// "pnl": "0",
// "markPx": "94095.59",
// "mgnRatio": "0.0582",
// "state": "NORMAL",
// "cTime": "1740950344401",
// "uTime": "1740950344401",
// "mgn": "4.7047795",
// "actType": "TRADING",
// "maxWAmt": "0",
// "tpTrgPx": "",
// "slTrgPx": ""
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "cTime", &[]);
let mut marginMode: Value = self.safe_string_lower(position.clone(), Value::Str("mgnMode".to_string()), &[]);
let mut leverage: Value = self.safe_string_k(position.clone(), "lever", &[]);
let mut initialMargin: Value = self.safe_string_k(position.clone(), "im", &[]);
let mut notional: Value = crate::precise::Precise::stringMul(&leverage, &initialMargin);
let mut qty: Value = self.safe_string_k(position.clone(), "qty", &[]);
let mut avgPrice: Value = self.safe_string_k(position.clone(), "openAvgPx", &[]);
let mut collateral: Value = crate::precise::Precise::stringMul(&qty, &avgPrice);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("notional".to_string(), notional.clone());
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liqPx", &[]));
m.insert("entryPrice".to_string(), self.safe_number_k(position.clone(), "openAvgPx", &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "upl", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "qty", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "markPx", &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_lower(position.clone(), Value::Str("posSide".to_string()), &[]));
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), self.safe_number_k(position.clone(), "mm", &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("collateral".to_string(), collateral.clone());
m.insert("initialMargin".to_string(), initialMargin.clone());
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), crate::runtime::parse_int(&leverage));
m.insert("marginRatio".to_string(), self.safe_number_k(position.clone(), "mgnRatio", &[]));
m.insert("stopLossPrice".to_string(), self.safe_number_k(position.clone(), "slTrgPx", &[]));
m.insert("takeProfitPrice".to_string(), self.safe_number_k(position.clone(), "tpTrgPx", &[]));
m
}));
Value::Null
}
pub async fn modify_margin_helper(&mut self, mut symbol: Value, mut amount: Value, mut type_var: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
amount = self.amount_to_precision(symbol.clone(), amount.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("amt".to_string(), crate::precise::Precise::stringAbs(&amount));
m.insert("type".to_string(), to_upper(&type_var));
m
});
// todo: hedged handling, tricky
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("posMode".to_string()))))) {
add_element_to_object(&mut request, &Value::Str("posMode".to_string()), Value::Str("BOTH".to_string()));
}
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_private_post_v3_trade_position_margin(&[__ws_arg_38]).await;
//
// {
// "code": 200,
// "data": {
// "amt": "50",
// "lever": "20",
// "symbol": "DOT_USDT_PERP",
// "posSide": "BOTH",
// "type": "ADD"
// },
// "msg": "Success"
// }
//
if is_equal(&type_var, &Value::Str("reduce".to_string())) {
amount = crate::precise::Precise::stringAbs(&amount);
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
return self.parse_margin_modification(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(data.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut rawType: Value = self.safe_string_k(data.clone(), "type", &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&rawType, &Value::Str("ADD".to_string())))), Value::Str("add".to_string()), Value::Str("reduce".to_string()));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("marginMode".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_number_k(data.clone(), "amt", &[]));
m.insert("total".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("status".to_string(), Value::Str("ok".to_string()));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name poloniex#reduceMargin
* @description remove margin from a position
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), negate(&amount), Value::Str("reduce".to_string()), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name poloniex#addMargin
* @description add margin
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Str("add".to_string()), &[params.clone()]).await;
Value::Null
}
pub fn nonce(&self) -> Value {
return self.milliseconds();
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut url: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("spot".to_string()));
if is_true(&self.in_array(api.clone(), Value::List(vec![Value::Str("swapPublic".to_string()), Value::Str("swapPrivate".to_string())]))) {
url = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("swap".to_string()));
}
if is_equal(&method, &Value::Str("GET".to_string())) && is_true(&(Value::Bool(in_op(¶ms, &Value::Str("symbol".to_string()))))) {
{ let __be_tmp = self.encode_uri_component(get_value(¶ms, &Value::Str("symbol".to_string()))); add_element_to_object(&mut params, &Value::Str("symbol".to_string()), __be_tmp); }; // handle symbols like 索拉拉/USDT'
}
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut implodedPath: Value = self.implode_params(path.clone(), params.clone());
if is_equal(&api, &Value::Str("public".to_string())) || is_equal(&api, &Value::Str("swapPublic".to_string())) {
url = add(&url, &add(&Value::Str("/".to_string()), &implodedPath));
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
} else {
self.check_required_credentials(&[]);
let mut timestamp: Value = to_string_val(&self.nonce());
let mut auth: Value = add(&method, &Value::Str("\n".to_string())); // eslint-disable-line quotes
url = add(&url, &add(&Value::Str("/".to_string()), &implodedPath));
auth = add(&auth, &add(&Value::Str("/".to_string()), &implodedPath));
if is_true(&(is_equal(&method, &Value::Str("POST".to_string())))) || is_true(&(is_equal(&method, &Value::Str("PUT".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))) {
auth = add(&auth, &Value::Str("\n".to_string())); // eslint-disable-line quotes
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
body = self.json(query.clone());
auth = add(&auth, &add(&add(&Value::Str("requestBody=".to_string()), &body), &Value::Str("&".to_string())));
}
auth = add(&auth, &add(&Value::Str("signTimestamp=".to_string()), ×tamp));
} else {
let mut sortedQuery: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("signTimestamp".to_string(), timestamp.clone());
m
}), &[query.clone()]);
sortedQuery = self.keysort(sortedQuery.clone(), &[]);
auth = add(&auth, &add(&Value::Str("\n".to_string()), &self.urlencode(sortedQuery.clone(), &[]))); // eslint-disable-line quotes
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
}
let mut signature: Value = self.hmac(self.encode(auth.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m.insert("key".to_string(), self.apiKey.clone());
m.insert("signTimestamp".to_string(), timestamp.clone());
m.insert("signature".to_string(), signature.clone());
m
});
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
//
// {
// "code" : 21709,
// "message" : "Low available balance"
// }
//
let mut responseCode: Value = self.safe_string_k(response.clone(), "code", &[]);
if is_true(&(!is_equal(&responseCode, &Value::Null))) && is_true(&(!is_equal(&responseCode, &Value::Str("200".to_string())))) {
let mut message: Value = self.safe_string2(response.clone(), Value::Str("message".to_string()), Value::Str("msg".to_string()), &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), responseCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}