// 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 BingxCore {
pub exchange: crate::exchange::Exchange,
}
impl BingxCore {
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 = BingxCore::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 BingxCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::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 BingxCore.
BingxCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_deposit_address(self, depositAddress, &[currency.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_liquidation(&self, liquidation: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_liquidation(self, liquidation, &[market.clone()])
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::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 BingxCore.
BingxCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_income(self, info, &[market.clone()])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::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 BingxCore.
BingxCore::parse_leverage(self, leverage, &[market.clone()])
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_market_leverage_tiers(self, info, &[market.clone()])
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::parse_deposit_withdraw_fee(self, fee, &[currency.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on BingxCore.
BingxCore::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 BingxCore.
BingxCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BingxCore {
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_all_orders_after" => self.cancel_all_orders_after(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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_market_buy_order_with_cost" => self.create_market_buy_order_with_cost(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,
"create_market_order_with_cost" => self.create_market_order_with_cost(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,
"create_market_sell_order_with_cost" => self.create_market_sell_order_with_cost(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,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_order_request" => self.create_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]),
"create_orders" => self.create_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"custom_encode" => self.custom_encode(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"edit_order" => self.edit_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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_inverse_swap_markets" => self.fetch_inverse_swap_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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_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_market_leverage_tiers" => self.fetch_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_liquidations" => self.fetch_my_liquidations(&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_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_history" => self.fetch_position_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position_mode" => self.fetch_position_mode(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_spot_markets" => self.fetch_spot_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_swap_markets" => self.fetch_swap_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_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,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"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_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_deposit_withdraw_fee" => self.parse_deposit_withdraw_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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_income" => self.parse_income(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_liquidation" => self.parse_liquidation(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_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_side" => self.parse_order_side(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type" => self.parse_order_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_params" => self.parse_params(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_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer_status" => self.parse_transfer_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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" => self.set_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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()[..]),
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BingxCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BingxCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BingxCore {
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("bingx".to_string()));
m.insert("name".to_string(), Value::Str("BingX".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("US".to_string())]));
m.insert("rateLimit".to_string(), Value::Int(100));
m.insert("version".to_string(), Value::Str("v1".to_string()));
m.insert("certified".to_string(), Value::Bool(true));
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("cancelAllOrdersAfter".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(true));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(true));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(true));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("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("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(true));
m.insert("fetchFundingHistory".to_string(), Value::Bool(true));
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("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(true));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(true));
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(true));
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("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Bool(true));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".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("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("reduceMargin".to_string(), Value::Bool(true));
m.insert("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(true));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m
}));
m.insert("hostname".to_string(), Value::Str("bingx.com".to_string()));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github-production-user-asset-6210df.s3.amazonaws.com/1294454/253675376-6983b72e-4999-4549-b177-33b374c195e3.jpg".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fund".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("spot".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("swap".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("contract".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("wallets".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("user".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("subAccount".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("account".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("copyTrading".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("cswap".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m.insert("api".to_string(), Value::Str("https://open-api.{hostname}/openApi".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fund".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("spot".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("swap".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("contract".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("wallets".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("user".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("subAccount".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("account".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("copyTrading".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("cswap".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m.insert("api".to_string(), Value::Str("https://open-api-vst.{hostname}/openApi".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://bingx.com/".to_string()));
m.insert("doc".to_string(), Value::Str("https://bingx-api.github.io/docs/".to_string()));
m.insert("referral".to_string(), Value::Str("https://bingx.com/invite/OHETOM".to_string()));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
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("maker".to_string(), self.parse_number(Value::Str("0.001".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.001".to_string()), &[]));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("quote".to_string()));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0005".to_string()), &[]));
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
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fund".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".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("server/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("common/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/historyOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/myTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("oco/orderList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("oco/openOrderList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("oco/historyOrderList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/order/cancelReplace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/cancelOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/cancelOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/cancelAllAfter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("oco/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("oco/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
m
}));
m.insert("v2".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("market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("v3".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("get/asset/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("capital/deposit/hisrec".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("capital/withdraw/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post/asset/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".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("ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/historicalTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/markPriceKlines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/multiAssetsRules".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingRules".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("positionSide/dual".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/batchCancelReplace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/fullOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("maintMarginRatio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/positionHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("positionMargin/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("twap/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("twap/historyOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("twap/orderDetail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/assetMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("user/marginAssets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/amend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/cancelReplace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("positionSide/dual".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/batchCancelReplace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/closePosition".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/getVst".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("twap/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("twap/cancelOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/assetMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/reverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/autoAddMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
m
}));
m.insert("v2".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("server/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/contracts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/premiumIndex".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/fundingRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/openInterest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("quote/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("user/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/income".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/openOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/forceOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/allFillOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/fillHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/income/export".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("quote/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/getVst".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/closeAllPositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/cancelAllAfter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/positionMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("trade/order/test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/batchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/allOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m.insert("v3".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("quote/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("user/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("cswap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".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("market/contracts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/premiumIndex".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/openInterest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/forceOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/allFillOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/openOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/orderDetail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/orderHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/commissionRate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("user/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/allOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/closeAllPositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/marginType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/positionMargin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trade/allOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/cancelOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("allPosition".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("allOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("wallets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("capital/config/getall".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capital/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capital/innerTransfer/records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("capital/subAccount/deposit/address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capital/deposit/subHisrec".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("capital/subAccount/innerTransfer/records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("capital/deposit/riskRecords".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("capital/withdraw/apply".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capital/innerTransfer/apply".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capital/subAccountInnerTransfer/apply".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("capital/deposit/createSubAddress".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("subAccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("allAccountBalance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("apiKey/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("apiKey/edit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("apiKey/del".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("updateStatus".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("uid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("apiKey/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/apiPermissions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/apiRestrictions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("allAccountBalance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("innerTransfer/authorizeSubAccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("subAccount/asset/transferHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subAccount/transferAsset/supportCoins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("subAccount/transferAsset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("user".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("auth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("userDataStream".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("copyTrading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("swap/trace/currentTrack".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("PFutures/traderDetail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("PFutures/profitHistorySummarys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("PFutures/profitDetail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("PFutures/tradingPairs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("spot/traderDetail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("spot/profitHistorySummarys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("spot/profitDetail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("spot/historyOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("swap/trace/closeTrackOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("swap/trace/setTPSL".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("PFutures/setCommission".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("spot/trader/sellOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v3".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("asset/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/transferRecord".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("capital/deposit/hisrec".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("capital/withdraw/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post/asset/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("asset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
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("transfer/supportCoins".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
m
}));
m
}));
m
}));
m.insert("agent".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v1".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
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("account/inviteAccountList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("reward/commissionDataList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/inviteRelationCheck".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("asset/depositDetailList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("reward/third/commissionDataList".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("asset/partnerData".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("commissionDataList/referralCode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/superiorCheck".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
m
}));
m
}));
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("3m".to_string(), Value::Str("3m".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("12h".to_string(), Value::Str("12h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m.insert("3d".to_string(), Value::Str("3d".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("400".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("401".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("403".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("404".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("429".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("418".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("500".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("504".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("100001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("100412".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("100202".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("100204".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("100400".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("100410".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("100421".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("100440".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("100500".to_string(), Value::Str("OperationFailed".to_string()).clone());
m.insert("100503".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("80001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("80012".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("80014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("80016".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("80017".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("100414".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("100419".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("100437".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("101204".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110425".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("Insufficient assets".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("illegal transferType".to_string(), Value::Str("BadRequest".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SNOW".to_string(), Value::Str("Snowman".to_string()));
m.insert("OMNI".to_string(), Value::Str("OmniCat".to_string()));
m.insert("NAP".to_string(), Value::Str("$NAP".to_string()));
m.insert("TRUMP".to_string(), Value::Str("TRUMPMAGA".to_string()));
m.insert("TRUMPSOL".to_string(), Value::Str("TRUMP".to_string()));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultType".to_string(), Value::Str("spot".to_string()));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeZone".to_string(), Value::Int(0));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("funding".to_string(), Value::Str("fund".to_string()));
m.insert("spot".to_string(), Value::Str("spot".to_string()));
m.insert("future".to_string(), Value::Str("stdFutures".to_string()));
m.insert("swap".to_string(), Value::Str("USDTMPerp".to_string()));
m.insert("linear".to_string(), Value::Str("USDTMPerp".to_string()));
m.insert("inverse".to_string(), Value::Str("coinMPerp".to_string()));
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fund".to_string(), Value::Str("funding".to_string()));
m.insert("spot".to_string(), Value::Str("spot".to_string()));
m.insert("stdFutures".to_string(), Value::Str("future".to_string()));
m.insert("USDTMPerp".to_string(), Value::Str("linear".to_string()));
m.insert("coinMPerp".to_string(), Value::Str("inverse".to_string()));
m
}));
m.insert("recvWindow".to_string(), multiply(&Value::Int(5), &Value::Int(1000)));
m.insert("broker".to_string(), Value::Str("CCXT".to_string()));
m.insert("defaultNetworks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ETH".to_string(), Value::Str("ETH".to_string()));
m.insert("USDT".to_string(), Value::Str("ERC20".to_string()));
m.insert("USDC".to_string(), Value::Str("ERC20".to_string()));
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("LTC".to_string(), Value::Str("LTC".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ARBITRUM".to_string(), Value::Str("ARB".to_string()));
m.insert("MATIC".to_string(), Value::Str("POLYGON".to_string()));
m.insert("ZKSYNC".to_string(), Value::Str("ZKSYNCERA".to_string()));
m.insert("AVAXC".to_string(), Value::Str("AVAX-C".to_string()));
m.insert("HBAR".to_string(), Value::Str("HEDERA".to_string()));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("defaultForLinear".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(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
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(true));
m
}));
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(true));
m
}));
m.insert("price".to_string(), Value::Bool(true));
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(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(5));
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(512));
m.insert("daysBack".to_string(), Value::Int(30));
m.insert("untilDays".to_string(), Value::Int(30));
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(true));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::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(20000));
m.insert("untilDays".to_string(), Value::Int(7));
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::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::Null);
m.insert("daysBackCanceled".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
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("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1440));
m
}));
m
}));
m.insert("defaultForInverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("defaultForLinear".to_string()));
m.insert("createOrders".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.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Null);
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("defaultForLinear".to_string()));
m.insert("fetchCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("private".to_string(), Value::Bool(true));
m
}));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("trailing".to_string(), Value::Bool(false));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m.insert("daysBack".to_string(), Value::Int(1));
m.insert("untilDays".to_string(), Value::Int(1));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(100));
m.insert("untilDays".to_string(), Value::Null);
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("defaultForLinear".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("defaultForInverse".to_string()));
m
}));
m
}));
m.insert("defaultForFuture".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("defaultForLinear".to_string()));
m.insert("fetchOrders".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("defaultForFuture".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("defaultForFuture".to_string()));
m
}));
m
}));
m
}));
m.insert("rollingWindowSize".to_string(), Value::Int(2000));
m
})]);
Value::Null
}
/*
* @method
* @name bingx#fetchTime
* @description fetches the current integer timestamp in milliseconds from the bingx server
* @see https://bingx-api.github.io/docs/#/swapV2/base-info.html#Get%20Server%20Time
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the bingx server
*/
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.swap_v2_public_get_server_time(&[params.clone()]).await;
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "serverTime": 1675319535362
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
return self.safe_integer_k(data.clone(), "serverTime", &[]);
Value::Null
}
/*
* @method
* @name bingx#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Wallet%20Deposits%20and%20Withdrawals/Query%20currency%20deposit%20and%20withdrawal%20data
* @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
}));
if !is_true(&self.check_required_credentials(&[Value::Bool(false)])) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut isSandbox: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if is_equal(&isSandbox, &Value::Bool(true)) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut response: Value = self.wallets_v1_private_get_capital_config_getall(&[params.clone()]).await;
//
// {
// "code": "0",
// "timestamp": "1779364918914",
// "data": [
// {
// "coin": "BTC",
// "name": "BTC",
// "networkList": [
// {
// "name": "BTC",
// "network": "BTC",
// "isDefault": true,
// "minConfirm": "2",
// "withdrawEnable": true,
// "depositEnable": true,
// "withdrawFee": "0.00004",
// "withdrawMax": "64.77131128",
// "withdrawMin": "0.000046",
// "depositMin": "0.00009",
// "withdrawPrecision": "8",
// "depositPrecision": "8",
// "contractAddress": "",
// "needTagOrMemo": "false",
// "displayName": "BTC"
// },
// {
// "name": "BTC",
// "network": "BEP20",
// "isDefault": true,
// "minConfirm": "10",
// "withdrawEnable": true,
// "depositEnable": true,
// "withdrawFee": "0.000001",
// "withdrawMax": "64.77131128",
// "withdrawMin": "0.000065",
// "depositMin": "0.000012",
// "withdrawPrecision": "8",
// "depositPrecision": "18",
// "contractAddress": "0x7130d2a12b9bcbfae4f2634d864a1ee1ce3ead9c",
// "needTagOrMemo": "false",
// "displayName": "BTCBEP20"
// }
// ]
// },
// ...
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_currencies(data.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 networkList: Value = self.safe_list_k(rawCurrency.clone(), "networkList", &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_291: bool = true;
while { if !__for_first_291 { j = add(&j, &Value::Int(1)); } __for_first_291 = false; is_less_than(&j, &get_array_length(&networkList)) } {
let mut rawNetwork: Value = get_value(&networkList, &j);
let mut rawNetwork: Value = get_value(&networkList, &j);
let mut network: Value = self.safe_string_k(rawNetwork.clone(), "network", &[]);
let mut networkCode: Value = self.network_id_to_code(&[network.clone(), code.clone()]);
let mut limits: Value = 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(rawNetwork.clone(), "withdrawMin", &[]));
m.insert("max".to_string(), self.safe_number_k(rawNetwork.clone(), "withdrawMax", &[]));
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(rawNetwork.clone(), "depositMin", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
});
let mut precision: Value = self.parse_number(self.parse_precision(&[self.safe_string_k(rawNetwork.clone(), "withdrawPrecision", &[])]), &[]);
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(), rawNetwork.clone());
m.insert("id".to_string(), network.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("fee".to_string(), self.safe_number_k(rawNetwork.clone(), "withdrawFee", &[]));
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(rawNetwork.clone(), "depositEnable", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(rawNetwork.clone(), "withdrawEnable", &[]));
m.insert("precision".to_string(), precision.clone());
m.insert("limits".to_string(), limits.clone());
m
}));
}
}
}
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("precision".to_string(), Value::Null);
m.insert("name".to_string(), name.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("networks".to_string(), networks.clone());
m.insert("fee".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m
}));
Value::Null
}
pub async fn fetch_spot_markets(&mut self, mut params: Value) -> Value {
let mut response: Value = self.spot_v1_public_get_common_symbols(&[params.clone()]).await;
//
// {
// "code": 0,
// "msg": "",
// "debugMsg": "",
// "data": {
// "symbols": [
// {
// "symbol": "GEAR-USDT",
// "minQty": 735, // deprecated
// "maxQty": 2941177, // deprecated.
// "minNotional": 5,
// "maxNotional": 20000,
// "status": 1,
// "tickSize": 0.000001,
// "stepSize": 1,
// "apiStateSell": true,
// "apiStateBuy": true,
// "timeOnline": 0,
// "offTime": 0,
// "maintainTime": 0
// },
// ...
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
let mut markets: Value = self.safe_list_k(data.clone(), "symbols", &[Value::List(vec![])]);
return self.parse_markets(markets.clone());
Value::Null
}
pub async fn fetch_swap_markets(&mut self, mut params: Value) -> Value {
let mut response: Value = self.swap_v2_public_get_quote_contracts(&[params.clone()]).await;
//
// {
// "code": 0,
// "msg": "",
// "data": [
// {
// "contractId": "100",
// "symbol": "BTC-USDT",
// "size": "0.0001",
// "quantityPrecision": "4",
// "pricePrecision": "1",
// "feeRate": "0.0005",
// "makerFeeRate": "0.0002",
// "takerFeeRate": "0.0005",
// "tradeMinLimit": "0",
// "tradeMinQuantity": "0.0001",
// "tradeMinUSDT": "2",
// "maxLongLeverage": "125",
// "maxShortLeverage": "125",
// "currency": "USDT",
// "asset": "BTC",
// "status": "1",
// "apiStateOpen": "true",
// "apiStateClose": "true",
// "ensureTrigger": true,
// "triggerFeeRate": "0.00020000"
// },
// ...
// ]
// }
//
let mut markets: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_markets(markets.clone());
Value::Null
}
pub async fn fetch_inverse_swap_markets(&mut self, mut params: Value) -> Value {
let mut response: Value = self.cswap_v1_public_get_market_contracts(&[params.clone()]).await;
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1720074487610,
// "data": [
// {
// "symbol": "BNB-USD",
// "pricePrecision": 2,
// "minTickSize": "10",
// "minTradeValue": "10",
// "minQty": "1.00000000",
// "status": 1,
// "timeOnline": 1713175200000
// },
// ]
// }
//
let mut markets: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_markets(markets.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut symbolParts: Value = split(&id, &Value::Str("-".to_string()));
let mut baseId: Value = get_value(&symbolParts, &Value::Int(0));
let mut quoteId: Value = get_value(&symbolParts, &Value::Int(1));
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut currency: Value = self.safe_string_k(market.clone(), "currency", &[]);
let mut checkIsInverse: Value = Value::Bool(false);
let mut checkIsLinear: Value = Value::Bool(true);
let mut minTickSize: Value = self.safe_number_k(market.clone(), "minTickSize", &[]);
if !is_equal(&minTickSize, &Value::Null) {
// inverse swap market
currency = baseId.clone();
checkIsInverse = Value::Bool(true);
checkIsLinear = Value::Bool(false);
}
let mut settle: Value = self.safe_currency_code(currency.clone(), &[]);
let mut pricePrecision: Value = self.safe_number_k(market.clone(), "tickSize", &[]);
if is_equal(&pricePrecision, &Value::Null) {
pricePrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "pricePrecision", &[])]), &[]);
}
let mut quantityPrecision: Value = self.safe_number_k(market.clone(), "stepSize", &[]);
if is_equal(&quantityPrecision, &Value::Null) {
quantityPrecision = self.parse_number(self.parse_precision(&[self.safe_string_k(market.clone(), "quantityPrecision", &[])]), &[]);
}
let mut type_var: Value = ternary(is_true(&(!is_equal(&settle, &Value::Null))), Value::Str("swap".to_string()), Value::Str("spot".to_string()));
let mut spot: Value = Value::Bool(is_equal(&type_var, &Value::Str("spot".to_string())));
let mut swap: Value = Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string())));
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
if !is_equal(&settle, &Value::Null) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), &settle));
}
let mut fees: Value = self.safe_dict(self.fees.clone(), type_var.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut contractSize: Value = ternary(is_true(&(swap)), self.parse_number(Value::Str("1".to_string()), &[]), Value::Null);
let mut isActive: Value = Value::Bool(false);
if is_true(&(is_equal(&self.safe_string_k(market.clone(), "apiStateOpen", &[]), &Value::Str("true".to_string())))) && is_true(&(is_equal(&self.safe_string_k(market.clone(), "apiStateClose", &[]), &Value::Str("true".to_string())))) {
isActive = Value::Bool(true); // swap active
} else if is_true(&(is_equal(&self.safe_bool_k(market.clone(), "apiStateSell", &[]), &Value::Bool(true)))) && is_true(&(is_equal(&self.safe_bool_k(market.clone(), "apiStateBuy", &[]), &Value::Bool(true)))) && is_true(&(is_equal(&self.safe_string_k(market.clone(), "status", &[]), &Value::Str("1".to_string())))) {
isActive = Value::Bool(true); // spot active
} else if is_true(&checkIsInverse) && is_true(&(is_equal(&self.safe_string_k(market.clone(), "status", &[]), &Value::Str("1".to_string())))) {
isActive = Value::Bool(true); // inverse swap active
}
let mut isInverse: Value = ternary(is_true(&(spot)), Value::Null, checkIsInverse.clone());
let mut isLinear: Value = ternary(is_true(&(spot)), Value::Null, checkIsLinear.clone());
let mut minAmount: Value = Value::Null;
if !is_true(&spot) {
minAmount = self.safe_number2(market.clone(), Value::Str("minQty".to_string()), Value::Str("tradeMinQuantity".to_string()), &[]);
}
let mut timeOnline: Value = self.safe_integer_k(market.clone(), "timeOnline", &[]);
if is_equal(&timeOnline, &Value::Int(0)) {
timeOnline = Value::Null;
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), currency.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), spot.clone());
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), isActive.clone());
m.insert("contract".to_string(), swap.clone());
m.insert("linear".to_string(), isLinear.clone());
m.insert("inverse".to_string(), isInverse.clone());
m.insert("taker".to_string(), self.safe_number_k(fees.clone(), "taker", &[]));
m.insert("maker".to_string(), self.safe_number_k(fees.clone(), "maker", &[]));
m.insert("feeSide".to_string(), self.safe_string_k(fees.clone(), "feeSide", &[]));
m.insert("contractSize".to_string(), contractSize.clone());
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(), quantityPrecision.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(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minAmount.clone());
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), minTickSize.clone());
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_n(market.clone(), Value::List(vec![Value::Str("minNotional".to_string()), Value::Str("tradeMinUSDT".to_string()), Value::Str("minTradeValue".to_string())]), &[]));
m.insert("max".to_string(), self.safe_number_k(market.clone(), "maxNotional", &[]));
m
}));
m
}));
m.insert("created".to_string(), timeOnline.clone());
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name bingx#fetchMarkets
* @description retrieves data on all markets for bingx
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Market%20Data/Spot%20trading%20symbols
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/USDT-M%20Perp%20Futures%20symbols
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Contract%20Information
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut requests: Value = Value::List(vec![self.fetch_swap_markets(params.clone()).await]);
let mut isSandbox: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if !is_equal(&isSandbox, &Value::Bool(true)) {
append_to_array(&mut requests, self.fetch_inverse_swap_markets(params.clone()).await);
append_to_array(&mut requests, self.fetch_spot_markets(params.clone()).await); // sandbox is swap only
}
let mut promises: Value = promise_all(&requests).await;
let mut linearSwapMarkets: Value = self.safe_list(promises.clone(), Value::Int(0), &[Value::List(vec![])]);
let mut inverseSwapMarkets: Value = self.safe_list(promises.clone(), Value::Int(1), &[Value::List(vec![])]);
let mut spotMarkets: Value = self.safe_list(promises.clone(), Value::Int(2), &[Value::List(vec![])]);
let mut swapMarkets: Value = self.array_concat(linearSwapMarkets.clone(), inverseSwapMarkets.clone());
return self.array_concat(spotMarkets.clone(), swapMarkets.clone());
Value::Null
}
/*
* @method
* @name bingx#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Market%20Data/Kline%2FCandlestick%20Data
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Kline%2FCandlestick%20Data
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Mark%20Price%20Kline%2FCandlestick%20Data
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Get%20K-line%20Data
* @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 (max 1000 for inverse swaps, 1440 otherwise)
* @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] 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 {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut maxLimit: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))), Value::Int(1000), Value::Int(1440));
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[Value::Bool(false)]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), 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
});
add_element_to_object(&mut request, &Value::Str("interval".to_string()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
let mut requestLimit: Value = ternary(is_true(&(is_equal(&limit, &Value::Null))), Value::Int(500), crate::runtime::Math::min(&limit, &maxLimit));
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), crate::runtime::Math::max(&subtract(&since, &Value::Int(1)), &Value::Int(0)));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), requestLimit.clone());
}
let mut until: Value = self.safe_integer2(params.clone(), Value::Str("until".to_string()), Value::Str("endTime".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
} else if is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))) && is_true(&(!is_equal(&since, &Value::Null))) {
let mut duration: Value = multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000));
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), self.sum(&[since.clone(), multiply(&duration, &requestLimit)]));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
// bingx spot klines are anchored to UTC+8 by default, unlike the swap klines and other exchanges
// the timeZone request parameter aligns the candle boundaries to UTC, live-verified for the spot endpoint
let mut timeZone: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("timeZone".to_string()), &[Value::Int(0)]); timeZone = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&timeZone, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeZone".to_string()), timeZone.clone());
}
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_public_get_market_kline(&[__ws_arg_0]).await;
} else {
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_public_get_market_klines(&[__ws_arg_1]).await;
} else {
let mut price: Value = self.safe_string_k(params.clone(), "price", &[]);
params = self.omit(params.clone(), Value::Str("price".to_string()), &[]);
if is_equal(&price, &Value::Str("mark".to_string())) {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v1_public_get_market_mark_price_klines(&[__ws_arg_2]).await;
} else {
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v3_public_get_quote_klines(&[__ws_arg_3]).await;
}
}
}
//
// {
// "code": 0,
// "msg": "",
// "data": [
// {
// "open": "19396.8",
// "close": "19394.4",
// "high": "19397.5",
// "low": "19385.7",
// "volume": "110.05",
// "time": 1666583700000
// },
// ...
// ]
// }
//
// fetchMarkOHLCV
//
// {
// "code": 0,
// "msg": "",
// "data": [
// {
// "open": "42191.7",
// "close": "42189.5",
// "high": "42196.5",
// "low": "42189.5",
// "volume": "0.00",
// "openTime": 1706508840000,
// "closeTime": 1706508840000
// }
// ]
// }
//
let mut ohlcvs: Value = self.safe_value_k(response.clone(), "data", &[Value::List(vec![])]);
if !is_true(&Value::Bool(is_array(&ohlcvs))) {
ohlcvs = Value::List(vec![ohlcvs.clone()]);
}
return self.parse_ohlc_vs(ohlcvs.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);
//
// {
// "open": "19394.4",
// "close": "19379.0",
// "high": "19394.4",
// "low": "19368.3",
// "volume": "167.44",
// "time": 1666584000000
// }
//
// fetchMarkOHLCV
//
// {
// "open": "42191.7",
// "close": "42189.5",
// "high": "42196.5",
// "low": "42189.5",
// "volume": "0.00",
// "openTime": 1706508840000,
// "closeTime": 1706508840000
// }
// spot
// [
// 1691402580000,
// 29093.61,
// 29093.93,
// 29087.73,
// 29093.24,
// 0.59,
// 1691402639999,
// 17221.07
// ]
//
if is_true(&Value::Bool(is_array(&ohlcv))) {
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), &[])]);
}
return Value::List(vec![self.safe_integer2(ohlcv.clone(), Value::Str("time".to_string()), Value::Str("closeTime".to_string()), &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv.clone(), "volume", &[])]);
Value::Null
}
/*
* @method
* @name bingx#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Market%20Data/Recent%20Trades%20List
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Recent%20Trades%20List
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} 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());
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTrades() is not supported for inverse swap markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTrades".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
let mut maxLimit: Value = ternary(is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))), Value::Int(500), Value::Int(1000));
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &maxLimit));
}
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_public_get_market_trades(&[__ws_arg_4]).await;
} else {
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_public_get_quote_trades(&[__ws_arg_5]).await;
}
//
// spot
//
// {
// "code": 0,
// "data": [
// {
// "id": 43148253,
// "price": 25714.71,
// "qty": 1.674571,
// "time": 1655085975589,
// "buyerMaker": false
// }
// ]
// }
//
// swap
//
// {
// "code":0,
// "msg":"",
// "data":[
// {
// "time": 1672025549368,
// "isBuyerMaker": true,
// "price": "16885.0",
// "qty": "3.3002",
// "quoteQty": "55723.87"
// },
// ...
// ]
// }
//
let mut trades: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(trades.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);
//
// spot fetchTrades
//
// {
// "id": 43148253,
// "price": 25714.71,
// "qty": 1.674571,
// "time": 1655085975589,
// "buyerMaker": false
// }
//
// spot fetchMyTrades
//
// {
// "symbol": "LTC-USDT",
// "id": 36237072,
// "orderId": 1674069326895775744,
// "price": "85.891",
// "qty": "0.0582",
// "quoteQty": "4.9988562000000005",
// "commission": -0.00005820000000000001,
// "commissionAsset": "LTC",
// "time": 1687964205000,
// "isBuyer": true,
// "isMaker": false
// }
//
// swap fetchTrades
//
// {
// "time": 1672025549368,
// "isBuyerMaker": true,
// "price": "16885.0",
// "qty": "3.3002",
// "quoteQty": "55723.87"
// }
//
// swap fetchMyTrades
//
// {
// "volume": "0.1",
// "price": "106.75",
// "amount": "10.6750",
// "commission": "-0.0053",
// "currency": "USDT",
// "orderId": "1676213270274379776",
// "liquidatedPrice": "0.00",
// "liquidatedMarginRatio": "0.00",
// "filledTime": "2023-07-04T20:56:01.000+0800"
// }
//
// ws spot
//
// {
// "E": 1690214529432,
// "T": 1690214529386,
// "e": "trade",
// "m": true,
// "p": "29110.19",
// "q": "0.1868",
// "s": "BTC-USDT",
// "t": "57903921"
// }
//
// ws linear swap
//
// {
// "q": "0.0421",
// "p": "29023.5",
// "T": 1690221401344,
// "m": false,
// "s": "BTC-USDT"
// }
//
// ws inverse swap
//
// {
// "e": "trade",
// "E": 1722920589665,
// "s": "BTC-USD",
// "t": "39125001",
// "p": "55360.0",
// "q": "1",
// "T": 1722920589582,
// "m": false
// }
//
// inverse swap fetchMyTrades
//
// {
// "orderId": "1817441228670648320",
// "symbol": "SOL-USD",
// "type": "MARKET",
// "side": "BUY",
// "positionSide": "LONG",
// "tradeId": "97244554",
// "volume": "2",
// "tradePrice": "182.652",
// "amount": "20.00000000",
// "realizedPnl": "0.00000000",
// "commission": "-0.00005475",
// "currency": "SOL",
// "buyer": true,
// "maker": false,
// "tradeTime": 1722146730000
// }
//
let mut time: Value = self.safe_integer_n(trade.clone(), Value::List(vec![Value::Str("time".to_string()), Value::Str("filledTm".to_string()), Value::Str("T".to_string()), Value::Str("tradeTime".to_string())]), &[]);
let mut datetimeId: Value = self.safe_string_k(trade.clone(), "filledTm", &[]);
if !is_equal(&datetimeId, &Value::Null) {
time = self.parse8601(datetimeId.clone());
}
if is_equal(&time, &Value::Int(0)) {
time = Value::Null;
}
let mut cost: Value = self.safe_string_k(trade.clone(), "quoteQty", &[]);
// const type = (cost === undefined) ? 'spot' : 'swap'; this is not reliable
let mut currencyId: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("currency".to_string()), Value::Str("N".to_string()), Value::Str("commissionAsset".to_string())]), &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut m: Value = self.safe_bool_k(trade.clone(), "m", &[]);
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("s".to_string()), Value::Str("symbol".to_string()), &[]);
let mut isBuyerMaker: Value = self.safe_bool_n(trade.clone(), Value::List(vec![Value::Str("buyerMaker".to_string()), Value::Str("isBuyerMaker".to_string()), Value::Str("maker".to_string())]), &[]);
let mut takeOrMaker: Value = Value::Null;
let mut isMakerSide: bool = is_true(&(is_equal(&isBuyerMaker, &Value::Bool(true)))) || is_true(&(is_equal(&m, &Value::Bool(true))));
if is_true(&(!is_equal(&isBuyerMaker, &Value::Null))) || is_true(&(!is_equal(&m, &Value::Null))) {
takeOrMaker = ternary(is_true(&isMakerSide), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
let mut side: Value = self.safe_string_lower2(trade.clone(), Value::Str("side".to_string()), Value::Str("S".to_string()), &[]);
if is_equal(&side, &Value::Null) {
if is_true(&(!is_equal(&isBuyerMaker, &Value::Null))) || is_true(&(!is_equal(&m, &Value::Null))) {
side = ternary(is_true(&isMakerSide), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
takeOrMaker = Value::Str("taker".to_string());
}
}
let mut isBuyer: Value = self.safe_bool_k(trade.clone(), "isBuyer", &[]);
if !is_equal(&isBuyer, &Value::Null) {
side = ternary(is_true(&isBuyer), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
}
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "isMaker", &[]);
if !is_equal(&isMaker, &Value::Null) {
takeOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
let mut amount: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("qty".to_string()), Value::Str("amount".to_string()), Value::Str("q".to_string())]), &[]);
if is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) && is_true(&(Value::Bool(in_op(&trade, &Value::Str("volume".to_string()))))) {
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
// private linear swap trades report 'amount' as the notional (quote) value, not the base amount;
// 'volume' is the exchange's own base-currency fill quantity (bingx linear contractSize is always 1),
// use it directly instead of 'notional / price', which picks up rounding noise from the notional field
amount = self.safe_string_k(trade.clone(), "volume", &[]);
} else {
// private trade returns num of contracts instead of base currency (as the order-related methods do)
let mut contractSize: Value = self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("tradeMinQuantity".to_string()), &[]);
let mut volume: Value = self.safe_string_k(trade.clone(), "volume", &[]);
amount = crate::precise::Precise::stringMul(&volume, &contractSize);
}
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string2(trade.clone(), Value::Str("id".to_string()), Value::Str("t".to_string()), &[]));
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), time.clone());
m.insert("datetime".to_string(), self.iso8601(time.clone()));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("-".to_string())]));
m.insert("order".to_string(), self.safe_string2(trade.clone(), Value::Str("orderId".to_string()), Value::Str("i".to_string()), &[]));
m.insert("type".to_string(), self.safe_string_lower(trade.clone(), Value::Str("o".to_string()), &[]));
m.insert("side".to_string(), self.parse_order_side(side.clone()));
m.insert("takerOrMaker".to_string(), takeOrMaker.clone());
m.insert("price".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("price".to_string()), Value::Str("p".to_string()), Value::Str("tradePrice".to_string())]), &[]));
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(crate::precise::Precise::stringAbs(&self.safe_string2(trade.clone(), Value::Str("commission".to_string()), Value::Str("n".to_string()), &[])), &[]));
m.insert("currency".to_string(), currencyCode.clone());
m
}));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Market%20Data/Order%20Book
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Order%20Book
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Query%20Depth%20Data
* @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 (max 1000)
* @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
});
let mut response: Value = Value::Null;
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrderBook".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&limit, &Value::Null) {
if is_equal(&marketType, &Value::Str("spot".to_string())) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(1000))); // api maximum 1000
} else {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), self.find_nearest_ceiling(Value::List(vec![Value::Int(5), Value::Int(10), Value::Int(20), Value::Int(50), Value::Int(100), Value::Int(500), Value::Int(1000)]), limit.clone()));
}
}
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_public_get_market_depth(&[__ws_arg_6]).await;
} else {
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_public_get_market_depth(&[__ws_arg_7]).await;
} else {
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_public_get_quote_depth(&[__ws_arg_8]).await;
}
}
//
// spot
//
// {
// "code":0,
// "timestamp":1743240504535,
// "data":{
// "bids":[
// ["83775.39","1.981875"],
// ["83775.38","0.001076"],
// ["83775.34","0.254716"],
// ],
// "asks":[
// ["83985.40","0.000013"],
// ["83980.00","0.000011"],
// ["83975.70","0.000061000000000000005"],
// ],
// "ts":1743240504535,
// "lastUpdateId":13565639906
// }
// }
//
//
// linear swap
//
// {
// "code":0,
// "msg":"",
// "data":{
// "T":1743240836255,
// "bids":[
// ["83760.7","7.0861"],
// ["83760.6","0.0044"],
// ["83757.7","1.9526"],
// ],
// "asks":[
// ["83784.3","8.3531"],
// ["83782.8","23.7289"],
// ["83780.1","18.0617"],
// ],
// "bidsCoin":[
// ["83760.7","0.0007"],
// ["83760.6","0.0000"],
// ["83757.7","0.0002"],
// ],
// "asksCoin":[
// ["83784.3","0.0008"],
// ["83782.8","0.0024"],
// ["83780.1","0.0018"],
// ]
// }
// }
//
// inverse swap
//
// {
// "code":0,
// "msg":"",
// "timestamp":1743240979146,
// "data":{
// "T":1743240978691,
// "bids":[
// ["83611.4","241.0"],
// ["83611.3","1.0"],
// ["83602.9","666.0"],
// ],
// "asks":[
// ["83645.0","4253.0"],
// ["83640.5","3188.0"],
// ["83636.0","5540.0"],
// ]
// }
// }
//
let mut orderbook: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut nonce: Value = self.safe_integer_k(orderbook.clone(), "lastUpdateId", &[]);
let mut timestamp: Value = self.safe_integer2(orderbook.clone(), Value::Str("T".to_string()), Value::Str("ts".to_string()), &[]);
let mut result: Value = self.parse_order_book(orderbook.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Int(0), Value::Int(1)]);
add_element_to_object(&mut result, &Value::Str("nonce".to_string()), nonce.clone());
return result;
Value::Null
}
/*
* @method
* @name bingx#fetchFundingRate
* @description fetch the current funding rate
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Mark%20Price%20and%20Funding%20Rate
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Price%20%26%20Current%20Funding%20Rate
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate(&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 mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_public_get_market_premium_index(&[__ws_arg_9]).await;
} else {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_public_get_quote_premium_index(&[__ws_arg_10]).await;
}
//
// {
// "code":0,
// "msg":"",
// "data":[
// {
// "symbol": "BTC-USDT",
// "markPrice": "16884.5",
// "indexPrice": "16886.9",
// "lastFundingRate": "0.0001",
// "nextFundingTime": 1672041600000
// },
// ...
// ]
// }
//
let mut data: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let mut dataList: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
data = self.safe_dict(dataList.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
data = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_funding_rate(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchFundingRates
* @description fetch the current funding rate for multiple symbols
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Mark%20Price%20and%20Funding%20Rate
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Price%20%26%20Current%20Funding%20Rate
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] "linear" or "inverse" (default is linear)
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Str("swap".to_string()), Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut firstMarket: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut subType: Value = Value::Str("linear".to_string());
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchFundingRates".to_string()), &[firstMarket.clone(), params.clone(), subType.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.cswap_v1_public_get_market_premium_index(&[params.clone()]).await;
} else {
response = self.swap_v2_public_get_quote_premium_index(&[params.clone()]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_funding_rates(data.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);
//
// {
// "symbol": "BTC-USDT",
// "markPrice": "16884.5",
// "indexPrice": "16886.9",
// "lastFundingRate": "0.0001",
// "nextFundingTime": 1672041600000
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
let mut nextFundingTimestamp: Value = self.safe_integer_k(contract.clone(), "nextFundingTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("-".to_string()), Value::Str("swap".to_string())]));
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(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "lastFundingRate", &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bingx#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Get%20Funding%20Rate%20History
* @param {string} symbol unified symbol of the market to fetch the funding rate history for, inverse (Coin-M) markets are not supported
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-history-structure} to fetch (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 to fetch
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @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());
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRateHistory() is not supported for inverse swap markets".to_string()))));
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.clone()]).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, &Value::Int(1000))); // api maximum 1000
}
{ 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_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_v2_public_get_quote_funding_rate(&[__ws_arg_11]).await;
//
// {
// "code":0,
// "msg":"",
// "data":[
// {
// "symbol": "BTC-USDT",
// "fundingRate": "0.0001",
// "fundingTime": 1585684800000
// },
// ...
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_funding_rate_histories(data.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": "BTC-USDT",
// "fundingRate": "0.0001",
// "fundingTime": 1585684800000
// }
//
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(), self.safe_symbol(self.safe_string_k(contract.clone(), "symbol", &[]), &[market.clone(), Value::Str("-".to_string()), Value::Str("swap".to_string())]));
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 bingx#fetchFundingHistory
* @description fetches historical funding received
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Account%20Endpoints/Get%20Account%20Profit%20and%20Loss%20Fund%20Flow
* @param {string} symbol unified symbol of the market to fetch the funding history for
* @param {int} [since] timestamp in ms of the earliest funding to fetch
* @param {int} [limit] the maximum amount of [funding history structures]{@link https://docs.ccxt.com/?id=funding-history-structure} to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest funding to fetch
* @returns {object[]} a list of [funding history structures]{@link https://docs.ccxt.com/?id=funding-history-structure}
*/
pub async fn fetch_funding_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(&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("fetchFundingHistory".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchFundingHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("24h".to_string()), params.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("incomeType".to_string(), Value::Str("FUNDING_FEE".to_string()));
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())));
}
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 mut until: Value = self.safe_integer2(params.clone(), Value::Str("until".to_string()), Value::Str("endTime".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_v2_private_get_user_income(&[__ws_arg_12]).await;
// {
// "code": 0,
// "msg": "",
// "data": [
// {
// "symbol": "LDO-USDT",
// "incomeType": "FUNDING_FEE",
// "income": "-0.0292",
// "asset": "USDT",
// "info": "Funding Fee",
// "time": 1702713615000,
// "tranId": "170***6*2_3*9_20***97",
// "tradeId": "170***6*2_3*9_20***97"
// }
// ]
// }
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_incomes(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_income(&self, mut income: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
// {
// "symbol": "LDO-USDT",
// "incomeType": "FUNDING_FEE",
// "income": "-0.0292",
// "asset": "USDT",
// "info": "Funding Fee",
// "time": 1702713615000,
// "tranId": "170***6*2_3*9_20***97",
// "tradeId": "170***6*2_3*9_20***97"
// }
let mut marketId: Value = self.safe_string_k(income.clone(), "symbol", &[]);
let mut currencyId: Value = self.safe_string_k(income.clone(), "asset", &[]);
let mut timestamp: Value = self.safe_integer_k(income.clone(), "time", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), income.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]));
m.insert("code".to_string(), self.safe_currency_code(currencyId.clone(), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), self.safe_string_k(income.clone(), "tranId", &[]));
m.insert("amount".to_string(), self.safe_number_k(income.clone(), "income", &[]));
m.insert("type".to_string(), Value::Str("funding".to_string()));
m
});
Value::Null
}
/*
* @method
* @name bingx#fetchOpenInterest
* @description retrieves the open interest of a trading pair
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Open%20Interest%20Statistics
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Get%20Swap%20Open%20Positions
* @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 mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_public_get_market_open_interest(&[__ws_arg_13]).await;
} else {
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_public_get_quote_open_interest(&[__ws_arg_14]).await;
}
//
// linear swap
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "openInterest": "3289641547.10",
// "symbol": "BTC-USDT",
// "time": 1672026617364
// }
// }
//
// inverse swap
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1720328247986,
// "data": [
// {
// "symbol": "BTC-USD",
// "openInterest": "749.1160",
// "timestamp": 1720310400000
// }
// ]
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
result = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
result = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_open_interest(result.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);
//
// linear swap
//
// {
// "openInterest": "3289641547.10",
// "symbol": "BTC-USDT",
// "time": 1672026617364
// }
//
// inverse swap
//
// {
// "symbol": "BTC-USD",
// "openInterest": "749.1160",
// "timestamp": 1720310400000
// }
//
let mut timestamp: Value = self.safe_integer2(interest.clone(), Value::Str("time".to_string()), Value::Str("timestamp".to_string()), &[]);
let mut id: Value = self.safe_string_k(interest.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(id.clone(), &[market.clone(), Value::Str("-".to_string()), Value::Str("swap".to_string())]);
let mut openInterest: Value = self.safe_number_k(interest.clone(), "openInterest", &[]);
let mut inverse: Value = self.safe_bool_k(market.clone(), "inverse", &[Value::Bool(false)]);
let mut isInverse: bool = is_equal(&inverse, &Value::Bool(true));
let mut openInterestAmount: Value = ternary(is_true(&isInverse), openInterest.clone(), Value::Null);
let mut openInterestValue: Value = ternary(is_true(&isInverse), Value::Null, openInterest.clone());
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("baseVolume".to_string(), Value::Null);
m.insert("quoteVolume".to_string(), Value::Null);
m.insert("openInterestAmount".to_string(), openInterestAmount.clone());
m.insert("openInterestValue".to_string(), openInterestValue.clone());
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 bingx#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Market%20Data/24hr%20Ticker%20Price%20Change%20Statistics
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/24hr%20Ticker%20Price%20Change%20Statistics
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Query%2024-Hour%20Price%20Change
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_public_get_ticker24hr(&[__ws_arg_15]).await;
} else {
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_public_get_market_ticker(&[__ws_arg_16]).await;
} else {
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_public_get_quote_ticker(&[__ws_arg_17]).await;
}
}
//
// spot and swap
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1720647285296,
// "data": [
// {
// "symbol": "SOL-USD",
// "priceChange": "-2.418",
// "priceChangePercent": "-1.6900%",
// "lastPrice": "140.574",
// "lastQty": "1",
// "highPrice": "146.190",
// "lowPrice": "138.586",
// "volume": "1464648.00",
// "quoteVolume": "102928.12",
// "openPrice": "142.994",
// "closeTime": "1720647284976",
// "bidPrice": "140.573",
// "bidQty": "372",
// "askPrice": "140.577",
// "askQty": "58"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
if !is_equal(&data, &Value::Null) {
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(first.clone(), &[market.clone()]);
}
let mut dataDict: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(dataDict.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Market%20Data/24hr%20Ticker%20Price%20Change%20Statistics
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/24hr%20Ticker%20Price%20Change%20Statistics
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Query%2024-Hour%20Price%20Change
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
if !is_equal(&firstSymbol, &Value::Null) {
market = self.market(firstSymbol.clone());
}
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTickers".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 subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); subType = 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.spot_v1_public_get_ticker24hr(&[params.clone()]).await;
} else {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.cswap_v1_public_get_market_ticker(&[params.clone()]).await;
} else {
response = self.swap_v2_public_get_quote_ticker(&[params.clone()]).await;
}
}
//
// spot and swap
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1720647285296,
// "data": [
// {
// "symbol": "SOL-USD",
// "priceChange": "-2.418",
// "priceChangePercent": "-1.6900%",
// "lastPrice": "140.574",
// "lastQty": "1",
// "highPrice": "146.190",
// "lowPrice": "138.586",
// "volume": "1464648.00",
// "quoteVolume": "102928.12",
// "openPrice": "142.994",
// "closeTime": "1720647284976",
// "bidPrice": "140.573",
// "bidQty": "372",
// "askPrice": "140.577",
// "askQty": "58"
// },
// ...
// ]
// }
//
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_tickers(tickers.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchMarkPrice
* @description fetches mark prices for the market
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Mark%20Price%20and%20Funding%20Rate
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Price%20%26%20Current%20Funding%20Rate
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@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());
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchMarkPrice".to_string()), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
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 response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_public_get_market_premium_index(&[__ws_arg_18]).await;
} else {
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_public_get_quote_premium_index(&[__ws_arg_19]).await;
}
if is_true(&Value::Bool(is_array(&get_value(&response, &Value::Str("data".to_string()))))) {
return self.parse_ticker(self.safe_dict(get_value(&response, &Value::Str("data".to_string())), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), &[market.clone()]);
}
return self.parse_ticker(get_value(&response, &Value::Str("data".to_string())), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchMarkPrices
* @description fetches mark prices for multiple markets
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Market%20Data/Mark%20Price%20and%20Funding%20Rate
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Market%20Data/Price%20%26%20Current%20Funding%20Rate
* @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_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;
}
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
if !is_equal(&firstSymbol, &Value::Null) {
market = self.market(firstSymbol.clone());
}
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchMarkPrices".to_string()), &[market.clone(), params.clone(), Value::Str("linear".to_string())]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.cswap_v1_public_get_market_premium_index(&[params.clone()]).await;
} else {
response = self.swap_v2_public_get_quote_premium_index(&[params.clone()]).await;
}
//
// spot and swap
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1720647285296,
// "data": [
// {
// "symbol": "SOL-USD",
// "priceChange": "-2.418",
// "priceChangePercent": "-1.6900%",
// "lastPrice": "140.574",
// "lastQty": "1",
// "highPrice": "146.190",
// "lowPrice": "138.586",
// "volume": "1464648.00",
// "quoteVolume": "102928.12",
// "openPrice": "142.994",
// "closeTime": "1720647284976",
// "bidPrice": "140.573",
// "bidQty": "372",
// "askPrice": "140.577",
// "askQty": "58"
// },
// ...
// ]
// }
//
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_tickers(tickers.clone(), &[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);
//
// mark price
// {
// "symbol": "string",
// "lastFundingRate": "string",
// "markPrice": "string",
// "indexPrice": "string",
// "nextFundingTime": "int64"
// }
//
// spot
// {
// "symbol": "BTC-USDT",
// "openPrice": "26032.08",
// "highPrice": "26178.86",
// "lowPrice": "25968.18",
// "lastPrice": "26113.60",
// "volume": "1161.79",
// "quoteVolume": "30288466.44",
// "openTime": "1693081020762",
// "closeTime": "1693167420762",
// added 2023-11-10:
// "bidPrice": 16726.0,
// "bidQty": 0.05,
// "askPrice": 16726.0,
// "askQty": 0.05,
// }
// swap
//
// {
// "symbol": "BTC-USDT",
// "priceChange": "52.5",
// "priceChangePercent": "0.31%", // they started to add the percent sign in value
// "lastPrice": "16880.5",
// "lastQty": "2.2238", // only present in swap!
// "highPrice": "16897.5",
// "lowPrice": "16726.0",
// "volume": "245870.1692",
// "quoteVolume": "4151395117.73",
// "openPrice": "16832.0",
// "openTime": 1672026667803,
// "closeTime": 1672026648425,
// added 2023-11-10:
// "bidPrice": 16726.0,
// "bidQty": 0.05,
// "askPrice": 16726.0,
// "askQty": 0.05,
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
let mut lastQty: Value = self.safe_string_k(ticker.clone(), "lastQty", &[]);
// in spot markets, lastQty is not present
// it's (bad, but) the only way we can check the tickers origin
let mut type_var: Value = ternary(is_true(&(is_equal(&lastQty, &Value::Null))), Value::Str("spot".to_string()), Value::Str("swap".to_string()));
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, type_var.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut open: Value = self.safe_string_k(ticker.clone(), "openPrice", &[]);
let mut high: Value = self.safe_string_k(ticker.clone(), "highPrice", &[]);
let mut low: Value = self.safe_string_k(ticker.clone(), "lowPrice", &[]);
let mut close: Value = self.safe_string_k(ticker.clone(), "lastPrice", &[]);
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "quoteVolume", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "volume", &[]);
let mut percentage: Value = self.safe_string_k(ticker.clone(), "priceChangePercent", &[]);
if !is_equal(&percentage, &Value::Null) {
percentage = replace_str(&percentage, &Value::Str("%".to_string()), &Value::Str("".to_string()));
}
let mut change: Value = self.safe_string_k(ticker.clone(), "priceChange", &[]);
let mut ts: Value = self.safe_integer_k(ticker.clone(), "closeTime", &[]);
if is_equal(&ts, &Value::Int(0)) {
ts = Value::Null;
}
let mut datetime: Value = self.iso8601(ts.clone());
let mut bid: Value = self.safe_string_k(ticker.clone(), "bidPrice", &[]);
let mut bidVolume: Value = self.safe_string_k(ticker.clone(), "bidQty", &[]);
let mut ask: Value = self.safe_string_k(ticker.clone(), "askPrice", &[]);
let mut askVolume: Value = self.safe_string_k(ticker.clone(), "askQty", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), ts.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("high".to_string(), high.clone());
m.insert("low".to_string(), low.clone());
m.insert("bid".to_string(), bid.clone());
m.insert("bidVolume".to_string(), bidVolume.clone());
m.insert("ask".to_string(), ask.clone());
m.insert("askVolume".to_string(), askVolume.clone());
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), open.clone());
m.insert("close".to_string(), close.clone());
m.insert("last".to_string(), Value::Null);
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), change.clone());
m.insert("percentage".to_string(), percentage.clone());
m.insert("average".to_string(), Value::Null);
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
m.insert("markPrice".to_string(), self.safe_string_k(ticker.clone(), "markPrice", &[]));
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 bingx#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Account%20Endpoints/Query%20Assets
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Account%20Endpoints/Query%20account%20data
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20Account%20Assets
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Fund%20Account/Query%20Assets
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.standard] whether to fetch standard contract balances
* @param {string} [params.type] the type of balance to fetch (spot, swap, funding) default is `spot`
* @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
*/
pub async fn fetch_balance(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = Value::Null;
let mut standard: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("standard".to_string()), &[Value::Bool(false)]); standard = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marketTypemarketTypeQueryVariable = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]);
let mut marketType: Value = get_value(&marketTypemarketTypeQueryVariable, &Value::Int(0));
let mut marketTypeQuery: Value = get_value(&marketTypemarketTypeQueryVariable, &Value::Int(1));
if is_true(&standard) {
response = self.contract_v1_private_get_balance(&[marketTypeQuery.clone()]).await;
} else if is_true(&(is_equal(&marketType, &Value::Str("funding".to_string())))) || is_true(&(is_equal(&marketType, &Value::Str("fund".to_string())))) {
response = self.fund_v1_private_get_account_balance(&[marketTypeQuery.clone()]).await;
} else if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.spot_v1_private_get_account_balance(&[marketTypeQuery.clone()]).await;
} else {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.cswap_v1_private_get_user_balance(&[marketTypeQuery.clone()]).await;
} else {
response = self.swap_v3_private_get_user_balance(&[marketTypeQuery.clone()]).await;
}
}
return self.parse_balance(response.clone());
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
//
// standard
//
// {
// "code": 0,
// "timestamp": 1721192833454,
// "data": [
// {
// "asset": "USDT",
// "balance": "4.72644300000000000000",
// "crossWalletBalance": "4.72644300000000000000",
// "crossUnPnl": "0",
// "availableBalance": "4.72644300000000000000",
// "maxWithdrawAmount": "4.72644300000000000000",
// "marginAvailable": false,
// "updateTime": 1721192833443
// },
// ]
// }
//
// spot
//
// {
// "code": 0,
// "msg": "",
// "debugMsg": "",
// "data": {
// "balances": [
// {
// "asset": "USDT",
// "free": "45.733046995800514",
// "locked": "0"
// },
// ]
// }
// }
//
// inverse swap
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1721191833813,
// "data": [
// {
// "asset": "SOL",
// "balance": "0.35707951",
// "equity": "0.35791051",
// "unrealizedProfit": "0.00083099",
// "availableMargin": "0.35160653",
// "usedMargin": "0.00630397",
// "freezedMargin": "0",
// "shortUid": "12851936"
// }
// ]
// }
//
// linear swap
//
// {
// "code": 0,
// "msg": "",
// "data": [
// {
// "userId": "116***295",
// "asset": "USDT",
// "balance": "194.8212",
// "equity": "196.7431",
// "unrealizedProfit": "1.9219",
// "realisedProfit": "-109.2504",
// "availableMargin": "193.7609",
// "usedMargin": "1.0602",
// "freezedMargin": "0.0000",
// "shortUid": "12851936"
// }
// ]
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut contractBalances: Value = self.safe_list_k(response.clone(), "data", &[]);
let mut firstContractBalances: Value = self.safe_dict(contractBalances.clone(), Value::Int(0), &[]);
let mut isContract: bool = !is_equal(&firstContractBalances, &Value::Null);
let mut spotData: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut spotBalances: Value = self.safe_list2(spotData.clone(), Value::Str("balances".to_string()), Value::Str("assets".to_string()), &[Value::List(vec![])]);
if is_true(&isContract) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_292: bool = true;
while { if !__for_first_292 { i = add(&i, &Value::Int(1)); } __for_first_292 = false; is_less_than(&i, &get_array_length(&contractBalances)) } {
let mut balance: Value = get_value(&contractBalances, &i);
let mut balance: Value = get_value(&contractBalances, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "asset", &[]);
if is_equal(¤cyId, &Value::Null) {
break;
}
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(balance.clone(), Value::Str("availableMargin".to_string()), Value::Str("availableBalance".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "usedMargin", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "maxWithdrawAmount", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
} else {
{
let mut i: Value = Value::Int(0);
let mut __for_first_293: bool = true;
while { if !__for_first_293 { i = add(&i, &Value::Int(1)); } __for_first_293 = false; is_less_than(&i, &get_array_length(&spotBalances)) } {
let mut balance: Value = get_value(&spotBalances, &i);
let mut balance: Value = get_value(&spotBalances, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "asset", &[]);
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_string_k(balance.clone(), "free", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "locked", &[]));
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 bingx#fetchPositionHistory
* @description fetches historical positions
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Position%20History
* @param {string} symbol unified contract symbol
* @param {int} [since] the earliest time in ms to fetch positions for
* @param {int} [limit] the maximum amount of records to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch positions for
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position_history(&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("pageSize".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTs".to_string()), since.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTs".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v1_private_get_trade_position_history(&[__ws_arg_20]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchPositionHistory() is not supported for inverse swap positions".to_string()))));
}
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "positionHistory": [
// {
// "positionId": "1861675561156571136",
// "symbol": "LTC-USDT",
// "isolated": false,
// "positionSide": "LONG",
// "openTime": 1732693017000,
// "updateTime": 1733310292000,
// "avgPrice": "95.18",
// "avgClosePrice": "129.48",
// "realisedProfit": "102.89",
// "netProfit": "99.63",
// "positionAmt": "30.0",
// "closePositionAmt": "30.0",
// "leverage": 6,
// "closeAllPositions": true,
// "positionCommission": "-0.33699650000000003",
// "totalFunding": "-2.921461693902908"
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut records: Value = self.safe_list_k(data.clone(), "positionHistory", &[Value::List(vec![])]);
let mut positions: Value = self.parse_positions(records.clone(), &[]);
return self.filter_by_symbol_since_limit(positions.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchPositions
* @description fetch all open positions
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Account%20Endpoints/Query%20position%20data
* @see https://bingx-api.github.io/docs/#/en-us/standard/contract-interface.html#position
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20warehouse
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.standard] whether to fetch standard contract positions
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut standard: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPositions".to_string()), Value::Str("standard".to_string()), &[Value::Bool(false)]); standard = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&standard) {
response = self.contract_v1_private_get_all_position(&[params.clone()]).await;
} else {
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
let mut firstSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
if !is_equal(&firstSymbol, &Value::Null) {
market = self.market(firstSymbol.clone());
}
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPositions".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Str("inverse".to_string())) {
response = self.cswap_v1_private_get_user_positions(&[params.clone()]).await;
} else {
response = self.swap_v2_private_get_user_positions(&[params.clone()]).await;
}
}
let mut positions: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_positions(positions.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchPosition
* @description fetch data on a single open contract trade position
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Account%20Endpoints/Query%20position%20data
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20warehouse
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchPosition() supports swap markets only".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 mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_user_positions(&[__ws_arg_21]).await;
} else {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_user_positions(&[__ws_arg_22]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_position(first.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// inverse swap
//
// {
// "symbol": "SOL-USD",
// "positionId": "1813080351385337856",
// "positionSide": "LONG",
// "isolated": false,
// "positionAmt": "1",
// "availableAmt": "1",
// "unrealizedProfit": "-0.00009074",
// "initialMargin": "0.00630398",
// "liquidationPrice": 23.968303426677032,
// "avgPrice": "158.63",
// "leverage": 10,
// "markPrice": "158.402",
// "riskRate": "0.00123783",
// "maxMarginReduction": "0",
// "updateTime": 1721107015848
// }
//
// linear swap
//
// {
// "positionId": "1792480725958881280",
// "symbol": "LTC-USDT",
// "currency": "USDT",
// "positionAmt": "0.1",
// "availableAmt": "0.1",
// "positionSide": "LONG",
// "isolated": false,
// "avgPrice": "83.53",
// "initialMargin": "1.3922",
// "margin": "0.3528",
// "leverage": 6,
// "unrealizedProfit": "-1.0393",
// "realisedProfit": "-0.2119",
// "liquidationPrice": 0,
// "pnlRatio": "-0.7465",
// "maxMarginReduction": "0.0000",
// "riskRate": "0.0008",
// "markPrice": "73.14",
// "positionValue": "7.3136",
// "onlyOnePosition": true,
// "updateTime": 1721088016688
// }
//
// standard position
//
// {
// "currentPrice": "82.91",
// "symbol": "LTC/USDT",
// "initialMargin": "5.00000000000000000000",
// "unrealizedProfit": "-0.26464500",
// "leverage": "20.000000000",
// "isolated": true,
// "entryPrice": "83.13",
// "positionSide": "LONG",
// "positionAmt": "1.20365912",
// }
//
// linear swap fetchPositionHistory
//
// {
// "positionId": "1861675561156571136",
// "symbol": "LTC-USDT",
// "isolated": false,
// "positionSide": "LONG",
// "openTime": 1732693017000,
// "updateTime": 1733310292000,
// "avgPrice": "95.18",
// "avgClosePrice": "129.48",
// "realisedProfit": "102.89",
// "netProfit": "99.63",
// "positionAmt": "30.0",
// "closePositionAmt": "30.0",
// "leverage": 6,
// "closeAllPositions": true,
// "positionCommission": "-0.33699650000000003",
// "totalFunding": "-2.921461693902908"
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "symbol", &[Value::Str("".to_string())]);
marketId = replace_str(&marketId, &Value::Str("/".to_string()), &Value::Str("-".to_string())); // standard return different format
let mut isolated: Value = self.safe_bool_k(position.clone(), "isolated", &[]);
let mut marginMode: Value = Value::Null;
if !is_equal(&isolated, &Value::Null) {
marginMode = ternary(is_true(&isolated), Value::Str("isolated".to_string()), Value::Str("cross".to_string()));
}
let mut timestamp: Value = self.safe_integer_k(position.clone(), "openTime", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_k(position.clone(), "positionId", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("-".to_string()), Value::Str("swap".to_string())]));
m.insert("notional".to_string(), self.safe_number_k(position.clone(), "positionValue", &[]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("liquidationPrice".to_string(), self.safe_number_omit_zero(position.clone(), Value::Str("liquidationPrice".to_string()), &[]));
m.insert("entryPrice".to_string(), self.safe_number2(position.clone(), Value::Str("avgPrice".to_string()), Value::Str("entryPrice".to_string()), &[]));
m.insert("unrealizedPnl".to_string(), self.safe_number_k(position.clone(), "unrealizedProfit", &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "realisedProfit", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "positionAmt", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("markPrice".to_string(), self.safe_number_k(position.clone(), "markPrice", &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("side".to_string(), self.safe_string_lower(position.clone(), Value::Str("positionSide".to_string()), &[]));
m.insert("hedged".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "updateTime", &[]));
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), self.safe_number_k(position.clone(), "initialMargin", &[]));
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.safe_number_k(position.clone(), "leverage", &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name bingx#createMarketOrderWithCost
* @description create a market order by providing the symbol, side and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} side 'buy' or 'sell'
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_market_order_with_cost(&mut self, mut symbol: Value, mut side: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
add_element_to_object(&mut params, &Value::Str("quoteOrderQty".to_string()), cost.clone());
return self.create_order(symbol.clone(), Value::Str("market".to_string()), side.clone(), cost.clone(), &[Value::Null, params.clone()]).await;
Value::Null
}
/*
* @method
* @name bingx#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_market_buy_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
add_element_to_object(&mut params, &Value::Str("quoteOrderQty".to_string()), cost.clone());
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), cost.clone(), &[Value::Null, params.clone()]).await;
Value::Null
}
/*
* @method
* @name bingx#createMarketSellOrderWithCost
* @description create a market sell order by providing the symbol and cost
* @param {string} symbol unified symbol of the market to create an order in
* @param {float} cost how much you want to trade in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_market_sell_order_with_cost(&mut self, mut symbol: Value, mut cost: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
add_element_to_object(&mut params, &Value::Str("quoteOrderQty".to_string()), cost.clone());
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("sell".to_string()), cost.clone(), &[Value::Null, params.clone()]).await;
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
/*
* @method
* @ignore
* @name bingx#createOrderRequest
* @description helper function to build request
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} request to be sent to the exchange
*/
let mut market: Value = self.market(symbol.clone());
let mut postOnly: Value = Value::Null;
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("createOrder".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
type_var = to_upper(&type_var);
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("type".to_string(), type_var.clone());
m.insert("side".to_string(), to_upper(&side));
m
});
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("MARKET".to_string())));
let mut isSpot: bool = is_equal(&marketType, &Value::Str("spot".to_string()));
let mut isTwapOrder: bool = is_equal(&type_var, &Value::Str("TWAP".to_string()));
if is_true(&isTwapOrder) && is_true(&isSpot) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" createOrder() twap order supports swap contracts only".to_string()))));
}
let mut stopLossPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), &[]);
let mut isTriggerOrder: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossPriceOrder: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isTakeProfitPriceOrder: bool = !is_equal(&takeProfitPrice, &Value::Null);
let mut exchangeClientOrderId: Value = ternary(is_true(&isSpot), Value::Str("newClientOrderId".to_string()), Value::Str("clientOrderID".to_string()));
let mut clientOrderId: Value = self.safe_string2(params.clone(), exchangeClientOrderId.clone(), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &exchangeClientOrderId, clientOrderId.clone());
}
let mut timeInForce: Value = self.safe_string_upper(params.clone(), Value::Str("timeInForce".to_string()), &[]);
{ let __destr_tmp = self.handle_post_only(isMarketOrder.clone(), Value::Bool(is_equal(&timeInForce, &Value::Str("PostOnly".to_string()))), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&postOnly, &Value::Bool(true)))) || is_true(&(is_equal(&timeInForce, &Value::Str("PostOnly".to_string())))) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("PostOnly".to_string()));
} else if is_equal(&timeInForce, &Value::Str("IOC".to_string())) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("IOC".to_string()));
} else if is_equal(&timeInForce, &Value::Str("GTC".to_string())) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("GTC".to_string()));
}
if is_true(&isSpot) {
let mut cost: Value = self.safe_string2(params.clone(), Value::Str("cost".to_string()), Value::Str("quoteOrderQty".to_string()), &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if !is_equal(&cost, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("quoteOrderQty".to_string()), self.parse_to_numeric(self.cost_to_precision(symbol.clone(), cost.clone())));
} else {
if is_true(&isMarketOrder) && is_true(&(!is_equal(&price, &Value::Null))) {
// keep the legacy behavior, to avoid breaking the old spot-market-buying code
let mut calculatedCost: Value = crate::precise::Precise::stringMul(&self.number_to_string(amount.clone()), &self.number_to_string(price.clone()));
add_element_to_object(&mut request, &Value::Str("quoteOrderQty".to_string()), self.parse_to_numeric(calculatedCost.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), self.parse_to_numeric(self.amount_to_precision(symbol.clone(), amount.clone())));
}
}
if !is_true(&isMarketOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), price.clone())));
}
if !is_equal(&triggerPrice, &Value::Null) {
if is_true(&isMarketOrder) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) && is_equal(&self.safe_string_k(request.clone(), "quoteOrderQty", &[]), &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder() requires the cost parameter (or the amount + price) for placing spot market-buy trigger orders".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
if is_equal(&type_var, &Value::Str("LIMIT".to_string())) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TRIGGER_LIMIT".to_string()));
} else if is_equal(&type_var, &Value::Str("MARKET".to_string())) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TRIGGER_MARKET".to_string()));
}
} else if is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) {
let mut stopTakePrice: Value = ternary(is_true(&(!is_equal(&stopLossPrice, &Value::Null))), stopLossPrice.clone(), takeProfitPrice.clone());
if is_equal(&type_var, &Value::Str("LIMIT".to_string())) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_STOP_LIMIT".to_string()));
} else if is_equal(&type_var, &Value::Str("MARKET".to_string())) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_STOP_MARKET".to_string()));
}
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), stopTakePrice.clone())));
}
} else {
if is_true(&isTwapOrder) {
let mut twapRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&request, &Value::Str("symbol".to_string())));
m.insert("side".to_string(), get_value(&request, &Value::Str("side".to_string())));
m.insert("positionSide".to_string(), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("LONG".to_string()), Value::Str("SHORT".to_string())));
m.insert("triggerPrice".to_string(), self.parse_to_numeric(self.price_to_precision(symbol.clone(), triggerPrice.clone())));
m.insert("totalAmount".to_string(), self.parse_to_numeric(self.amount_to_precision(symbol.clone(), amount.clone())));
m
});
return self.extend(twapRequest.clone(), &[params.clone()]);
}
if is_equal(&timeInForce, &Value::Str("FOK".to_string())) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("FOK".to_string()));
}
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut trailingPercent: Value = self.safe_string2(params.clone(), Value::Str("trailingPercent".to_string()), Value::Str("priceRate".to_string()), &[]);
let mut trailingType: Value = self.safe_string_k(params.clone(), "trailingType", &[Value::Str("TRAILING_STOP_MARKET".to_string())]);
let mut isTrailingAmountOrder: bool = !is_equal(&trailingAmount, &Value::Null);
let mut isTrailingPercentOrder: bool = !is_equal(&trailingPercent, &Value::Null);
let mut isTrailing: bool = is_true(&isTrailingAmountOrder) || is_true(&isTrailingPercentOrder);
let mut stopLossDict: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
let mut takeProfitDict: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLossDict, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfitDict, &Value::Null);
// only omit these keys if they are set ! https://github.com/ccxt/ccxt/pull/29185
if is_true(&hasStopLoss) {
params = self.omit(params.clone(), Value::Str("stopLoss".to_string()), &[]);
}
if is_true(&hasTakeProfit) {
params = self.omit(params.clone(), Value::Str("takeProfit".to_string()), &[]);
}
if is_true(&(is_true(&(is_equal(&type_var, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("TRIGGER_LIMIT".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("STOP".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("TAKE_PROFIT".to_string())))))) && !is_true(&isTrailing) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), price.clone())));
}
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]);
if is_true(&isTriggerOrder) {
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), triggerPrice.clone())));
if is_true(&isMarketOrder) || is_true(&(is_equal(&type_var, &Value::Str("TRIGGER_MARKET".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TRIGGER_MARKET".to_string()));
} else if is_true(&(is_equal(&type_var, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("TRIGGER_LIMIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TRIGGER_LIMIT".to_string()));
}
} else if is_true(&isStopLossPriceOrder) || is_true(&isTakeProfitPriceOrder) {
// This can be used to set the stop loss and take profit, but the position needs to be opened first
reduceOnly = Value::Bool(true);
if is_true(&isStopLossPriceOrder) {
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), stopLossPrice.clone())));
if is_true(&isMarketOrder) || is_true(&(is_equal(&type_var, &Value::Str("STOP_MARKET".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP_MARKET".to_string()));
} else if is_true(&(is_equal(&type_var, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("STOP".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("STOP".to_string()));
}
} else if is_true(&isTakeProfitPriceOrder) {
add_element_to_object(&mut request, &Value::Str("stopPrice".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), takeProfitPrice.clone())));
if is_true(&isMarketOrder) || is_true(&(is_equal(&type_var, &Value::Str("TAKE_PROFIT_MARKET".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT_MARKET".to_string()));
} else if is_true(&(is_equal(&type_var, &Value::Str("LIMIT".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("TAKE_PROFIT".to_string())))) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("TAKE_PROFIT".to_string()));
}
}
} else if is_true(&isTrailing) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), trailingType.clone());
if is_true(&isTrailingAmountOrder) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.parse_to_numeric(trailingAmount.clone()));
} else if is_true(&isTrailingPercentOrder) {
let mut requestTrailingPercent: Value = crate::precise::Precise::stringDiv(&trailingPercent, &Value::Str("100".to_string()));
add_element_to_object(&mut request, &Value::Str("priceRate".to_string()), self.parse_to_numeric(requestTrailingPercent.clone()));
}
}
if is_true(&hasStopLoss) || is_true(&hasTakeProfit) {
let mut stringifiedAmount: Value = self.number_to_string(amount.clone());
if is_true(&hasStopLoss) {
let mut slTriggerPrice: Value = self.safe_string2(stopLossDict.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut slWorkingType: Value = self.safe_string_k(stopLossDict.clone(), "workingType", &[Value::Str("MARK_PRICE".to_string())]);
let mut slType: Value = self.safe_string_k(stopLossDict.clone(), "type", &[Value::Str("STOP_MARKET".to_string())]);
let mut slRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), self.parse_to_numeric(self.price_to_precision(symbol.clone(), slTriggerPrice.clone())));
m.insert("workingType".to_string(), slWorkingType.clone());
m.insert("type".to_string(), slType.clone());
m
});
let mut slPrice: Value = self.safe_string_k(stopLossDict.clone(), "price", &[]);
if !is_equal(&slPrice, &Value::Null) {
add_element_to_object(&mut slRequest, &Value::Str("price".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), slPrice.clone())));
}
let mut slQuantity: Value = self.safe_string_k(stopLossDict.clone(), "quantity", &[stringifiedAmount.clone()]);
add_element_to_object(&mut slRequest, &Value::Str("quantity".to_string()), self.parse_to_numeric(self.amount_to_precision(symbol.clone(), slQuantity.clone())));
add_element_to_object(&mut request, &Value::Str("stopLoss".to_string()), self.json(slRequest.clone()));
}
if is_true(&hasTakeProfit) {
let mut tkTriggerPrice: Value = self.safe_string2(takeProfitDict.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut tkWorkingType: Value = self.safe_string_k(takeProfitDict.clone(), "workingType", &[Value::Str("MARK_PRICE".to_string())]);
let mut tpType: Value = self.safe_string_k(takeProfitDict.clone(), "type", &[Value::Str("TAKE_PROFIT_MARKET".to_string())]);
let mut tpRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("stopPrice".to_string(), self.parse_to_numeric(self.price_to_precision(symbol.clone(), tkTriggerPrice.clone())));
m.insert("workingType".to_string(), tkWorkingType.clone());
m.insert("type".to_string(), tpType.clone());
m
});
let mut slPrice: Value = self.safe_string_k(takeProfitDict.clone(), "price", &[]);
if !is_equal(&slPrice, &Value::Null) {
add_element_to_object(&mut tpRequest, &Value::Str("price".to_string()), self.parse_to_numeric(self.price_to_precision(symbol.clone(), slPrice.clone())));
}
let mut tkQuantity: Value = self.safe_string_k(takeProfitDict.clone(), "quantity", &[stringifiedAmount.clone()]);
add_element_to_object(&mut tpRequest, &Value::Str("quantity".to_string()), self.parse_to_numeric(self.amount_to_precision(symbol.clone(), tkQuantity.clone())));
add_element_to_object(&mut request, &Value::Str("takeProfit".to_string()), self.json(tpRequest.clone()));
}
}
let mut positionSide: Value = Value::Null;
let mut hedged: Value = self.safe_bool_k(params.clone(), "hedged", &[Value::Bool(false)]);
if is_equal(&hedged, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("reduceOnly".to_string()), &[]);
if is_equal(&reduceOnly, &Value::Bool(true)) {
positionSide = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("SHORT".to_string()), Value::Str("LONG".to_string()));
} else {
positionSide = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("LONG".to_string()), Value::Str("SHORT".to_string()));
}
} else {
positionSide = Value::Str("BOTH".to_string());
}
add_element_to_object(&mut request, &Value::Str("positionSide".to_string()), positionSide.clone());
let mut closePosition: Value = self.safe_bool_k(params.clone(), "closePosition", &[Value::Bool(false)]);
if !is_equal(&closePosition, &Value::Bool(true)) {
let mut amountReq: Value = amount.clone();
if !is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
amountReq = self.parse_to_numeric(self.amount_to_precision(symbol.clone(), amount.clone()));
}
add_element_to_object(&mut request, &Value::Str("quantity".to_string()), amountReq.clone()); // precision not available for inverse contracts
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("hedged".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("trailingType".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name bingx#createOrder
* @description create a trade order
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Place%20order
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Place%20order
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Place%20TWAP%20Order
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Trade%20order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much you want to trade in units of the base currency
* @param {float} [price] the price 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] a unique id for the order
* @param {bool} [params.postOnly] true to place a post only order
* @param {string} [params.timeInForce] spot supports 'PO', 'GTC' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
* @param {bool} [params.reduceOnly] *swap only* true or false whether the order is reduce only
* @param {float} [params.triggerPrice] triggerPrice at which the attached take profit / stop loss order will be triggered
* @param {float} [params.stopLossPrice] stop loss trigger price
* @param {float} [params.takeProfitPrice] take profit trigger price
* @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
* @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
* @param {float} [params.trailingPercent] *swap only* the percent to trail away from the current market price
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {boolean} [params.test] *swap only* whether to use the test endpoint or not, default is false
* @param {string} [params.positionSide] *contracts only* "BOTH" for one way mode, "LONG" for buy side of hedged mode, "SHORT" for sell side of hedged mode
* @param {boolean} [params.hedged] *swap only* whether the order is in hedged mode or one way mode
* @param {bool} [params.closePosition] *swap only* true to close the entire position with a TP/SL order, in which case the quantity is not sent
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut test: Value = self.safe_bool_k(params.clone(), "test", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("test".to_string()), &[]);
let mut request: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_equal(&test, &Value::Bool(true)) {
response = self.swap_v2_private_post_trade_order_test(&[request.clone()]).await;
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
response = self.cswap_v1_private_post_trade_order(&[request.clone()]).await;
} else if is_equal(&type_var, &Value::Str("twap".to_string())) {
response = self.swap_v1_private_post_twap_order(&[request.clone()]).await;
} else {
response = self.swap_v2_private_post_trade_order(&[request.clone()]).await;
}
} else {
response = self.spot_v1_private_post_trade_order(&[request.clone()]).await;
}
//
// spot
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "symbol": "XRP-USDT",
// "orderId": 1514090846268424192,
// "transactTime": 1649822362855,
// "price": "0.5",
// "origQty": "10",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "PENDING",
// "type": "LIMIT",
// "side": "BUY"
// }
// }
//
// linear swap
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "order": {
// "symbol": "BTC-USDT",
// "orderId": 1709036527545438208,
// "side": "BUY",
// "positionSide": "LONG",
// "type": "TRIGGER_LIMIT",
// "clientOrderID": "",
// "workingType": ""
// }
// }
// }
//
// inverse swap
//
// {
// "orderId": 1809841379603398656,
// "symbol": "SOL-USD",
// "positionSide": "LONG",
// "side": "BUY",
// "type": "LIMIT",
// "price": 100,
// "quantity": 1,
// "stopPrice": 0,
// "workingType": "",
// "timeInForce": ""
// }
//
// twap order
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1732693774386,
// "data": {
// "mainOrderId": "4633860139993029715"
// }
// }
//
if is_string(&response) {
// broken api engine : order-ids are too long numbers (i.e. 1742930526912864656)
// and JSON.parse can not handle them in JS, so we have to use .parseJson
// however, when order has an attached SL/TP, their value types need extra parsing
response = self.fix_stringified_json_members(response.clone());
let mut parsedResponse: Value = self.parse_json_value(response.clone());
response = parsedResponse.clone();
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
result = response.clone();
} else {
result = self.safe_dict_k(data.clone(), "order", &[data.clone()]);
}
} else {
result = data.clone();
}
// when the response arrives as an already-parsed dict, the attached SL/TP members are still stringified json
let mut stopLossDict: Value = self.safe_dict_k(result.clone(), "stopLoss", &[]);
let mut stopLoss: Value = self.safe_string_k(result.clone(), "stopLoss", &[]);
// for py fix, the SL is already parsed as object (instead of stringified, as it's provided)
// so we need trick to check if it's non-parsed string yet
if is_true(&(is_equal(&stopLossDict, &Value::Null))) && is_true(&(!is_equal(&stopLoss, &Value::Null))) && is_true(&(is_equal(&get_index_of(&stopLoss, &Value::Str("{".to_string())), &Value::Int(0)))) {
add_element_to_object(&mut result, &Value::Str("stopLoss".to_string()), self.parse_json_value(stopLoss.clone()));
}
let mut takeProfit: Value = self.safe_string_k(result.clone(), "takeProfit", &[]);
if is_true(&(!is_equal(&takeProfit, &Value::Null))) && is_true(&(is_equal(&get_index_of(&takeProfit, &Value::Str("{".to_string())), &Value::Int(0)))) {
add_element_to_object(&mut result, &Value::Str("takeProfit".to_string()), self.parse_json_value(takeProfit.clone()));
}
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#createOrders
* @description create a list of trade orders
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Place%20multiple%20orders
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Place%20multiple%20orders
* @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params, linear swap and spot only
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.sync] *spot only* if true, multiple orders are ordered serially and all orders do not require the same symbol/side/type
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_orders(&mut self, mut orders: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut marketIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_294: bool = true;
while { if !__for_first_294 { i = add(&i, &Value::Int(1)); } __for_first_294 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut rawOrder: Value = get_value(&orders, &i);
let mut rawOrder: Value = get_value(&orders, &i);
let mut marketId: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[Value::Str("".to_string())]);
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
append_to_array(&mut marketIds, marketId.clone());
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_number_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_number_k(rawOrder.clone(), "price", &[]);
let mut orderParams: Value = self.safe_dict_k(rawOrder.clone(), "params", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderRequest: Value = self.create_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), orderParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut symbols: Value = self.market_symbols(&[marketIds.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut symbolsLength: Value = get_array_length(&symbols);
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders() is not supported for inverse swap markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
if is_greater_than(&symbolsLength, &Value::Int(5)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrders() can not create more than 5 orders at once for swap markets".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("batchOrders".to_string()), self.json(ordersRequests.clone()));
response = self.swap_v2_private_post_trade_batch_orders(&[request.clone()]).await;
} else {
let mut sync: Value = self.safe_bool_k(params.clone(), "sync", &[Value::Bool(false)]);
if is_equal(&sync, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("sync".to_string()), Value::Bool(true));
}
add_element_to_object(&mut request, &Value::Str("data".to_string()), self.json(ordersRequests.clone()));
response = self.spot_v1_private_post_trade_batch_orders(&[request.clone()]).await;
}
//
// spot
//
// {
// "code": 0,
// "msg": "",
// "debugMsg": "",
// "data": {
// "orders": [
// {
// "symbol": "BTC-USDT",
// "orderId": 1720661389564968960,
// "transactTime": 1699072618272,
// "price": "25000",
// "origQty": "0.0002",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "PENDING",
// "type": "LIMIT",
// "side": "BUY"
// },
// ]
// }
// }
//
// swap
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "orders": [
// {
// "symbol": "BTC-USDT",
// "orderId": 1720657081994006528,
// "side": "BUY",
// "positionSide": "LONG",
// "type": "LIMIT",
// "clientOrderID": "",
// "workingType": ""
// },
// ]
// }
// }
//
if is_string(&response) {
// broken api engine : order-ids are too long numbers (i.e. 1742930526912864656)
// and JSON.parse can not handle them in JS, so we have to use .parseJson
// however, when order has an attached SL/TP, their value types need extra parsing
response = self.fix_stringified_json_members(response.clone());
let mut parsedResponse: Value = self.parse_json_value(response.clone());
response = parsedResponse.clone();
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut result: Value = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
return self.parse_orders(result.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_order_side(&self, mut side: Value) -> Value {
let mut sides: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BUY".to_string(), Value::Str("buy".to_string()));
m.insert("SELL".to_string(), Value::Str("sell".to_string()));
m.insert("SHORT".to_string(), Value::Str("sell".to_string()));
m.insert("LONG".to_string(), Value::Str("buy".to_string()));
m.insert("ask".to_string(), Value::Str("sell".to_string()));
m.insert("bid".to_string(), Value::Str("buy".to_string()));
m
});
return self.safe_string(sides.clone(), side.clone(), &[side.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("trigger_market".to_string(), Value::Str("market".to_string()));
m.insert("trigger_limit".to_string(), Value::Str("limit".to_string()));
m.insert("stop_limit".to_string(), Value::Str("limit".to_string()));
m.insert("stop_market".to_string(), Value::Str("market".to_string()));
m.insert("take_profit_market".to_string(), Value::Str("market".to_string()));
m.insert("stop".to_string(), Value::Str("limit".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.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);
//
// spot
// createOrder, createOrders, cancelOrder
//
// {
// "symbol": "XRP-USDT",
// "orderId": 1514090846268424192,
// "transactTime": 1649822362855,
// "price": "0.5",
// "origQty": "10",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "PENDING",
// "type": "LIMIT",
// "side": "BUY"
// }
//
// fetchOrder
//
// {
// "symbol": "ETH-USDT",
// "orderId": "1660602123001266176",
// "price": "1700",
// "origQty": "0.003",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "PENDING",
// "type": "LIMIT",
// "side": "BUY",
// "time": "1684753373276",
// "updateTime": "1684753373276",
// "origQuoteOrderQty": "0",
// "fee": "0",
// "feeAsset": "ETH"
// }
//
// fetchOpenOrders, fetchClosedOrders
//
// {
// "symbol": "XRP-USDT",
// "orderId": 1514073325788200960,
// "price": "0.5",
// "StopPrice": "0",
// "origQty": "20",
// "executedQty": "10",
// "cummulativeQuoteQty": "5",
// "status": "PENDING",
// "type": "LIMIT",
// "side": "BUY",
// "time": 1649818185647,
// "updateTime": 1649818185647,
// "origQuoteOrderQty": "0"
// "fee": "-0.01"
// }
//
//
// linear swap
// createOrder, createOrders
//
// {
// "symbol": "BTC-USDT",
// "orderId": 1590973236294713344,
// "side": "BUY",
// "positionSide": "LONG",
// "type": "LIMIT"
// }
//
// inverse swap createOrder
//
// {
// "orderId": 1809841379603398656,
// "symbol": "SOL-USD",
// "positionSide": "LONG",
// "side": "BUY",
// "type": "LIMIT",
// "price": 100,
// "quantity": 1,
// "stopPrice": 0,
// "workingType": "",
// "timeInForce": ""
// }
//
// fetchOrder, fetchOpenOrders, fetchClosedOrders
//
// {
// "symbol": "BTC-USDT",
// "orderId": 1709036527545438208,
// "side": "BUY",
// "positionSide": "LONG",
// "type": "TRIGGER_LIMIT",
// "origQty": "0.0010",
// "price": "22000.0",
// "executedQty": "0.0000",
// "avgPrice": "0.0",
// "cumQuote": "",
// "stopPrice": "23000.0",
// "profit": "",
// "commission": "",
// "status": "NEW",
// "time": 1696301035187,
// "updateTime": 1696301035187,
// "clientOrderId": "",
// "leverage": "",
// "takeProfit": "",
// "stopLoss": "",
// "advanceAttr": 0,
// "positionID": 0,
// "takeProfitEntrustPrice": 0,
// "stopLossEntrustPrice": 0,
// "orderType": "",
// "workingType": "MARK_PRICE"
// }
// with tp and sl
// {
// orderId: 1741440894764281900,
// symbol: 'LTC-USDT',
// positionSide: 'LONG',
// side: 'BUY',
// type: 'MARKET',
// price: 0,
// quantity: 1,
// stopPrice: 0,
// workingType: 'MARK_PRICE',
// clientOrderID: '',
// timeInForce: 'GTC',
// priceRate: 0,
// stopLoss: '{"stopPrice":50,"workingType":"MARK_PRICE","type":"STOP_MARKET","quantity":1}',
// takeProfit: '{"stopPrice":150,"workingType":"MARK_PRICE","type":"TAKE_PROFIT_MARKET","quantity":1}',
// reduceOnly: false
// }
//
// editOrder (swap)
//
// {
// cancelResult: 'true',
// cancelMsg: '',
// cancelResponse: {
// cancelClientOrderId: '',
// cancelOrderId: '1755336244265705472',
// symbol: 'SOL-USDT',
// orderId: '1755336244265705472',
// side: 'SELL',
// positionSide: 'SHORT',
// type: 'LIMIT',
// origQty: '1',
// price: '100.000',
// executedQty: '0',
// avgPrice: '0.000',
// cumQuote: '0',
// stopPrice: '',
// profit: '0.0000',
// commission: '0.000000',
// status: 'PENDING',
// time: '1707339747860',
// updateTime: '1707339747860',
// clientOrderId: '',
// leverage: '20X',
// workingType: 'MARK_PRICE',
// onlyOnePosition: false,
// reduceOnly: false
// },
// replaceResult: 'true',
// replaceMsg: '',
// newOrderResponse: {
// orderId: '1755338440612995072',
// symbol: 'SOL-USDT',
// positionSide: 'SHORT',
// side: 'SELL',
// type: 'LIMIT',
// price: '99',
// quantity: '2',
// stopPrice: '0',
// workingType: 'MARK_PRICE',
// clientOrderID: '',
// timeInForce: 'GTC',
// priceRate: '0',
// stopLoss: '',
// takeProfit: '',
// reduceOnly: false
// }
// }
//
// editOrder (spot)
//
// {
// cancelResult: { code: '0', msg: '', result: true },
// openResult: { code: '0', msg: '', result: true },
// orderOpenResponse: {
// symbol: 'SOL-USDT',
// orderId: '1755334007697866752',
// transactTime: '1707339214620',
// price: '99',
// stopPrice: '0',
// origQty: '0.2',
// executedQty: '0',
// cummulativeQuoteQty: '0',
// status: 'PENDING',
// type: 'LIMIT',
// side: 'SELL',
// clientOrderID: ''
// },
// orderCancelResponse: {
// symbol: 'SOL-USDT',
// orderId: '1755117055251480576',
// price: '100',
// stopPrice: '0',
// origQty: '0.2',
// executedQty: '0',
// cummulativeQuoteQty: '0',
// status: 'CANCELED',
// type: 'LIMIT',
// side: 'SELL'
// }
// }
//
// stop loss order
//
// {
// "symbol": "ETH-USDT",
// "orderId": "1792461744476422144",
// "price": "2775.65",
// "StopPrice": "2778.42",
// "origQty": "0.032359",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "NEW",
// "type": "TAKE_STOP_LIMIT",
// "side": "SELL",
// "time": "1716191156868",
// "updateTime": "1716191156868",
// "origQuoteOrderQty": "0",
// "fee": "0",
// "feeAsset": "USDT",
// "clientOrderID": ""
// }
//
// inverse swap cancelAllOrders, cancelOrder, fetchOrder, fetchOpenOrders, fetchClosedOrders, fetchCanceledOrders
//
// {
// "symbol": "SOL-USD",
// "orderId": "1809845251327672320",
// "side": "BUY",
// "positionSide": "LONG",
// "type": "LIMIT",
// "quantity": 1,
// "origQty": "0",
// "price": "90",
// "executedQty": "0",
// "avgPrice": "0",
// "cumQuote": "0",
// "stopPrice": "",
// "profit": "0.0000",
// "commission": "0.000000",
// "status": "CANCELLED",
// "time": 1720335707872,
// "updateTime": 1720335707912,
// "clientOrderId": "",
// "leverage": "",
// "takeProfit": {
// "type": "",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": "",
// "stopGuaranteed": ""
// },
// "stopLoss": {
// "type": "",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": "",
// "stopGuaranteed": ""
// },
// "advanceAttr": 0,
// "positionID": 0,
// "takeProfitEntrustPrice": 0,
// "stopLossEntrustPrice": 0,
// "orderType": "",
// "workingType": ""
// }
//
let mut info: Value = order.clone();
let mut newOrder: Value = self.safe_dict2(order.clone(), Value::Str("newOrderResponse".to_string()), Value::Str("orderOpenResponse".to_string()), &[]);
if !is_equal(&newOrder, &Value::Null) {
order = newOrder.clone();
}
let mut positionSide: Value = self.safe_string2(order.clone(), Value::Str("positionSide".to_string()), Value::Str("ps".to_string()), &[]);
let mut marketType: Value = ternary(is_true(&(is_equal(&positionSide, &Value::Null))), Value::Str("spot".to_string()), Value::Str("swap".to_string()));
let mut marketId: Value = self.safe_string2(order.clone(), Value::Str("symbol".to_string()), Value::Str("s".to_string()), &[]);
if is_equal(&market, &Value::Null) {
market = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, marketType.clone()]);
}
let mut side: Value = self.safe_string_lower2(order.clone(), Value::Str("side".to_string()), Value::Str("S".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_n(order.clone(), Value::List(vec![Value::Str("time".to_string()), Value::Str("transactTime".to_string()), Value::Str("E".to_string()), Value::Str("createdTime".to_string())]), &[]);
let mut lastTradeTimestamp: Value = self.safe_integer2(order.clone(), Value::Str("updateTime".to_string()), Value::Str("T".to_string()), &[]);
let mut statusId: Value = self.safe_string_upper_n(order.clone(), Value::List(vec![Value::Str("status".to_string()), Value::Str("X".to_string()), Value::Str("orderStatus".to_string())]), &[]);
let mut feeCurrencyCode: Value = self.safe_string2(order.clone(), Value::Str("feeAsset".to_string()), Value::Str("N".to_string()), &[]);
let mut feeCost: Value = self.safe_string_n(order.clone(), Value::List(vec![Value::Str("fee".to_string()), Value::Str("commission".to_string()), Value::Str("n".to_string())]), &[]);
if is_true(&(is_equal(&feeCurrencyCode, &Value::Null))) {
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if is_equal(&side, &Value::Str("buy".to_string())) {
feeCurrencyCode = get_value(&market, &Value::Str("base".to_string()));
} else {
feeCurrencyCode = get_value(&market, &Value::Str("quote".to_string()));
}
} else {
feeCurrencyCode = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))), get_value(&market, &Value::Str("settle".to_string())), get_value(&market, &Value::Str("quote".to_string())));
}
}
let mut stopLoss: Value = self.safe_value_k(order.clone(), "stopLoss", &[]);
let mut stopLossPrice: Value = Value::Null;
if is_true(&(!is_equal(&stopLoss, &Value::Null))) && is_true(&(!is_equal(&stopLoss, &Value::Str("".to_string())))) {
stopLossPrice = self.omit_zero(self.safe_string_k(stopLoss.clone(), "stopLoss", &[]));
}
if is_true(&(!is_equal(&stopLoss, &Value::Null))) && is_true(&(!is_number(&stopLoss))) && is_true(&(!is_equal(&stopLoss, &Value::Str("".to_string())))) {
// stopLoss: '{"stopPrice":50,"workingType":"MARK_PRICE","type":"STOP_MARKET","quantity":1}',
if is_string(&stopLoss) {
stopLoss = self.parse_json_value(stopLoss.clone());
}
stopLossPrice = self.omit_zero(self.safe_string_k(stopLoss.clone(), "stopPrice", &[]));
}
let mut takeProfit: Value = self.safe_value_k(order.clone(), "takeProfit", &[]);
let mut takeProfitPrice: Value = Value::Null;
if !is_equal(&takeProfit, &Value::Null) && is_true(&(!is_equal(&takeProfit, &Value::Str("".to_string())))) {
takeProfitPrice = self.omit_zero(self.safe_string_k(takeProfit.clone(), "takeProfit", &[]));
}
if is_true(&(!is_equal(&takeProfit, &Value::Null))) && is_true(&(!is_number(&takeProfit))) && is_true(&(!is_equal(&takeProfit, &Value::Str("".to_string())))) {
// takeProfit: '{"stopPrice":150,"workingType":"MARK_PRICE","type":"TAKE_PROFIT_MARKET","quantity":1}',
if is_string(&takeProfit) {
takeProfit = self.parse_json_value(takeProfit.clone());
}
takeProfitPrice = self.omit_zero(self.safe_string_k(takeProfit.clone(), "stopPrice", &[]));
}
let mut rawType: Value = self.safe_string_lower2(order.clone(), Value::Str("type".to_string()), Value::Str("o".to_string()), &[]);
let mut stopPrice: Value = self.omit_zero(self.safe_string2(order.clone(), Value::Str("StopPrice".to_string()), Value::Str("stopPrice".to_string()), &[]));
let mut triggerPrice: Value = stopPrice.clone();
if !is_equal(&stopPrice, &Value::Null) {
if is_true(&(is_greater_than(&get_index_of(&rawType, &Value::Str("stop".to_string())), &negate(&Value::Int(1))))) && is_true(&(is_equal(&stopLossPrice, &Value::Null))) {
stopLossPrice = stopPrice.clone();
triggerPrice = Value::Null;
}
if is_true(&(is_greater_than(&get_index_of(&rawType, &Value::Str("take".to_string())), &negate(&Value::Int(1))))) && is_true(&(is_equal(&takeProfitPrice, &Value::Null))) {
takeProfitPrice = stopPrice.clone();
triggerPrice = Value::Null;
}
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("id".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("orderId".to_string()), Value::Str("i".to_string()), Value::Str("mainOrderId".to_string())]), &[]));
m.insert("clientOrderId".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("clientOrderID".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("origClientOrderId".to_string()), Value::Str("c".to_string())]), &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("-".to_string()), marketType.clone()]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), lastTradeTimestamp.clone());
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(order.clone(), "updateTime", &[]));
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("side".to_string(), self.parse_order_side(side.clone()));
m.insert("price".to_string(), self.safe_string2(order.clone(), Value::Str("price".to_string()), Value::Str("p".to_string()), &[]));
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("stopLossPrice".to_string(), stopLossPrice.clone());
m.insert("takeProfitPrice".to_string(), takeProfitPrice.clone());
m.insert("average".to_string(), self.safe_string2(order.clone(), Value::Str("avgPrice".to_string()), Value::Str("ap".to_string()), &[]));
m.insert("cost".to_string(), self.safe_string_k(order.clone(), "cummulativeQuoteQty", &[]));
m.insert("amount".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("origQty".to_string()), Value::Str("q".to_string()), Value::Str("quantity".to_string()), Value::Str("totalAmount".to_string())]), &[]));
m.insert("filled".to_string(), self.safe_string2(order.clone(), Value::Str("executedQty".to_string()), Value::Str("z".to_string()), &[]));
m.insert("remaining".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_order_status(statusId.clone()));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), feeCurrencyCode.clone());
m.insert("cost".to_string(), crate::precise::Precise::stringAbs(&feeCost));
m
}));
m.insert("trades".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), self.safe_bool2(order.clone(), Value::Str("reduceOnly".to_string()), Value::Str("ro".to_string()), &[]));
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("PENDING".to_string(), Value::Str("open".to_string()));
m.insert("PARTIALLY_FILLED".to_string(), Value::Str("open".to_string()));
m.insert("RUNNING".to_string(), Value::Str("open".to_string()));
m.insert("FILLED".to_string(), Value::Str("closed".to_string()));
m.insert("CANCELED".to_string(), Value::Str("canceled".to_string()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".to_string()));
m.insert("FAILED".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name bingx#cancelOrder
* @description cancels an open order
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Cancel%20Order
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Cancel%20Order
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Cancel%20TWAP%20Order
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Cancel%20an%20Order
* @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.clientOrderId] 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 isTwapOrder: Value = self.safe_bool_k(params.clone(), "twap", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("twap".to_string()), &[]);
let mut response: Value = Value::Null;
let mut market: Value = Value::Null;
if is_equal(&isTwapOrder, &Value::Bool(true)) {
let mut twapRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mainOrderId".to_string(), id.clone());
m
});
let __ws_arg_23 = self.extend(twapRequest.clone(), &[params.clone()]);
response = self.swap_v1_private_post_twap_cancel_order(&[__ws_arg_23]).await;
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
market = 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 clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("clientOrderID".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string())]), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clientOrderID".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut type_var: Value = Value::Null;
let mut subType: 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 __destr_tmp = self.handle_sub_type_and_params(Value::Str("cancelOrder".to_string()), &[market.clone(), params.clone()]); subType = 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())) {
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_post_trade_cancel(&[__ws_arg_24]).await;
} else {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_delete_trade_cancel_order(&[__ws_arg_25]).await;
} else {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_delete_trade_order(&[__ws_arg_26]).await;
}
}
}
//
// spot
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "symbol": "XRP-USDT",
// "orderId": 1514090846268424192,
// "price": "0.5",
// "origQty": "10",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "CANCELED",
// "type": "LIMIT",
// "side": "BUY"
// }
// }
//
// inverse swap
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "order": {
// "symbol": "SOL-USD",
// "orderId": "1816002957423951872",
// "side": "BUY",
// "positionSide": "Long",
// "type": "Pending",
// "quantity": 0,
// "origQty": "0",
// "price": "150",
// "executedQty": "0",
// "avgPrice": "0",
// "cumQuote": "0",
// "stopPrice": "",
// "profit": "0.0000",
// "commission": "0.000000",
// "status": "CANCELLED",
// "time": 1721803819410,
// "updateTime": 1721803819427,
// "clientOrderId": "",
// "leverage": "",
// "takeProfit": {
// "type": "",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": "",
// "stopGuaranteed": ""
// },
// "stopLoss": {
// "type": "",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": "",
// "stopGuaranteed": ""
// },
// "advanceAttr": 0,
// "positionID": 0,
// "takeProfitEntrustPrice": 0,
// "stopLossEntrustPrice": 0,
// "orderType": "",
// "workingType": ""
// }
// }
// }
//
// linear swap
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "order": {
// "symbol": "LINK-USDT",
// "orderId": 1597783850786750464,
// "side": "BUY",
// "positionSide": "LONG",
// "type": "TRIGGER_MARKET",
// "origQty": "5.0",
// "price": "5.0000",
// "executedQty": "0.0",
// "avgPrice": "0.0000",
// "cumQuote": "0",
// "stopPrice": "5.0000",
// "profit": "",
// "commission": "",
// "status": "CANCELLED",
// "time": 1669776330000,
// "updateTime": 1669776330000
// }
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.safe_dict_k(data.clone(), "order", &[data.clone()]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#cancelAllOrders
* @description cancel all open orders
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Cancel%20all%20Open%20Orders%20on%20a%20Symbol
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Cancel%20All%20Open%20Orders
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Cancel%20all%20orders
* @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' (default is 'spot' if symbol is not provided)
* @param {string} [params.subType] 'linear' or 'inverse' for swap markets (default is 'linear' if symbol is not provided)
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut marketType: Value = Value::Str("spot".to_string());
let mut subType: 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 __destr_tmp = self.handle_sub_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone()]); subType = 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())) {
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_post_trade_cancel_open_orders(&[__ws_arg_27]).await;
} else if is_equal(&marketType, &Value::Str("swap".to_string())) {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_delete_trade_all_open_orders(&[__ws_arg_28]).await;
} else {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_delete_trade_all_open_orders(&[__ws_arg_29]).await;
}
} else {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" cancelAllOrders is only supported for spot and swap markets.".to_string()))));
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list2(data.clone(), Value::Str("success".to_string()), Value::Str("orders".to_string()), &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[]);
Value::Null
}
/*
* @method
* @name bingx#cancelOrders
* @description cancel multiple orders
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Cancel%20multiple%20orders
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Cancel%20multiple%20orders
* @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
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() 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 clientOrderIds: Value = self.safe_value_k(params.clone(), "clientOrderIds", &[]);
params = self.omit(params.clone(), Value::Str("clientOrderIds".to_string()), &[]);
let mut idsToParse: Value = ids.clone();
let mut areClientOrderIds: bool = !is_equal(&clientOrderIds, &Value::Null);
if is_true(&areClientOrderIds) {
idsToParse = clientOrderIds.clone();
}
let mut parsedIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_295: bool = true;
while { if !__for_first_295 { i = add(&i, &Value::Int(1)); } __for_first_295 = false; is_less_than(&i, &get_array_length(&idsToParse)) } {
let mut id: Value = get_value(&idsToParse, &i);
let mut id: Value = get_value(&idsToParse, &i);
let mut stringId: Value = to_string_val(&id);
append_to_array(&mut parsedIds, stringId.clone());
}
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let mut spotReqKey: Value = ternary(is_true(&areClientOrderIds), Value::Str("clientOrderIDs".to_string()), Value::Str("orderIds".to_string()));
add_element_to_object(&mut request, &spotReqKey, join(&parsedIds, &Value::Str(",".to_string())));
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_post_trade_cancel_orders(&[__ws_arg_30]).await;
} else {
if is_true(&areClientOrderIds) {
add_element_to_object(&mut request, &Value::Str("clientOrderIDList".to_string()), self.json(parsedIds.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("orderIdList".to_string()), parsedIds.clone());
}
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_delete_trade_batch_orders(&[__ws_arg_31]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut success: Value = self.safe_list2(data.clone(), Value::Str("success".to_string()), Value::Str("orders".to_string()), &[Value::List(vec![])]);
return self.parse_orders(success.clone(), &[]);
Value::Null
}
/*
* @method
* @name bingx#cancelAllOrdersAfter
* @description dead man's switch, cancel all orders after the given timeout
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Cancel%20All%20After
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Cancel%20All%20After
* @param {number} timeout time in milliseconds, 0 represents cancel the timer
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] spot or swap market
* @param {string} [params.subType] 'linear' or 'inverse' (default is 'linear'), 'inverse' is not supported
* @returns {object} the api result
*/
pub async fn cancel_all_orders_after(&mut self, mut timeout: 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 isActive: Value = Value::Bool(is_greater_than(&timeout, &Value::Int(0)));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), ternary(is_true(&(isActive)), Value::Str("ACTIVATE".to_string()), Value::Str("CLOSE".to_string())));
m.insert("timeOut".to_string(), ternary(is_true(&(isActive)), (self.parse_to_int(divide(&timeout, &Value::Int(1000)))), Value::Int(0)));
m
});
let mut response: Value = Value::Null;
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrdersAfter".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 subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("cancelAllOrdersAfter".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) && is_true(&(is_equal(&subType, &Value::Str("inverse".to_string())))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelAllOrdersAfter() is not supported for inverse swap markets".to_string()))));
}
if is_equal(&type_var, &Value::Str("spot".to_string())) {
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_post_trade_cancel_all_after(&[__ws_arg_32]).await;
} else if is_equal(&type_var, &Value::Str("swap".to_string())) {
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_post_trade_cancel_all_after(&[__ws_arg_33]).await;
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" cancelAllOrdersAfter() is not supported for ".to_string())), &type_var), &Value::Str(" markets".to_string()))));
}
return response;
Value::Null
}
/*
* @method
* @name bingx#fetchOrder
* @description fetches information on an order made by the user
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Query%20Order%20details
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Order%20details
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/TWAP%20Order%20Details
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20Order
* @param {string} id the order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.twap] if fetching twap order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut isTwapOrder: Value = self.safe_bool_k(params.clone(), "twap", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("twap".to_string()), &[]);
let mut response: Value = Value::Null;
let mut market: Value = Value::Null;
if is_equal(&isTwapOrder, &Value::Bool(true)) {
let mut twapRequest: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mainOrderId".to_string(), id.clone());
m
});
let __ws_arg_34 = self.extend(twapRequest.clone(), &[params.clone()]);
response = self.swap_v1_private_get_twap_order_detail(&[__ws_arg_34]).await;
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol argument".to_string()))));
}
market = 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("orderId".to_string(), id.clone());
m
});
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone()]); subType = 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())) {
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_get_trade_query(&[__ws_arg_35]).await;
} else {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_trade_order_detail(&[__ws_arg_36]).await;
} else {
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_trade_order(&[__ws_arg_37]).await;
}
}
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.safe_dict_k(data.clone(), "order", &[data.clone()]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/All%20Orders
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Order%20history (returns less fields than above)
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {int} [params.orderId] Only return subsequent orders, and return the latest order by default
* @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(&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 type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrders".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("swap".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrders() is only supported for swap markets".to_string()))));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.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_38 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_v1_private_get_trade_full_order(&[__ws_arg_38]).await;
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "orders": [
// {
// "symbol": "PYTH-USDT",
// "orderId": 1736007506620112100,
// "side": "SELL",
// "positionSide": "SHORT",
// "type": "LIMIT",
// "origQty": "33",
// "price": "0.3916",
// "executedQty": "33",
// "avgPrice": "0.3916",
// "cumQuote": "13",
// "stopPrice": "",
// "profit": "0.0000",
// "commission": "-0.002585",
// "status": "FILLED",
// "time": 1702731418000,
// "updateTime": 1702731470000,
// "clientOrderId": "",
// "leverage": "15X",
// "takeProfit": {
// "type": "TAKE_PROFIT",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": ""
// },
// "stopLoss": {
// "type": "STOP",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": ""
// },
// "advanceAttr": 0,
// "positionID": 0,
// "takeProfitEntrustPrice": 0,
// "stopLossEntrustPrice": 0,
// "orderType": "",
// "workingType": "MARK_PRICE",
// "stopGuaranteed": false,
// "triggerOrderId": 1736012449498123500
// }
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Current%20Open%20Orders
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Current%20All%20Open%20Orders
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20all%20current%20pending%20orders
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20TWAP%20Entrusted%20Order
* @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 order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.twap] if fetching twap open orders
* @returns {object[]} 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;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone()]); subType = 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())) {
let __ws_arg_39 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_get_trade_open_orders(&[__ws_arg_39]).await;
} else {
let mut isTwapOrder: Value = self.safe_bool_k(params.clone(), "twap", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("twap".to_string()), &[]);
if is_equal(&isTwapOrder, &Value::Bool(true)) {
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v1_private_get_twap_open_orders(&[__ws_arg_40]).await;
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_41 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_trade_open_orders(&[__ws_arg_41]).await;
} else {
let __ws_arg_42 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_trade_open_orders(&[__ws_arg_42]).await;
}
}
//
// spot
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "orders": [
// {
// "symbol": "XRP-USDT",
// "orderId": 1514073325788200960,
// "price": "0.5",
// "origQty": "20",
// "executedQty": "0",
// "cummulativeQuoteQty": "0",
// "status": "PENDING",
// "type": "LIMIT",
// "side": "BUY",
// "time": 1649818185647,
// "updateTime": 1649818185647,
// "origQuoteOrderQty": "0"
// }
// ]
// }
// }
//
// inverse swap
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "orders": [
// {
// "symbol": "SOL-USD",
// "orderId": "1816013900044320768",
// "side": "BUY",
// "positionSide": "Long",
// "type": "LIMIT",
// "quantity": 1,
// "origQty": "",
// "price": "150",
// "executedQty": "0",
// "avgPrice": "0.000",
// "cumQuote": "",
// "stopPrice": "",
// "profit": "0.0000",
// "commission": "0.0000",
// "status": "Pending",
// "time": 1721806428334,
// "updateTime": 1721806428352,
// "clientOrderId": "",
// "leverage": "",
// "takeProfit": {
// "type": "TAKE_PROFIT",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": "MARK_PRICE",
// "stopGuaranteed": ""
// },
// "stopLoss": {
// "type": "STOP",
// "quantity": 0,
// "stopPrice": 0,
// "price": 0,
// "workingType": "MARK_PRICE",
// "stopGuaranteed": ""
// },
// "advanceAttr": 0,
// "positionID": 0,
// "takeProfitEntrustPrice": 0,
// "stopLossEntrustPrice": 0,
// "orderType": "",
// "workingType": "MARK_PRICE"
// }
// ]
// }
// }
//
// linear swap
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "orders": [
// {
// "symbol": "LINK-USDT",
// "orderId": 1585839271162413056,
// "side": "BUY",
// "positionSide": "LONG",
// "type": "TRIGGER_MARKET",
// "origQty": "5.0",
// "price": "9",
// "executedQty": "0.0",
// "avgPrice": "0",
// "cumQuote": "0",
// "stopPrice": "5",
// "profit": "0.0000",
// "commission": "0.000000",
// "status": "CANCELLED",
// "time": 1667631605000,
// "updateTime": 1667631605000
// },
// ]
// }
// }
//
// twap
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1702731661854,
// "data": {
// "list": [
// {
// "symbol": "BNB-USDT",
// "side": "BUY",
// "positionSide": "LONG",
// "priceType": "constant",
// "priceVariance": "2000",
// "triggerPrice": "68000",
// "interval": 8,
// "amountPerOrder": "0.111",
// "totalAmount": "0.511",
// "orderStatus": "Running",
// "executedQty": "0.1",
// "duration": 800,
// "maxDuration": 9000,
// "createdTime": 1702731661854,
// "updateTime": 1702731661854
// }
// ],
// "total": 1
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list2(data.clone(), Value::Str("orders".to_string()), Value::Str("list".to_string()), &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Query%20Order%20history
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Order%20history
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/User's%20History%20Orders
* @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
* @param {string} symbol unified market symbol of the closed orders
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the max number of closed orders to return
* @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 {boolean} [params.standard] whether to fetch standard contract orders
* @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 orders: Value = 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 bingx#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Query%20Order%20history
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Order%20history
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/User's%20History%20Orders
* @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
* @param {string} symbol unified market symbol of the canceled orders
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the max number of canceled orders to return
* @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 {boolean} [params.standard] whether to fetch standard contract orders
* @returns {object} 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 orders: Value = 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 bingx#fetchCanceledAndClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Query%20Order%20history
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Order%20history
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/User's%20History%20Orders
* @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20TWAP%20Historical%20Orders
* @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 {boolean} [params.standard] whether to fetch standard contract orders
* @param {boolean} [params.twap] if fetching twap orders
* @returns {object[]} 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;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut type_var: Value = Value::Null;
let mut subType: Value = Value::Null;
let mut standard: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchCanceledAndClosedOrders".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchCanceledAndClosedOrders".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchCanceledAndClosedOrders".to_string()), Value::Str("standard".to_string()), &[Value::Bool(false)]); standard = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&standard) {
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
response = self.contract_v1_private_get_all_orders(&[__ws_arg_43]).await;
} else if is_equal(&type_var, &Value::Str("spot".to_string())) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_get_trade_history_orders(&[__ws_arg_44]).await;
} else {
let mut isTwapOrder: Value = self.safe_bool_k(params.clone(), "twap", &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::Str("twap".to_string()), &[]);
if is_equal(&isTwapOrder, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("pageIndex".to_string()), Value::Int(1));
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), ternary(is_true(&(is_equal(&limit, &Value::Null))), Value::Int(100), limit.clone()));
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), ternary(is_true(&(is_equal(&since, &Value::Null))), Value::Int(1), since.clone()));
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[self.milliseconds()]);
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
let __ws_arg_45 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v1_private_get_twap_history_orders(&[__ws_arg_45]).await;
} else if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_46 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_trade_order_history(&[__ws_arg_46]).await;
} else {
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_trade_all_orders(&[__ws_arg_47]).await;
}
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list2(data.clone(), Value::Str("orders".to_string()), Value::Str("list".to_string()), &[Value::List(vec![])]);
return self.parse_orders(orders.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bingx#transfer
* @description transfer currency internally between wallets on the same account
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Fund%20Account/Asset%20Transfer%20New
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from (spot, swap, futures, or funding)
* @param {string} toAccount account to transfer to (spot, swap (linear or inverse), future, or funding)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("transfer".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[toAccount.clone()]);
if is_equal(&fromId, &Value::Str("swap".to_string())) {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
fromId = Value::Str("coinMPerp".to_string());
} else {
fromId = Value::Str("USDTMPerp".to_string());
}
}
if is_equal(&toId, &Value::Str("swap".to_string())) {
if is_equal(&subType, &Value::Str("inverse".to_string())) {
toId = Value::Str("coinMPerp".to_string());
} else {
toId = Value::Str("USDTMPerp".to_string());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fromAccount".to_string(), fromId.clone());
m.insert("toAccount".to_string(), toId.clone());
m.insert("asset".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let __ws_arg_48 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.api_asset_v1_private_post_transfer(&[__ws_arg_48]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(response.clone(), "timestamp", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("id".to_string(), self.safe_string2(data.clone(), Value::Str("transferId".to_string()), Value::Str("tranId".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("fromAccount".to_string(), fromAccount.clone());
m.insert("toAccount".to_string(), toAccount.clone());
m.insert("status".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bingx#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Fund%20Account/Asset%20transfer%20records%20new
* @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 {string} params.fromAccount (mandatory) transfer from (spot, swap (linear or inverse), future, or funding)
* @param {string} params.toAccount (mandatory) transfer to (spot, swap(linear or inverse), future, or funding)
* @param {boolean} [params.paginate] whether to paginate the results (default false)
* @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 accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromAccount: Value = self.safe_string_k(params.clone(), "fromAccount", &[]);
let mut toAccount: Value = self.safe_string_k(params.clone(), "toAccount", &[]);
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[toAccount.clone()]);
if is_equal(&fromId, &Value::Null) || is_equal(&toId, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fromAccount & toAccount parameters are required".to_string()))));
}
if !is_equal(&fromAccount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("fromAccount".to_string()), fromId.clone());
}
if !is_equal(&toAccount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("toAccount".to_string()), toId.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("fromAccount".to_string()), Value::Str("toAccount".to_string())]), &[]);
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()), &[Value::Null, since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
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_49 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.api_v3_private_get_asset_transfer_record(&[__ws_arg_49]).await;
//
// {
// "total": 2,
// "rows": [
// {
// "asset": "LTC",
// "amount": "0.05000000000000000000",
// "status": "CONFIRMED",
// "transferId": "1051461075661819338791",
// "timestamp": 1752202092000,
// "fromAccount": "spot",
// "toAccount": "USDTMPerp"
// }
// ]
// }
//
let mut rows: Value = self.safe_list_k(response.clone(), "rows", &[Value::List(vec![])]);
return self.parse_transfers(rows.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 tranId: Value = self.safe_string_k(transfer.clone(), "transferId", &[]);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "timestamp", &[]);
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "asset", &[]);
let mut currencyCode: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut status: Value = self.safe_string_k(transfer.clone(), "status", &[]);
let mut accountsById: Value = self.safe_dict_k(self.options.clone(), "accountsById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string_k(transfer.clone(), "fromAccount", &[]);
let mut toId: Value = self.safe_string_k(transfer.clone(), "toAccount", &[]);
let mut fromAccount: Value = self.safe_string(accountsById.clone(), fromId.clone(), &[fromId.clone()]);
let mut toAccount: Value = self.safe_string(accountsById.clone(), toId.clone(), &[toId.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), tranId.clone());
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(), fromAccount.clone());
m.insert("toAccount".to_string(), toAccount.clone());
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("CONFIRMED".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchDepositAddressesByNetwork
* @description fetch the deposit addresses for a currency associated with this account
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Wallet%20Deposits%20and%20Withdrawals/Main%20Account%20Deposit%20Address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary [address structures]{@link https://docs.ccxt.com/?id=address-structure}, indexed by the network
*/
pub async fn fetch_deposit_addresses_by_network(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut defaultRecvWindow: Value = self.safe_integer_k(self.options.clone(), "recvWindow", &[]);
let mut recvWindow: Value = self.safe_integer_k(params.clone(), "recvWindow", &[defaultRecvWindow.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("offset".to_string(), Value::Int(0));
m.insert("limit".to_string(), Value::Int(1000));
m.insert("recvWindow".to_string(), recvWindow.clone());
m
});
let __ws_arg_50 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.wallets_v1_private_get_capital_deposit_address(&[__ws_arg_50]).await;
//
// {
// "code": "0",
// "timestamp": "1695200226859",
// "data": {
// "data": [
// {
// "coinId": "799",
// "coin": "USDT",
// "network": "BEP20",
// "address": "6a7eda2817462dabb6493277a2cfe0f5c3f2550b",
// "tag": ''
// }
// ],
// "total": "1"
// }
// }
//
let mut data: Value = self.safe_list(self.safe_dict_k(response.clone(), "data", &[]), Value::Str("data".to_string()), &[]);
let mut parsed: Value = self.parse_deposit_addresses(data.clone(), &[Value::List(vec![get_value(¤cy, &Value::Str("code".to_string()))]), Value::Bool(false)]);
return self.index_by(parsed.clone(), Value::Str("network".to_string()));
Value::Null
}
/*
* @method
* @name bingx#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Wallet%20Deposits%20and%20Withdrawals/Main%20Account%20Deposit%20Address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] The chain of currency. This only apply for multi-chain currency, and there is no need for single chain currency
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut network: Value = self.safe_string_k(params.clone(), "network", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("network".to_string())]), &[]);
let mut addressStructures: Value = self.fetch_deposit_addresses_by_network(code.clone(), &[params.clone()]).await;
if !is_equal(&network, &Value::Null) {
return self.safe_dict(addressStructures.clone(), network.clone(), &[]);
} else {
let mut options: Value = self.safe_dict_k(self.options.clone(), "defaultNetworks", &[]);
let mut defaultNetworkForCurrency: Value = self.safe_string(options.clone(), code.clone(), &[]);
if !is_equal(&defaultNetworkForCurrency, &Value::Null) {
return self.safe_dict(addressStructures.clone(), defaultNetworkForCurrency.clone(), &[]);
} else {
let mut keys: Value = object_keys(&addressStructures);
let mut key: Value = self.safe_string(keys.clone(), Value::Int(0), &[]);
return self.safe_dict(addressStructures.clone(), key.clone(), &[]);
}
}
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "coinId":"4",
// "coin":"USDT",
// "network":"OMNI",
// "address":"1HXyx8HVQRY7Nhqz63nwnRB7SpS9xQPzLN",
// "addressWithPrefix":"1HXyx8HVQRY7Nhqz63nwnRB7SpS9xQPzLN"
// }
//
let mut tag: Value = self.safe_string_k(depositAddress.clone(), "tag", &[]);
let mut currencyId: Value = self.safe_string_k(depositAddress.clone(), "coin", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut code: Value = get_value(¤cy, &Value::Str("code".to_string()));
let mut address: Value = self.safe_string2(depositAddress.clone(), Value::Str("addressWithPrefix".to_string()), Value::Str("address".to_string()), &[]);
let mut networkId: Value = self.safe_string_k(depositAddress.clone(), "network", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
// despite its name the addressWithPrefix field sometimes arrives without
// the 0x prefix on the evm networks, see https://github.com/ccxt/ccxt/issues/24331
if !is_equal(&address, &Value::Null) {
let mut isPrefixed: bool = is_true(&Value::Bool(starts_with(&address, &Value::Str("0x".to_string())))) || is_true(&Value::Bool(starts_with(&address, &Value::Str("0X".to_string()))));
let mut evmNetworks: Value = Value::List(vec![Value::Str("BEP20".to_string()), Value::Str("BSC".to_string()), Value::Str("ERC20".to_string()), Value::Str("ETH".to_string()), Value::Str("HECO".to_string()), Value::Str("MATIC".to_string()), Value::Str("POLYGON".to_string()), Value::Str("ARBITRUM".to_string()), Value::Str("ARB".to_string()), Value::Str("OPTIMISM".to_string()), Value::Str("AVAXC".to_string()), Value::Str("BASE".to_string()), Value::Str("FTM".to_string()), Value::Str("LINEA".to_string()), Value::Str("ZKSYNC".to_string()), Value::Str("OPBNB".to_string())]);
if !is_true(&isPrefixed) && is_true(&self.in_array(networkCode.clone(), evmNetworks.clone())) {
address = add(&Value::Str("0x".to_string()), &address);
}
}
self.check_address(&[address.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m
});
Value::Null
}
/*
* @method
* @name bingx#fetchDeposits
* @description fetch all deposits made to an account
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Wallet%20deposits%20and%20withdrawals/Deposit%20records
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch deposits for
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposits(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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());
add_element_to_object(&mut request, &Value::Str("coin".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()), crate::runtime::Math::min(&limit, &Value::Int(1000))); // api maximum 1000
}
{ 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_51 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_v3_private_get_capital_deposit_hisrec(&[__ws_arg_51]).await;
return self.parse_transactions(response.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Wallet%20deposits%20and%20withdrawals/Withdraw%20records
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of withdrawals structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch withdrawals for
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_withdrawals(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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());
add_element_to_object(&mut request, &Value::Str("coin".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()), crate::runtime::Math::min(&limit, &Value::Int(1000))); // api maximum 1000
}
{ 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_52 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.spot_v3_private_get_capital_withdraw_history(&[__ws_arg_52]).await;
return self.parse_transactions(response.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchDeposits
//
// {
// "amount":"0.00999800",
// "coin":"PAXG",
// "network":"ETH",
// "status":1,
// "address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
// "addressTag":"",
// "txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
// "insertTime":1599621997000,
// "transferType":0,
// "unlockConfirm":"12/12", // confirm times for unlocking
// "confirmTimes":"12/12"
// }
//
// fetchWithdrawals
//
// {
// "address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
// "amount": "8.91000000",
// "applyTime": "2019-10-12 11:12:02",
// "coin": "USDT",
// "id": "b6ae22b3aa844210a7041aee7589627c",
// "withdrawOrderId": "WITHDRAWtest123",
// "network": "ETH",
// "transferType": 0
// "status": 6,
// "transactionFee": "0.004",
// "confirmNo":3,
// "info": "The address is not valid. Please confirm with the recipient",
// "txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"
// }
//
// withdraw
//
// {
// "code":0,
// "timestamp":1705274263621,
// "data":{
// "id":"1264246141278773252"
// }
// }
//
// parse withdraw-type output first...
//
let mut data: Value = self.safe_value_k(transaction.clone(), "data", &[]);
let mut dataId: Value = ternary(is_true(&(is_equal(&data, &Value::Null))), Value::Null, self.safe_string_k(data.clone(), "id", &[]));
let mut id: Value = self.safe_string_k(transaction.clone(), "id", &[dataId.clone()]);
let mut address: Value = self.safe_string_k(transaction.clone(), "address", &[]);
let mut tag: Value = self.safe_string_k(transaction.clone(), "addressTag", &[]);
let mut timestamp: Value = self.safe_integer2(transaction.clone(), Value::Str("insertTime".to_string()), Value::Str("timestamp".to_string()), &[]);
let mut datetime: Value = self.iso8601(timestamp.clone());
if is_equal(×tamp, &Value::Null) {
datetime = self.safe_string_k(transaction.clone(), "applyTime", &[]);
timestamp = self.parse8601(datetime.clone());
}
let mut network: Value = self.safe_string_k(transaction.clone(), "network", &[]);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(!is_equal(&network, &Value::Null))) && is_true(&(!is_equal(&code, &network))) && is_greater_than_or_equal(&get_index_of(&code, &network), &Value::Int(0)) {
if !is_equal(&network, &Value::Null) {
code = replace_str(&code, &network, &Value::Str("".to_string()));
}
}
let mut rawType: Value = self.safe_string_k(transaction.clone(), "transferType", &[]);
let mut type_var: Value = ternary(is_true(&(is_equal(&rawType, &Value::Str("0".to_string())))), Value::Str("deposit".to_string()), Value::Str("withdrawal".to_string()));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.clone());
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "txId", &[]));
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), self.network_id_to_code(&[network.clone(), code.clone()]));
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), datetime.clone());
m.insert("address".to_string(), address.clone());
m.insert("addressFrom".to_string(), Value::Null);
m.insert("addressTo".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m.insert("tagFrom".to_string(), tag.clone());
m.insert("tagTo".to_string(), Value::Null);
m.insert("updated".to_string(), Value::Null);
m.insert("comment".to_string(), self.safe_string_k(transaction.clone(), "info", &[]));
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_number_k(transaction.clone(), "transactionFee", &[]));
m.insert("rate".to_string(), Value::Null);
m
}));
m.insert("internal".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("pending".to_string()));
m.insert("1".to_string(), Value::Str("ok".to_string()));
m.insert("10".to_string(), Value::Str("pending".to_string()));
m.insert("20".to_string(), Value::Str("rejected".to_string()));
m.insert("30".to_string(), Value::Str("ok".to_string()));
m.insert("40".to_string(), Value::Str("rejected".to_string()));
m.insert("50".to_string(), Value::Str("ok".to_string()));
m.insert("60".to_string(), Value::Str("pending".to_string()));
m.insert("70".to_string(), Value::Str("rejected".to_string()));
m.insert("2".to_string(), Value::Str("pending".to_string()));
m.insert("3".to_string(), Value::Str("rejected".to_string()));
m.insert("4".to_string(), Value::Str("pending".to_string()));
m.insert("5".to_string(), Value::Str("rejected".to_string()));
m.insert("6".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name bingx#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Change%20Margin%20Type
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Set%20Margin%20Type
* @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());
if !is_equal(&get_value(&market, &Value::Str("type".to_string())), &Value::Str("swap".to_string())) {
panic!("{}", crate::exchange_errors::bad_symbol(add(&self.id, &Value::Str(" setMarginMode() supports swap contracts only".to_string()))));
}
marginMode = to_upper(&marginMode);
if is_equal(&marginMode, &Value::Str("CROSS".to_string())) {
marginMode = Value::Str("CROSSED".to_string());
}
if !is_equal(&marginMode, &Value::Str("ISOLATED".to_string())) && !is_equal(&marginMode, &Value::Str("CROSSED".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setMarginMode() marginMode argument should be isolated or cross".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(), marginMode.clone());
m
});
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("setMarginMode".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_53 = self.extend(request.clone(), &[params.clone()]);
return self.cswap_v1_private_post_trade_margin_type(&[__ws_arg_53]).await;
} else {
let __ws_arg_54 = self.extend(request.clone(), &[params.clone()]);
return self.swap_v2_private_post_trade_margin_type(&[__ws_arg_54]).await;
}
Value::Null
}
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
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Int(1));
m
});
let __ws_arg_55 = self.extend(request.clone(), &[params.clone()]);
return self.set_margin(symbol.clone(), amount.clone(), &[__ws_arg_55]).await;
Value::Null
}
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
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Int(2));
m
});
let __ws_arg_56 = self.extend(request.clone(), &[params.clone()]);
return self.set_margin(symbol.clone(), amount.clone(), &[__ws_arg_56]).await;
Value::Null
}
/*
* @method
* @name bingx#setMargin
* @description Either adds or reduces margin in an isolated position in order to set the margin to a specific value
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Modify%20Isolated%20Position%20Margin
* @param {string} symbol unified market symbol of the market to set margin in
* @param {float} amount the amount to set the margin to
* @param {object} [params] parameters specific to the exchange API endpoint
* @returns {object} A [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn set_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut type_var: Value = self.safe_integer_k(params.clone(), "type", &[]); // 1 increase margin 2 decrease margin
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMargin() requires a type parameter either 1 (increase margin) or 2 (decrease margin)".to_string()))));
}
if !is_true(&self.in_array(type_var.clone(), Value::List(vec![Value::Int(1), Value::Int(2)]))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMargin() requires a type parameter either 1 (increase margin) or 2 (decrease margin)".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("amount".to_string(), self.amount_to_precision(get_value(&market, &Value::Str("symbol".to_string())), amount.clone()));
m.insert("type".to_string(), type_var.clone());
m
});
let __ws_arg_57 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_v2_private_post_trade_position_margin(&[__ws_arg_57]).await;
return self.parse_margin_modification(response.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "code": 0,
// "msg": "",
// "amount": 1,
// "type": 1
// }
//
let mut type_var: Value = self.safe_string_k(data.clone(), "type", &[]);
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(), ternary(is_true(&(is_equal(&type_var, &Value::Str("1".to_string())))), Value::Str("add".to_string()), Value::Str("reduce".to_string())));
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), self.safe_number_k(data.clone(), "amount", &[]));
m.insert("total".to_string(), self.safe_number_k(data.clone(), "margin", &[]));
m.insert("code".to_string(), self.safe_string_k(market.clone(), "settle", &[]));
m.insert("status".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bingx#fetchLeverage
* @description fetch the set leverage for a market
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Leverage%20and%20Available%20Positions
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20Leverage
* @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 mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_58 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_trade_leverage(&[__ws_arg_58]).await;
} else {
let __ws_arg_59 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_trade_leverage(&[__ws_arg_59]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_leverage(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// linear swap
//
// {
// "longLeverage": 5,
// "shortLeverage": 5,
// "maxLongLeverage": 125,
// "maxShortLeverage": 125,
// "availableLongVol": "0.0000",
// "availableShortVol": "0.0000",
// "availableLongVal": "0.0",
// "availableShortVal": "0.0",
// "maxPositionLongVal": "0.0",
// "maxPositionShortVal": "0.0"
// }
//
// inverse swap
//
// {
// "symbol": "SOL-USD",
// "longLeverage": 5,
// "shortLeverage": 5,
// "maxLongLeverage": 50,
// "maxShortLeverage": 50,
// "availableLongVol": "4000000",
// "availableShortVol": "4000000"
// }
//
let mut marketId: Value = self.safe_string_k(leverage.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("marginMode".to_string(), Value::Null);
m.insert("longLeverage".to_string(), self.safe_integer_k(leverage.clone(), "longLeverage", &[]));
m.insert("shortLeverage".to_string(), self.safe_integer_k(leverage.clone(), "shortLeverage", &[]));
m
});
Value::Null
}
/*
* @method
* @name bingx#setLeverage
* @description set the level of leverage for a market
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Set%20Leverage
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Modify%20Leverage
* @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.side] hedged: ['long' or 'short']. one way: ['both']
* @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()))));
}
let mut side: Value = self.safe_string_upper(params.clone(), Value::Str("side".to_string()), &[]);
self.check_required_argument(Value::Str("setLeverage".to_string()), side.clone(), Value::Str("side".to_string()), &[Value::List(vec![Value::Str("LONG".to_string()), Value::Str("SHORT".to_string()), Value::Str("BOTH".to_string())])]);
params = self.omit(params.clone(), Value::Str("side".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("side".to_string(), side.clone());
m.insert("leverage".to_string(), leverage.clone());
m
});
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_60 = self.extend(request.clone(), &[params.clone()]);
return self.cswap_v1_private_post_trade_leverage(&[__ws_arg_60]).await;
} else {
let __ws_arg_61 = self.extend(request.clone(), &[params.clone()]);
return self.swap_v2_private_post_trade_leverage(&[__ws_arg_61]).await;
}
Value::Null
}
/*
* @method
* @name bingx#fetchMyTrades
* @description fetch all trades made by the user
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Query%20transaction%20details
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20historical%20transaction%20orders
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20Order%20Trade%20Detail
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is undefined
* @param {string} params.trandingUnit COIN (directly represent assets such as BTC and ETH) or CONT (represents the number of contract sheets)
* @param {string} params.orderId the order id required for inverse swap
* @returns {object[]} 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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut fills: Value = Value::Null;
let mut response: Value = Value::Null;
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let mut orderId: Value = self.safe_string_k(params.clone(), "orderId", &[]);
if is_equal(&orderId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires an orderId argument for inverse swap trades".to_string()))));
}
let __ws_arg_62 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_trade_all_fill_orders(&[__ws_arg_62]).await;
fills = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let mut now: Value = self.milliseconds();
if !is_equal(&since, &Value::Null) {
let mut startTimeReq: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("startTime".to_string()), Value::Str("startTs".to_string()));
add_element_to_object(&mut request, &startTimeReq, since.clone());
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("startTs".to_string()), subtract(&now, &multiply(&multiply(&multiply(&multiply(&Value::Int(30), &Value::Int(24)), &Value::Int(60)), &Value::Int(60)), &Value::Int(1000)))); // 30 days for swap
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
let mut endTimeReq: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("endTime".to_string()), Value::Str("endTs".to_string()));
add_element_to_object(&mut request, &endTimeReq, until.clone());
} else if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("endTs".to_string()), now.clone());
}
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 500, maximum 1000
}
let __ws_arg_63 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_get_trade_my_trades(&[__ws_arg_63]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
fills = self.safe_list_k(data.clone(), "fills", &[Value::List(vec![])]);
} else {
let mut tradingUnit: Value = self.safe_string_upper(params.clone(), Value::Str("tradingUnit".to_string()), &[Value::Str("CONT".to_string())]);
params = self.omit(params.clone(), Value::Str("tradingUnit".to_string()), &[]);
add_element_to_object(&mut request, &Value::Str("tradingUnit".to_string()), tradingUnit.clone());
let __ws_arg_64 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_trade_all_fill_orders(&[__ws_arg_64]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
fills = self.safe_list_k(data.clone(), "fill_orders", &[Value::List(vec![])]);
}
}
return self.parse_trades(fills.clone(), &[market.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
pub fn parse_deposit_withdraw_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// currencie structure
//
let mut networks: Value = self.safe_dict_k(fee.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networkCodes: Value = object_keys(&networks);
let mut networksLength: Value = get_array_length(&networkCodes);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), networks.clone());
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
if !is_equal(&networksLength, &Value::Int(0)) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_296: bool = true;
while { if !__for_first_296 { i = add(&i, &Value::Int(1)); } __for_first_296 = false; is_less_than(&i, &networksLength) } {
let mut networkCode: Value = get_value(&networkCodes, &i);
let mut networkCode: Value = get_value(&networkCodes, &i);
let mut network: Value = get_value(&networks, &networkCode);
let mut network: Value = get_value(&networks, &networkCode);
add_element_to_object(get_value_mut(&mut result, &Value::Str("networks".to_string())), &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), self.safe_number_k(network.clone(), "fee", &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m
}));
if is_equal(&networksLength, &Value::Int(1)) {
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".to_string())), &Value::Str("fee".to_string()), self.safe_number_k(network.clone(), "withdrawFee", &[]));
add_element_to_object(get_value_mut(&mut result, &Value::Str("withdraw".to_string())), &Value::Str("percentage".to_string()), Value::Bool(false));
}
}
}
}
return result;
Value::Null
}
/*
* @method
* @name bingx#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Wallet%20Deposits%20and%20Withdrawals/Query%20currency%20deposit%20and%20withdrawal%20data
* @param {string[]|undefined} codes list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.fetch_currencies(&[params.clone()]).await;
let mut depositWithdrawFees: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut responseCodes: Value = object_keys(&response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_297: bool = true;
while { if !__for_first_297 { i = add(&i, &Value::Int(1)); } __for_first_297 = false; is_less_than(&i, &get_array_length(&responseCodes)) } {
let mut code: Value = get_value(&responseCodes, &i);
let mut code: Value = get_value(&responseCodes, &i);
if is_true(&(is_equal(&codes, &Value::Null))) || is_true(&(self.in_array(code.clone(), codes.clone()))) {
let mut entry: Value = get_value(&response, &code);
let mut entry: Value = get_value(&response, &code);
add_element_to_object(&mut depositWithdrawFees, &code, self.parse_deposit_withdraw_fee(entry.clone(), &[]));
}
}
}
return depositWithdrawFees;
Value::Null
}
/*
* @method
* @name bingx#withdraw
* @description make a withdrawal
* @see https://bingx-api.github.io/docs-v3/#/en/Account%20and%20Wallet/Wallet%20Deposits%20and%20Withdrawals/Withdraw
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} [tag]
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.walletType] 1 fund (funding) account, 2 standard account, 3 perpetual account, 15 spot account
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
{ let __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
self.check_address(&[address.clone()]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut defaultWalletType: Value = Value::Int(15); // spot
let mut walletType: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params2(params.clone(), Value::Str("withdraw".to_string()), Value::Str("type".to_string()), Value::Str("walletType".to_string()), &[defaultWalletType.clone()]); walletType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut walletTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("funding".to_string(), Value::Int(1));
m.insert("fund".to_string(), Value::Int(1));
m.insert("standard".to_string(), Value::Int(2));
m.insert("perpetual".to_string(), Value::Int(3));
m.insert("spot".to_string(), Value::Int(15));
m
});
walletType = self.safe_integer(walletTypes.clone(), walletType.clone(), &[defaultWalletType.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("address".to_string(), address.clone());
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("walletType".to_string(), walletType.clone());
m
});
let mut network: Value = self.safe_string_upper(params.clone(), Value::Str("network".to_string()), &[]);
if !is_equal(&network, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("network".to_string()), self.network_code_to_id(network.clone(), &[get_value(¤cy, &Value::Str("code".to_string()))]));
}
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("addressTag".to_string()), tag.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("walletType".to_string()), Value::Str("network".to_string())]), &[]);
let __ws_arg_65 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.wallets_v1_private_post_capital_withdraw_apply(&[__ws_arg_65]).await;
let mut data: Value = self.safe_value_k(response.clone(), "data", &[]);
return self.parse_transaction(data.clone(), &[]);
Value::Null
}
pub fn parse_params(&self, mut params: Value) -> Value {
// const sortedParams = this.keysort (params);
let mut copied: Value = self.clone_value(params.clone());
let mut rawKeys: Value = object_keys(¶ms);
let mut keys: Value = self.sort(rawKeys.clone(), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_299: bool = true;
while { if !__for_first_299 { i = add(&i, &Value::Int(1)); } __for_first_299 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
let mut value: Value = get_value(¶ms, &key);
let mut value: Value = get_value(¶ms, &key);
if is_true(&Value::Bool(is_array(&value))) {
let mut arrStr: Value = Value::Str("[".to_string());
{
let mut j: Value = Value::Int(0);
let mut __for_first_298: bool = true;
while { if !__for_first_298 { j = add(&j, &Value::Int(1)); } __for_first_298 = false; is_less_than(&j, &get_array_length(&value)) } {
let mut arrayElement: Value = get_value(&value, &j);
let mut arrayElement: Value = get_value(&value, &j);
if is_greater_than(&j, &Value::Int(0)) {
arrStr = add(&arrStr, &Value::Str(",".to_string()));
}
arrStr = add(&arrStr, &to_string_val(&arrayElement));
}
}
arrStr = add(&arrStr, &Value::Str("]".to_string()));
add_element_to_object(&mut copied, &key, arrStr.clone());
}
}
}
return copied;
Value::Null
}
/*
* @method
* @name bingx#fetchMyLiquidations
* @description retrieves the users liquidated positions
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/User's%20Force%20Orders
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20force%20orders
* @param {string} [symbol] unified CCXT market symbol
* @param {int} [since] the earliest time in ms to fetch liquidations for
* @param {int} [limit] the maximum number of liquidation structures to retrieve (max 100)
* @param {object} [params] exchange specific parameters for the bingx api endpoint
* @param {int} [params.until] timestamp in ms of the latest liquidation
* @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/?id=liquidation-structure}
*/
pub async fn fetch_my_liquidations(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("autoCloseType".to_string(), Value::Str("LIQUIDATION".to_string()));
m
});
{ 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 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())));
}
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, &Value::Int(100))); // api maximum 100
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchMyLiquidations".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
let mut liquidations: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_66 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_trade_force_orders(&[__ws_arg_66]).await;
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1721280071678,
// "data": [
// {
// "orderId": "string",
// "symbol": "string",
// "type": "string",
// "side": "string",
// "positionSide": "string",
// "price": "string",
// "quantity": "float64",
// "stopPrice": "string",
// "workingType": "string",
// "status": "string",
// "time": "int64",
// "avgPrice": "string",
// "executedQty": "string",
// "profit": "string",
// "commission": "string",
// "updateTime": "string"
// }
// ]
// }
//
liquidations = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
} else {
let __ws_arg_67 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_trade_force_orders(&[__ws_arg_67]).await;
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "orders": [
// {
// "time": "int64",
// "symbol": "string",
// "side": "string",
// "type": "string",
// "positionSide": "string",
// "cumQuote": "string",
// "status": "string",
// "stopPrice": "string",
// "price": "string",
// "origQty": "string",
// "avgPrice": "string",
// "executedQty": "string",
// "orderId": "int64",
// "profit": "string",
// "commission": "string",
// "workingType": "string",
// "updateTime": "int64"
// },
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
liquidations = self.safe_list_k(data.clone(), "orders", &[Value::List(vec![])]);
}
return self.parse_liquidations(liquidations.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_liquidation(&self, mut liquidation: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "time": "int64",
// "symbol": "string",
// "side": "string",
// "type": "string",
// "positionSide": "string",
// "cumQuote": "string",
// "status": "string",
// "stopPrice": "string",
// "price": "string",
// "origQty": "string",
// "avgPrice": "string",
// "executedQty": "string",
// "orderId": "int64",
// "profit": "string",
// "commission": "string",
// "workingType": "string",
// "updateTime": "int64"
// }
//
let mut marketId: Value = self.safe_string_k(liquidation.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(liquidation.clone(), "time", &[]);
let mut contractsString: Value = self.safe_string_k(liquidation.clone(), "executedQty", &[]);
let mut contractSizeString: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
let mut priceString: Value = self.safe_string_k(liquidation.clone(), "avgPrice", &[]);
let mut baseValueString: Value = crate::precise::Precise::stringMul(&contractsString, &contractSizeString);
let mut quoteValueString: Value = crate::precise::Precise::stringMul(&baseValueString, &priceString);
return self.safe_liquidation(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), liquidation.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("contracts".to_string(), self.parse_number(contractsString.clone(), &[]));
m.insert("contractSize".to_string(), self.parse_number(contractSizeString.clone(), &[]));
m.insert("price".to_string(), self.parse_number(priceString.clone(), &[]));
m.insert("baseValue".to_string(), self.parse_number(baseValueString.clone(), &[]));
m.insert("quoteValue".to_string(), self.parse_number(quoteValueString.clone(), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}), &[]);
Value::Null
}
/*
* @method
* @name bingx#closePosition
* @description closes open positions for a market
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Close%20All%20Positions
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Close%20position%20by%20position%20ID
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Close%20all%20positions%20in%20bulk
* @param {string} symbol Unified CCXT market symbol
* @param {string} [side] not used by bingx
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string|undefined} [params.positionId] the id of the position you would like to close, only supported for linear swap
* @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 positionId: Value = self.safe_string_k(params.clone(), "positionId", &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if !is_equal(&positionId, &Value::Null) {
if is_true(&(!is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" closePosition() with a positionId is only supported for linear swap markets".to_string()))));
}
let __ws_arg_68 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v1_private_post_trade_close_position(&[__ws_arg_68]).await;
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
let __ws_arg_69 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_post_trade_close_all_positions(&[__ws_arg_69]).await;
} else {
let __ws_arg_70 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_post_trade_close_all_positions(&[__ws_arg_70]).await;
}
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bitget#closePositions
* @description closes open positions for a market
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Close%20All%20Positions
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Close%20all%20positions%20in%20bulk
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.recvWindow] request valid time window value
* @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 defaultRecvWindow: Value = self.safe_integer_k(self.options.clone(), "recvWindow", &[]);
let mut recvWindow: Value = self.safe_integer_k(params.clone(), "recvWindow", &[defaultRecvWindow.clone()]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("closeAllPositions".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("closeAllPositions".to_string()), &[Value::Null, params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("margin".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&self.id, &Value::Str(" closePositions () cannot be used for ".to_string())), &marketType), &Value::Str(" markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("recvWindow".to_string(), recvWindow.clone());
m
});
let mut response: Value = Value::Null;
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_71 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_post_trade_close_all_positions(&[__ws_arg_71]).await;
} else {
let __ws_arg_72 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_post_trade_close_all_positions(&[__ws_arg_72]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut success: Value = self.safe_list_k(data.clone(), "success", &[Value::List(vec![])]);
let mut positions: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_300: bool = true;
while { if !__for_first_300 { i = add(&i, &Value::Int(1)); } __for_first_300 = false; is_less_than(&i, &get_array_length(&success)) } {
let mut position: Value = self.parse_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("positionId".to_string(), get_value(&success, &i));
m
}), &[]);
append_to_array(&mut positions, position.clone());
}
}
return positions;
Value::Null
}
/*
* @method
* @name bingx#fetchPositionMode
* @description fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20position%20mode
* @param {string} symbol unified market symbol, inverse (Coin-M) markets are not supported
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an object detailing whether the market is in hedged or one-way mode
*/
pub async fn fetch_position_mode(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
self.load_markets(&[]).await;
market = self.market(symbol.clone());
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPositionMode".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&subType, &Value::Str("inverse".to_string())))) || is_true(&(is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchPositionMode() is not supported for inverse swap markets".to_string()))));
}
let mut response: Value = self.swap_v1_private_get_position_side_dual(&[params.clone()]).await;
//
// {
// "code": "0",
// "msg": "",
// "timeStamp": "1709002057516",
// "data": {
// "dualSidePosition": "false"
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut dualSidePosition: Value = self.safe_string_k(data.clone(), "dualSidePosition", &[]);
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(&dualSidePosition, &Value::Str("true".to_string())))));
m
});
Value::Null
}
/*
* @method
* @name bingx#setPositionMode
* @description set hedged to true or false for a market
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Set%20Position%20Mode
* @param {bool} hedged set to true to use dualSidePosition
* @param {string} symbol unified market symbol, inverse (Coin-M) markets are not supported
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
self.load_markets(&[]).await;
market = self.market(symbol.clone());
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("setPositionMode".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&subType, &Value::Str("inverse".to_string())))) || is_true(&(is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)))))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setPositionMode() is not supported for inverse swap markets".to_string()))));
}
let mut dualSidePosition: Value = Value::Null;
if is_true(&hedged) {
dualSidePosition = Value::Str("true".to_string());
} else {
dualSidePosition = Value::Str("false".to_string());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("dualSidePosition".to_string(), dualSidePosition.clone());
m
});
let __ws_arg_73 = self.extend(request.clone(), &[params.clone()]);
return self.swap_v1_private_post_position_side_dual(&[__ws_arg_73]).await;
Value::Null
}
/*
* @method
* @name bingx#editOrder
* @description cancels an order and places a new order
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Cancel%20an%20Existing%20Order%20and%20Send%20a%20New%20Order // spot
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Cancel%20an%20Existing%20Order%20and%20Send%20a%20New%20Orde // swap
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of the currency you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.triggerPrice] Trigger price used for TAKE_STOP_LIMIT, TAKE_STOP_MARKET, TRIGGER_LIMIT, TRIGGER_MARKET order types.
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {string} [params.cancelClientOrderID] the user-defined id of the order to be canceled, 1-40 characters, different orders cannot use the same clientOrderID, only supports a query range of 2 hours
* @param {string} [params.cancelRestrictions] cancel orders with specified status, NEW: New order, PENDING: Pending order, PARTIALLY_FILLED: Partially filled
* @param {string} [params.cancelReplaceMode] STOP_ON_FAILURE - if the cancel order fails, it will not continue to place a new order, ALLOW_FAILURE - regardless of whether the cancel order succeeds or fails, it will continue to place a new order
* @param {float} [params.quoteOrderQty] order amount
* @param {string} [params.newClientOrderId] custom order id consisting of letters, numbers, and _, 1-40 characters, different orders cannot use the same newClientOrderId.
* @param {string} [params.positionSide] *contract only* position direction, required for single position as BOTH, for both long and short positions only LONG or SHORT can be chosen, defaults to LONG if empty
* @param {string} [params.reduceOnly] *contract only* true or false, default=false for single position mode. this parameter is not accepted for both long and short positions mode
* @param {float} [params.priceRate] *contract only* for type TRAILING_STOP_Market or TRAILING_TP_SL, Max = 1
* @param {string} [params.workingType] *contract only* StopPrice trigger price types, MARK_PRICE (default), CONTRACT_PRICE, or INDEX_PRICE
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
add_element_to_object(&mut request, &Value::Str("cancelOrderId".to_string()), id.clone());
add_element_to_object(&mut request, &Value::Str("cancelReplaceMode".to_string()), Value::Str("STOP_ON_FAILURE".to_string()));
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)) {
response = self.swap_v1_private_post_trade_cancel_replace(&[request.clone()]).await;
} else {
response = self.spot_v1_private_post_trade_order_cancel_replace(&[request.clone()]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bingx#fetchMarginMode
* @description fetches the margin mode of the trading pair
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Query%20Margin%20Type
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20Margin%20Type
* @param {string} symbol unified symbol of the market to fetch the margin mode for
* @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 mut subType: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchMarginMode".to_string()), &[market.clone(), params.clone()]); subType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&subType, &Value::Str("inverse".to_string())) {
let __ws_arg_74 = self.extend(request.clone(), &[params.clone()]);
response = self.cswap_v1_private_get_trade_margin_type(&[__ws_arg_74]).await;
} else {
let __ws_arg_75 = self.extend(request.clone(), &[params.clone()]);
response = self.swap_v2_private_get_trade_margin_type(&[__ws_arg_75]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_mode(data.clone(), &[market.clone()]);
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_lower(marginMode.clone(), Value::Str("marginType".to_string()), &[]);
marginType = ternary(is_true(&(is_equal(&marginType, &Value::Str("crossed".to_string())))), Value::Str("cross".to_string()), marginType.clone());
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::Str("-".to_string()), Value::Str("swap".to_string())]));
m.insert("marginMode".to_string(), marginType.clone());
m
});
Value::Null
}
/*
* @method
* @name bingx#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://bingx-api.github.io/docs-v3/#/en/Spot/Trades%20Endpoints/Query%20Trading%20Commission%20Rate
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Account%20Endpoints/Query%20Trading%20Commission%20Rate
* @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Trades%20Endpoints/Query%20Trade%20Commission%20Rate
* @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());
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 response: Value = Value::Null;
let mut commission: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_76 = self.extend(request.clone(), &[params.clone()]);
response = self.spot_v1_private_get_user_commission_rate(&[__ws_arg_76]).await;
//
// {
// "code": 0,
// "msg": "",
// "debugMsg": "",
// "data": {
// "takerCommissionRate": 0.001,
// "makerCommissionRate": 0.001
// }
// }
//
commission = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
response = self.cswap_v1_private_get_user_commission_rate(&[params.clone()]).await;
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1721365261438,
// "data": {
// "takerCommissionRate": "0.0005",
// "makerCommissionRate": "0.0002"
// }
// }
//
commission = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
} else {
response = self.swap_v2_private_get_user_commission_rate(&[params.clone()]).await;
//
// {
// "code": 0,
// "msg": "",
// "data": {
// "commission": {
// "takerCommissionRate": 0.0005,
// "makerCommissionRate": 0.0002
// }
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
commission = self.safe_dict_k(data.clone(), "commission", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
}
return self.parse_trading_fee(commission.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);
//
// {
// "takerCommissionRate": 0.001,
// "makerCommissionRate": 0.001
// }
//
let mut symbol: Value = ternary(is_true(&(!is_equal(&market, &Value::Null))), get_value(&market, &Value::Str("symbol".to_string())), Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), symbol.clone());
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(false));
m.insert("tierBased".to_string(), Value::Bool(false));
m
});
Value::Null
}
pub fn custom_encode(&self, mut params: Value) -> Value {
// const sortedParams = this.keysort (params);
let mut rawKeys: Value = object_keys(¶ms);
let mut keys: Value = self.sort(rawKeys.clone(), &[]);
let mut adjustedValue: Value = Value::Null;
let mut result: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_302: bool = true;
while { if !__for_first_302 { i = add(&i, &Value::Int(1)); } __for_first_302 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
let mut value: Value = get_value(¶ms, &key);
let mut value: Value = get_value(¶ms, &key);
if is_true(&Value::Bool(is_array(&value))) {
let mut arrStr: Value = Value::Null;
{
let mut j: Value = Value::Int(0);
let mut __for_first_301: bool = true;
while { if !__for_first_301 { j = add(&j, &Value::Int(1)); } __for_first_301 = false; is_less_than(&j, &get_array_length(&value)) } {
let mut arrayElement: Value = get_value(&value, &j);
let mut arrayElement: Value = get_value(&value, &j);
let mut isString: bool = is_string(&arrayElement);
if is_true(&isString) {
if is_greater_than(&j, &Value::Int(0)) {
arrStr = add(&arrStr, &add(&add(&add(&Value::Str(",".to_string()), &Value::Str("\"".to_string())), &to_string_val(&arrayElement)), &Value::Str("\"".to_string())));
} else {
arrStr = add(&add(&Value::Str("\"".to_string()), &to_string_val(&arrayElement)), &Value::Str("\"".to_string()));
}
} else {
if is_greater_than(&j, &Value::Int(0)) {
arrStr = add(&arrStr, &add(&Value::Str(",".to_string()), &to_string_val(&arrayElement)));
} else {
arrStr = to_string_val(&arrayElement);
}
}
}
}
adjustedValue = add(&add(&Value::Str("[".to_string()), &arrStr), &Value::Str("]".to_string()));
value = adjustedValue.clone();
}
if is_equal(&i, &Value::Int(0)) {
result = add(&add(&key, &Value::Str("=".to_string())), &value);
} else {
result = add(&result, &add(&add(&add(&Value::Str("&".to_string()), &key), &Value::Str("=".to_string())), &value));
}
}
}
return result;
Value::Null
}
/*
* @method
* @name bingx#fetchMarketLeverageTiers
* @description retrieve information on the maximum leverage, for different trade sizes for a single market
* @see https://bingx-api.github.io/docs-v3/#/en/Swap/Trades%20Endpoints/Position%20and%20Maintenance%20Margin%20Ratio
* @param {string} symbol unified market symbol, inverse (Coin-M) markets are not supported
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
*/
pub async fn fetch_market_leverage_tiers(&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("swap".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchMarketLeverageTiers() supports swap markets only".to_string()))));
}
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchMarketLeverageTiers() is not supported for inverse swap markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_77 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.swap_v1_private_get_maint_margin_ratio(&[__ws_arg_77]).await;
//
// {
// "code": 0,
// "msg": "",
// "timestamp": 1767789967284,
// "data": [
// {
// "tier": "Tier 1",
// "symbol": "ETH-USDT",
// "minPositionVal": "0",
// "maxPositionVal": "900000",
// "maintMarginRatio": "0.003300",
// "maintAmount": "0.000000"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_market_leverage_tiers(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_market_leverage_tiers(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// {
// "tier": "Tier 1",
// "symbol": "ETH-USDT",
// "minPositionVal": "0",
// "maxPositionVal": "900000",
// "maintMarginRatio": "0.003300",
// "maintAmount": "0.000000"
// }
// ]
//
let mut tiers: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_303: bool = true;
while { if !__for_first_303 { i = add(&i, &Value::Int(1)); } __for_first_303 = false; is_less_than(&i, &get_array_length(&info)) } {
let mut tier: Value = self.safe_dict(info.clone(), i.clone(), &[]);
let mut tierString: Value = self.safe_string_k(tier.clone(), "tier", &[]);
let mut tierParts: Value = split(&tierString, &Value::Str(" ".to_string()));
let mut marketId: Value = self.safe_string_k(tier.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_number(tierParts.clone(), Value::Int(1), &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("currency".to_string(), self.safe_string_k(market.clone(), "settle", &[]));
m.insert("minNotional".to_string(), self.safe_number_k(tier.clone(), "minPositionVal", &[]));
m.insert("maxNotional".to_string(), self.safe_number_k(tier.clone(), "maxPositionVal", &[]));
m.insert("maintenanceMarginRate".to_string(), self.safe_number_k(tier.clone(), "maintMarginRatio", &[]));
m.insert("maxLeverage".to_string(), Value::Null);
m.insert("info".to_string(), tier.clone());
m
}));
}
}
return tiers;
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut section = 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 type_var: Value = get_value(§ion, &Value::Int(0));
let mut version: Value = get_value(§ion, &Value::Int(1));
let mut access: Value = get_value(§ion, &Value::Int(2));
let mut isSandbox: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
let mut url: Value = self.implode_hostname(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &type_var));
if is_true(&(is_equal(&isSandbox, &Value::Bool(true)))) && is_equal(&url, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" does not have a testnet/sandbox URL for ".to_string())), &type_var), &Value::Str(" endpoints".to_string()))));
}
path = self.implode_params(path.clone(), params.clone());
let mut versionIsTransfer: bool = is_equal(&version, &Value::Str("transfer".to_string()));
let mut versionIsAsset: bool = is_equal(&version, &Value::Str("asset".to_string()));
if is_true(&versionIsTransfer) || is_true(&versionIsAsset) {
if is_true(&versionIsTransfer) {
type_var = Value::Str("account/transfer".to_string());
} else {
type_var = Value::Str("api/asset".to_string());
}
version = get_value(§ion, &Value::Int(2));
access = get_value(§ion, &Value::Int(3));
}
let mut flatAccountPaths: Value = Value::List(vec![Value::Str("account/apiPermissions".to_string()), Value::Str("account/apiRestrictions".to_string())]);
if !is_true(&self.in_array(path.clone(), flatAccountPaths.clone())) {
if is_equal(&type_var, &Value::Str("spot".to_string())) && is_equal(&version, &Value::Str("v3".to_string())) {
url = add(&url, &Value::Str("/api".to_string()));
} else {
url = add(&url, &add(&Value::Str("/".to_string()), &type_var));
}
}
url = add(&url, &add(&add(&add(&Value::Str("/".to_string()), &version), &Value::Str("/".to_string())), &path));
params = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
add_element_to_object(&mut params, &Value::Str("timestamp".to_string()), self.nonce());
params = self.keysort(params.clone(), &[]);
if is_equal(&access, &Value::Str("public".to_string())) {
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(params.clone(), &[])));
}
} else if is_equal(&access, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut isJsonContentType: bool = is_true(&(is_true(&(is_equal(&type_var, &Value::Str("subAccount".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("account/transfer".to_string())))))) && is_true(&(is_equal(&method, &Value::Str("POST".to_string()))));
let mut parsedParams: Value = Value::Null;
let mut encodeRequest: Value = Value::Null;
if is_true(&isJsonContentType) {
encodeRequest = self.custom_encode(params.clone());
} else {
parsedParams = self.parse_params(params.clone());
encodeRequest = self.rawencode(parsedParams.clone(), &[Value::Bool(true)]);
}
let mut encodeRequestSafe: Value = ternary(is_true(&(is_equal(&encodeRequest, &Value::Null))), Value::Str("".to_string()), encodeRequest.clone());
let mut signature: Value = self.hmac(self.encode(encodeRequestSafe.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("X-BX-APIKEY".to_string(), self.apiKey.clone());
m.insert("X-SOURCE-KEY".to_string(), self.safe_string_k(self.options.clone(), "broker", &[Value::Str("CCXT".to_string())]));
m
});
if is_true(&isJsonContentType) {
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
add_element_to_object(&mut params, &Value::Str("signature".to_string()), signature.clone());
body = self.json(params.clone());
} else {
let mut query: Value = self.urlencode(parsedParams.clone(), &[Value::Bool(true)]);
url = add(&url, &add(&add(&add(&add(&Value::Str("?".to_string()), &query), &Value::Str("&".to_string())), &Value::Str("signature=".to_string())), &signature));
}
}
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 nonce(&self) -> Value {
return self.milliseconds();
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 handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
//
// {
// "code": 80014,
// "msg": "Invalid parameters, err:Key: 'GetTickerRequest.Symbol' Error:Field validation for "Symbol" failed on the "len=0|endswith=-USDT" tag",
// "data": {
// }
// }
//
let mut code: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut message: Value = self.safe_string_k(response.clone(), "msg", &[]);
let mut transferErrorMsg: Value = self.safe_string_k(response.clone(), "transferErrorMsg", &[]); // handling with errors from transfer endpoint
if is_true(&(!is_equal(&transferErrorMsg, &Value::Null))) || is_true(&(!is_equal(&code, &Value::Null) && !is_equal(&code, &Value::Str("0".to_string())))) {
if !is_equal(&transferErrorMsg, &Value::Null) {
message = transferErrorMsg.clone();
}
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), message.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}