// 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 P2bCore {
pub exchange: crate::exchange::Exchange,
}
impl P2bCore {
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 = P2bCore::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 P2bCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on P2bCore.
P2bCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on P2bCore.
P2bCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on P2bCore.
P2bCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on P2bCore.
P2bCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on P2bCore.
P2bCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on P2bCore.
P2bCore::parse_balance(self, response)
}
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 P2bCore.
P2bCore::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 P2bCore.
P2bCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for P2bCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_order" => self.cancel_order(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,
"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_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_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for P2bCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for P2bCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl P2bCore {
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("p2b".to_string()));
m.insert("name".to_string(), Value::Str("p2b".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("LT".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v2".to_string()));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(false));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createMarketOrder".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(false));
m.insert("createStopLimitOrder".to_string(), Value::Bool(false));
m.insert("createStopMarketOrder".to_string(), Value::Bool(false));
m.insert("createStopOrder".to_string(), Value::Bool(false));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchDeposit".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(false));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingRates".to_string(), Value::Bool(false));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(false));
m.insert("fetchLedgerEntry".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(false));
m.insert("fetchMarginModes".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMarkPrice".to_string(), Value::Bool(false));
m.insert("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(false));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(false));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(false));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingLimits".to_string(), Value::Bool(false));
m.insert("fetchTransactionFee".to_string(), Value::Bool(false));
m.insert("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawAddresses".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(false));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("referral".to_string(), Value::Str("https://p2pb2b.com?referral=ee784c53".to_string()));
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/122f0c86-f3a6-4334-910f-4d8edc865696".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.p2pb2b.com/api/v2/public".to_string()));
m.insert("private".to_string(), Value::Str("https://api.p2pb2b.com/api/v2".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://p2pb2b.com/".to_string()));
m.insert("doc".to_string(), Value::Str("https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md".to_string()));
m.insert("fees".to_string(), Value::Str("https://p2pb2b.com/fee-schedule/".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(1));
m
}));
m.insert("market".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("book".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("depth/result".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/kline".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("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("account/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/new".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/market_order_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/market_deal_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/order_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/executed_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
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("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.2".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1".to_string()), &[]), self.parse_number(Value::Str("0.19".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5".to_string()), &[]), self.parse_number(Value::Str("0.18".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10".to_string()), &[]), self.parse_number(Value::Str("0.17".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25".to_string()), &[]), self.parse_number(Value::Str("0.16".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75".to_string()), &[]), self.parse_number(Value::Str("0.15".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100".to_string()), &[]), self.parse_number(Value::Str("0.14".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("150".to_string()), &[]), self.parse_number(Value::Str("0.13".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300".to_string()), &[]), self.parse_number(Value::Str("0.12".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("450".to_string()), &[]), self.parse_number(Value::Str("0.11".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.1".to_string()), &[])])]));
m.insert("maker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.2".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1".to_string()), &[]), self.parse_number(Value::Str("0.18".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5".to_string()), &[]), self.parse_number(Value::Str("0.16".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10".to_string()), &[]), self.parse_number(Value::Str("0.14".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25".to_string()), &[]), self.parse_number(Value::Str("0.12".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("75".to_string()), &[]), self.parse_number(Value::Str("0.1".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100".to_string()), &[]), self.parse_number(Value::Str("0.08".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("150".to_string()), &[]), self.parse_number(Value::Str("0.06".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300".to_string()), &[]), self.parse_number(Value::Str("0.04".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("450".to_string()), &[]), self.parse_number(Value::Str("0.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500".to_string()), &[]), self.parse_number(Value::Str("0.01".to_string()), &[])])]));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(false));
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("triggerPriceType".to_string(), Value::Null);
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("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(1));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("daysBackCanceled".to_string(), divide(&Value::Int(1), &Value::Int(12)));
m.insert("untilDays".to_string(), Value::Int(1));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(500));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("1001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1003".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1005".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1006".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1007".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1008".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1009".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1010".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1011".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1012".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1013".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("1014".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("1015".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("1016".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("2010".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2020".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2021".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2030".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2040".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("2050".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2051".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2052".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2060".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2061".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2062".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("2070".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3020".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3030".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3040".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3050".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3060".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3070".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3080".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3090".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3100".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3110".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("4001".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("6010".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name p2b#fetchMarkets
* @description retrieves data on all markets for p2b
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#markets
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_markets(&[params.clone()]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": [
// {
// "name": "ETH_BTC",
// "stock": "ETH",
// "money": "BTC",
// "precision": {
// "money": "5",
// "stock": "4",
// "fee": "4"
// },
// "limits": {
// "min_amount": "0.0001",
// "max_amount": "100000",
// "step_size": "0.0001",
// "min_price": "0.00001",
// "max_price": "922327",
// "tick_size": "0.00001",
// "min_total": "0.0001"
// }
// },
// ...
// ]
// }
//
let mut markets: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_markets(markets.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut marketId: Value = self.safe_string_k(market.clone(), "name", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "stock", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "money", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut limits: Value = self.safe_dict_k(market.clone(), "limits", &[]);
let mut maxAmount: Value = self.safe_string_k(limits.clone(), "max_amount", &[]);
let mut maxPrice: Value = self.safe_string_k(limits.clone(), "max_price", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), marketId.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(), Value::Bool(true));
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.safe_number_k(limits.clone(), "step_size", &[]));
m.insert("price".to_string(), self.safe_number_k(limits.clone(), "tick_size", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(limits.clone(), "min_amount", &[]));
m.insert("max".to_string(), self.parse_number(self.omit_zero(maxAmount.clone()), &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(limits.clone(), "min_price", &[]));
m.insert("max".to_string(), self.parse_number(self.omit_zero(maxPrice.clone()), &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(limits.clone(), "min_total", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
});
Value::Null
}
/*
* @method
* @name p2b#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#tickers
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.public_get_tickers(&[params.clone()]).await;
//
// {
// success: true,
// errorCode: '',
// message: '',
// result: {
// KNOLIX_BTC: {
// at: '1699252631',
// ticker: {
// bid: '0.0000332',
// ask: '0.0000333',
// low: '0.0000301',
// high: '0.0000338',
// last: '0.0000333',
// vol: '15.66',
// deal: '0.000501828',
// change: '10.63'
// }
// },
// ...
// },
// cache_time: '1699252631.103631',
// current_time: '1699252644.487566'
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_tickers(result.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name p2b#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#ticker
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_ticker(&[__ws_arg_0]).await;
//
// {
// success: true,
// errorCode: '',
// message: '',
// result: {
// bid: '0.342',
// ask: '0.3421',
// open: '0.3317',
// high: '0.3499',
// low: '0.3311',
// last: '0.3421',
// volume: '17855383.1',
// deal: '6107478.3423',
// change: '3.13'
// },
// cache_time: '1699252953.832795',
// current_time: '1699252958.859391'
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_product(response.clone(), Value::Str("cache_time".to_string()), Value::Int(1000), &[]);
let __ws_arg_1 = self.iso8601(timestamp.clone());
let __ws_arg_2 = self.parse_ticker(result.clone(), &[market.clone()]);
return self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), __ws_arg_1);
m
}), &[__ws_arg_2]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// parseTickers
//
// {
// at: '1699252631',
// ticker: {
// bid: '0.0000332',
// ask: '0.0000333',
// low: '0.0000301',
// high: '0.0000338',
// last: '0.0000333',
// vol: '15.66',
// deal: '0.000501828',
// change: '10.63'
// }
// }
//
// parseTicker
//
// {
// bid: '0.342',
// ask: '0.3421',
// open: '0.3317',
// high: '0.3499',
// low: '0.3311',
// last: '0.3421',
// volume: '17855383.1',
// deal: '6107478.3423',
// change: '3.13'
// }
//
let mut timestamp: Value = self.safe_integer_product(ticker.clone(), Value::Str("at".to_string()), Value::Int(1000), &[]);
if is_true(&Value::Bool(in_op(&ticker, &Value::Str("ticker".to_string())))) {
ticker = self.safe_value_k(ticker.clone(), "ticker", &[]);
}
let mut last: Value = self.safe_string_k(ticker.clone(), "last", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "low", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "bid", &[]));
m.insert("bidVolume".to_string(), Value::Null);
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "ask", &[]));
m.insert("askVolume".to_string(), Value::Null);
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "open", &[]));
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), self.safe_string_k(ticker.clone(), "change", &[]));
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("vol".to_string()), Value::Str("volume".to_string()), &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "deal", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name p2b#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#depth-result
* @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
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {string} [params.interval] 0 (default), 0.00000001, 0.0000001, 0.000001, 0.00001, 0.0001, 0.001, 0.01, 0.1, 1
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".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());
}
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_depth_result(&[__ws_arg_3]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": {
// "asks": [
// [
// "4.53", // Price
// "523.95" // Amount
// ],
// ...
// ],
// "bids": [
// [
// "4.51",
// "244.75"
// ],
// ...
// ]
// },
// "cache_time": 1698733470.469175,
// "current_time": 1698733470.469274
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_product(response.clone(), Value::Str("current_time".to_string()), Value::Int(1000), &[]);
return self.parse_order_book(result.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Int(0), Value::Int(1)]);
Value::Null
}
/*
* @method
* @name p2b#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#history
* @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] 1-100, default=50
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} params.lastId order id
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut lastId: Value = self.safe_integer_k(params.clone(), "lastId", &[]);
if is_equal(&lastId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchTrades () requires an extra parameter params[\"lastId\"]".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("lastId".to_string(), lastId.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_history(&[__ws_arg_4]).await;
//
// {
// success: true,
// errorCode: '',
// message: '',
// result: [
// {
// id: '7495738622',
// type: 'sell',
// time: '1699255565.445418',
// amount: '252.6',
// price: '0.3422'
// },
// ...
// ],
// cache_time: '1699255571.413633',
// current_time: '1699255571.413828'
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_trades(result.clone(), &[market.clone(), since.clone(), limit.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
//
// {
// id: '7495738622',
// type: 'sell',
// time: '1699255565.445418',
// amount: '252.6',
// price: '0.3422'
// }
//
// fetchMyTrades
//
// {
// "deal_id": 7450617292, // Deal id
// "deal_time": 1698506956.66224, // Deal execution time
// "deal_order_id": 171955225751, // Deal order id
// "opposite_order_id": 171955110512, // Opposite order id
// "side": "sell", // Deal side
// "price": "0.05231", // Deal price
// "amount": "0.002", // Deal amount
// "deal": "0.00010462", // Total (price * amount)
// "deal_fee": "0.000000188316", // Deal fee
// "role": "taker", // Role. Taker or maker
// "isSelfTrade": false // is self trade
// }
//
// fetchOrderTrades
//
// {
// "id": 7429883128, // Deal id
// "time": 1698237535.41196, // Deal execution time
// "fee": "0.01755848704", // Deal fee
// "price": "34293.92", // Deal price
// "amount": "0.00032", // Deal amount
// "dealOrderId": 171366551416, // Deal order id
// "role": 1, // Deal role (1 - maker, 2 - taker)
// "deal": "10.9740544" // Total (price * amount)
// }
//
let mut timestamp: Value = self.safe_integer_product2(trade.clone(), Value::Str("time".to_string()), Value::Str("deal_time".to_string()), Value::Int(1000), &[]);
let mut takerOrMaker: Value = self.safe_string_k(trade.clone(), "role", &[]);
if is_equal(&takerOrMaker, &Value::Str("1".to_string())) {
takerOrMaker = Value::Str("maker".to_string());
} else if is_equal(&takerOrMaker, &Value::Str("2".to_string())) {
takerOrMaker = Value::Str("taker".to_string());
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("id".to_string()), Value::Str("deal_id".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("order".to_string(), self.safe_string2(trade.clone(), Value::Str("dealOrderId".to_string()), Value::Str("deal_order_id".to_string()), &[]));
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string2(trade.clone(), Value::Str("type".to_string()), Value::Str("side".to_string()), &[]));
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), self.safe_string_k(trade.clone(), "price", &[]));
m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "amount", &[]));
m.insert("cost".to_string(), self.safe_string_k(trade.clone(), "deal", &[]));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_string_k(market.clone(), "quote", &[]));
m.insert("cost".to_string(), self.safe_string2(trade.clone(), Value::Str("fee".to_string()), Value::Str("deal_fee".to_string()), &[]));
m
}));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name p2b#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#kline
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe 1m, 1h, or 1d
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] 1-500, default=50
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.offset] default=0, with this value the last candles are returned
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), timeframe.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_market_kline(&[__ws_arg_5]).await;
//
// {
// success: true,
// errorCode: '',
// message: '',
// result: [
// [
// 1699253400, // Kline open time
// '0.3429', // Open price
// '0.3427', // Close price
// '0.3429', // Highest price
// '0.3427', // Lowest price
// '1900.4', // Volume for stock currency
// '651.46278', // Volume for money currency
// 'ADA_USDT' // Market name
// ],
// ...
// ],
// cache_time: '1699256375.030292',
// current_time: '1699256375.030494'
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_ohlc_vs(result.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_integer_product(ohlcv.clone(), Value::Int(0), Value::Int(1000), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name p2b#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#all-balances
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_post_account_balances(&[params.clone()]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": {
// "USDT": {
// "available": "71.81328046",
// "freeze": "10.46103091"
// },
// "BTC": {
// "available": "0.00135674",
// "freeze": "0.00020003"
// }
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_balance(result.clone());
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
//
// {
// "USDT": {
// "available": "71.81328046",
// "freeze": "10.46103091"
// },
// "BTC": {
// "available": "0.00135674",
// "freeze": "0.00020003"
// }
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut keys: Value = object_keys(&response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1021: bool = true;
while { if !__for_first_1021 { i = add(&i, &Value::Int(1)); } __for_first_1021 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut currencyId: Value = get_value(&keys, &i);
let mut currencyId: Value = get_value(&keys, &i);
let mut balance: Value = get_value(&response, ¤cyId);
let mut balance: Value = get_value(&response, ¤cyId);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut used: Value = self.safe_string_k(balance.clone(), "freeze", &[]);
let mut available: Value = self.safe_string_k(balance.clone(), "available", &[]);
let mut account: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("free".to_string(), available.clone());
m.insert("used".to_string(), used.clone());
m
});
add_element_to_object(&mut result, &code, account.clone());
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name p2b#createOrder
* @description create a trade order
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#create-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type must be '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
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&type_var, &Value::Str("market".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder () can only accept orders with type \"limit\"".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), side.clone());
m.insert("amount".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("price".to_string(), self.price_to_precision(symbol.clone(), price.clone()));
m
});
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_order_new(&[__ws_arg_6]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": {
// "orderId": 171906478744, // Order id
// "market": "ETH_BTC", // Market name
// "price": "0.04348", // Price
// "side": "buy", // Side
// "type": "limit", // Order type
// "timestamp": 1698484861.746517, // Order creation time
// "dealMoney": "0", // Filled total
// "dealStock": "0", // Filled amount
// "amount": "0.0277", // Original amount
// "takerFee": "0.002", // taker fee
// "makerFee": "0.002", // maker fee
// "left": "0.0277", // Unfilled amount
// "dealFee": "0" // Filled fee
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name p2b#cancelOrder
* @description cancels an open order
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#cancel-order
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("orderId".to_string(), id.clone());
m
});
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_order_cancel(&[__ws_arg_7]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": {
// "orderId": 171906478744,
// "market": "ETH_BTC",
// "price": "0.04348",
// "side": "buy",
// "type": "limit",
// "timestamp": 1698484861.746517,
// "dealMoney": "0",
// "dealStock": "0",
// "amount": "0.0277",
// "takerFee": "0.002",
// "makerFee": "0.002",
// "left": "0.0277",
// "dealFee": "0"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
return self.parse_order(result.clone(), &[]);
Value::Null
}
/*
* @method
* @name p2b#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#open-orders
* @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
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {int} [params.offset] 0-10000, default=0
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOpenOrders () requires the symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".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());
}
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_orders(&[__ws_arg_8]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": [
// {
// "orderId": 171913325964,
// "market": "ETH_BTC",
// "price": "0.06534",
// "side": "sell",
// "type": "limit",
// "timestamp": 1698487986.836821,
// "dealMoney": "0",
// "dealStock": "0",
// "amount": "0.0018",
// "takerFee": "0.0018",
// "makerFee": "0.0016",
// "left": "0.0018",
// "dealFee": "0"
// },
// ...
// ]
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name p2b#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#deals-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] 1-100, default=50
* @param {object} [params] extra parameters specific to the exchange API endpoint
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {int} [params.offset] 0-10000, default=0
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.safe_market(&[symbol.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_order(&[__ws_arg_9]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": {
// "offset": 0,
// "limit": 50,
// "records": [
// {
// "id": 7429883128, // Deal id
// "time": 1698237535.41196, // Deal execution time
// "fee": "0.01755848704", // Deal fee
// "price": "34293.92", // Deal price
// "amount": "0.00032", // Deal amount
// "dealOrderId": 171366551416, // Deal order id
// "role": 1, // Deal role (1 - maker, 2 - taker)
// "deal": "10.9740544" // Total (price * amount)
// }
// ]
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut records: Value = self.safe_list_k(result.clone(), "records", &[Value::List(vec![])]);
return self.parse_trades(records.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name p2b#fetchMyTrades
* @description fetch all trades made by the user, only the transaction records in the past 3 month can be queried, the time between since and params["until"] cannot be longer than 24 hours
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#deals-history-by-market
* @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, default = params["until"] - 86400000
* @param {int} [limit] 1-100, default=50
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch orders for, default = current timestamp or since + 86400000
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {int} [params.offset] 0-10000, default=0
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
if is_equal(&until, &Value::Null) {
if is_equal(&since, &Value::Null) {
until = self.milliseconds();
} else {
until = add(&since, &Value::Int(86400000));
}
}
if is_equal(&since, &Value::Null) {
since = subtract(&until, &Value::Int(86400000));
}
if is_greater_than(&(subtract(&until, &since)), &Value::Int(86400000)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchMyTrades () the time between since and params[\"until\"] cannot be greater than 24 hours".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut sinceSec: Value = self.parse_to_int(divide(&since, &Value::Int(1000)));
let mut untilSec: Value = self.parse_to_int(divide(&until, &Value::Int(1000)));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("market".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("startTime".to_string(), sinceSec.clone());
m.insert("endTime".to_string(), untilSec.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_market_deal_history(&[__ws_arg_10]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": {
// "total": 2, // Total records in the queried range
// "deals": [
// {
// "deal_id": 7450617292, // Deal id
// "deal_time": 1698506956.66224, // Deal execution time
// "deal_order_id": 171955225751, // Deal order id
// "opposite_order_id": 171955110512, // Opposite order id
// "side": "sell", // Deal side
// "price": "0.05231", // Deal price
// "amount": "0.002", // Deal amount
// "deal": "0.00010462", // Total (price * amount)
// "deal_fee": "0.000000188316", // Deal fee
// "role": "taker", // Role. Taker or maker
// "isSelfTrade": false // is self trade
// },
// ...
// ]
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut deals: Value = self.safe_list_k(result.clone(), "deals", &[Value::List(vec![])]);
return self.parse_trades(deals.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name p2b#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user, the time between since and params["until"] cannot be longer than 24 hours
* @see https://github.com/P2B-team/p2b-api-docs/blob/master/api-doc.md#orders-history-by-market
* @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, default = params["until"] - 86400000
* @param {int} [limit] 1-100, default=50
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch orders for, default = current timestamp or since + 86400000
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {int} [params.offset] 0-10000, default=0
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
if is_equal(&until, &Value::Null) {
if is_equal(&since, &Value::Null) {
until = self.milliseconds();
} else {
until = add(&since, &Value::Int(86400000));
}
}
if is_equal(&since, &Value::Null) {
since = subtract(&until, &Value::Int(86400000));
}
if is_greater_than(&(subtract(&until, &since)), &Value::Int(86400000)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchClosedOrders () the time between since and params[\"until\"] cannot be greater than 24 hours".to_string()))));
}
let mut sinceSec: Value = self.parse_to_int(divide(&since, &Value::Int(1000)));
let mut untilSec: Value = self.parse_to_int(divide(&until, &Value::Int(1000)));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("startTime".to_string(), sinceSec.clone());
m.insert("endTime".to_string(), untilSec.clone());
m
});
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("market".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_order_history(&[__ws_arg_11]).await;
//
// {
// "success": true,
// "errorCode": "",
// "message": "",
// "result": {
// "LTC_USDT": [
// {
// "id": 173985944395,
// "amount": "0.1",
// "price": "73",
// "type": "limit",
// "side": "sell",
// "ctime": 1699436194.390845,
// "ftime": 1699436194.390847,
// "market": "LTC_USDT",
// "takerFee": "0.002",
// "makerFee": "0.002",
// "dealFee": "0.01474",
// "dealStock": "0.1",
// "dealMoney": "7.37"
// }
// ]
// }
// }
//
let mut result: Value = self.safe_value_k(response.clone(), "result", &[]);
let mut orders: Value = Value::List(vec![]);
let mut keys: Value = object_keys(&result);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1022: bool = true;
while { if !__for_first_1022 { i = add(&i, &Value::Int(1)); } __for_first_1022 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut marketId: Value = get_value(&keys, &i);
let mut marketId: Value = get_value(&keys, &i);
let mut marketOrders: Value = get_value(&result, &marketId);
let mut marketOrders: Value = get_value(&result, &marketId);
let mut parsedOrders: Value = self.parse_orders(marketOrders.clone(), &[market.clone(), since.clone(), limit.clone()]);
orders = self.array_concat(orders.clone(), parsedOrders.clone());
}
}
return orders;
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// cancelOrder, fetchOpenOrders, createOrder
//
// {
// "orderId": 171906478744,
// "market": "ETH_BTC",
// "price": "0.04348",
// "side": "buy",
// "type": "limit",
// "timestamp": 1698484861.746517,
// "dealMoney": "0",
// "dealStock": "0",
// "amount": "0.0277",
// "takerFee": "0.002",
// "makerFee": "0.002",
// "left": "0.0277",
// "dealFee": "0"
// }
//
// fetchClosedOrders
//
// {
// "id": 171366547790, // Order id
// "amount": "0.00032", // Original amount
// "price": "34293.92", // Order price
// "type": "limit", // Order type
// "side": "sell", // Order side
// "ctime": 1698237533.497241, // Order creation time
// "ftime": 1698237535.41196, // Order fill time
// "market": "BTC_USDT", // Market name
// "takerFee": "0.0018", // Taker fee
// "makerFee": "0.0016", // Market fee
// "dealFee": "0.01755848704", // Deal fee
// "dealStock": "0.00032", // Filled amount
// "dealMoney": "10.9740544" // Filled total
// }
//
let mut timestamp: Value = self.safe_integer_product2(order.clone(), Value::Str("timestamp".to_string()), Value::Str("ctime".to_string()), Value::Int(1000), &[]);
let mut marketId: Value = self.safe_string_k(order.clone(), "market", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), self.safe_string2(order.clone(), Value::Str("id".to_string()), Value::Str("orderId".to_string()), &[]));
m.insert("clientOrderId".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), self.safe_string_k(order.clone(), "type", &[]));
m.insert("timeInForce".to_string(), Value::Null);
m.insert("postOnly".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_k(order.clone(), "side", &[]));
m.insert("price".to_string(), self.safe_string_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_string_k(order.clone(), "amount", &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("average".to_string(), Value::Null);
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "dealStock", &[]));
m.insert("remaining".to_string(), self.safe_string_k(order.clone(), "left", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(&market, &Value::Str("quote".to_string())));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "dealFee", &[]));
m
}));
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
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 = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &self.implode_params(path.clone(), params.clone()));
params = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
if is_equal(&method, &Value::Str("GET".to_string())) {
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(params.clone(), &[])));
}
}
if is_equal(&api, &Value::Str("private".to_string())) {
add_element_to_object(&mut params, &Value::Str("request".to_string()), add(&Value::Str("/api/v2/".to_string()), &path));
add_element_to_object(&mut params, &Value::Str("nonce".to_string()), to_string_val(&self.nonce()));
let mut payload: Value = self.string_to_base64(self.json(params.clone()), &[]); // Body json encoded in base64
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m.insert("X-TXC-APIKEY".to_string(), self.apiKey.clone());
m.insert("X-TXC-PAYLOAD".to_string(), payload.clone());
m.insert("X-TXC-SIGNATURE".to_string(), self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha512".to_string()), &[]));
m
});
body = self.json(params.clone());
}
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;
}
//
// {"success":false,"errorCode":2021,"message":"Unknown market.","result":[]}
// {"success":false,"errorCode":1010,"message":"This action is unauthorized.","result":[]}
// {"success":true,"errorCode":"","message":"","result":{...},"cache_time":1787611797.535462,"current_time":1787611797.535973}
//
let mut success: Value = self.safe_bool_k(response.clone(), "success", &[Value::Bool(true)]);
if !is_equal(&success, &Value::Bool(true)) {
let mut errorCode: Value = self.safe_string_k(response.clone(), "errorCode", &[]);
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())), errorCode.clone(), feedback.clone());
if is_less_than(&code, &Value::Int(400)) {
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
}
return Value::Null;
Value::Null
}
}