// 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 WeexCore {
pub exchange: crate::exchange::Exchange,
}
impl WeexCore {
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 = WeexCore::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 WeexCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_position(self, position, &[market.clone()])
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_last_price(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_last_price(self, entry, &[market.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_ledger_entry(self, entry, &[currency.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_funding_rate_history(self, entry, &[market.clone()])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_margin_mode(self, margin_mode, &[market.clone()])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on WeexCore.
WeexCore::parse_leverage(self, leverage, &[market.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 WeexCore.
WeexCore::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 WeexCore.
WeexCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for WeexCore {
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,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"close_all_positions" => self.close_all_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_contract_order" => self.create_contract_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_contract_order_request" => self.create_contract_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_spot_order" => self.create_spot_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_spot_order_request" => self.create_spot_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"encode_margin_mode" => self.encode_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"encode_trigger_price_type" => self.encode_trigger_price_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_canceled_and_closed_orders" => self.fetch_canceled_and_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_canceled_orders" => self.fetch_canceled_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_contract_ohlcv" => self.fetch_contract_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_last_prices" => self.fetch_last_prices(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&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_leverages" => self.fetch_leverages(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_mode" => self.fetch_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_modes" => self.fetch_margin_modes(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_mark_price" => self.fetch_mark_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_mark_prices" => self.fetch_mark_prices(&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_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders" => self.fetch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(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_positions_for_symbol" => self.fetch_positions_for_symbol(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_ohlcv" => self.fetch_spot_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_status" => self.fetch_status(&args.get(0..).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_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transfers" => self.fetch_transfers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"from_sandbox_market_id" => self.from_sandbox_market_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"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(),
"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_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_last_price" => self.parse_last_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_type" => self.parse_ledger_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_mode" => self.parse_margin_mode(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_margin_type" => self.parse_margin_type(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_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_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_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_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer_status" => self.parse_transfer_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_margin_mode" => self.set_margin_mode(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()[..]),
"to_sandbox_market_id" => self.to_sandbox_market_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for WeexCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for WeexCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl WeexCore {
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("weex".to_string()));
m.insert("name".to_string(), Value::Str("Weex".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("SG".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(20));
m.insert("version".to_string(), Value::Str("v3".to_string()));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
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("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("cancelOrdersWithClientOrderId".to_string(), Value::Bool(true));
m.insert("cancelOrderWithClientOrderId".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(true));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createLimitBuyOrder".to_string(), Value::Bool(true));
m.insert("createLimitOrder".to_string(), Value::Bool(true));
m.insert("createLimitSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(false));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(false));
m.insert("createStopLossOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(false));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("deposit".to_string(), Value::Bool(false));
m.insert("editOrder".to_string(), Value::Bool(false));
m.insert("editOrders".to_string(), Value::Bool(false));
m.insert("editOrderWithClientOrderId".to_string(), Value::Bool(false));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchADLRank".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".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("fetchCanceledAndClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(false));
m.insert("fetchConvertQuote".to_string(), Value::Bool(false));
m.insert("fetchConvertTrade".to_string(), Value::Bool(false));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("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("fetchDepositWithdrawFee".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFees".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(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(true));
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("fetchL2OrderBook".to_string(), Value::Bool(false));
m.insert("fetchL3OrderBook".to_string(), Value::Bool(false));
m.insert("fetchLastPrices".to_string(), Value::Bool(true));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverages".to_string(), Value::Bool(true));
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(true));
m.insert("fetchMarginModes".to_string(), Value::Bool(true));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
m.insert("fetchMarkPrice".to_string(), Value::Bool(true));
m.insert("fetchMarkPrices".to_string(), Value::Bool(true));
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(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".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("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchOrderWithClientOrderId".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionADLRank".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsADLRank".to_string(), Value::Bool(false));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(true));
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("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
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("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
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("fetchWithdrawalWhitelist".to_string(), Value::Bool(false));
m.insert("privateAPI".to_string(), Value::Bool(false));
m.insert("publicAPI".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
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("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/bc67b9f2-75d2-4b8d-963a-18f2fcd9d13c".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api-spot.weex.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api-spot.weex.com".to_string()));
m.insert("contract".to_string(), Value::Str("https://api-contract.weex.com".to_string()));
m.insert("contractPrivate".to_string(), Value::Str("https://api-contract.weex.com".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api-spot.weex.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api-spot.weex.com".to_string()));
m.insert("contract".to_string(), Value::Str("https://api-contract.weex.com".to_string()));
m.insert("contractPrivate".to_string(), Value::Str("https://api-contract.weex.com".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.weex.com".to_string()));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://www.weex.com/api-doc".to_string())]));
m.insert("referral".to_string(), Value::Str("https://www.weex.com/register?vipCode=qfyh".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("api/v3/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v3/coins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("api/v3/exchangeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("api/v3/ping".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v3/apiTradingSymbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("api/v3/market/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("api/v3/market/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("api/v3/market/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(125));
m
}));
m.insert("api/v3/market/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("api/v3/market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("api/v3/market/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
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("api/v3/account/".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v3/account/transferRecords".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("api/v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("api/v3/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("api/v3/allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("api/v3/myTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v3/rebate/affiliate/getAffiliateUIDs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("api/v3/rebate/affiliate/getChannelUserTradeAndAsset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("api/v3/rebate/affiliate/getAffiliateCommission".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("api/v3/rebate/affiliate/getInternalWithdrawalStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("api/v3/rebate/affiliate/querySubChannelTransactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("api/v3/agency/verifyReferrals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("api/v3/agency/getAssert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("api/v3/agency/getDealData".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("api/v3/account/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v3/account/fundingBills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("api/v3/order/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("api/v3/rebate/affiliate/internalWithdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api/v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("api/v3/order/batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m
}));
m.insert("contract".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("capi/v3/market/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/exchangeInfo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(200));
m
}));
m.insert("capi/v3/market/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("capi/v3/market/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/indexPriceKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/markPriceKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/historyKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("capi/v3/market/symbolPrice".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/openInterest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/market/premiumIndex".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/market/fundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("capi/v3/market/apiTradingSymbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m
}));
m
}));
m.insert("contractPrivate".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("capi/v3/account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/account/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/account/accountConfig".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/account/symbolConfig".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/account/position/allPosition".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("capi/v3/account/position/singlePosition".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("capi/v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("capi/v3/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/userTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/openAlgoOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("capi/v3/allAlgoOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/sim/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/sim/position/allPosition".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("capi/v3/sim/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("capi/v3/account/income".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/account/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("capi/v3/account/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("capi/v3/account/positionMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("capi/v3/account/modifyAutoAppendMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("capi/v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/closePositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("capi/v3/algoOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/placeTpSlOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/modifyTpSlOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capi/v3/sim/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("capi/v3/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("capi/v3/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/allOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("capi/v3/algoOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("capi/v3/algoOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m
}));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m.insert("password".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("8h".to_string(), Value::Str("8h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
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("-1000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1054".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("-1040".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1041".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1042".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1043".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1044".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1045".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1046".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1047".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1049".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-1050".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1051".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1052".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1053".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1055".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1056".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1057".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1058".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-1115".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1116".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1117".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1121".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-1128".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1135".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1140".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1141".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("-1142".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1150".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1160".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1170".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1171".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1180".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1190".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-2007".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-2200".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("-3006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3200".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3235".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-3236".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("-3313".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-3613".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("FAILED_ORDER_NOT_FOUND".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount not enough".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("INVALID_ARGUMENT".to_string(), Value::Str("BadRequest".to_string()).clone());
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("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.1".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.1".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.1".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.09".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.08".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000000".to_string()), &[]), self.parse_number(Value::Str("0.06".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.05".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.04".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0.03".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0".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.1".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.08".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.07".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000000".to_string()), &[]), self.parse_number(Value::Str("0.05".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.04".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.03".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.01".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])])]));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("get".to_string()));
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.1".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.1".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.1".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.09".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.08".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000000".to_string()), &[]), self.parse_number(Value::Str("0.06".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.05".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.04".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0.03".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0".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.1".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000".to_string()), &[]), self.parse_number(Value::Str("0.08".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.07".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("2000000".to_string()), &[]), self.parse_number(Value::Str("0.05".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.04".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.03".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("25000000".to_string()), &[]), self.parse_number(Value::Str("0.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.01".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0".to_string()), &[])])]));
m
}));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("quote".to_string()));
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.08".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.02".to_string()), &[]));
m.insert("tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), Value::List(vec![Value::List(vec![self.parse_number(Value::Str("0".to_string()), &[]), self.parse_number(Value::Str("0.08".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.075".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.06".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.055".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0.05".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.048".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0.045".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300000000".to_string()), &[]), self.parse_number(Value::Str("0.042".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000000".to_string()), &[]), self.parse_number(Value::Str("0.04".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.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("1000000".to_string()), &[]), self.parse_number(Value::Str("0.02".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("5000000".to_string()), &[]), self.parse_number(Value::Str("0.018".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("10000000".to_string()), &[]), self.parse_number(Value::Str("0.018".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("30000000".to_string()), &[]), self.parse_number(Value::Str("0.016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("50000000".to_string()), &[]), self.parse_number(Value::Str("0.016".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("100000000".to_string()), &[]), self.parse_number(Value::Str("0.014".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("300000000".to_string()), &[]), self.parse_number(Value::Str("0.012".to_string()), &[])]), Value::List(vec![self.parse_number(Value::Str("500000000".to_string()), &[]), self.parse_number(Value::Str("0.01".to_string()), &[])])]));
m
}));
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("XBT".to_string(), Value::Str("XBT".to_string()));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("partner".to_string(), Value::Str("b-WEEX111125".to_string()));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
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("trading".to_string(), Value::Str("spot".to_string()));
m.insert("fund".to_string(), Value::Str("funding".to_string()));
m.insert("funding".to_string(), Value::Str("funding".to_string()));
m.insert("swap".to_string(), Value::Str("contract".to_string()));
m.insert("contract".to_string(), Value::Str("contract".to_string()));
m.insert("futures".to_string(), Value::Str("contract".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BEP20".to_string(), Value::Str("BEP20(BSC)".to_string()));
m.insert("BSC".to_string(), Value::Str("BEP20(BSC)".to_string()));
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("POLYGON".to_string(), Value::Str("POLYGON(MATIC)".to_string()));
m.insert("MATIC".to_string(), Value::Str("POLYGON(MATIC)".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBITRUM(ARB)".to_string()));
m.insert("SOL".to_string(), Value::Str("SOLANA(SOL)".to_string()));
m.insert("OP".to_string(), Value::Str("OPTIMISM(OP)".to_string()));
m.insert("OPTIMISM".to_string(), Value::Str("OPTIMISM(OP)".to_string()));
m.insert("AVAXC".to_string(), Value::Str("AVALANCHE_C(AVAX_C)".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BEP20(BSC)".to_string(), Value::Str("BEP20".to_string()));
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
m.insert("POLYGON(MATIC)".to_string(), Value::Str("MATIC".to_string()));
m.insert("ARBITRUM(ARB)".to_string(), Value::Str("ARBITRUM".to_string()));
m.insert("SOLANA(SOL)".to_string(), Value::Str("SOL".to_string()));
m.insert("OPTIMISM(OP)".to_string(), Value::Str("OP".to_string()));
m.insert("AVALANCHE_C(AVAX_C)".to_string(), Value::Str("AVAXC".to_string()));
m
}));
m.insert("timeframes".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("1m".to_string(), Value::Str("1m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("2h".to_string(), Value::Str("2h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("6h".to_string(), Value::Str("6h".to_string()));
m.insert("8h".to_string(), Value::Str("8h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("1w".to_string(), Value::Str("1w".to_string()));
m
}));
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("test".to_string(), Value::Bool(false));
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(false));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".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(false));
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::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(10));
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(100));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Int(100000));
m.insert("untilDays".to_string(), Value::Int(100000));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(true));
m
}));
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(300));
m
}));
m
}));
m.insert("forDerivs".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(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(false));
m
}));
m.insert("price".to_string(), Value::Bool(false));
m
}));
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(false));
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::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(10));
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(100));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
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(100));
m.insert("trigger".to_string(), Value::Bool(true));
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("fetchCanceledAndClosedOrders".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("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
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("forDerivs".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m
})]);
Value::Null
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
/*
* @method
* @name weex#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://www.weex.com/api-doc/spot/ConfigAPI/Ping
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_api_v3_ping(&[params.clone()]).await;
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("ok".to_string()));
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
m
});
Value::Null
}
/*
* @method
* @name weex#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://www.weex.com/api-doc/spot/ConfigAPI/GetServerTime
* @see https://www.weex.com/api-doc/contract/Market_API/GetServerTime
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap', default is 'spot'
* @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 type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTime".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if !is_equal(&type_var, &Value::Str("spot".to_string())) {
response = self.contract_get_capi_v3_market_time(&[params.clone()]).await;
} else {
response = self.public_get_api_v3_time(&[params.clone()]).await;
}
return self.safe_integer_k(response.clone(), "serverTime", &[]);
Value::Null
}
/*
* @method
* @name weex#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://www.weex.com/api-doc/spot/ConfigAPI/CurrencyInfo
* @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_api_v3_coins(&[params.clone()]).await;
return self.parse_currencies(response.clone());
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut currencyId: Value = self.safe_string_k(rawCurrency.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut name: Value = self.safe_string_k(rawCurrency.clone(), "name", &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut chains: Value = self.safe_list_k(rawCurrency.clone(), "networkList", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_1094: bool = true;
while { if !__for_first_1094 { j = add(&j, &Value::Int(1)); } __for_first_1094 = false; is_less_than(&j, &get_array_length(&chains)) } {
let mut chain: Value = self.safe_dict(chains.clone(), j.clone(), &[]);
let mut networkId: Value = self.safe_string_k(chain.clone(), "network", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.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(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(chain.clone(), "depositEnable", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(chain.clone(), "withdrawEnable", &[]));
m.insert("fee".to_string(), self.safe_number_k(chain.clone(), "withdrawFee", &[]));
m.insert("precision".to_string(), self.safe_number_k(chain.clone(), "withdrawIntegerMultiple", &[]));
m.insert("isDefault".to_string(), self.safe_bool_k(chain.clone(), "isDefault", &[Value::Bool(false)]));
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(), self.safe_number_k(chain.clone(), "depositDust", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m
}));
}
}
}
let mut networkKeys: Value = object_keys(&networks);
let mut networksLength: Value = get_array_length(&networkKeys);
let mut emptyChains: bool = is_equal(&networksLength, &Value::Int(0)); // non-functional coins
let mut valueForEmpty: Value = ternary(is_true(&emptyChains), Value::Bool(false), Value::Null);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rawCurrency.clone());
m.insert("code".to_string(), code.clone());
m.insert("id".to_string(), currencyId.clone());
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m.insert("name".to_string(), name.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), valueForEmpty.clone());
m.insert("withdraw".to_string(), valueForEmpty.clone());
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
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.insert("networks".to_string(), networks.clone());
m
}));
Value::Null
}
/*
* @method
* @name weex#fetchMarkets
* @description retrieves data on all markets for exchagne
* @see https://www.weex.com/api-doc/spot/ConfigAPI/GetProductInfo // spot
* @see https://www.weex.com/api-doc/contract/Market_API/GetContractInfo // contract
* @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
}));
if is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut promises: Value = Value::List(vec![self.public_get_api_v3_exchange_info(&[params.clone()]).await, self.contract_get_capi_v3_market_exchange_info(&[params.clone()]).await]);
let mut spotResponsecontractResponseVariable = promise_all(&promises).await;
let mut spotResponse: Value = get_value(&spotResponsecontractResponseVariable, &Value::Int(0));
let mut contractResponse: Value = get_value(&spotResponsecontractResponseVariable, &Value::Int(1));
let mut spotArray: Value = self.safe_list_k(spotResponse.clone(), "symbols", &[Value::List(vec![])]);
let mut contractArray: Value = self.safe_list_k(contractResponse.clone(), "symbols", &[Value::List(vec![])]);
let mut result: Value = self.array_concat(spotArray.clone(), contractArray.clone());
return self.parse_markets(result.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
//
// spot
// {
// "symbol": "ETHUSDT",
// "status": "TRADING",
// "baseAsset": "ETH",
// "baseAssetPrecision": "8",
// "quoteAsset": "USDT",
// "quoteAssetPrecision": "8",
// "tickSize": "0.01",
// "stepSize": "0.00001",
// "minTradeAmount": "0.0001",
// "maxTradeAmount": "99999",
// "takerFeeRate": "0.001",
// "makerFeeRate": "0.001",
// "buyLimitPriceRatio": "0.1",
// "sellLimitPriceRatio": "0.1",
// "marketBuyLimitSize": "99999",
// "marketSellLimitSize": "99999",
// "marketFallbackPriceRatio": "0",
// "enableTrade": true,
// "enableDisplay": true,
// "displayDigitMerge": "0.01,0.1,0.5,1,5",
// "displayNew": false,
// "displayHot": false
// }
//
// contract
// {
// "symbol": "ETHUSDT",
// "baseAsset": "ETH",
// "quoteAsset": "USDT",
// "marginAsset": "USDT",
// "pricePrecision": "2",
// "quantityPrecision": "3",
// "baseAssetPrecision": "2",
// "quotePrecision": "8",
// "contractVal": "0.001",
// "delivery": [
// "00:00:00",
// "08:00:00",
// "16:00:00"
// ],
// "forwardContractFlag": true,
// "minLeverage": "1",
// "maxLeverage": "400",
// "buyLimitPriceRatio": "0.01",
// "sellLimitPriceRatio": "0.01",
// "makerFeeRate": "0.0002",
// "takerFeeRate": "0.0008",
// "minOrderSize": "0.001",
// "maxOrderSize": "1000000",
// "maxPositionSize": "5000000",
// "marketOpenLimitSize": "2300"
// }
//
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseAsset", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteAsset", &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "marginAsset", &[]);
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 active: Value = Value::Bool(true);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut isSpot: Value = Value::Bool(true);
let mut isLinear: Value = Value::Null;
let mut isInverse: Value = Value::Null;
if !is_equal(&settle, &Value::Null) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &settle));
isSpot = Value::Bool(false);
if is_equal(&settle, "e) {
isLinear = Value::Bool(true);
isInverse = Value::Bool(false);
} else if is_equal(&settle, &base) {
isLinear = Value::Bool(false);
isInverse = Value::Bool(true);
}
} else {
active = self.safe_bool_k(market.clone(), "enableTrade", &[Value::Bool(false)]);
}
let mut amountPrecision: Value = self.safe_number_k(market.clone(), "stepSize", &[]);
let mut pricePrecision: Value = self.safe_number_k(market.clone(), "tickSize", &[]);
if is_equal(&amountPrecision, &Value::Null) {
let mut amountPrecisionString: Value = self.parse_precision(&[self.safe_string_k(market.clone(), "quantityPrecision", &[])]);
let mut pricePrecisionString: Value = self.parse_precision(&[self.safe_string_k(market.clone(), "pricePrecision", &[])]);
amountPrecision = self.parse_number(amountPrecisionString.clone(), &[]);
pricePrecision = self.parse_number(pricePrecisionString.clone(), &[]);
}
let mut fees: Value = self.safe_dict(self.fees.clone(), ternary(is_true(&isSpot), Value::Str("spot".to_string()), Value::Str("contract".to_string())), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing id".to_string()))));
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("lowercaseId".to_string(), to_lower(&id));
m.insert("numericId".to_string(), self.safe_integer_k(market.clone(), "contractId", &[]));
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(), ternary(is_true(&isSpot), Value::Str("spot".to_string()), Value::Str("swap".to_string())));
m.insert("spot".to_string(), isSpot.clone());
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(!is_true(&isSpot)));
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(!is_true(&isSpot)));
m.insert("linear".to_string(), isLinear.clone());
m.insert("inverse".to_string(), isInverse.clone());
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "takerFeeRate", &[]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "makerFeeRate", &[]));
m.insert("feeSide".to_string(), get_value(&fees, &Value::Str("feeSide".to_string())));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractVal", &[]));
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(), amountPrecision.clone());
m.insert("price".to_string(), pricePrecision.clone());
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(), self.safe_number_k(market.clone(), "minLeverage", &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxLeverage", &[]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number2(market.clone(), Value::Str("minTradeAmount".to_string()), Value::Str("minOrderSize".to_string()), &[]));
m.insert("max".to_string(), self.safe_number2(market.clone(), Value::Str("maxTradeAmount".to_string()), Value::Str("maxOrderSize".to_string()), &[]));
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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("percentage".to_string(), get_value(&fees, &Value::Str("percentage".to_string())));
m.insert("tierBased".to_string(), get_value(&fees, &Value::Str("tierBased".to_string())));
m.insert("tiers".to_string(), get_value(&fees, &Value::Str("tiers".to_string())));
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name weex#fetchTickers
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.weex.com/api-doc/spot/MarketDataAPI/GetAllTickerInfo // spot
* @see https://www.weex.com/api-doc/contract/Market_API/GetTicker24h // contract
* @param {string} symbols unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap', default is 'spot' (used if symbols are not provided)
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
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)); }
let mut symbolsLength: Value = Value::Int(0);
if !is_equal(&symbols, &Value::Null) {
symbolsLength = get_array_length(&symbols);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&symbolsLength, &Value::Int(1)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
//
// [
// {
// "symbol": "ETHUSDT",
// "priceChange": "-72.98",
// "priceChangePercent": "-0.033811",
// "lastPrice": "2085.46",
// "bidPrice": "2085.44",
// "bidQty": "1.53848",
// "askPrice": "2085.47",
// "askQty": "1.87504",
// "openPrice": "2158.44",
// "highPrice": "2168.40",
// "lowPrice": "2061.12",
// "volume": "157359.56105",
// "quoteVolume": "331284305.7193626",
// "openTime": 1775493000000,
// "closeTime": 1775579400000,
// "count": 59727
// }
// ]
//
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_api_v3_market_ticker24hr(&[__ws_arg_0]).await;
} else {
//
// [
// {
// "symbol": "ETHUSDT",
// "priceChange": "-75.49",
// "priceChangePercent": "-0.034992",
// "lastPrice": "2081.80",
// "openPrice": "2157.29",
// "highPrice": "2167.51",
// "lowPrice": "2059.17",
// "volume": "623160.426",
// "quoteVolume": "1310647345.19346",
// "openTime": 1775493000000,
// "closeTime": 1775579400000,
// "markPrice": "2081.8",
// "indexPrice": "2082.75"
// }
// ]
//
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_get_capi_v3_market_ticker24hr(&[__ws_arg_1]).await;
}
if !is_true(&Value::Bool(is_array(&response))) {
response = Value::List(vec![response.clone()]);
}
return self.parse_tickers(response.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchBidsAsks
* @description fetches the bid and ask price and volume for multiple markets
* @see https://www.weex.com/api-doc/spot/MarketDataAPI/GetBookTicker // spot
* @see https://www.weex.com/api-doc/contract/Market_API/GetBookTicker // contract
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap', default is 'spot' (used if symbols are not provided)
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_bids_asks(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBidsAsks".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.public_get_api_v3_market_ticker_book_ticker(&[params.clone()]).await;
} else {
response = self.contract_get_capi_v3_market_ticker_book_ticker(&[params.clone()]).await;
}
if !is_true(&Value::Bool(is_array(&response))) {
response = Value::List(vec![response.clone()]);
}
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1095: bool = true;
while { if !__for_first_1095 { i = add(&i, &Value::Int(1)); } __for_first_1095 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut rawTicker: Value = get_value(&response, &i);
let mut rawTicker: Value = get_value(&response, &i);
// book tickers have no markPrice, so resolve the market from the endpoint type to disambiguate the spot/swap market id in parseTicker
let mut marketId: Value = self.safe_string_k(rawTicker.clone(), "symbol", &[]);
let mut tickerMarket: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
append_to_array(&mut results, self.parse_ticker(rawTicker.clone(), &[tickerMarket.clone()]));
}
}
return self.filter_by_array_tickers(results.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
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": "ETHUSDT",
// "priceChange": "-72.98",
// "priceChangePercent": "-0.033811",
// "lastPrice": "2085.46",
// "bidPrice": "2085.44",
// "bidQty": "1.53848",
// "askPrice": "2085.47",
// "askQty": "1.87504",
// "openPrice": "2158.44",
// "highPrice": "2168.40",
// "lowPrice": "2061.12",
// "volume": "157359.56105",
// "quoteVolume": "331284305.7193626",
// "openTime": 1775493000000,
// "closeTime": 1775579400000,
// "count": 59727
// }
//
// swap
// {
// "symbol": "ETHUSDT",
// "priceChange": "-75.49",
// "priceChangePercent": "-0.034992",
// "lastPrice": "2081.80",
// "openPrice": "2157.29",
// "highPrice": "2167.51",
// "lowPrice": "2059.17",
// "volume": "623160.426",
// "quoteVolume": "1310647345.19346",
// "openTime": 1775493000000,
// "closeTime": 1775579400000,
// "markPrice": "2081.8",
// "indexPrice": "2082.75"
// }
//
// fetchMarkPrice (markPrice or indexPrice is copied from the raw 'price' field by fetchMarkPrice before parsing, depending on the requested priceType)
// {
// "symbol": "ETHUSDT",
// "price": "1929.18",
// "markPrice": "1929.18",
// "time": 1786347445044
// }
//
// fetchMarkPrices
// {
// "symbol": "ETHUSDT",
// "markPrice": "1929.88",
// "indexPrice": "1930.15",
// "forecastFundingRate": "0.00003489",
// "lastFundingRate": "0.00004879",
// "interestRate": "0.001",
// "nextFundingTime": 1786348800000,
// "time": 1786347284100,
// "collectCycle": 480
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
let mut markPrice: Value = self.safe_string_k(ticker.clone(), "markPrice", &[]);
let mut marketType: Value = Value::Str("spot".to_string());
if is_true(&(!is_equal(&markPrice, &Value::Null))) || is_true(&(is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))))) {
// 24hr swap tickers carry markPrice, but book tickers do not, so also honor the market resolved by the caller
marketType = Value::Str("swap".to_string());
}
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut timestamp: Value = self.safe_integer2(ticker.clone(), Value::Str("closeTime".to_string()), Value::Str("time".to_string()), &[]);
let mut percentage: Value = crate::precise::Precise::stringMul(&self.safe_string_k(ticker.clone(), "priceChangePercent", &[]), &Value::Str("100".to_string()));
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
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_string_k(ticker.clone(), "highPrice", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "lowPrice", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "bidPrice", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bidQty", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "askPrice", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "askQty", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "openPrice", &[]));
m.insert("close".to_string(), self.safe_string_k(ticker.clone(), "lastPrice", &[]));
m.insert("last".to_string(), self.safe_string_k(ticker.clone(), "lastPrice", &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "priceChange", &[]));
m.insert("percentage".to_string(), percentage.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "volume", &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "quoteVolume", &[]));
m.insert("markPrice".to_string(), markPrice.clone());
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "indexPrice", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchLastPrices
* @description fetches the last price for multiple markets
* @see https://www.weex.com/api-doc/spot/MarketDataAPI/GetTickerInfo
* @param {string[]} [symbols] unified symbols of the markets to fetch the last prices for, all spot markets are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of lastprice structures
*/
pub async fn fetch_last_prices(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLastPrices".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&type_var, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLastPrices() supports spot markets only, use fetchMarkPrices() or fetchTickers() for contract markets".to_string()))));
}
let mut response: Value = self.public_get_api_v3_market_ticker_price(&[params.clone()]).await;
return self.parse_last_prices(response.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_last_price(&self, mut entry: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETHUSDT",
// "price": "1929.67"
// }
//
let mut marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("spot".to_string())]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("price".to_string(), self.safe_number_omit_zero(entry.clone(), Value::Str("price".to_string()), &[]));
m.insert("side".to_string(), Value::Null);
m.insert("info".to_string(), entry.clone());
m
});
Value::Null
}
/*
* @method
* @name weex#fetchMarkPrice
* @description fetches mark price for the market
* @see https://www.weex.com/api-doc/contract/Market_API/GetSymbolPrice
* @param {string} symbol unified symbol of the market to fetch the mark price for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.priceType] "MARK" (default) or "INDEX", with "INDEX" the price is returned as the indexPrice of the ticker
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_mark_price(&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());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchMarkPrice() supports contract markets only".to_string()))));
}
let mut priceType: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMarkPrice".to_string()), Value::Str("priceType".to_string()), &[Value::Str("MARK".to_string())]); priceType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }; // the endpoint defaults to INDEX
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("priceType".to_string(), priceType.clone());
m
});
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_get_capi_v3_market_symbol_price(&[__ws_arg_2]).await;
//
// {
// "symbol": "ETHUSDT",
// "price": "1929.18",
// "time": 1786347445044
// }
//
// normalize here instead of falling back to 'price' in parseTicker, so a bare 'price' field in other payloads can never silently become the mark price
let mut ticker: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[response.clone()]);
if is_equal(&priceType, &Value::Str("INDEX".to_string())) {
{ let __be_tmp = self.safe_string_k(ticker.clone(), "price", &[]); add_element_to_object(&mut ticker, &Value::Str("indexPrice".to_string()), __be_tmp); };
} else {
{ let __be_tmp = self.safe_string_k(ticker.clone(), "price", &[]); add_element_to_object(&mut ticker, &Value::Str("markPrice".to_string()), __be_tmp); };
}
return self.parse_ticker(ticker.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchMarkPrices
* @description fetches mark prices for multiple markets
* @see https://www.weex.com/api-doc/contract/Market_API/GetCurrentFundingRate
* @param {string[]} [symbols] unified symbols of the markets to fetch the mark prices for, all contract markets 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_mark_prices(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Str("swap".to_string())]); // reject non-contract symbols instead of silently filtering the result to an empty dict
let mut response: Value = self.contract_get_capi_v3_market_premium_index(&[params.clone()]).await;
return self.parse_tickers(response.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://www.weex.com/api-doc/spot/MarketDataAPI/GetDepthData // spot
* @see https://www.weex.com/api-doc/contract/Market_API/GetDepthData // contract
* @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 (default 15, max 200)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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_true(&(!is_equal(&limit, &Value::Null))) && is_true(&(is_greater_than(&limit, &Value::Int(15)))) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), Value::Int(200)); // default is 15, max is 200
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_api_v3_market_depth(&[__ws_arg_3]).await;
} else {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_get_capi_v3_market_depth(&[__ws_arg_4]).await;
}
//
// {
// "asks": [
// [
// "2096.77",
// "45.592"
// ]
// ],
// "bids": [
// [
// "2096.76",
// "49.162"
// ]
// ],
// "lastUpdateId": 14138610208
// }
//
let mut orderbook: Value = self.parse_order_book(response.clone(), symbol.clone(), &[]);
add_element_to_object(&mut orderbook, &Value::Str("nonce".to_string()), self.safe_integer_k(response.clone(), "lastUpdateId", &[]));
return orderbook;
Value::Null
}
/*
* @method
* @name weex#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://www.weex.com/api-doc/spot/MarketDataAPI/GetKLineData // spot
* @see https://www.weex.com/api-doc/contract/Market_API/GetKlines // contract last price
* @see https://www.weex.com/api-doc/contract/Market_API/GetIndexPriceKlines // contract index price
* @see https://www.weex.com/api-doc/contract/Market_API/GetMarkPriceKlines // contract mark price
* @see https://www.weex.com/api-doc/contract/Market_API/GetHistoryKlines // contract historical klines
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch (default 100, max 300)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* Check fetchSpotOHLCV() and fetchContractOHLCV() for more details on the extra parameters that can be used in 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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
return self.fetch_spot_ohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), params.clone()]).await;
} else {
return self.fetch_contract_ohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @ignore
* @name weex#fetchSpotOHLCV
* @description helper method for fetchOHLCV
* @see https://www.weex.com/api-doc/spot/MarketDataAPI/GetKLineData
* @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
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_spot_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("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 __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_api_v3_market_klines(&[__ws_arg_5]).await;
return self.parse_ohlc_vs(self.to_array(response.clone()), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @ignore
* @name weex#fetchContractOHLCV
* @description helper method for fetchOHLCV
* @see https://www.weex.com/api-doc/contract/Market_API/GetKlines // contract last price
* @see https://www.weex.com/api-doc/contract/Market_API/GetIndexPriceKlines // contract index price
* @see https://www.weex.com/api-doc/contract/Market_API/GetMarkPriceKlines // contract mark price
* @see https://www.weex.com/api-doc/contract/Market_API/GetHistoryKlines // contract historical klines
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch (default 100, max 100 for historical klines, max 1000 for other contract klines)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @param {boolean} [params.paginate] whether to automatically paginate requests until the required number of candles is returned
* @param {boolean} [params.historical] whether to fetch historical klines (default is false). If false, will fetch last price klines
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_contract_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 maxHistoricalLimit: Value = Value::Int(100);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("historical".to_string(), Value::Bool(true));
m
})]);
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), maxHistoricalLimit.clone()]).await;
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut historical: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("historical".to_string()), &[]); historical = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut timeframeOption: Value = self.safe_dict_k(self.options.clone(), "timeframes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractTimeframes: Value = self.safe_dict_k(timeframeOption.clone(), "contract", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
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(contractTimeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m
});
let mut priceType: Value = self.safe_string_upper(params.clone(), Value::Str("price".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("historical".to_string()), Value::Str("until".to_string()), Value::Str("price".to_string())]), &[]);
let mut response: Value = Value::Null;
if !is_equal(&limit, &Value::Null) {
limit = crate::runtime::Math::min(&limit, &Value::Int(1000)); // hardcap threshold
}
if is_true(&historical) {
if !is_equal(&priceType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("priceType".to_string()), priceType.clone());
}
let mut startTime: Value = since.clone();
let mut endTime: Value = until.clone();
if is_true(&(is_equal(&since, &Value::Null))) || is_true(&(is_equal(&until, &Value::Null))) {
let mut now: Value = self.milliseconds();
let mut duration: Value = multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000));
let mut numberOfCandles: Value = ternary(is_true(&(!is_equal(&limit, &Value::Null) && !is_equal(&limit, &Value::Null) && !is_equal(&limit, &Value::Int(0)))), limit.clone(), maxHistoricalLimit.clone());
let mut timeDelta: Value = multiply(&numberOfCandles, &duration);
if is_true(&(is_equal(&since, &Value::Null))) && is_true(&(is_equal(&until, &Value::Null))) {
endTime = now.clone();
startTime = subtract(&now, &timeDelta);
} else if is_equal(&since, &Value::Null) {
if is_equal(&until, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOHLCV() requires a since or until argument".to_string()))));
}
startTime = subtract(&until, &timeDelta);
} else {
endTime = add(&since, &timeDelta);
}
}
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), startTime.clone());
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), endTime.clone());
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_get_capi_v3_market_history_klines(&[__ws_arg_6]).await;
} else {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if is_equal(&priceType, &Value::Str("MARK".to_string())) {
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_get_capi_v3_market_mark_price_klines(&[__ws_arg_7]).await;
} else if is_equal(&priceType, &Value::Str("INDEX".to_string())) {
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_get_capi_v3_market_index_price_klines(&[__ws_arg_8]).await;
} else {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_get_capi_v3_market_klines(&[__ws_arg_9]).await;
}
}
return self.parse_ohlc_vs(self.to_array(response.clone()), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_integer(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name weex#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://www.weex.com/api-doc/spot/MarketDataAPI/GetTradeData // spot
* @see https://www.weex.com/api-doc/contract/Market_API/GetRecentTrades // contract
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch (default 100, max 1000)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000)));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_api_v3_market_trades(&[__ws_arg_10]).await;
} else {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_get_capi_v3_market_trades(&[__ws_arg_11]).await;
}
//
// [
// {
// "id": "875fba11-f8a1-42ad-915d-012ccb375e8a",
// "price": "2114.77",
// "qty": "0.01000",
// "quoteQty": "21.1477000",
// "time": 1775594995485,
// "isBuyerMaker": false,
// "isBestMatch": true
// }
// ]
//
let mut responseList: Value = Value::List(vec![]);
if !is_equal(&response, &Value::Null) {
responseList = self.to_array(response.clone());
}
return self.parse_trades(responseList.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": "875fba11-f8a1-42ad-915d-012ccb375e8a",
// "price": "2114.77",
// "qty": "0.01000",
// "quoteQty": "21.1477000",
// "time": 1775594995485,
// "isBuyerMaker": false,
// "isBestMatch": true
// }
//
// fetchMyTrades (spot)
// {
// "symbol": "DOGEUSDT",
// "id": 736825748291060702,
// "orderId": 736825748215563230,
// "price": "0.09349",
// "qty": "250.0",
// "quoteQty": "23.3725",
// "commission": "0.0233725",
// "time": 1775672947953,
// "isBuyer": false
// }
//
// fetchMyTrades (contract)
// {
// "id": 737074389731770728,
// "orderId": 737074043320009064,
// "symbol": "DOGEUSDT",
// "buyer": true,
// "commission": "0.00183500",
// "commissionAsset": "USDT",
// "maker": true,
// "price": "0.09175",
// "qty": "100",
// "quoteQty": "9.17500",
// "realizedPnl": "0",
// "side": "BUY",
// "positionSide": "LONG",
// "time": 1775732228692
// }
//
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "time", &[]);
let mut isBuyer: Value = self.safe_bool_k(trade.clone(), "isBuyer", &[]);
let mut side: Value = self.safe_string_lower(trade.clone(), Value::Str("side".to_string()), &[]);
let mut isBuyerMaker: Value = self.safe_bool_k(trade.clone(), "isBuyerMaker", &[]);
if !is_equal(&isBuyer, &Value::Null) {
side = ternary(is_true(&isBuyer), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
} else if !is_equal(&isBuyerMaker, &Value::Null) {
side = ternary(is_true(&isBuyerMaker), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
}
let mut isSpot: Value = Value::Bool(true);
if is_equal(&market, &Value::Null) {
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
let mut realizedPnl: Value = self.safe_string_k(trade.clone(), "realizedPnl", &[]);
let mut marketType: Value = ternary(is_true(&(!is_equal(&realizedPnl, &Value::Null))), Value::Str("swap".to_string()), Value::Str("spot".to_string()));
market = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
isSpot = Value::Bool(is_equal(&marketType, &Value::Str("spot".to_string())));
} else {
isSpot = get_value(&market, &Value::Str("spot".to_string()));
}
let mut fee: Value = Value::Null;
let mut commission: Value = self.safe_string_k(trade.clone(), "commission", &[]);
if !is_equal(&commission, &Value::Null) {
let mut commissionAsset: Value = self.safe_string_k(trade.clone(), "commissionAsset", &[]);
let mut feeCurrency: Value = self.safe_currency_code(commissionAsset.clone(), &[]);
if is_equal(&isSpot, &Value::Bool(true)) {
if is_equal(&side, &Value::Str("buy".to_string())) {
feeCurrency = get_value(&market, &Value::Str("base".to_string()));
} else {
feeCurrency = get_value(&market, &Value::Str("quote".to_string()));
}
}
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), commission.clone());
m.insert("currency".to_string(), feeCurrency.clone());
m
});
}
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "maker", &[]);
let mut takerOrMaker: Value = Value::Null;
if !is_equal(&isMaker, &Value::Null) {
takerOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
} else if !is_equal(&isBuyerMaker, &Value::Null) {
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_string_k(trade.clone(), "id", &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), self.safe_string_k(trade.clone(), "price", &[]));
m.insert("amount".to_string(), self.safe_string_k(trade.clone(), "qty", &[]));
m.insert("cost".to_string(), self.safe_string_k(trade.clone(), "quoteQty", &[]));
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchOpenInterest
* @description retrieves the open interest of a contract trading pair
* @see https://www.weex.com/api-doc/contract/Market_API/GetOpenInterest
* @param {string} symbol unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @returns {object} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_get_capi_v3_market_open_interest(&[__ws_arg_12]).await;
return self.parse_open_interest(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETHUSDT",
// "openInterest": "1772356.352",
// "time": 1775595582598
// }
//
let mut marketId: Value = self.safe_string_k(interest.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut timestamp: Value = self.safe_integer_k(interest.clone(), "time", &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("openInterestAmount".to_string(), self.safe_string_k(interest.clone(), "openInterest", &[]));
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchFundingRates
* @description fetch the funding rate for multiple markets
* @see https://www.weex.com/api-doc/contract/Market_API/GetCurrentFundingRate
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] "linear" or "inverse"
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rates-structure}, indexed by market symbols
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut symbolsLength: Value = Value::Int(0);
if !is_equal(&symbols, &Value::Null) {
symbolsLength = get_array_length(&symbols);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&symbolsLength, &Value::Int(1)) {
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_get_capi_v3_market_premium_index(&[__ws_arg_13]).await;
return self.parse_funding_rates(response.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "time", &[]);
let mut nextFundingTimestamp: Value = self.safe_integer_k(contract.clone(), "nextFundingTime", &[]);
let mut interval: Value = Value::Null;
let mut collectCycle: Value = self.safe_string_k(contract.clone(), "collectCycle", &[]);
if !is_equal(&collectCycle, &Value::Null) {
interval = crate::precise::Precise::stringDiv(&collectCycle, &Value::Str("60".to_string()));
interval = add(&interval, &Value::Str("h".to_string()));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("markPrice".to_string(), self.safe_number_k(contract.clone(), "markPrice", &[]));
m.insert("indexPrice".to_string(), self.safe_number_k(contract.clone(), "indexPrice", &[]));
m.insert("interestRate".to_string(), self.safe_number_k(contract.clone(), "interestRate", &[]));
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "lastFundingRate", &[]));
m.insert("fundingTimestamp".to_string(), timestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("nextFundingRate".to_string(), self.safe_number_k(contract.clone(), "forecastFundingRate", &[]));
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), interval.clone());
m
});
Value::Null
}
/*
* @method
* @name weex#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://www.weex.com/api-doc/contract/Market_API/GetFundingRateHistory
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of funding rate records to fetch (default 100, max 1000)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest funding rate
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure}
*/
pub async fn fetch_funding_rate_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchFundingRateHistory() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".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_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_get_capi_v3_market_funding_rate(&[__ws_arg_14]).await;
return self.parse_funding_rate_histories(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_funding_rate_history(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETHUSDT",
// "fundingRate": "0.00001031",
// "fundingTime": 1775577600000,
// "markPrice": "2079.26"
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "fundingTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "fundingRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name weex#fetchBalance
* @see https://www.weex.com/api-doc/spot/AccountAPI/GetAccountBalance // spot
* @see https://www.weex.com/api-doc/contract/Account_API/GetAccountBalance // contract
* @see https://www.weex.com/api-doc/contract/demo/GetAccountBalance // contract in sandbox mode
* @description query for balance and get the amount of funds available for trading or funds locked in positions
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap' (default is 'spot', in sandbox mode only 'swap' is available and is used by default)
* @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
}));
let mut requestedType: Value = self.safe_string_k(params.clone(), "type", &[]);
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if is_true(&(is_equal(&sandboxMode, &Value::Bool(true)))) && is_true(&(is_equal(&requestedType, &Value::Null))) {
type_var = Value::Str("swap".to_string()); // the demo trading API only provides the swap account, don't let the default spot type break a bare fetchBalance() call
}
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) {
if is_equal(&sandboxMode, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchBalance() only supports the swap account in sandbox mode, use params[\"type\"] = \"swap\"".to_string()))));
}
//
// {
// "makerCommission": 0,
// "takerCommission": 0,
// "commissionRates": {
// "maker": "0.00000000",
// "taker": "0.00000000"
// },
// "canTrade": true,
// "canWithdraw": true,
// "canDeposit": true,
// "updateTime": 1775601317093,
// "accountType": "SPOT",
// "balances": [
// {
// "asset": "USDT",
// "free": "20.00000000",
// "locked": "0"
// }
// ],
// "permissions": [
// "SPOT"
// ],
// "uid": 8886281669
// }
//
response = self.private_get_api_v3_account(&[params.clone()]).await;
} else {
//
// [
// {
// "asset": "USDT", // SUSDT in sandbox mode
// "balance": "20.00000000",
// "availableBalance": "20.00000000",
// "frozen": "0",
// "unrealizePnl": "0"
// }
// ]
//
if is_equal(&sandboxMode, &Value::Bool(true)) {
response = self.contract_private_get_capi_v3_sim_balance(&[params.clone()]).await;
} else {
response = self.contract_private_get_capi_v3_account_balance(&[params.clone()]).await;
}
}
return self.parse_balance(response.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
});
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut balances: Value = self.safe_list_k(response.clone(), "balances", &[response.clone()]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1096: bool = true;
while { if !__for_first_1096 { i = add(&i, &Value::Int(1)); } __for_first_1096 = false; is_less_than(&i, &get_array_length(&balances)) } {
let mut entry: Value = self.safe_dict(balances.clone(), i.clone(), &[]);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "asset", &[]);
if is_true(&(is_equal(&sandboxMode, &Value::Bool(true)))) && is_true(&(is_equal(¤cyId, &Value::Str("SUSDT".to_string())))) {
currencyId = Value::Str("USDT".to_string()); // demo trading balances are denominated in the demo asset SUSDT
}
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string2(entry.clone(), Value::Str("availableBalance".to_string()), Value::Str("free".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string2(entry.clone(), Value::Str("frozen".to_string()), Value::Str("locked".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(entry.clone(), "balance", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name weex#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://www.weex.com/api-doc/spot/AccountAPI/TransferRecords
* @param {string} [code] unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfers structures to retrieve (default 10, max 100)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn fetch_transfers(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
let mut maxLimit: Value = Value::Int(100);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTransfers".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_dynamic(Value::Str("fetchTransfers".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("after".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("before".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_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v3_account_transfer_records(&[__ws_arg_15]).await;
return self.parse_transfers(response.clone(), &[currency.clone(), since.clone(), limit.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);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "tradeTime", &[]);
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "coinName", &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut status: Value = self.safe_string_k(transfer.clone(), "status", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("currency".to_string(), currencyCode.clone());
m.insert("amount".to_string(), self.safe_number_k(transfer.clone(), "amount", &[]));
m.insert("fromAccount".to_string(), self.safe_string_lower(transfer.clone(), Value::Str("fromType".to_string()), &[]));
m.insert("toAccount".to_string(), self.safe_string_lower(transfer.clone(), Value::Str("toType".to_string()), &[]));
m.insert("status".to_string(), self.parse_transfer_status(status.clone()));
m
});
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Successful".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name weex#createOrder
* @description Create an order on the exchange
* @see https://www.weex.com/api-doc/spot/orderApi/PlaceOrder // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/PlaceOrder // contract
* @see https://www.weex.com/api-doc/contract/Transaction_API/PlacePendingOrder // contract trigger
* @see https://www.weex.com/api-doc/contract/Transaction_API/PlaceTpSlOrder // contract take profit / stop loss
* @see https://www.weex.com/api-doc/contract/demo/PlaceOrder // contract in sandbox mode
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] 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
* Check createSpotOrder() and createContractOrder() for more details on the extra parameters that can be used in params
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
return self.create_contract_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else {
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if is_equal(&sandboxMode, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() only supports swap markets in sandbox mode".to_string()))));
}
return self.create_spot_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name weex#createSpotOrder
* @description helper method for creating spot orders
* @see https://www.weex.com/api-doc/spot/orderApi/PlaceOrder
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] 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 {string} [params.clientOrderId] client order id
* @param {string} [params.timeInForce] 'GTC', 'IOC', or 'FOK'
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_spot_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_spot_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = self.private_post_api_v3_order(&[request.clone()]).await;
//
// {
// "symbol": "DOGEUSDT",
// "orderId": 736557215397183592,
// "clientOrderId": "c4551206d34641efbeb64abaa066946d",
// "transactTime": 1775608924724
// }
//
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseOrder() returned empty response".to_string()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
pub fn create_spot_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createSpotOrderRequest() requires a side argument".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), to_upper(&side));
m.insert("type".to_string(), to_upper(&type_var));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
if is_equal(&type_var, &Value::Str("limit".to_string())) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
if is_equal(&clientOrderId, &Value::Null) {
let mut partner: Value = self.safe_string_k(params.clone(), "partner", &[Value::Str("b-WEEX111125".to_string())]);
clientOrderId = add(&add(&partner, &Value::Str("-".to_string())), &self.uuid22(&[]));
}
add_element_to_object(&mut request, &Value::Str("newClientOrderId".to_string()), clientOrderId.clone());
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name weex#createContractOrder
* @description helper method for creating contract orders
* @see https://www.weex.com/api-doc/contract/Transaction_API/PlaceOrder
* @see https://www.weex.com/api-doc/contract/Transaction_API/PlacePendingOrder
* @see https://www.weex.com/api-doc/contract/demo/PlaceOrder // sandbox mode
* @param {string} symbol Unified CCXT market symbol
* @param {string} type 'limit' or 'market'
* @param {string} side 'buy' or 'sell'
* @param {float} amount the amount of currency to trade
* @param {float} [price] 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 {string} [params.clientOrderId] client order id
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered and the triggerPriceType
* @param {float} [params.takeProfit.triggerPrice] The price at which the take profit order will be triggered, takeProfit.stopPrice is supported as an alias
* @param {string} [params.takeProfit.triggerPriceType] The type of the trigger price for the take profit order, either 'last' or 'mark' (default is 'last')
* @param {float} [params.takeProfit.price] not supported, the attached take profit always executes at market price
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered and the triggerPriceType
* @param {float} [params.stopLoss.triggerPrice] The price at which the stop loss order will be triggered, stopLoss.stopPrice is supported as an alias
* @param {string} [params.stopLoss.triggerPriceType] The type of the trigger price for the stop loss order, either 'last' or 'mark' (default is 'last')
* @param {float} [params.stopLoss.price] not supported, the attached stop loss always executes at market price
* @param {float} [params.stopLossPrice] price to trigger a standalone stop-loss order on an open position, the price argument is used as its execution price for limit orders
* @param {string} [params.stopLossPriceType] The type of the trigger price for the stop loss order, either 'last' or 'mark' (default is 'last')
* @param {float} [params.takeProfitPrice] price to trigger a standalone take-profit order on an open position, the price argument is used as its execution price for limit orders
* @param {string} [params.takeProfitPriceType] The type of the trigger price for the take profit order, either 'last' or 'mark' (default is 'last')
* @param {float} [params.triggerPrice] the price at which a trigger (entry conditional) order is triggered, cannot be used together with stopLossPrice or takeProfitPrice
* @param {bool} [params.reduceOnly] A mark to reduce the position size only. Set to false by default. Need to set the position size when reduceOnly is true.
* @param {string} [params.timeInForce] GTC, IOC, or FOK (default is GTC for limit orders, not supported for trigger orders)
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_contract_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_contract_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut triggerPrice: Value = self.safe_string_k(request.clone(), "triggerPrice", &[]);
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut response: Value = Value::Null;
if !is_equal(&triggerPrice, &Value::Null) {
if is_equal(&sandboxMode, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() does not support stopLossPrice or takeProfitPrice orders in sandbox mode".to_string()))));
}
response = self.contract_private_post_capi_v3_algo_order(&[request.clone()]).await;
} else if is_equal(&sandboxMode, &Value::Bool(true)) {
response = self.contract_private_post_capi_v3_sim_order(&[request.clone()]).await;
} else {
response = self.contract_private_post_capi_v3_order(&[request.clone()]).await;
}
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" createOrder() returned empty response".to_string()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
pub fn create_contract_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createContractOrderRequest() requires a side argument".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.to_sandbox_market_id(market.clone()));
m.insert("side".to_string(), to_upper(&side));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m.insert("type".to_string(), to_upper(&type_var));
m
});
let mut isMarketOrder: bool = is_equal(&type_var, &Value::Str("market".to_string()));
if !is_true(&isMarketOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut triggerPricestopLossPricetakeProfitPricequeryVariable = self.handle_trigger_prices_and_params(symbol.clone(), params.clone(), &[]);
let mut triggerPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPricequeryVariable, &Value::Int(0));
let mut stopLossPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPricequeryVariable, &Value::Int(1));
let mut takeProfitPrice: Value = get_value(&triggerPricestopLossPricetakeProfitPricequeryVariable, &Value::Int(2));
let mut query: Value = get_value(&triggerPricestopLossPricetakeProfitPricequeryVariable, &Value::Int(3));
let mut isTrigger: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLoss: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isTakeProfit: bool = !is_equal(&takeProfitPrice, &Value::Null);
if is_true(&isTrigger) && is_true(&(is_true(&isStopLoss) || is_true(&isTakeProfit))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() cannot use the triggerPrice parameter together with the stopLossPrice or takeProfitPrice parameters".to_string()))));
}
let mut reduceOnly: Value = self.safe_bool_k(query.clone(), "reduceOnly", &[]);
if is_true(&isStopLoss) || is_true(&isTakeProfit) {
reduceOnly = Value::Bool(true);
}
let mut isReduceOnly: bool = is_equal(&reduceOnly, &Value::Bool(true));
let mut positionSide: Value = Value::Str("LONG".to_string());
if is_true(&isReduceOnly) {
if is_equal(&side, &Value::Str("buy".to_string())) {
positionSide = Value::Str("SHORT".to_string());
}
} else if is_equal(&side, &Value::Str("sell".to_string())) {
positionSide = Value::Str("SHORT".to_string());
}
add_element_to_object(&mut request, &Value::Str("positionSide".to_string()), positionSide.clone());
let mut takeProfit: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
let mut stopLoss: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
// the exchange accepts but silently ignores execution prices for attached take profit / stop loss, they always execute at market price
if is_true(&hasTakeProfit) && is_true(&(!is_equal(&self.safe_number_k(takeProfit.clone(), "price", &[]), &Value::Null))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() does not support the price field inside the takeProfit params, the attached take profit executes at market price".to_string()))));
}
if is_true(&hasStopLoss) && is_true(&(!is_equal(&self.safe_number_k(stopLoss.clone(), "price", &[]), &Value::Null))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() does not support the price field inside the stopLoss params, the attached stop loss executes at market price".to_string()))));
}
let mut timeInForce: Value = self.safe_string_k(params.clone(), "timeInForce", &[]);
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
let mut partner: Value = self.safe_string_k(params.clone(), "partner", &[Value::Str("b-WEEX111125".to_string())]);
clientOrderId = add(&add(&partner, &Value::Str("-".to_string())), &self.uuid22(&[]));
}
let mut callerMethodName: Value = self.safe_string_k(params.clone(), "callerMethodName", &[]);
if is_true(&isTrigger) {
// entry conditional order, triggers a regular order when the trigger price is reached
if is_equal(&callerMethodName, &Value::Str("createOrders".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() does not support trigger orders".to_string()))));
}
if !is_equal(&timeInForce, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() cannot use the timeInForce parameter with trigger orders".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("clientAlgoId".to_string()), clientOrderId.clone());
add_element_to_object(&mut params, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
if is_true(&isMarketOrder) {
add_element_to_object(&mut params, &Value::Str("type".to_string()), Value::Str("STOP_MARKET".to_string()));
} else {
add_element_to_object(&mut params, &Value::Str("type".to_string()), Value::Str("STOP".to_string()));
}
// conditional orders attach take profit / stop loss through the preset* fields instead of tpTriggerPrice/slTriggerPrice
if is_true(&hasStopLoss) {
let mut stopLossTriggerPrice: Value = self.safe_number2(stopLoss.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("presetStopLossPrice".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
let mut stopLossPriceType: Value = self.safe_string_k(stopLoss.clone(), "triggerPriceType", &[]);
if !is_equal(&stopLossPriceType, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("SlWorkingType".to_string()), self.encode_trigger_price_type(stopLossPriceType.clone()));
}
}
if is_true(&hasTakeProfit) {
let mut takeProfitTriggerPrice: Value = self.safe_number2(takeProfit.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("presetTakeProfitPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
let mut takeProfitPriceType: Value = self.safe_string_k(takeProfit.clone(), "triggerPriceType", &[]);
if !is_equal(&takeProfitPriceType, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("TpWorkingType".to_string()), self.encode_trigger_price_type(takeProfitPriceType.clone()));
}
}
} else if is_true(&isStopLoss) || is_true(&isTakeProfit) {
if is_equal(&callerMethodName, &Value::Str("createOrders".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() does not support stop loss and take profit orders".to_string()))));
}
if !is_equal(&timeInForce, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() cannot use timeInForce parameter with stopLoss and takeProfit orders".to_string()))));
}
if is_true(&hasStopLoss) || is_true(&hasTakeProfit) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() cannot use both stopLossPrice/takeProfitPrice parameters and stopLoss/takeProfit objects in params at the same time".to_string()))));
}
if is_true(&isStopLoss) && is_true(&isTakeProfit) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() cannot use both stopLossPrice and takeProfitPrice parameters at the same time".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("clientAlgoId".to_string()), clientOrderId.clone());
let mut orderType: Value = Value::Null;
if is_true(&isStopLoss) {
let mut stopLossPriceType: Value = self.safe_string2(params.clone(), Value::Str("stopLossPriceType".to_string()), Value::Str("triggerPriceType".to_string()), &[]);
if !is_equal(&stopLossPriceType, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("SlWorkingType".to_string()), self.encode_trigger_price_type(stopLossPriceType.clone()));
}
add_element_to_object(&mut params, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
if is_true(&isMarketOrder) {
orderType = Value::Str("STOP_MARKET".to_string());
} else {
orderType = Value::Str("STOP".to_string());
}
} else if is_true(&isTakeProfit) {
let mut takeProfitPriceType: Value = self.safe_string2(params.clone(), Value::Str("takeProfitPriceType".to_string()), Value::Str("triggerPriceType".to_string()), &[]);
if !is_equal(&takeProfitPriceType, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("TpWorkingType".to_string()), self.encode_trigger_price_type(takeProfitPriceType.clone()));
}
add_element_to_object(&mut params, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
if is_true(&isMarketOrder) {
orderType = Value::Str("TAKE_PROFIT_MARKET".to_string());
} else {
orderType = Value::Str("TAKE_PROFIT".to_string());
}
}
add_element_to_object(&mut params, &Value::Str("type".to_string()), orderType.clone());
} else {
if !is_true(&isMarketOrder) && is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("GTC".to_string()));
}
add_element_to_object(&mut request, &Value::Str("newClientOrderId".to_string()), clientOrderId.clone());
if is_true(&hasStopLoss) {
let mut stopLossTriggerPrice: Value = self.safe_number2(stopLoss.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("slTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
let mut stopLossPriceType: Value = self.safe_string_k(stopLoss.clone(), "triggerPriceType", &[]);
if !is_equal(&stopLossPriceType, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("SlWorkingType".to_string()), self.encode_trigger_price_type(stopLossPriceType.clone()));
}
}
if is_true(&hasTakeProfit) {
let mut takeProfitTriggerPrice: Value = self.safe_number2(takeProfit.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("tpTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
let mut takeProfitPriceType: Value = self.safe_string_k(takeProfit.clone(), "triggerPriceType", &[]);
if !is_equal(&takeProfitPriceType, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("TpWorkingType".to_string()), self.encode_trigger_price_type(takeProfitPriceType.clone()));
}
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("takeProfit".to_string()), Value::Str("stopLoss".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("triggerPriceType".to_string()), Value::Str("stopLossPriceType".to_string()), Value::Str("takeProfitPriceType".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("callerMethodName".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
pub fn encode_trigger_price_type(&self, mut triggerPriceType: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Str("MARK_PRICE".to_string()));
m.insert("last".to_string(), Value::Str("CONTRACT_PRICE".to_string()));
m
});
return self.safe_string(types.clone(), triggerPriceType.clone(), &[triggerPriceType.clone()]);
Value::Null
}
/*
* @method
* @name weex#cancelOrder
* @description cancels an open order
* @see https://www.weex.com/api-doc/spot/orderApi/CancelOrder // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/CancelOrder // contract
* @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 {string} [params.type] 'spot' or 'swap' (default is 'spot')
* @param {boolean} [params.trigger] *contract orders only* whether the order to cancel is a trigger order
* @param {string} [params.clientOrderId] *non-trigger orders only* a unique id for the order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool_k(params.clone(), "trigger", &[Value::Bool(false)]);
if is_true(&(is_equal(&trigger, &Value::Bool(true)))) && is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires an id argument for trigger orders".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("trigger".to_string())]), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("origClientOrderId".to_string()), clientOrderId.clone());
} else if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires an id argument or clientOrderId parameter".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) {
// by orderId
// {
// "orderId": 736775987680772200,
// "status": "CANCELED"
// }
//
// by clientOrderId
// {
// "origClientOrderId": "test_cancel_order",
// "status": "CANCELED"
// }
//
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v3_order(&[__ws_arg_16]).await;
} else if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_delete_capi_v3_algo_order(&[__ws_arg_17]).await;
} else {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_delete_capi_v3_order(&[__ws_arg_18]).await;
}
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseOrder() returned empty response".to_string()))));
}
let mut order: Value = self.parse_order(response.clone(), &[market.clone()]);
add_element_to_object(&mut order, &Value::Str("status".to_string()), Value::Str("canceled".to_string()));
return order;
Value::Null
}
/*
* @method
* @name weex#cancelAllOrders
* @description cancel all open orders
* @see https://www.weex.com/api-doc/spot/orderApi/Cancel-Symbol-Orders // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/CancelAllOrders // contract
* @see https://www.weex.com/api-doc/contract/Transaction_API/CancelAllPendingOrders // contract trigger
* @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 {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @param {boolean} [params.trigger] *swap only* true for cancelling trigger orders (default is false)
* @returns Response from the exchange
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
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("cancelAllOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool_k(params.clone(), "trigger", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("trigger".to_string()), &[]);
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument for spot markets".to_string()))));
}
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v3_open_orders(&[__ws_arg_19]).await;
} else if is_equal(&trigger, &Value::Bool(true)) {
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_delete_capi_v3_algo_open_orders(&[__ws_arg_20]).await;
} else {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_delete_capi_v3_all_open_orders(&[__ws_arg_21]).await;
}
let mut extendedParams: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m
});
return self.parse_orders(response.clone(), &[market.clone(), Value::Null, Value::Null, extendedParams.clone()]);
Value::Null
}
/*
* @method
* @name weex#cancelOrders
* @description cancel multiple orders
* @see https://www.weex.com/api-doc/spot/orderApi/BulkCancel // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/CancelOrdersBatch // contract
* @param {string[]} ids order ids
* @param {string} [symbol] unified market symbol, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string[]} [params.clientOrderIds] client order ids (could be an alternative to ids)
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
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("cancelOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isSpot: bool = is_equal(&marketType, &Value::Str("spot".to_string()));
let mut clientOrderIds: Value = self.safe_list_k(params.clone(), "clientOrderIds", &[]);
params = self.omit(params.clone(), Value::Str("clientOrderIds".to_string()), &[]);
if !is_equal(&clientOrderIds, &Value::Null) {
if is_true(&isSpot) {
add_element_to_object(&mut request, &Value::Str("origClientOrderIds".to_string()), clientOrderIds.clone());
} else {
add_element_to_object(&mut request, &Value::Str("origClientOrderIdList".to_string()), clientOrderIds.clone());
}
} else if !is_equal(&ids, &Value::Null) {
if is_true(&isSpot) {
add_element_to_object(&mut request, &Value::Str("orderIds".to_string()), ids.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderIdList".to_string()), ids.clone());
}
} else {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires an ids argument or clientOrderIds parameter".to_string()))));
}
let mut response: Value = Value::Null;
if is_true(&isSpot) {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_api_v3_order_batch(&[__ws_arg_22]).await;
} else {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_delete_capi_v3_batch_orders(&[__ws_arg_23]).await;
}
let mut ordersResponse: Value = self.safe_list_k(response.clone(), "orderList", &[Value::List(vec![])]);
let mut extendedParams: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("canceled".to_string()));
m
});
return self.parse_orders(ordersResponse.clone(), &[market.clone(), Value::Null, Value::Null, extendedParams.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchOrder
* @description fetches information on an order made by the user
* @see https://www.weex.com/api-doc/spot/orderApi/OrderDetails // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetSingleOrderInfo // contract
* @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 {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @param {string} [params.clientOrderId] *spot only* a unique id for the order, used if id is not provided
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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("fetchOrder".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isSpot: bool = is_equal(&marketType, &Value::Str("spot".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_true(&(is_equal(&id, &Value::Null))) && !is_true(&isSpot) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires an id argument for non-spot markets".to_string()))));
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("origClientOrderId".to_string()), clientOrderId.clone());
} else if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires an id argument or clientOrderId parameter for spot markets".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut response: Value = Value::Null;
if is_true(&isSpot) {
//
// {
// "symbol": "DOGEUSDT",
// "orderId": 736800333186991070,
// "clientOrderId": "082007092f624a18bb7af2ab42e7c8e8",
// "price": "0.08500",
// "origQty": "300.0",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "NEW",
// "timeInForce": "GTC",
// "type": "LIMIT",
// "side": "BUY",
// "time": 1775666888520,
// "updateTime": 1775666888536,
// "isWorking": true
// }
//
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v3_order(&[__ws_arg_24]).await;
} else {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_capi_v3_order(&[__ws_arg_25]).await;
}
if is_equal(&response, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&self.id, &Value::Str(" parseOrder() returned empty response".to_string()))));
}
return self.parse_order(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchOpenOrders
* @see https://www.weex.com/api-doc/spot/orderApi/UnfinishedOrders // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetCurrentOrderStatus // contract
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetCurrentPendingOrders // contract trigger
* @description fetch all unfilled currently open orders
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @param {boolean} [params.trigger] *swap only* whether to fetch trigger orders (default is false)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut isSpot: bool = is_equal(&marketType, &Value::Str("spot".to_string()));
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOpenOrders".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)); }
let mut maxLimit: Value = Value::Int(100);
if is_true(&paginate) {
if is_true(&isSpot) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOpenOrders() pagination is not supported for spot markets".to_string()))));
}
return self.fetch_paginated_call_dynamic(Value::Str("fetchOpenOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
let mut response: Value = Value::Null;
if is_true(&isSpot) {
//
// [
// {
// "symbol": "DOGEUSDT",
// "orderId": 736807745679786974,
// "clientOrderId": "e6dc41082bf342f580a19264d82dab31",
// "price": "0.12000",
// "origQty": "299.0",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "NEW",
// "timeInForce": "GTC",
// "type": "LIMIT",
// "side": "SELL",
// "time": 1775668655796,
// "updateTime": 1775668655810,
// "isWorking": true
// }
// ]
//
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v3_open_orders(&[__ws_arg_26]).await;
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut trigger: Value = self.safe_bool_k(params.clone(), "trigger", &[Value::Bool(false)]);
if is_equal(&trigger, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("trigger".to_string()), &[]);
//
// [
// {
// "algoId": 737074389748547944,
// "clientAlgoId": "d574f517-cea5-433e-b029-415590d3bb80",
// "algoType": "CONDITIONAL",
// "orderType": "STOP_MARKET",
// "symbol": "DOGEUSDT",
// "side": "SELL",
// "positionSide": "LONG",
// "timeInForce": "IOC",
// "quantity": "100",
// "algoStatus": "UNTRIGGERED",
// "actualOrderId": 737074043320009064,
// "actualPrice": "0.00000",
// "triggerPrice": "0.02000",
// "price": "0.00000",
// "tpTriggerPrice": null,
// "tpPrice": null,
// "slTriggerPrice": null,
// "slPrice": null,
// "tpOrderType": null,
// "workingType": "CONTRACT_PRICE",
// "closePosition": false,
// "reduceOnly": true,
// "createTime": 1775732228695,
// "updateTime": 1775732228695,
// "triggerTime": 0
// }
// ]
//
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_capi_v3_open_algo_orders(&[__ws_arg_27]).await;
} else {
//
// [
// {
// "avgPrice": "0.00000",
// "clientOrderId": "857e1482-3225-44ce-bc0a-947714c5cabc",
// "cumQuote": "0",
// "executedQty": "0",
// "orderId": 737185556881998184,
// "origQty": "1400",
// "price": "0.05000",
// "reduceOnly": false,
// "side": "BUY",
// "positionSide": "LONG",
// "status": "NEW",
// "stopPrice": "0",
// "symbol": "DOGEUSDT",
// "time": 1775758733006,
// "timeInForce": "GTC",
// "type": "LIMIT",
// "updateTime": 1775758733006,
// "workingType": "UNKNOWN_PRICE_TYPE"
// }
// ]
//
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_capi_v3_open_orders(&[__ws_arg_28]).await;
}
}
let mut extendedParams: 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(), extendedParams.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://www.weex.com/api-doc/spot/orderApi/HistoryOrders // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetOrderHistory // contract
* @see https://www.weex.com/api-doc/contract/demo/GetOrderHistory // contract in sandbox mode
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch orders for
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @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 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("fetchClosedOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut orders: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchClosedOrders() requires a symbol argument for spot markets".to_string()))));
}
orders = self.fetch_orders(&[symbol.clone(), since.clone(), Value::Null, params.clone()]).await;
} else {
orders = self.fetch_canceled_and_closed_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
return self.filter_by(orders.clone(), Value::Str("status".to_string()), Value::Str("closed".to_string()), &[]);
Value::Null
}
/*
* @method
* @name weex#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://www.weex.com/api-doc/spot/orderApi/HistoryOrders // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetOrderHistory // contract
* @see https://www.weex.com/api-doc/contract/demo/GetOrderHistory // contract in sandbox mode
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch orders for
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_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 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("fetchCanceledOrders".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut orders: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchCanceledOrders() requires a symbol argument for spot markets".to_string()))));
}
orders = self.fetch_orders(&[symbol.clone(), since.clone(), Value::Null, params.clone()]).await;
} else {
orders = self.fetch_canceled_and_closed_orders(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
return self.filter_by(orders.clone(), Value::Str("status".to_string()), Value::Str("canceled".to_string()), &[]);
Value::Null
}
/*
* @method
* @name weex#fetchOrders
* @description fetches information on multiple spot orders made by the user
* @see https://www.weex.com/api-doc/spot/orderApi/HistoryOrders // spot
* @param {string} symbol unified market symbol of the market orders were made in (required for spot orders)
* @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 {object} [params.until] end time, ms
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrders() 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());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrders() supports spot markets only".to_string()))));
}
let mut maxLimit: Value = Value::Int(1000);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrders".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_dynamic(Value::Str("fetchOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &maxLimit));
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".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_29 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_api_v3_all_orders(&[__ws_arg_29]).await;
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchCanceledAndClosedOrders
* @description fetches information on multiple closed and canceled orders made by the user
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetOrderHistory // contract
* @see https://www.weex.com/api-doc/contract/demo/GetOrderHistory // contract in sandbox mode
* @param {string} [symbol] unified market symbol of the market orders were made in (required for spot orders)
* @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 {object} [params.until] end time, ms
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_and_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 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("fetchCanceledAndClosedOrders".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(&self.id, &Value::Str(" fetchCanceledAndClosedOrders() does not support spot markets. Use fetchOrders() instead and filter by status \"canceled\" or \"closed\"".to_string()))));
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchCanceledAndClosedOrders".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)); }
let mut maxLimit: Value = Value::Int(1000);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchCanceledAndClosedOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.to_sandbox_market_id(market.clone()));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut response: Value = Value::Null;
if is_equal(&sandboxMode, &Value::Bool(true)) {
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_capi_v3_sim_order_history(&[__ws_arg_30]).await;
} else {
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_capi_v3_order_history(&[__ws_arg_31]).await;
}
return self.parse_orders(response.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder (spot)
// {
// "symbol": "DOGEUSDT",
// "orderId": 736557215397183592,
// "clientOrderId": "c4551206d34641efbeb64abaa066946d",
// "transactTime": 1775608924724
// }
//
// fetchOpenOrders / fetchOrders / fetchOrder (spot)
// {
// "symbol": "DOGEUSDT",
// "orderId": 736800333186991070,
// "clientOrderId": "082007092f624a18bb7af2ab42e7c8e8",
// "price": "0.08500",
// "origQty": "300.0",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "NEW",
// "timeInForce": "GTC",
// "type": "LIMIT",
// "side": "BUY",
// "time": 1775666888520,
// "updateTime": 1775666888536,
// "isWorking": true
// }
//
// fetchOpenOrders (contract)
// {
// "avgPrice": "0.00000",
// "clientOrderId": "857e1482-3225-44ce-bc0a-947714c5cabc",
// "cumQuote": "0",
// "executedQty": "0",
// "orderId": 737185556881998184,
// "origQty": "1400",
// "price": "0.05000",
// "reduceOnly": false,
// "side": "BUY",
// "positionSide": "LONG",
// "status": "NEW",
// "stopPrice": "0",
// "symbol": "DOGEUSDT",
// "time": 1775758733006,
// "timeInForce": "GTC",
// "type": "LIMIT",
// "updateTime": 1775758733006,
// "workingType": "UNKNOWN_PRICE_TYPE"
// }
//
// fetchOpenOrders (contract-trigger)
// {
// "algoId": 737074389748547944,
// "clientAlgoId": "d574f517-cea5-433e-b029-415590d3bb80",
// "algoType": "CONDITIONAL",
// "orderType": "STOP_MARKET",
// "symbol": "DOGEUSDT",
// "side": "SELL",
// "positionSide": "LONG",
// "timeInForce": "IOC",
// "quantity": "100",
// "algoStatus": "UNTRIGGERED",
// "actualOrderId": 737074043320009064,
// "actualPrice": "0.00000",
// "triggerPrice": "0.02000",
// "price": "0.00000",
// "tpTriggerPrice": null,
// "tpPrice": null,
// "slTriggerPrice": null,
// "slPrice": null,
// "tpOrderType": null,
// "workingType": "CONTRACT_PRICE",
// "closePosition": false,
// "reduceOnly": true,
// "createTime": 1775732228695,
// "updateTime": 1775732228695,
// "triggerTime": 0
// }
//
// fetchCanceledAndClosedOrders (swap only)
// {
// "avgPrice": "0.00000",
// "clientOrderId": "7bd80776-0c3f-4ed9-ab9c-a616d66fac5e",
// "cumQuote": "0",
// "executedQty": "0",
// "orderId": 737074389744353640,
// "origQty": "100",
// "price": "0.00000",
// "reduceOnly": true,
// "side": "SELL",
// "positionSide": "LONG",
// "status": "CANCELED",
// "stopPrice": "1.00000",
// "symbol": "DOGEUSDT",
// "time": 1775732228695,
// "timeInForce": "IOC",
// "type": "TAKE_PROFIT_MARKET",
// "updateTime": 1775732228695,
// "workingType": "CONTRACT_PRICE"
// }
//
let mut errorCode: Value = self.safe_string_k(order.clone(), "errorCode", &[]);
let mut errorMessage: Value = self.safe_string_k(order.clone(), "errorMsg", &[]);
if is_true(&(!is_equal(&errorCode, &Value::Null))) || is_true(&(!is_equal(&errorMessage, &Value::Null))) {
self.handle_order_or_position_error(errorCode.clone(), errorMessage.clone(), order.clone());
}
if is_equal(&market, &Value::Null) {
let mut marketId: Value = self.from_sandbox_market_id(self.safe_string_k(order.clone(), "symbol", &[]));
let mut positionSide: Value = self.safe_string_k(order.clone(), "positionSide", &[]);
let mut marketType: Value = ternary(is_true(&(is_equal(&positionSide, &Value::Null))), Value::Str("spot".to_string()), Value::Str("swap".to_string()));
market = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
}
let mut timestamp: Value = self.safe_integer_n(order.clone(), Value::List(vec![Value::Str("transactTime".to_string()), Value::Str("time".to_string()), Value::Str("createTime".to_string())]), &[]);
let mut rawStatus: Value = self.safe_string_lower2(order.clone(), Value::Str("status".to_string()), Value::Str("algoStatus".to_string()), &[]); // algo (trigger) order payloads carry algoStatus instead of status
let mut triggerPrice: Value = self.omit_zero(self.safe_string2(order.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]));
let mut rawType: Value = self.safe_string_upper2(order.clone(), Value::Str("type".to_string()), Value::Str("orderType".to_string()), &[]);
let mut isReduceOnly: Value = self.safe_bool_k(order.clone(), "reduceOnly", &[]);
// entry conditional orders reuse the STOP/TAKE_PROFIT types with reduceOnly set to false, their trigger price is not a stop loss / take profit price
// a missing reduceOnly counts as reduce-only to keep the legacy mapping for responses that omit the field
let mut isEntryTrigger: bool = !is_true(&self.safe_bool_k(order.clone(), "reduceOnly", &[Value::Bool(true)]));
let mut takeProfitPrice: Value = Value::Null;
let mut stopLossPrice: Value = Value::Null;
if !is_true(&isEntryTrigger) {
if is_equal(&rawType, &Value::Str("TAKE_PROFIT_MARKET".to_string())) || is_equal(&rawType, &Value::Str("TAKE_PROFIT".to_string())) {
takeProfitPrice = triggerPrice.clone();
} else if is_equal(&rawType, &Value::Str("STOP_LOSS".to_string())) || is_equal(&rawType, &Value::Str("STOP".to_string())) || is_equal(&rawType, &Value::Str("STOP_MARKET".to_string())) {
stopLossPrice = triggerPrice.clone();
}
}
if is_equal(&takeProfitPrice, &Value::Null) {
takeProfitPrice = self.omit_zero(self.safe_string_k(order.clone(), "tpTriggerPrice", &[])); // attached take profit of a regular or conditional order
}
if is_equal(&stopLossPrice, &Value::Null) {
stopLossPrice = self.omit_zero(self.safe_string_k(order.clone(), "slTriggerPrice", &[])); // attached stop loss of a regular or conditional order
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("orderId".to_string()), Value::Str("algoId".to_string()), Value::Str("successOrderId".to_string())]), &[]));
m.insert("clientOrderId".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("origClientOrderId".to_string()), Value::Str("clientAlgoId".to_string())]), &[]));
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("type".to_string(), self.parse_order_type(rawType.clone()));
m.insert("timeInForce".to_string(), self.safe_string_k(order.clone(), "timeInForce", &[]));
m.insert("postOnly".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), isReduceOnly.clone());
m.insert("side".to_string(), self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]));
m.insert("amount".to_string(), self.safe_string2(order.clone(), Value::Str("origQty".to_string()), Value::Str("quantity".to_string()), &[]));
m.insert("price".to_string(), self.safe_string_k(order.clone(), "price", &[]));
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("cost".to_string(), self.safe_string2(order.clone(), Value::Str("cummulativeQuoteQty".to_string()), Value::Str("cumQuote".to_string()), &[]));
m.insert("filled".to_string(), self.safe_string_k(order.clone(), "executedQty", &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fee".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_order_status(rawStatus.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(order.clone(), "updateTime", &[]));
m.insert("average".to_string(), self.safe_string_k(order.clone(), "avgPrice", &[]));
m.insert("trades".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), stopLossPrice.clone());
m.insert("takeProfitPrice".to_string(), takeProfitPrice.clone());
m.insert("info".to_string(), order.clone());
m
}), &[market.clone()]);
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("partial_fill".to_string(), Value::Str("closed".to_string()));
m.insert("full_fill".to_string(), Value::Str("closed".to_string()));
m.insert("filled".to_string(), Value::Str("closed".to_string()));
m.insert("cancelled".to_string(), Value::Str("canceled".to_string()));
m.insert("canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("rejected".to_string(), Value::Str("rejected".to_string()));
m.insert("untriggered".to_string(), Value::Str("open".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("LIMIT".to_string(), Value::Str("limit".to_string()));
m.insert("MARKET".to_string(), Value::Str("market".to_string()));
m.insert("STOP_LOSS".to_string(), Value::Str("limit".to_string()));
m.insert("STOP".to_string(), Value::Str("limit".to_string()));
m.insert("TAKE_PROFIT".to_string(), Value::Str("limit".to_string()));
m.insert("TAKE_PROFIT_MARKET".to_string(), Value::Str("market".to_string()));
m.insert("STOP_MARKET".to_string(), Value::Str("market".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn handle_order_or_position_error(&self, mut errorCode: Value, mut errorMessage: Value, mut order: Value) {
if is_equal(&errorCode, &Value::Null) {
errorCode = Value::Str("".to_string());
}
if is_equal(&errorMessage, &Value::Null) {
errorMessage = Value::Str("".to_string());
}
if is_true(&(is_equal(&errorCode, &Value::Str("".to_string())))) && is_true(&(is_equal(&errorMessage, &Value::Str("".to_string())))) {
return;
}
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &self.json(order.clone()));
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorMessage.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), errorMessage.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), errorCode.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::invalid_order(feedback));
}
/*
* @method
* @name weex#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://www.weex.com/api-doc/spot/orderApi/TransactionDetails // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetTradeDetails // contract
* @param {string} id order id
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id.clone());
m
});
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_my_trades(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_32]).await;
Value::Null
}
/*
* @method
* @name weex#fetchMyTrades
* @see https://www.weex.com/api-doc/spot/orderApi/TransactionDetails // spot
* @see https://www.weex.com/api-doc/contract/Transaction_API/GetTradeDetails // contract
* @description fetch all trades made by the user
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {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)
* @param {string} [params.type] 'spot' or 'swap', used if symbol is not provided (default is 'spot')
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
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 isSpot: bool = is_equal(&marketType, &Value::Str("spot".to_string()));
if is_true(&isSpot) && is_true(&(is_equal(&symbol, &Value::Null))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol argument for spot markets".to_string()))));
}
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()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut maxLimit: Value = Value::Int(100);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&isSpot) {
//
// [
// {
// "symbol": "DOGEUSDT",
// "id": 736825748291060702,
// "orderId": 736825748215563230,
// "price": "0.09349",
// "qty": "250.0",
// "quoteQty": "23.3725",
// "commission": "0.0233725",
// "time": 1775672947953,
// "isBuyer": false
// }
// ]
//
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_api_v3_my_trades(&[__ws_arg_33]).await;
} else {
//
// [
// {
// "id": 737074389731770728,
// "orderId": 737074043320009064,
// "symbol": "DOGEUSDT",
// "buyer": true,
// "commission": "0.00183500",
// "commissionAsset": "USDT",
// "maker": true,
// "price": "0.09175",
// "qty": "100",
// "quoteQty": "9.17500",
// "realizedPnl": "0",
// "side": "BUY",
// "positionSide": "LONG",
// "time": 1775732228692
// }
// ]
//
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_private_get_capi_v3_user_trades(&[__ws_arg_34]).await;
}
let mut responseList: Value = Value::List(vec![]);
if !is_equal(&response, &Value::Null) {
responseList = self.to_array(response.clone());
}
return self.parse_trades(responseList.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://www.weex.com/api-doc/spot/AccountAPI/GetBillRecords // spot
* @see https://www.weex.com/api-doc/spot/AccountAPI/GetFundBillRecords // funding
* @see https://www.weex.com/api-doc/contract/Account_API/GetContractBills // contract
* @param {string} [code] unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined, max is 100
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest ledger entry
* @param {string} [params.type] 'spot', 'funding' or 'swap' (default is 'spot')
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLedger".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut maxLimit: Value = Value::Int(100);
if is_true(&paginate) {
return self.fetch_paginated_call_dynamic(Value::Str("fetchLedger".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut accountType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, params.clone()]); accountType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
accountType = self.safe_string(accountsByType.clone(), accountType.clone(), &[accountType.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut items: Value = Value::Null;
let mut currency: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
}
if is_equal(&accountType, &Value::Str("contract".to_string())) {
if is_equal(¤cy, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchLedger() could not resolve currency".to_string()))));
}
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("currency".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".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_35 = self.extend(request.clone(), &[params.clone()]);
let mut contractResponse: Value = self.contract_private_post_capi_v3_account_income(&[__ws_arg_35]).await;
items = self.safe_list_k(contractResponse.clone(), "items", &[Value::List(vec![])]);
} else if is_equal(&accountType, &Value::Str("funding".to_string())) {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".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_36 = self.extend(request.clone(), &[params.clone()]);
let mut fundingResponse: Value = self.private_post_api_v3_account_funding_bills(&[__ws_arg_36]).await;
items = self.safe_list_k(fundingResponse.clone(), "items", &[Value::List(vec![])]);
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("after".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("before".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_37 = self.extend(request.clone(), &[params.clone()]);
let mut billsResponse: Value = self.private_post_api_v3_account_bills(&[__ws_arg_37]).await;
items = self.to_array(billsResponse.clone());
}
return self.parse_ledger(items.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// spot
// {
// "billId": "736825748291061726",
// "coinId": 82,
// "coinName": "DOGE",
// "bizType": "trade_out",
// "fillSize": "250.0",
// "fillValue": "23.372500",
// "deltaAmount": "-250.0",
// "afterAmount": "49.70000000",
// "fees": "0",
// "cTime": "1775672947953"
// }
//
// contract
// {
// "billId": 736791763716407518,
// "asset": "USDT",
// "symbol": null,
// "income": "-90.00000000",
// "incomeType": "withdraw",
// "balance": "106.00000000",
// "fillFee": "0",
// "time": 1775664845399,
// "transferReason": "UNKNOWN_TRANSFER_REASON"
// }
//
// funding
// {
// "billId": "16502414",
// "coinId": 2,
// "coinName": "USDT",
// "bizType": "transfer_out",
// "fillSize": null,
// "fillValue": null,
// "deltaAmount": "-100.00000000",
// "afterAmount": "0.00000000",
// "fees": "0.00000000",
// "cTime": "1775664588931"
// }
//
let mut currencyId: Value = self.safe_string2(item.clone(), Value::Str("coinName".to_string()), Value::Str("asset".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer2(item.clone(), Value::Str("cTime".to_string()), Value::Str("time".to_string()), &[]);
let mut amountRaw: Value = self.safe_string2(item.clone(), Value::Str("deltaAmount".to_string()), Value::Str("income".to_string()), &[]);
let mut after: Value = self.safe_string2(item.clone(), Value::Str("afterAmount".to_string()), Value::Str("balance".to_string()), &[]);
let mut before: Value = crate::precise::Precise::stringSub(&after, &amountRaw);
let mut amount: Value = self.parse_number(crate::precise::Precise::stringAbs(&amountRaw), &[]);
let mut direction: Value = Value::Str("in".to_string());
if is_equal(&amountRaw, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" parseLedgerEntry() missing amountRaw".to_string()))));
}
if is_greater_than_or_equal(&get_index_of(&amountRaw, &Value::Str("-".to_string())), &Value::Int(0)) {
direction = Value::Str("out".to_string());
}
let mut rawType: Value = self.safe_string2(item.clone(), Value::Str("bizType".to_string()), Value::Str("incomeType".to_string()), &[]);
let mut transferReason: Value = self.safe_string_k(item.clone(), "transferReason", &[]);
let mut isContractEntry: bool = !is_equal(&transferReason, &Value::Null);
if is_true(&isContractEntry) {
if is_true(&(is_equal(&rawType, &Value::Str("withdraw".to_string())))) || is_true(&(is_equal(&rawType, &Value::Str("deposit".to_string())))) {
rawType = Value::Str("transfer".to_string());
}
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string_k(item.clone(), "billId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("direction".to_string(), direction.clone());
m.insert("account".to_string(), Value::Null);
m.insert("referenceId".to_string(), Value::Null);
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_ledger_type(rawType.clone()));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("before".to_string(), self.parse_number(before.clone(), &[]));
m.insert("after".to_string(), self.parse_number(after.clone(), &[]));
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(), code.clone());
m.insert("cost".to_string(), self.safe_number2(item.clone(), Value::Str("fees".to_string()), Value::Str("fillFee".to_string()), &[]));
m
}));
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_ledger_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("transfer_in".to_string(), Value::Str("transfer".to_string()));
m.insert("transfer_out".to_string(), Value::Str("transfer".to_string()));
m.insert("deposit".to_string(), Value::Str("deposit".to_string()));
m.insert("withdraw".to_string(), Value::Str("withdrawal".to_string()));
m.insert("trade_in".to_string(), Value::Str("trade".to_string()));
m.insert("trade_out".to_string(), Value::Str("trade".to_string()));
m.insert("position_open_long".to_string(), Value::Str("trade".to_string()));
m.insert("position_open_short".to_string(), Value::Str("trade".to_string()));
m.insert("position_close_long".to_string(), Value::Str("trade".to_string()));
m.insert("position_close_short".to_string(), Value::Str("trade".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchPositions
* @description fetch all open positions
* @see https://www.weex.com/api-doc/contract/Account_API/GetAllPositions
* @see https://www.weex.com/api-doc/contract/demo/GetAllPositions // sandbox mode
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut response: Value = Value::Null;
if is_equal(&sandboxMode, &Value::Bool(true)) {
response = self.contract_private_get_capi_v3_sim_position_all_position(&[params.clone()]).await;
} else {
response = self.contract_private_get_capi_v3_account_position_all_position(&[params.clone()]).await;
}
return self.parse_positions(response.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchPosition
* @description fetch data on an open position
* @see https://www.weex.com/api-doc/contract/Account_API/GetSinglePosition
* @param {string} symbol unified market symbol of the market the position is held in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position(&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
}));
let mut positions: Value = self.fetch_positions_for_symbol(symbol.clone(), &[params.clone()]).await;
return self.safe_dict(positions.clone(), Value::Int(0), &[]);
Value::Null
}
/*
* @method
* @description fetch open positions for a single market
* @name weex#fetchPositionsForSymbol
* @see https://www.weex.com/api-doc/contract/Account_API/GetSinglePosition
* @description fetch all open positions for specific symbol
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions_for_symbol(&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 sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if is_equal(&sandboxMode, &Value::Bool(true)) {
return self.fetch_positions(&[Value::List(vec![get_value(&market, &Value::Str("symbol".to_string()))]), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_get_capi_v3_account_position_single_position(&[__ws_arg_38]).await;
return self.parse_positions(response.clone(), &[Value::List(vec![get_value(&market, &Value::Str("symbol".to_string()))])]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": 737191855967437160,
// "asset": "USDT",
// "symbol": "DOGEUSDT",
// "side": "LONG",
// "marginType": "CROSSED",
// "separatedMode": "COMBINED",
// "separatedOpenOrderId": 0,
// "leverage": "20.00",
// "size": "300",
// "openValue": "27.96900",
// "openFee": "0.02237520",
// "fundingFee": "0",
// "marginSize": "100",
// "isolatedMargin": "0",
// "isAutoAppendIsolatedMargin": false,
// "cumOpenSize": "300",
// "cumOpenValue": "27.96900",
// "cumOpenFee": "0.02237520",
// "cumCloseSize": "0",
// "cumCloseValue": "0",
// "cumCloseFee": "0",
// "cumFundingFee": "0",
// "cumLiquidateFee": "0",
// "createdMatchSequenceId": 5762536243,
// "updatedMatchSequenceId": 5762741613,
// "createdTime": 1775760234825,
// "updatedTime": 1775763170789,
// "unrealizePnl": "0.00600",
// "liquidatePrice": "0"
// }
//
// watchPoisions
// {
// "id": "739004481374519656",
// "coin": "USDT",
// "symbol": "DOGEUSDT",
// "side": "LONG",
// "marginMode": "CROSSED",
// "separatedMode": "COMBINED",
// "separatedOpenOrderId": "0",
// "leverage": "11",
// "size": "100",
// "openValue": "9.31100",
// "openFee": "0.00744880",
// "fundingFee": "0",
// "isolatedMargin": "0",
// "autoAppendIsolatedMargin": false,
// "cumOpenSize": "100",
// "cumOpenValue": "9.31100",
// "cumOpenFee": "0.00744880",
// "cumCloseSize": "0",
// "cumCloseValue": "0",
// "cumCloseFee": "0",
// "cumFundingFee": "0",
// "cumLiquidateFee": "0",
// "createdMatchSequenceId": "5792711540",
// "updatedMatchSequenceId": "5792711540",
// "createdTime": "1776192398399",
// "updatedTime": "1776192398399"
// }
//
let mut errorMessage: Value = self.safe_string_k(position.clone(), "errorMsg", &[]);
let mut errorCode: Value = self.safe_string_k(position.clone(), "errorCode", &[]);
if !is_equal(&errorMessage, &Value::Null) {
self.handle_order_or_position_error(errorCode.clone(), errorMessage.clone(), position.clone());
}
let mut marketId: Value = self.from_sandbox_market_id(self.safe_string2(position.clone(), Value::Str("symbol".to_string()), Value::Str("coinId".to_string()), &[])); // coinId might be used in testnet: https://github.com/ccxt/ccxt/issues/28576#issuecomment-4439400273
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "createdTime", &[]);
let mut marginType: Value = self.safe_string2(position.clone(), Value::Str("marginType".to_string()), Value::Str("marginMode".to_string()), &[]);
let mut marginMode: Value = Value::Str("cross".to_string());
if is_equal(&marginType, &Value::Str("ISOLATED".to_string())) {
marginMode = Value::Str("isolated".to_string());
}
let mut separatedMode: Value = self.safe_string_k(position.clone(), "separatedMode", &[]);
let mut hedged: Value = Value::Null;
if is_equal(&separatedMode, &Value::Str("COMBINED".to_string())) {
hedged = Value::Bool(false);
} else if is_equal(&separatedMode, &Value::Str("SEPARATED".to_string())) {
hedged = Value::Bool(true);
}
let mut notional: Value = self.safe_string_k(position.clone(), "openValue", &[]);
let mut size: Value = self.safe_string_k(position.clone(), "size", &[]);
let mut entryPrice: Value = crate::precise::Precise::stringDiv(¬ional, &size);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("id".to_string(), self.safe_string2(position.clone(), Value::Str("id".to_string()), Value::Str("positionId".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("contracts".to_string(), self.parse_number(size.clone(), &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_lower(position.clone(), Value::Str("side".to_string()), &[]));
m.insert("notional".to_string(), self.parse_number(notional.clone(), &[]));
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealizePnl", &[]));
m.insert("realizedPnl".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("entryPrice".to_string(), self.parse_number(entryPrice.clone(), &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), self.safe_number_k(position.clone(), "liquidatePrice", &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("hedged".to_string(), hedged.clone());
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "marginSize", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "updatedTime", &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("info".to_string(), position.clone());
m
}));
Value::Null
}
/*
* @method
* @name weex#closeAllPositions
* @description closes all open positions for a market type
* @see https://www.weex.com/api-doc/contract/Transaction_API/ClosePositions
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} A list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn close_all_positions(&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.contract_private_post_capi_v3_close_positions(&[params.clone()]).await;
return self.parse_positions(response.clone(), &[]);
Value::Null
}
/*
* @method
* @name weex#closePosition
* @description closes open positions for a market
* @see https://www.weex.com/api-doc/contract/Transaction_API/ClosePositions
* @param {string} symbol Unified CCXT market symbol
* @param {string} [side] not used by current exchange
* @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 close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = 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("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_39 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_post_capi_v3_close_positions(&[__ws_arg_39]).await;
let mut orders: Value = self.parse_orders(response.clone(), &[market.clone()]);
return self.safe_dict(orders.clone(), Value::Int(0), &[]);
Value::Null
}
/*
* @method
* @name weex#fetchTradingFee
* @see https://www.weex.com/api-doc/contract/Account_API/GetCommissionRate // contract
* @description fetch the trading fees for a contract market
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [fee structure]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_trading_fee(&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());
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTradingFee() is not supported for spot markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_get_capi_v3_account_commission_rate(&[__ws_arg_40]).await;
return self.parse_trading_fee(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_trading_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// contract
// {
// "symbol": "DOGEUSDT",
// "makerCommissionRate": "0.0002",
// "takerCommissionRate": "0.0008"
// }
//
let mut marketId: Value = self.safe_string_k(fee.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("maker".to_string(), self.safe_number_k(fee.clone(), "makerCommissionRate", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee.clone(), "takerCommissionRate", &[]));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
/*
* @method
* @name weex#fetchMarginMode
* @description fetches the margin mode of a specific symbol
* @see https://www.weex.com/api-doc/contract/Account_API/GetSymbolConfig
* @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} a [margin mode structure]{@link https://docs.ccxt.com/?id=margin-mode-structure}
*/
pub async fn fetch_margin_mode(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_get_capi_v3_account_symbol_config(&[__ws_arg_41]).await;
//
// [
// {
// "symbol": "DOGEUSDT",
// "marginType": "CROSSED",
// "separatedType": "COMBINED",
// "crossLeverage": "20.00",
// "isolatedLongLeverage": "20.00",
// "isolatedShortLeverage": "20.00"
// }
// ]
//
let mut marginMode: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_mode(marginMode.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchMarginModes
* @description fetches margin modes the symbols, with symbols=undefined all markets are returned
* @see https://www.weex.com/api-doc/contract/Account_API/GetSymbolConfig
* @param {string[]} symbols unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [margin mode structures]{@link https://docs.ccxt.com/?id=margin-mode-structure}
*/
pub async fn fetch_margin_modes(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.contract_private_get_capi_v3_account_symbol_config(&[params.clone()]).await;
return self.parse_margin_modes(self.to_array(response.clone()), &[symbols.clone(), Value::Str("symbol".to_string()), Value::Str("swap".to_string())]);
Value::Null
}
pub fn parse_margin_mode(&self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(marginMode.clone(), "symbol", &[]);
let mut marginType: Value = self.safe_string_k(marginMode.clone(), "marginType", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), marginMode.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
m.insert("marginMode".to_string(), self.parse_margin_type(marginType.clone()));
m
});
Value::Null
}
pub fn parse_margin_type(&self, mut marginType: Value) -> Value {
let mut marginTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CROSSED".to_string(), Value::Str("cross".to_string()));
m.insert("ISOLATED".to_string(), Value::Str("isolated".to_string()));
m
});
return self.safe_string(marginTypes.clone(), marginType.clone(), &[marginType.clone()]);
Value::Null
}
/*
* @method
* @name weex#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://www.weex.com/api-doc/contract/Account_API/ChangeMarginModeTRADE
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_margin_mode(&mut self, mut marginMode: 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(" setMarginMode() 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("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("marginType".to_string(), self.encode_margin_mode(marginMode.clone()));
m
});
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
return self.contract_private_post_capi_v3_account_margin_type(&[__ws_arg_42]).await;
Value::Null
}
pub fn encode_margin_mode(&self, mut marginMode: Value) -> Value {
let mut marginTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cross".to_string(), Value::Str("CROSSED".to_string()));
m.insert("isolated".to_string(), Value::Str("ISOLATED".to_string()));
m
});
let mut result: Value = self.safe_string(marginTypes.clone(), marginMode.clone(), &[]);
if is_equal(&result, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" marginMode must be either cross or isolated".to_string()))));
}
return result;
Value::Null
}
/*
* @method
* @name weex#fetchLeverage
* @description fetch the set leverage for a market
* @see https://www.weex.com/api-doc/contract/Account_API/GetSymbolConfig
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_get_capi_v3_account_symbol_config(&[__ws_arg_43]).await;
let mut marginMode: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(marginMode.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name weex#fetchLeverages
* @description fetch the set leverage for all markets
* @see https://www.weex.com/api-doc/contract/Account_API/GetSymbolConfig
* @param {string[]} [symbols] a list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverages(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.contract_private_get_capi_v3_account_symbol_config(&[params.clone()]).await;
return self.parse_leverages(self.to_array(response.clone()), &[symbols.clone(), Value::Str("symbol".to_string()), Value::Str("swap".to_string())]);
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 marketId: Value = self.safe_string_k(leverage.clone(), "symbol", &[]);
let mut marginType: Value = self.safe_string_k(leverage.clone(), "marginType", &[]);
let mut marginMode: Value = self.parse_margin_type(marginType.clone());
let mut crossLeverage: Value = self.safe_number_k(leverage.clone(), "crossLeverage", &[]);
let mut longLeverage: Value = self.safe_number_k(leverage.clone(), "isolatedLongLeverage", &[]);
let mut shortLeverage: Value = self.safe_number_k(leverage.clone(), "isolatedShortLeverage", &[]);
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
longLeverage = crossLeverage.clone();
shortLeverage = crossLeverage.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(), Value::Null, Value::Str("swap".to_string())]));
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 weex#setLeverage
* @description set the level of leverage for a market
* @see https://www.weex.com/api-doc/contract/Account_API/UpdateLeverageTRADE
* @param {float} 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' (default is 'cross' if specific leverage parameters are not provided)
* @param {number} [params.crossLeverage] *cross margin mode only* leverage for cross margin mode when marginMode is 'cross'
* @param {number} [params.isolatedLongLeverage] *isolated margin mode only* leverage for long positions when marginMode is 'isolated'
* @param {number} [params.isolatedShortLeverage] *isolated margin mode only* leverage for short positions when marginMode is 'isolated'
* If specific leverage parameters are not provided
* the leverage value will be applied to both long and short positions if marginMode is 'isolated'
* or to cross margin mode if marginMode is 'cross'
* If marginMode is not provided and specific leverage parameters are not provided too
* the leverage value will be applied to cross leverage
* @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()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let 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) {
add_element_to_object(&mut request, &Value::Str("marginType".to_string()), self.encode_margin_mode(marginMode.clone()));
}
let mut isolatedLongLeverage: Value = self.safe_number_k(params.clone(), "isolatedLongLeverage", &[]);
let mut isolatedShortLeverage: Value = self.safe_number_k(params.clone(), "isolatedShortLeverage", &[]);
let mut crossLeverage: Value = self.safe_number_k(params.clone(), "crossLeverage", &[]);
if is_true(&(is_equal(&isolatedLongLeverage, &Value::Null))) && is_true(&(is_equal(&isolatedShortLeverage, &Value::Null))) && is_true(&(is_equal(&crossLeverage, &Value::Null))) {
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
add_element_to_object(&mut request, &Value::Str("isolatedLongLeverage".to_string()), leverage.clone());
add_element_to_object(&mut request, &Value::Str("isolatedShortLeverage".to_string()), leverage.clone());
} else {
add_element_to_object(&mut request, &Value::Str("crossLeverage".to_string()), leverage.clone());
}
}
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
return self.contract_private_post_capi_v3_account_leverage(&[__ws_arg_44]).await;
Value::Null
}
/*
* @method
* @name weex#fetchPositionMode
* @description fetchs the position mode, hedged or one way
* @see https://www.weex.com/api-doc/contract/Account_API/GetSymbolConfig
* @param {string} symbol unified symbol of the market to fetch the order book for
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_45 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_get_capi_v3_account_symbol_config(&[__ws_arg_45]).await;
let mut entry: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut separatedType: Value = self.safe_string_k(entry.clone(), "separatedType", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("hedged".to_string(), Value::Bool((is_equal(&separatedType, &Value::Str("SEPARATED".to_string())))));
m
});
Value::Null
}
/*
* @method
* @name weex#setPositionMode
* @description set hedged to true or false for a market
* @see https://www.weex.com/api-doc/contract/Account_API/ChangeMarginModeTRADE
* @param {bool} hedged set to true to use dualSidePosition
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.marginMode 'cross' or 'isolated' (default is 'cross')
* @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
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setPositionMode() 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 marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setPositionMode".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(" setPositionMode() also sets marginMode, so a marginMode parameter is required".to_string()))));
}
let mut separatedType: Value = ternary(is_true(&hedged), Value::Str("SEPARATED".to_string()), Value::Str("COMBINED".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("marginType".to_string(), self.encode_margin_mode(marginMode.clone()));
m.insert("separatedType".to_string(), separatedType.clone());
m
});
let __ws_arg_46 = self.extend(request.clone(), &[params.clone()]);
return self.contract_private_post_capi_v3_account_margin_type(&[__ws_arg_46]).await;
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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut isolatedPositionId: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("positionId".to_string()), Value::Str("id".to_string()), Value::Str("isolatedPositionId".to_string())]), &[]);
if is_equal(&isolatedPositionId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" modifyMarginHelper() requires a positionId parameter".to_string()))));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("positionId".to_string()), Value::Str("id".to_string())]), &[]);
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("isolatedPositionId".to_string(), isolatedPositionId.clone());
m.insert("amount".to_string(), self.cost_to_precision(symbol.clone(), amount.clone()));
m.insert("type".to_string(), type_var.clone());
m
});
let mut parsedType: Value = ternary(is_true(&(is_equal(&type_var, &Value::Int(1)))), Value::Str("add".to_string()), Value::Str("reduce".to_string()));
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.contract_private_post_capi_v3_account_position_margin(&[__ws_arg_47]).await;
let __ws_arg_48 = self.parse_margin_modification(response.clone(), &[market.clone()]);
let __ws_arg_49 = self.parse_number(amount.clone(), &[]);
return self.extend(__ws_arg_48, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), __ws_arg_49);
m.insert("type".to_string(), parsedType.clone());
m
})]);
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);
//
// {
// "code": "200",
// "msg": "success",
// "requestTime": 1764505776347
// }
//
let mut msg: Value = self.safe_string_k(data.clone(), "msg", &[]);
let mut status: Value = ternary(is_true(&(is_equal(&msg, &Value::Str("success".to_string())))), Value::Str("ok".to_string()), Value::Str("failed".to_string()));
let mut timestamp: Value = self.safe_integer_k(data.clone(), "requestTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), Value::Null);
m.insert("total".to_string(), Value::Null);
m.insert("code".to_string(), self.safe_string_k(market.clone(), "settle", &[]));
m.insert("status".to_string(), status.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name weex#reduceMargin
* @description remove margin from a position
* @see https://www.weex.com/api-doc/contract/Account_API/AdjustPositionMarginTRADE
* @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
* @param {string} params.positionId the id of the position to reduce margin from, required
* @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(), amount.clone(), Value::Int(2), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name weex#addMargin
* @description add margin
* @see https://www.weex.com/api-doc/contract/Account_API/AdjustPositionMarginTRADE
* @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
* @param {string} params.positionId the id of the position to add margin to, required
* @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::Int(1), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @ignore
* @name weex#toSandboxMarketId
* @description get the market id to send in a request, converting to the demo-trading market id (e.g. BTCSUSDT) when sandbox mode is enabled, only valid for USDT-margined linear markets which is all the demo environment provides
* @param {object} market a unified market structure
* @returns {string} the market id for the request
*/
pub fn to_sandbox_market_id(&self, mut market: Value) -> Value {
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseId", &[]);
if is_true(&(is_equal(&sandboxMode, &Value::Bool(true)))) && is_true(&(!is_equal(&baseId, &Value::Null))) {
return add(&baseId, &Value::Str("SUSDT".to_string()));
}
return self.safe_string_k(market.clone(), "id", &[]);
Value::Null
}
/*
* @method
* @ignore
* @name weex#fromSandboxMarketId
* @description convert a demo-trading market id (e.g. BTCSUSDT) from a response back into the live market id (e.g. BTCUSDT) when sandbox mode is enabled
* @param {string} [marketId] a market id from an exchange response
* @returns {string} the live market id
*/
pub fn from_sandbox_market_id(&self, mut marketId: Value) -> Value {
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if is_true(&(!is_equal(&sandboxMode, &Value::Bool(true)))) || is_true(&(is_equal(&marketId, &Value::Null))) {
return marketId;
}
if is_true(&(!is_equal(&self.markets_by_id, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.markets_by_id, &marketId)))) {
return marketId;
}
if is_true(&Value::Bool(ends_with(&marketId, &Value::Str("SUSDT".to_string())))) {
let mut baseLength: Value = subtract(&get_array_length(&marketId), &Value::Int(5));
return add(&slice(&marketId, &Value::Int(0), &baseLength), &Value::Str("USDT".to_string()));
}
return marketId;
Value::Null
}
pub fn set_sandbox_mode(&mut self, mut enable: Value) {
self.super_set_sandbox_mode(enable.clone());
add_element_to_object(&mut self.options, &Value::Str("sandboxMode".to_string()), enable.clone());
}
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 endpoint: Value = self.implode_params(path.clone(), params.clone());
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut isBatch: bool = is_greater_than_or_equal(&get_index_of(&path, &Value::Str("batch".to_string())), &Value::Int(0));
if !is_true(&isBatch) && is_true(&(is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))))) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
endpoint = add(&endpoint, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
}
if is_true(&(is_equal(&api, &Value::Str("private".to_string())))) || is_true(&(is_equal(&api, &Value::Str("contractPrivate".to_string())))) {
let mut sandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if is_true(&(is_equal(&sandboxMode, &Value::Bool(true)))) && is_true(&(!is_equal(&get_index_of(&path, &Value::Str("capi/v3/sim/".to_string())), &Value::Int(0)))) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &path), &Value::Str(" is not available in sandbox mode, demo trading only supports fetchBalance, createOrder, fetchPositions, fetchClosedOrders and fetchCanceledOrders for swap markets".to_string()))));
}
self.check_required_credentials(&[]);
let mut timestamp: Value = self.number_to_string(self.nonce());
let mut payload: Value = add(&add(&add(×tamp, &method), &Value::Str("/".to_string())), &endpoint);
if is_true(&(is_equal(&method, &Value::Str("POST".to_string())))) || is_true(&isBatch) {
body = self.json(query.clone());
payload = add(&payload, &body);
}
let mut signature: Value = self.hmac(self.encode(payload.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("ACCESS-KEY".to_string(), self.apiKey.clone());
m.insert("ACCESS-SIGN".to_string(), signature.clone());
m.insert("ACCESS-PASSPHRASE".to_string(), self.password.clone());
m.insert("ACCESS-TIMESTAMP".to_string(), timestamp.clone());
m
});
if is_true(&(is_equal(&method, &Value::Str("POST".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))) {
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
}
} else {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("User-Agent".to_string(), Value::Str("ccxt".to_string()));
m
});
}
let mut url: Value = add(&add(&get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api), &Value::Str("/".to_string())), &endpoint);
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 {
//
// {
// "code": -1140,
// "msg": "Either orderId or origClientOrderId must be sent."
// }
//
let mut message: Value = self.safe_string_k(response.clone(), "msg", &[]);
if !is_equal(&message, &Value::Null) {
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" ".to_string())), &body)));
}
return Value::Null;
Value::Null
}
}