// 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 BybitCore {
pub exchange: crate::exchange::Exchange,
}
impl BybitCore {
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 = BybitCore::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 BybitCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_order(self, order, &[market.clone()])
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::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 BybitCore.
BybitCore::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 BybitCore.
BybitCore::parse_deposit_address(self, depositAddress, &[currency.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_ledger_entry(self, entry, &[currency.clone()])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::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 BybitCore.
BybitCore::parse_liquidation(self, liquidation, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_borrow_interest(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_borrow_interest(self, info, &[market.clone()])
}
fn parse_adl_rank(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_adl_rank(self, info, &[market.clone()])
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_income(self, info, &[market.clone()])
}
fn parse_greeks(&self, greeks: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_greeks(self, greeks, &[market.clone()])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_margin_mode(self, margin_mode, &[market.clone()])
}
fn parse_conversion(&self, conversion: crate::Value, from_currency: crate::Value, to_currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_conversion(self, conversion, &[from_currency.clone(), to_currency.clone()])
}
fn parse_borrow_rate(&self, info: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::parse_borrow_rate(self, info, &[currency.clone()])
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::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 BybitCore.
BybitCore::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 BybitCore.
BybitCore::parse_deposit_withdraw_fee(self, fee, &[currency.clone()])
}
fn create_expired_option_market(&self, symbol: crate::Value) -> crate::Value {
// Forward to the inherent method on BybitCore.
BybitCore::create_expired_option_market(self, symbol)
}
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 BybitCore.
BybitCore::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 BybitCore.
BybitCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BybitCore {
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_pagination_cursor_to_result" => self.add_pagination_cursor_to_result(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"borrow_cross_margin" => self.borrow_cross_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_order_request" => self.cancel_order_request(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders_for_symbols" => self.cancel_orders_for_symbols(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_convert_trade" => self.create_convert_trade(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_expired_option_market" => self.create_expired_option_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_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,
"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,
"edit_order_request" => self.edit_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()[..]),
"edit_orders" => self.edit_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_all_greeks" => self.fetch_all_greeks(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_bids_asks" => self.fetch_bids_asks(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_interest" => self.fetch_borrow_interest(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_rate_history" => self.fetch_borrow_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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_order" => self.fetch_closed_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_convert_currencies" => self.fetch_convert_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_convert_quote" => self.fetch_convert_quote(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,
"fetch_convert_trade" => self.fetch_convert_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_convert_trade_history" => self.fetch_convert_trade_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_cross_borrow_rate" => self.fetch_cross_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_derivatives_market_leverage_tiers" => self.fetch_derivatives_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_derivatives_open_interest_history" => self.fetch_derivatives_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_future_markets" => self.fetch_future_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_greeks" => self.fetch_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_long_short_ratio_history" => self.fetch_long_short_ratio_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_mode" => self.fetch_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_settlement_history" => self.fetch_my_settlement_history(&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_interest_history" => self.fetch_open_interest_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_order" => self.fetch_open_order(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_option" => self.fetch_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option_chain" => self.fetch_option_chain(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_option_markets" => self.fetch_option_markets(args.get(0).cloned().unwrap_or(crate::Value::Null)).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_classic" => self.fetch_order_classic(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_orders_classic" => self.fetch_orders_classic(&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_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_adl_rank" => self.fetch_positions_adl_rank(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_history" => self.fetch_positions_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_settlement_history" => self.fetch_settlement_history(&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_status" => self.fetch_status(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transfers" => self.fetch_transfers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_volatility_history" => self.fetch_volatility_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"get_amount" => self.get_amount(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"get_bybit_type" => self.get_bybit_type(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()[..]),
"get_cost" => self.get_cost(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"get_leverage_tiers_paginated" => self.get_leverage_tiers_paginated(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"get_price" => self.get_price(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"is_unified_enabled" => self.is_unified_enabled(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"nonce" => self.nonce(),
"parse_adl_rank" => self.parse_adl_rank(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_borrow_interest" => self.parse_borrow_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_borrow_rate" => self.parse_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_conversion" => self.parse_conversion(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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_greeks" => self.parse_greeks(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_ledger_entry" => self.parse_ledger_entry(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_leverage" => self.parse_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_leverage_tiers" => self.parse_leverage_tiers(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_long_short_ratio" => self.parse_long_short_ratio(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_loan" => self.parse_margin_loan(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_mode_type" => self.parse_margin_mode_type(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_option" => self.parse_option(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_settlement" => self.parse_settlement(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_settlements" => self.parse_settlements(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_time_in_force" => self.parse_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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)),
"parse_volatility_history" => self.parse_volatility_history(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"repay_cross_margin" => self.repay_cross_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,
"safe_market" => self.safe_market(&args.get(0..).unwrap_or(&[]).to_vec()[..]),
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"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,
"upgrade_unified_trade_account" => self.upgrade_unified_trade_account(&args.get(0..).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 BybitCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BybitCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BybitCore {
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("bybit".to_string()));
m.insert("name".to_string(), Value::Str("Bybit".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("VG".to_string())]));
m.insert("version".to_string(), Value::Str("v5".to_string()));
m.insert("userAgent".to_string(), Value::Null);
m.insert("rateLimit".to_string(), Value::Int(20));
m.insert("hostname".to_string(), Value::Str("bybit.com".to_string()));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("certified".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Bool(true));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(true));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(true));
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("cancelOrdersForSymbols".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(false));
m.insert("createConvertTrade".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".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("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(true));
m.insert("createStopLossOrder".to_string(), Value::Bool(true));
m.insert("createStopMarketOrder".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("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("editOrders".to_string(), Value::Bool(true));
m.insert("fetchAllGreeks".to_string(), Value::Bool(true));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(true));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrder".to_string(), Value::Bool(true));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(true));
m.insert("fetchConvertQuote".to_string(), Value::Bool(true));
m.insert("fetchConvertTrade".to_string(), Value::Bool(true));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposit".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(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::Str("emulated".to_string()));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(true));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(true));
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("fetchMyLiquidations".to_string(), Value::Bool(true));
m.insert("fetchMySettlementHistory".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("fetchOpenInterestHistory".to_string(), Value::Bool(true));
m.insert("fetchOpenOrder".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(true));
m.insert("fetchOptionChain".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionADLRank".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsADLRank".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(true));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(true));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(true));
m.insert("fetchStatus".to_string(), Value::Bool(true));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(true));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("repayCrossMargin".to_string(), Value::Bool(true));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".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("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1".to_string()));
m.insert("3m".to_string(), Value::Str("3".to_string()));
m.insert("5m".to_string(), Value::Str("5".to_string()));
m.insert("15m".to_string(), Value::Str("15".to_string()));
m.insert("30m".to_string(), Value::Str("30".to_string()));
m.insert("1h".to_string(), Value::Str("60".to_string()));
m.insert("2h".to_string(), Value::Str("120".to_string()));
m.insert("4h".to_string(), Value::Str("240".to_string()));
m.insert("6h".to_string(), Value::Str("360".to_string()));
m.insert("12h".to_string(), Value::Str("720".to_string()));
m.insert("1d".to_string(), Value::Str("D".to_string()));
m.insert("1w".to_string(), Value::Str("W".to_string()));
m.insert("1M".to_string(), Value::Str("M".to_string()));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("https://api-testnet.{hostname}".to_string()));
m.insert("futures".to_string(), Value::Str("https://api-testnet.{hostname}".to_string()));
m.insert("v2".to_string(), Value::Str("https://api-testnet.{hostname}".to_string()));
m.insert("public".to_string(), Value::Str("https://api-testnet.{hostname}".to_string()));
m.insert("private".to_string(), Value::Str("https://api-testnet.{hostname}".to_string()));
m
}));
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/97a5d0b3-de10-423d-90e1-6620960025ed".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("https://api.{hostname}".to_string()));
m.insert("futures".to_string(), Value::Str("https://api.{hostname}".to_string()));
m.insert("v2".to_string(), Value::Str("https://api.{hostname}".to_string()));
m.insert("public".to_string(), Value::Str("https://api.{hostname}".to_string()));
m.insert("private".to_string(), Value::Str("https://api.{hostname}".to_string()));
m
}));
m.insert("demotrading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("https://api-demo.{hostname}".to_string()));
m.insert("futures".to_string(), Value::Str("https://api-demo.{hostname}".to_string()));
m.insert("v2".to_string(), Value::Str("https://api-demo.{hostname}".to_string()));
m.insert("public".to_string(), Value::Str("https://api-demo.{hostname}".to_string()));
m.insert("private".to_string(), Value::Str("https://api-demo.{hostname}".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.bybit.com".to_string()));
m.insert("doc".to_string(), Value::List(vec![Value::Str("https://bybit-exchange.github.io/docs/inverse/".to_string()), Value::Str("https://bybit-exchange.github.io/docs/linear/".to_string()), Value::Str("https://github.com/bybit-exchange".to_string())]));
m.insert("fees".to_string(), Value::Str("https://help.bybit.com/hc/en-us/articles/360039261154".to_string()));
m.insert("referral".to_string(), Value::Str("https://www.bybit.com/invite?ref=XDK12WP".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/v3/public/symbols".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/quote/depth".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/quote/depth/merged".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/quote/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/quote/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/quote/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/quote/ticker/price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/quote/ticker/bookTicker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/server-time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/infos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/margin-product-infos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/v3/public/margin-ensure-tokens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v3/public/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/public/copytrading/symbol/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/order-book/L2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/instruments-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/mark-price-kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/index-price-kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/funding/history-funding-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/risk-limit/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/delivery-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/recent-trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/open-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("derivatives/v3/public/insurance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/announcements/index".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/system/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/mark-price-kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/index-price-kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/premium-index-price-kline".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/instruments-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/rpi_orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/full_orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/funding/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/recent-trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/open-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/historical-volatility".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/insurance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/risk-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/delivery-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/new-delivery-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/account-ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/index-price-components".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/price-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/adlAlert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/market/fee-group-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-lever-token/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-lever-token/reference".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-cross-margin-trade/data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-cross-margin-trade/pledge-token".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-cross-margin-trade/borrow-token".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/collateral-data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/loanable-data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan-common/loanable-data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan-common/collateral-data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan-fixed/supply-order-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan-fixed/borrow-order-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/product-infos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/ensure-tokens-convert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/earn/product".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
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("v5/market/instruments-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/private/wallet/fund/records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("spot/v3/private/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/open-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/history-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/my-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/reference".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/cross-margin-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/v3/private/cross-margin-account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/v3/private/cross-margin-loan-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/v3/private/cross-margin-repay-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/v3/private/margin-loan-infos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/v3/private/margin-repaid-infos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/v3/private/margin-ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("asset/v3/private/transfer/inter-transfer/list/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/v3/private/transfer/sub-member/list/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/v3/private/transfer/sub-member-transfer/list/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/v3/private/transfer/universal-transfer/list/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("asset/v3/private/coin-info/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("asset/v3/private/deposit/address/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("contract/v3/private/copytrading/order/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("contract/v3/private/copytrading/position/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("contract/v3/private/copytrading/wallet/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("contract/v3/private/position/limit-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("contract/v3/private/order/unfilled-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/order/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/execution/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/closed-pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/account/wallet/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/account/fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/account/wallet/fund-records".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/order/unfilled-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/order/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/position/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/execution/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/delivery-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/settlement-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/account/wallet/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/account/transaction-log".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/account/borrow-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/account/borrow-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/account/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("user/v3/private/frozen-sub-member".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/v3/private/query-sub-members".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("user/v3/private/query-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("user/v3/private/get-member-type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/v3/private/transfer/transfer-coin/list/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/v3/private/transfer/account-coin/balance/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/v3/private/transfer/account-coins/balance/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("asset/v3/private/transfer/asset-info/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/v3/public/deposit/allowed-deposit-list/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.17));
m
}));
m.insert("asset/v3/private/deposit/record/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("asset/v3/private/withdraw/record/query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/order/realtime".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/order/spot-borrow-check".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/position/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/execution/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/closed-pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/get-closed-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/move-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/symbol-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/pre-upgrade/order/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/pre-upgrade/execution/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/pre-upgrade/position/closed-pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/pre-upgrade/account/transaction-log".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/pre-upgrade/asset/delivery-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/pre-upgrade/asset/settlement-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/wallet-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/borrow-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/instruments-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/collateral-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/option-asset-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/asset/coin-greeks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/account/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/transaction-log".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(1.66));
m
}));
m.insert("v5/account/contract-transaction-log".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/query-dcp-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/user-setting-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/pay-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/trade-info-for-analysis".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/smp-group".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/account/mmp-state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/asset-overview".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/exchange/query-coin-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.5));
m
}));
m.insert("v5/asset/exchange/convert-result-query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.5));
m
}));
m.insert("v5/asset/exchange/query-convert-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.5));
m
}));
m.insert("v5/asset/exchange/order-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/fundinghistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/portfolio-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/total-members-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/delivery-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/settlement-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/transfer/query-asset-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/transfer/query-account-coins-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("v5/asset/transfer/query-account-coin-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/transfer/query-transfer-coin-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/transfer/query-inter-transfer-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/transfer/query-sub-member-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/transfer/query-universal-transfer-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("v5/asset/deposit/query-allowed-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/deposit/query-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/deposit/query-sub-member-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/deposit/query-internal-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/deposit/query-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/deposit/query-sub-member-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/coin/query-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(28));
m
}));
m.insert("v5/asset/withdraw/query-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/withdraw/query-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/withdraw/withdrawable-amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/withdraw/vasp/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/covert/small-balance-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/covert/small-balance-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/convert/small-balance-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/convert/small-balance-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/fiat/query-coin-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/fiat/reference-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/fiat/trade-query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/fiat/query-trade-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/fiat/balance-query".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/query-sub-members".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/query-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/sub-apikeys".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/get-member-type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/aff-customer-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/del-submember".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/submembers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/escrow_sub_members".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/user/invitation/referrals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/affiliate/aff-user-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/affiliate/affiliate-sub-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-lever-token/order-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/spot-margin-trade/flexible-available-inventory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/interest-rate-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/max-borrowable".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/position-tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/coinstate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/currency-data".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/fixedborrow-contract-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/fixedborrow-order-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/fixedborrow-order-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/liability".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/repayment-available-amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/get-auto-repay-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-cross-margin-trade/loan-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/spot-cross-margin-trade/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/spot-cross-margin-trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/spot-cross-margin-trade/repay-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/crypto-loan/borrowable-collateralisable-number".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/ongoing-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/repayment-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/borrow-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/max-collateral-amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/adjustment-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan-common/max-collateral-amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-common/adjustment-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-common/position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-flexible/ongoing-coin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-flexible/borrow-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-flexible/repayment-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-fixed/borrow-contract-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-fixed/supply-contract-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-fixed/borrow-order-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-fixed/renew-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-fixed/supply-order-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-fixed/repayment-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/ins-loan/product-infos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/ensure-tokens".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/ensure-tokens-convert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/loan-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/repaid-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/ltv-convert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/coin-delta-amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/lending/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/lending/history-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/lending/account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/broker/earning-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/broker/earnings-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/broker/account-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/broker/asset/query-sub-member-deposit-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/earn/product".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/earn/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/earn/position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/earn/yield".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/earn/hourly-yield".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("spot/v3/private/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/cancel-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/cancel-orders-by-ids".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/purchase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("spot/v3/private/cross-margin-loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("spot/v3/private/cross-margin-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("asset/v3/private/transfer/inter-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(150));
m
}));
m.insert("asset/v3/private/withdraw/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(300));
m
}));
m.insert("asset/v3/private/withdraw/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/v3/private/transfer/sub-member-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(150));
m
}));
m.insert("asset/v3/private/transfer/transfer-sub-member-save".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(150));
m
}));
m.insert("asset/v3/private/transfer/universal-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/v3/private/create-sub-member".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/v3/private/create-sub-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/v3/private/update-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/v3/private/delete-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/v3/private/update-sub-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("user/v3/private/delete-sub-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("contract/v3/private/copytrading/order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("contract/v3/private/copytrading/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("contract/v3/private/copytrading/order/close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("contract/v3/private/copytrading/position/close".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("contract/v3/private/copytrading/position/set-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(40));
m
}));
m.insert("contract/v3/private/copytrading/wallet/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(25));
m
}));
m.insert("contract/v3/private/copytrading/order/trading-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("contract/v3/private/order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/order/cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/order/replace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/set-auto-add-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/switch-isolated".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/switch-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/switch-tpsl-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/set-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/trading-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/position/set-risk-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("contract/v3/private/account/setMarginMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("unified/v3/private/order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("unified/v3/private/order/replace".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("unified/v3/private/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("unified/v3/private/order/create-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("unified/v3/private/order/replace-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("unified/v3/private/order/cancel-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("unified/v3/private/order/cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("unified/v3/private/position/set-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("unified/v3/private/position/tpsl/switch-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("unified/v3/private/position/set-risk-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("unified/v3/private/position/trading-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("unified/v3/private/account/upgrade-unified-account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("unified/v3/private/account/setMarginMode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("fht/compliance/tax/v3/private/registertime".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("fht/compliance/tax/v3/private/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("fht/compliance/tax/v3/private/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("fht/compliance/tax/v3/private/url".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/order/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("v5/order/amend".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/order/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("v5/order/cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/order/create-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/order/amend-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/order/cancel-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/order/disconnected-cancel-all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/order/pre-check".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/set-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/switch-isolated".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/set-tpsl-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/switch-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/set-risk-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/trading-stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/set-auto-add-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/add-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/move-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/position/confirm-pending-mmr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/upgrade-to-uta".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/quick-repayment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/set-margin-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/set-hedging-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/mmp-modify".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/mmp-reset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/no-convert-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/set-limit-px-action".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/set-delta-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/exchange/quote-apply".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/asset/exchange/convert-execute".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v5/asset/transfer/inter-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/transfer/save-transfer-sub-member".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(150));
m
}));
m.insert("v5/asset/transfer/universal-transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/deposit/deposit-to-account".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/travel-rule/deposit/submit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/asset/withdraw/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/withdraw/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/asset/covert/get-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/asset/covert/small-balance-execute".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/fiat/quote-apply".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/fiat/trade-execute".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/create-sub-member".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/create-sub-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/frozen-sub-member".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/update-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/update-sub-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/delete-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/delete-sub-api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/agreement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/user/create-demo-member".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/spot-lever-token/purchase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("v5/spot-lever-token/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("v5/spot-margin-trade/switch-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/set-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/set-auto-repay-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/fixedborrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-margin-trade/fixedborrow-renew".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/spot-cross-margin-trade/loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("v5/spot-cross-margin-trade/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("v5/spot-cross-margin-trade/switch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(2.5));
m
}));
m.insert("v5/crypto-loan/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan/adjust-ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/crypto-loan-common/adjust-ltv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-common/max-loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("v5/crypto-loan-flexible/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-flexible/repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-flexible/repay-collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-fixed/borrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-fixed/renew".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-fixed/supply".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-fixed/borrow-order-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-fixed/supply-order-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-fixed/fully-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/crypto-loan-fixed/repay-collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("v5/ins-loan/association-uid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/ins-loan/repay-loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/lending/purchase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/lending/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/lending/redeem-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/set-collateral-switch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/set-collateral-switch-batch".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/account/demo-apply-money".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/broker/award/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/broker/award/distribute-award".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/broker/award/distribution-record".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v5/earn/place-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m
}));
m
}));
m
}));
m.insert("httpExceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("403".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("-10009".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1021".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1103".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-1140".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-1197".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-2013".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("-2015".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-6017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-6025".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-6029".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("5004".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("7001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10002".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("10003".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("10004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("10005".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10006".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("10007".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("10008".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("10009".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("10010".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10016".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("10017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("10018".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("10020".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10024".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10027".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10028".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("10029".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("12137".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("12201".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("12141".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("100028".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("110001".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("110003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110004".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110006".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110007".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110012".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110013".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110014".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110015".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110019".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110020".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110021".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110022".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110023".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110024".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110025".to_string(), Value::Str("NoChange".to_string()).clone());
m.insert("110026".to_string(), Value::Str("MarginModeAlreadySet".to_string()).clone());
m.insert("110027".to_string(), Value::Str("NoChange".to_string()).clone());
m.insert("110028".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110029".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110030".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110031".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110032".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110033".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110034".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110035".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110036".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110037".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110038".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110039".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110040".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110041".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110042".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110043".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110044".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110045".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110046".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110047".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110048".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110049".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110050".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110051".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110052".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110053".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("110054".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110055".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110056".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110057".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110058".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110059".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110060".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110061".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110062".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("110063".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("110064".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110065".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("110066".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("110067".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("110068".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("110069".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("110070".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110071".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("110072".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110073".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("110092".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110093".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("110094".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("130021".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("130074".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("131001".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("131084".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131200".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131201".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131202".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131203".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131204".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131205".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131206".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131207".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131208".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131209".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131210".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131211".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131212".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("131213".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131214".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131215".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131216".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131217".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131231".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("131232".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("131002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131003".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("131085".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("131086".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131088".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131089".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131090".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131091".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131092".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131093".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131094".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131095".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131096".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("131097".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131098".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("131099".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("140001".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("140003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140004".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140006".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140007".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140012".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140013".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140014".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140015".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140019".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140020".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140021".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140022".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140023".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140024".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140025".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140026".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140027".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140028".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140029".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140030".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140031".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140032".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140033".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140034".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140035".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140036".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140037".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140038".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140039".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140040".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140041".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140042".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140043".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140044".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140045".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140046".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140047".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140048".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140049".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140050".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140051".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140052".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140053".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("140054".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140055".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140056".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140057".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140058".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140059".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140060".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140061".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140062".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("140063".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("140064".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("140065".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("140066".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("140067".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("140068".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("140069".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("140070".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("170005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170007".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("170010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170019".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170031".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("170032".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("170033".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("170034".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("170035".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("170036".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("170037".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("170105".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("170115".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170116".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170117".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170121".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170124".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170130".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("170131".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("170132".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170133".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170134".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170135".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170136".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170137".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170139".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170140".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170141".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170142".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170143".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170144".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170145".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170146".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170147".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170148".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170149".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("170150".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("170151".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170157".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170159".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170190".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170191".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170192".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170193".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170194".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170195".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170196".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170197".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170198".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170199".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170200".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170201".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("170202".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170203".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170204".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170206".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170209".to_string(), Value::Str("RestrictedLocation".to_string()).clone());
m.insert("170210".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170213".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("170217".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170218".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170221".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("170222".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("170223".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("170224".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("170226".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("170227".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("170228".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170229".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170234".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("170241".to_string(), Value::Str("ManualInteractionNeeded".to_string()).clone());
m.insert("170371".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("170372".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175003".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("175004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175006".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("175007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175010".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("175012".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175013".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175015".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("175027".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("176002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176005".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176008".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176007".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176010".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176009".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176012".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176011".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176013".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176015".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("176016".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176019".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176020".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176021".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176022".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176023".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176024".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176025".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176026".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176027".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176028".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176029".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176030".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176031".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176034".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176035".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("176036".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("176037".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("176038".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176039".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("176040".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("181000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("181001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("181002".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("181003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("181004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("182000".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("181017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20001".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("20003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20010".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20012".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20013".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20015".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20018".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20019".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20020".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20021".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("20022".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20023".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20031".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20070".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20071".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("20084".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("30003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30009".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30010".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("30011".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("30012".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("30013".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("30014".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30015".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30016".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30017".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30018".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30019".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30020".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30021".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30022".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30023".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30024".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30025".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30026".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30027".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30028".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30029".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30030".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30031".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("30032".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30033".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("30034".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("30035".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("30036".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30037".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30041".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30042".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("30043".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30044".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30045".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30049".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("30050".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30051".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30052".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30054".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30057".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30063".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30067".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("30068".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("30074".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30075".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("30078".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("33004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("34026".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("34036".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("35015".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("340099".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("3400045".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("3100116".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3100198".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("3200300".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Not supported symbols".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("Request timeout".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("unknown orderInfo".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("invalid api_key".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("oc_diff".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("new_oc".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("openapi sign params error!".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("enableDemoTrading".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("usePrivateInstrumentsInfo".to_string(), Value::Bool(false));
m.insert("types".to_string(), Value::List(vec![Value::Str("spot".to_string()), Value::Str("linear".to_string()), Value::Str("inverse".to_string()), Value::Str("option".to_string())]));
m.insert("options".to_string(), Value::List(vec![Value::Str("BTC".to_string()), Value::Str("ETH".to_string()), Value::Str("SOL".to_string()), Value::Str("XRP".to_string()), Value::Str("MNT".to_string()), Value::Str("DOGE".to_string())]));
m.insert("loadAllOptions".to_string(), Value::Bool(false));
m.insert("loadExpiredOptions".to_string(), Value::Bool(false));
m
}));
m.insert("enableUnifiedMargin".to_string(), Value::Null);
m.insert("enableUnifiedAccount".to_string(), Value::Null);
m.insert("unifiedMarginStatus".to_string(), Value::Null);
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(false));
m
}));
m.insert("createUnifiedMarginAccount".to_string(), Value::Bool(false));
m.insert("defaultType".to_string(), Value::Str("swap".to_string()));
m.insert("defaultSubType".to_string(), Value::Str("linear".to_string()));
m.insert("defaultSettle".to_string(), Value::Str("USDT".to_string()));
m.insert("code".to_string(), Value::Str("BTC".to_string()));
m.insert("recvWindow".to_string(), multiply(&Value::Int(5), &Value::Int(1000)));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("brokerId".to_string(), Value::Str("CCXT".to_string()));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("margin".to_string(), Value::Str("SPOT".to_string()));
m.insert("future".to_string(), Value::Str("CONTRACT".to_string()));
m.insert("swap".to_string(), Value::Str("CONTRACT".to_string()));
m.insert("option".to_string(), Value::Str("OPTION".to_string()));
m.insert("investment".to_string(), Value::Str("INVESTMENT".to_string()));
m.insert("unified".to_string(), Value::Str("UNIFIED".to_string()));
m.insert("funding".to_string(), Value::Str("FUND".to_string()));
m.insert("fund".to_string(), Value::Str("FUND".to_string()));
m.insert("contract".to_string(), Value::Str("CONTRACT".to_string()));
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SPOT".to_string(), Value::Str("spot".to_string()));
m.insert("MARGIN".to_string(), Value::Str("spot".to_string()));
m.insert("CONTRACT".to_string(), Value::Str("contract".to_string()));
m.insert("OPTION".to_string(), Value::Str("option".to_string()));
m.insert("INVESTMENT".to_string(), Value::Str("investment".to_string()));
m.insert("UNIFIED".to_string(), Value::Str("unified".to_string()));
m.insert("FUND".to_string(), Value::Str("fund".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("BRC20".to_string(), Value::Str("BTC".to_string()));
m.insert("ETH".to_string(), Value::Str("ETH".to_string()));
m.insert("ERC20".to_string(), Value::Str("ETH".to_string()));
m.insert("TRX".to_string(), Value::Str("TRX".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRX".to_string()));
m.insert("BSC".to_string(), Value::Str("BSC".to_string()));
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("SOL".to_string(), Value::Str("SOL".to_string()));
m.insert("ACA".to_string(), Value::Str("ACA".to_string()));
m.insert("ADA".to_string(), Value::Str("ADA".to_string()));
m.insert("ALGO".to_string(), Value::Str("ALGO".to_string()));
m.insert("APT".to_string(), Value::Str("APTOS".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("ARBI".to_string()));
m.insert("ARBITRUM_NOVA".to_string(), Value::Str("ARBINOVA".to_string()));
m.insert("AVAXC".to_string(), Value::Str("CAVAX".to_string()));
m.insert("AVAXX".to_string(), Value::Str("XAVAX".to_string()));
m.insert("COSMOS".to_string(), Value::Str("ATOM".to_string()));
m.insert("ATOM".to_string(), Value::Str("ATOM".to_string()));
m.insert("BCH".to_string(), Value::Str("BCH".to_string()));
m.insert("BEP2".to_string(), Value::Str("BNB".to_string()));
m.insert("DOGE".to_string(), Value::Str("DOGE".to_string()));
m.insert("DOT".to_string(), Value::Str("DOT".to_string()));
m.insert("EGLD".to_string(), Value::Str("EGLD".to_string()));
m.insert("EOS".to_string(), Value::Str("EOS".to_string()));
m.insert("ETC".to_string(), Value::Str("ETC".to_string()));
m.insert("ETHW".to_string(), Value::Str("ETHW".to_string()));
m.insert("FIL".to_string(), Value::Str("FIL".to_string()));
m.insert("STEP".to_string(), Value::Str("FITFI".to_string()));
m.insert("SONIC".to_string(), Value::Str("SONIC".to_string()));
m.insert("GLMR".to_string(), Value::Str("GLMR".to_string()));
m.insert("HBAR".to_string(), Value::Str("HBAR".to_string()));
m.insert("ICP".to_string(), Value::Str("ICP".to_string()));
m.insert("KLAY".to_string(), Value::Str("KLAY".to_string()));
m.insert("LTC".to_string(), Value::Str("LTC".to_string()));
m.insert("POLYGON".to_string(), Value::Str("MATIC".to_string()));
m.insert("MATIC".to_string(), Value::Str("MATIC".to_string()));
m.insert("NEAR".to_string(), Value::Str("NEAR".to_string()));
m.insert("OASYS".to_string(), Value::Str("OAS".to_string()));
m.insert("OASIS".to_string(), Value::Str("ROSE".to_string()));
m.insert("ONE".to_string(), Value::Str("ONE".to_string()));
m.insert("OP".to_string(), Value::Str("OP".to_string()));
m.insert("SCRT".to_string(), Value::Str("SCRT".to_string()));
m.insert("STX".to_string(), Value::Str("STX".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("WAX".to_string(), Value::Str("WAXP".to_string()));
m.insert("XEC".to_string(), Value::Str("XEC".to_string()));
m.insert("XLM".to_string(), Value::Str("XLM".to_string()));
m.insert("XRP".to_string(), Value::Str("XRP".to_string()));
m.insert("XTZ".to_string(), Value::Str("XTZ".to_string()));
m.insert("ZIL".to_string(), Value::Str("ZIL".to_string()));
m.insert("ZKSYNCLITE".to_string(), Value::Str("ZKSYNC".to_string()));
m.insert("ZKSYNCERA".to_string(), Value::Str("ZKV2".to_string()));
m.insert("0G".to_string(), Value::Str("ZEROGRAVITY".to_string()));
m.insert("MANTLE".to_string(), Value::Str("MANTLE".to_string()));
m.insert("CHZ".to_string(), Value::Str("CHILIZ".to_string()));
m.insert("BASE".to_string(), Value::Str("BASE".to_string()));
m.insert("CELO".to_string(), Value::Str("CELO".to_string()));
m.insert("SCROLL".to_string(), Value::Str("SCROLL".to_string()));
m.insert("SUI".to_string(), Value::Str("SUI".to_string()));
m.insert("DYDX".to_string(), Value::Str("DYDX".to_string()));
m.insert("HUMANITY".to_string(), Value::Str("HUMANITY".to_string()));
m.insert("HYPER".to_string(), Value::Str("HYPEREVM".to_string()));
m.insert("MONAD".to_string(), Value::Str("MONAD".to_string()));
m.insert("MOVE".to_string(), Value::Str("MOVE".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("TRX".to_string(), Value::Str("TRC20".to_string()));
m.insert("BSC".to_string(), Value::Str("BEP20".to_string()));
m.insert("OP".to_string(), Value::Str("OP".to_string()));
m.insert("MATIC".to_string(), Value::Str("MATIC".to_string()));
m.insert("SPL".to_string(), Value::Str("SOL".to_string()));
m
}));
m.insert("defaultNetwork".to_string(), Value::Str("ERC20".to_string()));
m.insert("defaultNetworks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USDT".to_string(), Value::Str("TRC20".to_string()));
m
}));
m.insert("intervals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("5m".to_string(), Value::Str("5min".to_string()));
m.insert("15m".to_string(), Value::Str("15min".to_string()));
m.insert("30m".to_string(), Value::Str("30min".to_string()));
m.insert("1h".to_string(), Value::Str("1h".to_string()));
m.insert("4h".to_string(), Value::Str("4h".to_string()));
m.insert("1d".to_string(), Value::Str("1d".to_string()));
m
}));
m.insert("useMarkPriceForPositionCollateral".to_string(), Value::Bool(false));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(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(true));
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("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(false));
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
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(10));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), multiply(&Value::Int(365), &Value::Int(2)));
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(true));
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::Int(50));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("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(50));
m.insert("daysBack".to_string(), multiply(&Value::Int(365), &Value::Int(2)));
m.insert("daysBackCanceled".to_string(), Value::Int(1));
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m.insert("editOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(10));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m.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("triggerDirection".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("price".to_string(), Value::Bool(true));
m
}));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(true));
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("default".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".to_string()));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("feeSide".to_string(), Value::Str("get".to_string()));
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), Value::Float(0.00075));
m.insert("maker".to_string(), Value::Float(0.0001));
m
}));
m.insert("funding".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(false));
m.insert("percentage".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m.insert("rollingWindowSize".to_string(), Value::Int(5000));
m
})]);
Value::Null
}
/*
* @method
* @name bybit#enableDemoTrading
* @description enables or disables demo trading mode
* @see https://bybit-exchange.github.io/docs/v5/demo
* @param {boolean} [enable] true if demo trading should be enabled, false otherwise
*/
pub fn enable_demo_trading(&mut self, mut enable: Value) {
if is_true(&self.isSandboxModeEnabled) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" demo trading does not support in sandbox environment".to_string()))));
}
// enable demo trading in bybit, see: https://bybit-exchange.github.io/docs/v5/demo
if is_true(&enable) {
{ let __be_tmp = get_value(&self.urls, &Value::Str("api".to_string())); add_element_to_object(&mut self.urls, &Value::Str("apiBackupDemoTrading".to_string()), __be_tmp); };
{ let __be_tmp = get_value(&self.urls, &Value::Str("demotrading".to_string())); add_element_to_object(&mut self.urls, &Value::Str("api".to_string()), __be_tmp); };
} else if is_true(&Value::Bool(in_op(&self.urls, &Value::Str("apiBackupDemoTrading".to_string())))) {
{ let __be_tmp = get_value(&self.urls, &Value::Str("apiBackupDemoTrading".to_string())); add_element_to_object(&mut self.urls, &Value::Str("api".to_string()), __be_tmp); };
let mut newUrls: Value = self.omit(self.urls.clone(), Value::Str("apiBackupDemoTrading".to_string()), &[]);
self.urls = newUrls.clone();
}
add_element_to_object(&mut self.options, &Value::Str("enableDemoTrading".to_string()), enable.clone());
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
pub fn add_pagination_cursor_to_result(&self, mut response: Value) -> Value {
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_n(result.clone(), Value::List(vec![Value::Str("list".to_string()), Value::Str("rows".to_string()), Value::Str("data".to_string()), Value::Str("dataList".to_string())]), &[Value::List(vec![])]);
let mut paginationCursor: Value = self.safe_string2(result.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), &[]);
let mut dataLength: Value = get_array_length(&data);
if is_true(&(!is_equal(&paginationCursor, &Value::Null))) && is_true(&(is_greater_than(&dataLength, &Value::Int(0)))) {
let mut first: Value = get_value(&data, &Value::Int(0));
add_element_to_object(&mut first, &Value::Str("nextPageCursor".to_string()), paginationCursor.clone());
add_element_to_object(&mut data, &Value::Int(0), first.clone());
}
return data;
Value::Null
}
/*
* @method
* @name bybit#isUnifiedEnabled
* @see https://bybit-exchange.github.io/docs/v5/user/apikey-info#http-request
* @see https://bybit-exchange.github.io/docs/v5/account/account-info
* @description returns [enableUnifiedMargin, enableUnifiedAccount] so the user can check if unified account is enabled
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {any} [enableUnifiedMargin, enableUnifiedAccount]
*/
pub async fn is_unified_enabled(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
// The API key of user id must own one of permissions will be allowed to call following API endpoints:
// SUB UID: "Account Transfer"
// MASTER UID: "Account Transfer", "Subaccount Transfer", "Withdrawal"
let mut enableUnifiedMargin: Value = self.safe_bool_k(self.options.clone(), "enableUnifiedMargin", &[]);
let mut enableUnifiedAccount: Value = self.safe_bool_k(self.options.clone(), "enableUnifiedAccount", &[]);
if is_equal(&enableUnifiedMargin, &Value::Null) || is_equal(&enableUnifiedAccount, &Value::Null) {
if is_equal(&get_value(&self.options, &Value::Str("enableDemoTrading".to_string())), &Value::Bool(true)) {
// info endpoint is not available in demo trading
// so we're assuming UTA is enabled
add_element_to_object(&mut self.options, &Value::Str("enableUnifiedMargin".to_string()), Value::Bool(false));
add_element_to_object(&mut self.options, &Value::Str("enableUnifiedAccount".to_string()), Value::Bool(true));
add_element_to_object(&mut self.options, &Value::Str("unifiedMarginStatus".to_string()), Value::Int(6));
return Value::List(vec![get_value(&self.options, &Value::Str("enableUnifiedMargin".to_string())), get_value(&self.options, &Value::Str("enableUnifiedAccount".to_string()))]);
}
let mut rawPromises: Value = Value::List(vec![self.private_get_v5_user_query_api(&[params.clone()]).await, self.private_get_v5_account_info(&[params.clone()]).await]);
let mut promises: Value = promise_all(&rawPromises).await;
let mut response: Value = get_value(&promises, &Value::Int(0));
let mut accountInfo: Value = get_value(&promises, &Value::Int(1));
//
// {
// "retCode": 0,
// "retMsg": "",
// "result": {
// "id": "13770661",
// "note": "XXXXXX",
// "apiKey": "XXXXXX",
// "readOnly": 0,
// "secret": "",
// "permissions": {
// "ContractTrade": [...],
// "Spot": [...],
// "Wallet": [...],
// "Options": [...],
// "Derivatives": [...],
// "CopyTrading": [...],
// "BlockTrade": [...],
// "Exchange": [...],
// "NFT": [...],
// },
// "ips": [...],
// "type": 1,
// "deadlineDay": 83,
// "expiredAt": "2023-05-15T03:21:05Z",
// "createdAt": "2022-10-16T02:24:40Z",
// "unified": 0,
// "uta": 0,
// "userID": 24600000,
// "inviterID": 0,
// "vipLevel": "No VIP",
// "mktMakerLevel": "0",
// "affiliateID": 0,
// "rsaPublicKey": "",
// "isMaster": false
// },
// "retExtInfo": {},
// "time": 1676891757649
// }
// account info
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "marginMode": "REGULAR_MARGIN",
// "updatedTime": "1697078946000",
// "unifiedMarginStatus": 4,
// "dcpStatus": "OFF",
// "timeWindow": 10,
// "smpGroup": 0,
// "isMasterTrader": false,
// "spotHedgingStatus": "OFF"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut accountResult: Value = self.safe_dict_k(accountInfo.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
{ let __be_tmp = Value::Bool(is_equal(&self.safe_integer_k(result.clone(), "unified", &[]), &Value::Int(1))); add_element_to_object(&mut self.options, &Value::Str("enableUnifiedMargin".to_string()), __be_tmp); };
{ let __be_tmp = Value::Bool(is_equal(&self.safe_integer_k(result.clone(), "uta", &[]), &Value::Int(1))); add_element_to_object(&mut self.options, &Value::Str("enableUnifiedAccount".to_string()), __be_tmp); };
{ let __be_tmp = self.safe_integer_k(accountResult.clone(), "unifiedMarginStatus", &[Value::Int(6)]); add_element_to_object(&mut self.options, &Value::Str("unifiedMarginStatus".to_string()), __be_tmp); }; // default to uta 2.0 pro if not found
}
return Value::List(vec![get_value(&self.options, &Value::Str("enableUnifiedMargin".to_string())), get_value(&self.options, &Value::Str("enableUnifiedAccount".to_string()))]);
Value::Null
}
/*
* @method
* @name bybit#upgradeUnifiedTradeAccount
* @description upgrades the account to unified trade account *warning* this is irreversible
* @see https://bybit-exchange.github.io/docs/v5/account/upgrade-unified-account
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {any} nothing
*/
pub async fn upgrade_unified_trade_account(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.private_post_v5_account_upgrade_to_uta(&[params.clone()]).await;
Value::Null
}
pub fn create_expired_option_market(&self, mut symbol: Value) -> Value {
// support expired option contracts
let mut quote: Value = Value::Null;
let mut settle: Value = Value::Null;
let mut optionParts: Value = split(&symbol, &Value::Str("-".to_string()));
let mut symbolBase: Value = split(&symbol, &Value::Str("/".to_string()));
let mut base: Value = Value::Null;
let mut expiry: Value = Value::Null;
if is_greater_than(&get_index_of(&symbol, &Value::Str("/".to_string())), &negate(&Value::Int(1))) {
base = self.safe_string(symbolBase.clone(), Value::Int(0), &[]);
expiry = self.safe_string(optionParts.clone(), Value::Int(1), &[]);
let mut symbolQuoteAndSettle: Value = self.safe_string(symbolBase.clone(), Value::Int(1), &[]);
if is_equal(&symbolQuoteAndSettle, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" createExpiredOptionMarket() missing symbolQuoteAndSettle".to_string()))));
}
let mut splitQuote: Value = split(&symbolQuoteAndSettle, &Value::Str(":".to_string()));
let mut quoteAndSettle: Value = self.safe_string(splitQuote.clone(), Value::Int(0), &[]);
quote = quoteAndSettle.clone();
settle = quoteAndSettle.clone();
} else {
base = self.safe_string(optionParts.clone(), Value::Int(0), &[]);
expiry = self.convert_market_id_expire_date(self.safe_string(optionParts.clone(), Value::Int(1), &[]));
if is_true(&Value::Bool(ends_with(&symbol, &Value::Str("-USDT".to_string())))) {
quote = Value::Str("USDT".to_string());
settle = Value::Str("USDT".to_string());
} else {
quote = Value::Str("USDC".to_string());
settle = Value::Str("USDC".to_string());
}
}
let mut strike: Value = self.safe_string(optionParts.clone(), Value::Int(2), &[]);
let mut optionType: Value = self.safe_string(optionParts.clone(), Value::Int(3), &[]);
let mut datetime: Value = self.convert_expire_date(expiry.clone());
let mut timestamp: Value = self.parse8601(datetime.clone());
let mut amountPrecision: Value = Value::Null;
let mut pricePrecision: Value = Value::Null;
// hard coded amount and price precisions from fetchOptionMarkets
if is_equal(&base, &Value::Str("BTC".to_string())) {
amountPrecision = self.parse_number(Value::Str("0.01".to_string()), &[]);
pricePrecision = self.parse_number(Value::Str("5".to_string()), &[]);
} else if is_equal(&base, &Value::Str("ETH".to_string())) {
amountPrecision = self.parse_number(Value::Str("0.1".to_string()), &[]);
pricePrecision = self.parse_number(Value::Str("0.1".to_string()), &[]);
} else if is_equal(&base, &Value::Str("SOL".to_string())) {
amountPrecision = self.parse_number(Value::Str("1".to_string()), &[]);
pricePrecision = self.parse_number(Value::Str("0.01".to_string()), &[]);
}
let mut convertedExpireDate: Value = self.convert_expire_date_to_market_id_date(expiry.clone());
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), add(&add(&add(&add(&add(&add(&base, &Value::Str("-".to_string())), &convertedExpireDate), &Value::Str("-".to_string())), &strike), &Value::Str("-".to_string())), &optionType));
m.insert("symbol".to_string(), add(&add(&add(&add(&add(&add(&add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle), &Value::Str("-".to_string())), &expiry), &Value::Str("-".to_string())), &strike), &Value::Str("-".to_string())), &optionType));
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(), base.clone());
m.insert("quoteId".to_string(), quote.clone());
m.insert("settleId".to_string(), settle.clone());
m.insert("active".to_string(), Value::Bool(false));
m.insert("type".to_string(), Value::Str("option".to_string()));
m.insert("subType".to_string(), ternary(is_true(&(is_equal(&base, &settle))), Value::Str("inverse".to_string()), Value::Str("linear".to_string())));
m.insert("linear".to_string(), Value::Bool((!is_equal(&base, &settle))));
m.insert("inverse".to_string(), Value::Bool((is_equal(&base, &settle))));
m.insert("spot".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
m.insert("expiry".to_string(), timestamp.clone());
m.insert("expiryDatetime".to_string(), datetime.clone());
m.insert("optionType".to_string(), ternary(is_true(&(is_equal(&optionType, &Value::Str("C".to_string())))), Value::Str("call".to_string()), Value::Str("put".to_string())));
m.insert("strike".to_string(), self.parse_number(strike.clone(), &[]));
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amountPrecision.clone());
m.insert("price".to_string(), pricePrecision.clone());
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("info".to_string(), Value::Null);
m
});
Value::Null
}
pub fn safe_market(&self, optional_args: &[Value]) -> Value {
let mut marketId = get_arg(optional_args, 0, Value::Null);
let mut market = get_arg(optional_args, 1, Value::Null);
let mut delimiter = get_arg(optional_args, 2, Value::Null);
let mut marketType = get_arg(optional_args, 3, Value::Null);
let mut isOption: bool = is_true(&(!is_equal(&marketId, &Value::Null))) && is_true(&(is_true(&(is_greater_than(&get_index_of(&marketId, &Value::Str("-C".to_string())), &negate(&Value::Int(1))))) || is_true(&(is_greater_than(&get_index_of(&marketId, &Value::Str("-P".to_string())), &negate(&Value::Int(1)))))));
if is_true(&isOption) && is_true(&(is_true(&(is_equal(&self.markets_by_id, &Value::Null))) || !is_true(&(Value::Bool(in_op(&self.markets_by_id, &marketId)))))) {
return self.create_expired_option_market(marketId.clone());
}
return self.super_safe_market(marketId.clone(), market.clone(), delimiter.clone(), marketType.clone());
Value::Null
}
pub fn get_bybit_type(&self, mut method: Value, mut market: 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 = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(method.clone(), &[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(method.clone(), &[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("option".to_string())) || is_equal(&type_var, &Value::Str("spot".to_string())) {
return Value::List(vec![type_var.clone(), params.clone()]);
}
return Value::List(vec![subType.clone(), params.clone()]);
Value::Null
}
pub fn get_amount(&self, mut symbol: Value, mut amount: Value) -> Value {
// some markets like options might not have the precision available
// and we shouldn't crash in those cases
let mut market: Value = self.market(symbol.clone());
let mut emptyPrecisionAmount: bool = is_equal(&get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("amount".to_string())), &Value::Null);
let mut amountString: Value = self.number_to_string(amount.clone());
if !is_true(&emptyPrecisionAmount) && is_true(&(!is_equal(&amountString, &Value::Str("0".to_string())))) {
return self.amount_to_precision(symbol.clone(), amount.clone());
}
return amountString;
Value::Null
}
pub fn get_price(&self, mut symbol: Value, mut price: Value) -> Value {
if is_equal(&price, &Value::Null) {
return price;
}
let mut market: Value = self.market(symbol.clone());
let mut emptyPrecisionPrice: bool = is_equal(&get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("price".to_string())), &Value::Null);
if !is_true(&emptyPrecisionPrice) {
return self.price_to_precision(symbol.clone(), price.clone());
}
return price;
Value::Null
}
pub fn get_cost(&self, mut symbol: Value, mut cost: Value) -> Value {
let mut market: Value = self.market(symbol.clone());
let mut emptyPrecisionPrice: bool = is_equal(&get_value(&get_value(&market, &Value::Str("precision".to_string())), &Value::Str("price".to_string())), &Value::Null);
if !is_true(&emptyPrecisionPrice) {
return self.cost_to_precision(symbol.clone(), cost.clone());
}
return cost;
Value::Null
}
/*
* @method
* @name bybit#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://bybit-exchange.github.io/docs/v5/system-status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure](https://docs.ccxt.com/#/?id=exchange-status-structure)
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_v5_system_status(&[params.clone()]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "id": "f9d6842d-5331-11f0-8fd3-c241b123dd9e",
// "title": "t01",
// "state": "completed",
// "begin": "1751012688000",
// "end": "1751012760000",
// "href": "",
// "serviceTypes": [ 1, 2, 3, 4, 5 ],
// "product": [ 1, 2, 3, 4 ],
// "uidSuffix": [],
// "maintainType": 3,
// "env": 2
// }
// ]
// },
// "retExtInfo": {},
// "time": 1751858399649
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut list: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut status: Value = Value::Str("ok".to_string());
let mut eta: Value = Value::Null;
let mut url: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_476: bool = true;
while { if !__for_first_476 { i = add(&i, &Value::Int(1)); } __for_first_476 = false; is_less_than(&i, &get_array_length(&list)) } {
let mut event: Value = get_value(&list, &i);
let mut event: Value = get_value(&list, &i);
let mut state: Value = self.safe_string_k(event.clone(), "state", &[]);
if is_equal(&state, &Value::Str("ongoing".to_string())) {
status = Value::Str("maintenance".to_string());
eta = self.safe_integer_k(event.clone(), "end", &[]);
url = self.safe_string_k(event.clone(), "href", &[]);
break;
} else if is_equal(&state, &Value::Str("scheduled".to_string())) {
eta = self.safe_integer_k(event.clone(), "begin", &[]);
url = self.safe_string_k(event.clone(), "href", &[]);
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), status.clone());
m.insert("updated".to_string(), Value::Null);
m.insert("eta".to_string(), eta.clone());
m.insert("url".to_string(), url.clone());
m.insert("info".to_string(), response.clone());
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://bybit-exchange.github.io/docs/v5/market/time
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int} the current integer timestamp in milliseconds from the exchange server
*/
pub async fn fetch_time(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_v5_market_time(&[params.clone()]).await;
return self.safe_integer_k(response.clone(), "time", &[]);
Value::Null
}
/*
* @method
* @name bybit#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://bybit-exchange.github.io/docs/v5/asset/coin-info
* @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
});
}
if is_equal(&get_value(&self.options, &Value::Str("enableDemoTrading".to_string())), &Value::Bool(true)) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
let mut response: Value = self.private_get_v5_asset_coin_query_info(&[params.clone()]).await;
//
// {
// "retCode": 0,
// "retMsg": "",
// "result": {
// "rows": [
// {
// "name": "BTC",
// "coin": "BTC",
// "remainAmount": "150",
// "chains": [
// {
// "chainType": "BTC",
// "confirmation": "10000",
// "withdrawFee": "0.0005",
// "depositMin": "0.0005",
// "withdrawMin": "0.001",
// "chain": "BTC",
// "chainDeposit": "1",
// "chainWithdraw": "1",
// "minAccuracy": "8"
// }
// ]
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672194582264
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rows: Value = self.safe_list_k(data.clone(), "rows", &[Value::List(vec![])]);
return self.parse_currencies(rows.clone());
Value::Null
}
pub fn parse_currency(&self, mut currency: Value) -> Value {
let mut currencyId: Value = self.safe_string_k(currency.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut name: Value = self.safe_string_k(currency.clone(), "name", &[]);
let mut chains: Value = self.safe_list_k(currency.clone(), "chains", &[Value::List(vec![])]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut j: Value = Value::Int(0);
let mut __for_first_477: bool = true;
while { if !__for_first_477 { j = add(&j, &Value::Int(1)); } __for_first_477 = false; is_less_than(&j, &get_array_length(&chains)) } {
let mut chain: Value = get_value(&chains, &j);
let mut chain: Value = get_value(&chains, &j);
let mut networkId: Value = self.safe_string_k(chain.clone(), "chain", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut networks, &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Bool(is_equal(&self.safe_integer_k(chain.clone(), "chainDeposit", &[]), &Value::Int(1))));
m.insert("withdraw".to_string(), Value::Bool(is_equal(&self.safe_integer_k(chain.clone(), "chainWithdraw", &[]), &Value::Int(1))));
m.insert("fee".to_string(), self.safe_number_k(chain.clone(), "withdrawFee", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(chain.clone(), "minAccuracy", &[])]), &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(chain.clone(), "withdrawMin", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(chain.clone(), "depositMin", &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), currency.clone());
m.insert("code".to_string(), code.clone());
m.insert("id".to_string(), currencyId.clone());
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("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), networks.clone());
m.insert("type".to_string(), Value::Str("crypto".to_string()));
m
}));
Value::Null
}
/*
* @method
* @name bybit#fetchMarkets
* @description retrieves data on all markets for bybit
* @see https://bybit-exchange.github.io/docs/v5/market/instrument
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut promisesUnresolved: Value = Value::List(vec![]);
let mut types: Value = Value::Null;
let mut defaultTypes: Value = Value::List(vec![Value::Str("spot".to_string()), Value::Str("linear".to_string()), Value::Str("inverse".to_string()), Value::Str("option".to_string())]);
let mut fetchMarketsOptions: Value = self.safe_dict_k(self.options.clone(), "fetchMarkets", &[]);
if !is_equal(&fetchMarketsOptions, &Value::Null) {
types = self.safe_list_k(fetchMarketsOptions.clone(), "types", &[defaultTypes.clone()]);
} else {
// for backward-compatibility
types = self.safe_list_k(self.options.clone(), "fetchMarkets", &[defaultTypes.clone()]);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_479: bool = true;
while { if !__for_first_479 { i = add(&i, &Value::Int(1)); } __for_first_479 = false; is_less_than(&i, &get_array_length(&types)) } {
let mut marketType: Value = get_value(&types, &i);
let mut marketType: Value = get_value(&types, &i);
if is_equal(&marketType, &Value::Str("spot".to_string())) {
append_to_array(&mut promisesUnresolved, self.fetch_spot_markets(params.clone()).await);
} else if is_equal(&marketType, &Value::Str("linear".to_string())) {
append_to_array(&mut promisesUnresolved, self.fetch_future_markets(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), Value::Str("linear".to_string()));
m
})]).await);
} else if is_equal(&marketType, &Value::Str("inverse".to_string())) {
append_to_array(&mut promisesUnresolved, self.fetch_future_markets(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), Value::Str("inverse".to_string()));
m
})]).await);
} else if is_equal(&marketType, &Value::Str("option".to_string())) {
let mut optionsCurrencies: Value = self.safe_list_k(fetchMarketsOptions.clone(), "options", &[Value::List(vec![Value::Str("BTC".to_string()), Value::Str("ETH".to_string()), Value::Str("SOL".to_string())])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_478: bool = true;
while { if !__for_first_478 { j = add(&j, &Value::Int(1)); } __for_first_478 = false; is_less_than(&j, &get_array_length(&optionsCurrencies)) } {
let mut currency: Value = get_value(&optionsCurrencies, &j);
let mut currency: Value = get_value(&optionsCurrencies, &j);
append_to_array(&mut promisesUnresolved, self.fetch_option_markets(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("baseCoin".to_string(), currency.clone());
m
})).await);
}
}
} else {
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&add(&self.id, &Value::Str(" fetchMarkets() this.options fetchMarkets \"".to_string())), &marketType), &Value::Str("\" is not a supported market type".to_string()))));
}
}
}
let mut promises: Value = promise_all(&promisesUnresolved).await;
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_480: bool = true;
while { if !__for_first_480 { i = add(&i, &Value::Int(1)); } __for_first_480 = false; is_less_than(&i, &get_array_length(&promises)) } {
let mut parsedMarket: Value = get_value(&promises, &i);
let mut parsedMarket: Value = get_value(&promises, &i);
result = self.array_concat(result.clone(), parsedMarket.clone());
}
}
return result;
Value::Null
}
pub async fn fetch_spot_markets(&mut self, mut params: Value) -> Value {
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), Value::Str("spot".to_string()));
m
});
let mut usePrivateInstrumentsInfo: Value = self.handle_option(Value::Str("fetchMarkets".to_string()), Value::Str("usePrivateInstrumentsInfo".to_string()), &[Value::Bool(false)]);
let mut response: Value = Value::Null;
if is_equal(&usePrivateInstrumentsInfo, &Value::Bool(true)) {
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_market_instruments_info(&[__ws_arg_0]).await;
} else {
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_v5_market_instruments_info(&[__ws_arg_1]).await;
}
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "spot",
// "list": [
// {
// "symbol": "BTCUSDT",
// "baseCoin": "BTC",
// "quoteCoin": "USDT",
// "innovation": "0",
// "status": "Trading",
// "marginTrading": "both",
// "lotSizeFilter": {
// "basePrecision": "0.000001",
// "quotePrecision": "0.00000001",
// "minOrderQty": "0.00004",
// "maxOrderQty": "63.01197227",
// "minOrderAmt": "1",
// "maxOrderAmt": "100000"
// },
// "priceFilter": {
// "tickSize": "0.01"
// }
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672712468011
// }
//
let mut responseResult: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut markets: Value = self.safe_list_k(responseResult.clone(), "list", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
let mut takerFee: Value = self.parse_number(Value::Str("0.001".to_string()), &[]);
let mut makerFee: Value = self.parse_number(Value::Str("0.001".to_string()), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_481: bool = true;
while { if !__for_first_481 { i = add(&i, &Value::Int(1)); } __for_first_481 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut market: Value = get_value(&markets, &i);
let mut market: Value = get_value(&markets, &i);
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCoin", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCoin", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut active: Value = Value::Bool(is_equal(&status, &Value::Str("Trading".to_string())));
let mut lotSizeFilter: Value = self.safe_dict_k(market.clone(), "lotSizeFilter", &[]);
let mut priceFilter: Value = self.safe_dict_k(market.clone(), "priceFilter", &[]);
let mut quotePrecision: Value = self.safe_number_k(lotSizeFilter.clone(), "quotePrecision", &[]);
let mut marginTrading: Value = self.safe_string_k(market.clone(), "marginTrading", &[Value::Str("none".to_string())]);
let mut allowsMargin: Value = Value::Bool(!is_equal(&marginTrading, &Value::Str("none".to_string())));
append_to_array(&mut result, 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(), Value::Null);
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), Value::Null);
m.insert("type".to_string(), Value::Str("spot".to_string()));
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), allowsMargin.clone());
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active.clone());
m.insert("contract".to_string(), Value::Bool(false));
m.insert("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
m.insert("taker".to_string(), takerFee.clone());
m.insert("maker".to_string(), makerFee.clone());
m.insert("contractSize".to_string(), Value::Null);
m.insert("expiry".to_string(), Value::Null);
m.insert("expiryDatetime".to_string(), Value::Null);
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(lotSizeFilter.clone(), "basePrecision", &[]));
m.insert("price".to_string(), self.safe_number_k(priceFilter.clone(), "tickSize", &[quotePrecision.clone()]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(lotSizeFilter.clone(), "minOrderQty", &[]));
m.insert("max".to_string(), self.safe_number_k(lotSizeFilter.clone(), "maxOrderQty", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(lotSizeFilter.clone(), "minOrderAmt", &[]));
m.insert("max".to_string(), self.safe_number_k(lotSizeFilter.clone(), "maxOrderAmt", &[]));
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
})]));
}
}
return result;
Value::Null
}
pub async fn fetch_future_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
add_element_to_object(&mut params, &Value::Str("limit".to_string()), Value::Int(1000)); // minimize number of requests
let mut preLaunchMarkets: Value = Value::List(vec![]);
let mut usePrivateInstrumentsInfo: Value = self.handle_option(Value::Str("fetchMarkets".to_string()), Value::Str("usePrivateInstrumentsInfo".to_string()), &[Value::Bool(false)]);
let mut response: Value = Value::Null;
if is_equal(&usePrivateInstrumentsInfo, &Value::Bool(true)) {
response = self.private_get_v5_market_instruments_info(&[params.clone()]).await;
} else {
let mut linearPromises: Value = Value::List(vec![self.public_get_v5_market_instruments_info(&[params.clone()]).await, self.public_get_v5_market_instruments_info(&[self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("PreLaunch".to_string()));
m
})])]).await]);
let mut promises: Value = promise_all(&linearPromises).await;
response = self.safe_dict(promises.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
preLaunchMarkets = self.safe_dict(promises.clone(), Value::Int(1), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut markets: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
let mut paginationCursor: Value = self.safe_string_k(data.clone(), "nextPageCursor", &[]);
if !is_equal(&paginationCursor, &Value::Null) {
while !is_equal(&paginationCursor, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("cursor".to_string()), paginationCursor.clone());
let mut responseInner: Value = Value::Null;
if is_equal(&usePrivateInstrumentsInfo, &Value::Bool(true)) {
responseInner = self.private_get_v5_market_instruments_info(&[params.clone()]).await;
} else {
responseInner = self.public_get_v5_market_instruments_info(&[params.clone()]).await;
}
let mut dataNew: Value = self.safe_dict_k(responseInner.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rawMarkets: Value = self.safe_list_k(dataNew.clone(), "list", &[Value::List(vec![])]);
let mut rawMarketsLength: Value = get_array_length(&rawMarkets);
if is_equal(&rawMarketsLength, &Value::Int(0)) {
break;
}
markets = self.array_concat(rawMarkets.clone(), markets.clone());
paginationCursor = self.safe_string_k(dataNew.clone(), "nextPageCursor", &[]);
}
}
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "linear",
// "list": [
// {
// "symbol": "BTCUSDT",
// "contractType": "LinearPerpetual",
// "status": "Trading",
// "baseCoin": "BTC",
// "quoteCoin": "USDT",
// "launchTime": "1585526400000",
// "deliveryTime": "0",
// "deliveryFeeRate": "",
// "priceScale": "2",
// "leverageFilter": {
// "minLeverage": "1",
// "maxLeverage": "100.00",
// "leverageStep": "0.01"
// },
// "priceFilter": {
// "minPrice": "0.50",
// "maxPrice": "999999.00",
// "tickSize": "0.50"
// },
// "lotSizeFilter": {
// "maxOrderQty": "100.000",
// "minOrderQty": "0.001",
// "qtyStep": "0.001",
// "postOnlyMaxOrderQty": "1000.000"
// },
// "unifiedMarginTrade": true,
// "fundingInterval": 480,
// "settleCoin": "USDT"
// }
// ],
// "nextPageCursor": ""
// },
// "retExtInfo": {},
// "time": 1672712495660
// }
//
let mut preLaunchData: Value = self.safe_dict_k(preLaunchMarkets.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut preLaunchMarketsList: Value = self.safe_list_k(preLaunchData.clone(), "list", &[Value::List(vec![])]);
markets = self.array_concat(markets.clone(), preLaunchMarketsList.clone());
let mut result: Value = Value::List(vec![]);
let mut category: Value = self.safe_string_k(data.clone(), "category", &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_482: bool = true;
while { if !__for_first_482 { i = add(&i, &Value::Int(1)); } __for_first_482 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut market: Value = get_value(&markets, &i);
let mut market: Value = get_value(&markets, &i);
if is_equal(&category, &Value::Null) {
category = self.safe_string_k(market.clone(), "category", &[]);
}
let mut linear: Value = Value::Bool(is_equal(&category, &Value::Str("linear".to_string())));
let mut inverse: Value = Value::Bool(is_equal(&category, &Value::Str("inverse".to_string())));
let mut contractType: Value = self.safe_string_k(market.clone(), "contractType", &[]);
let mut inverseFutures: bool = is_equal(&contractType, &Value::Str("InverseFutures".to_string()));
let mut linearFutures: bool = is_equal(&contractType, &Value::Str("LinearFutures".to_string()));
let mut linearPerpetual: bool = is_equal(&contractType, &Value::Str("LinearPerpetual".to_string()));
let mut inversePerpetual: bool = is_equal(&contractType, &Value::Str("InversePerpetual".to_string()));
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCoin", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCoin", &[]);
let mut defaultSettledId: Value = ternary(is_true(&linear), quoteId.clone(), baseId.clone());
let mut settleId: Value = self.safe_string_k(market.clone(), "settleCoin", &[defaultSettledId.clone()]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settle: Value = Value::Null;
if is_true(&linearPerpetual) && is_true(&(is_equal(&settleId, &Value::Str("USD".to_string())))) {
settle = Value::Str("USDC".to_string());
} else {
settle = self.safe_currency_code(settleId.clone(), &[]);
}
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut lotSizeFilter: Value = self.safe_dict_k(market.clone(), "lotSizeFilter", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut priceFilter: Value = self.safe_dict_k(market.clone(), "priceFilter", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut leverage: Value = self.safe_dict_k(market.clone(), "leverageFilter", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut swap: Value = Value::Bool(is_true(&linearPerpetual) || is_true(&inversePerpetual));
let mut future: Value = Value::Bool(is_true(&inverseFutures) || is_true(&linearFutures));
let mut type_var: Value = Value::Null;
if is_true(&swap) {
type_var = Value::Str("swap".to_string());
} else if is_true(&future) {
type_var = Value::Str("future".to_string());
}
let mut expiry: Value = Value::Null;
// some swaps have deliveryTime meaning delisting time
if !is_true(&swap) {
expiry = self.omit_zero(self.safe_string_k(market.clone(), "deliveryTime", &[]));
if !is_equal(&expiry, &Value::Null) {
expiry = crate::runtime::parse_int(&expiry);
}
}
let mut expiryDatetime: Value = self.iso8601(expiry.clone());
symbol = add(&add(&symbol, &Value::Str(":".to_string())), &settle);
if !is_equal(&expiry, &Value::Null) {
symbol = add(&add(&symbol, &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[]));
}
let mut contractSize: Value = ternary(is_true(&inverse), self.safe_number2(lotSizeFilter.clone(), Value::Str("minTradingQty".to_string()), Value::Str("minOrderQty".to_string()), &[]), self.parse_number(Value::Str("1".to_string()), &[]));
let mut parsedMarket: Value = self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Null);
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), future.clone());
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), Value::Bool((is_equal(&status, &Value::Str("Trading".to_string())))));
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), linear.clone());
m.insert("inverse".to_string(), inverse.clone());
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "takerFee", &[self.parse_number(Value::Str("0.0006".to_string()), &[])]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "makerFee", &[self.parse_number(Value::Str("0.0001".to_string()), &[])]));
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), expiryDatetime.clone());
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(lotSizeFilter.clone(), "qtyStep", &[]));
m.insert("price".to_string(), self.safe_number_k(priceFilter.clone(), "tickSize", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(leverage.clone(), "minLeverage", &[]));
m.insert("max".to_string(), self.safe_number_k(leverage.clone(), "maxLeverage", &[]));
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number2(lotSizeFilter.clone(), Value::Str("minTradingQty".to_string()), Value::Str("minOrderQty".to_string()), &[]));
m.insert("max".to_string(), self.safe_number2(lotSizeFilter.clone(), Value::Str("maxTradingQty".to_string()), Value::Str("maxOrderQty".to_string()), &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(priceFilter.clone(), "minPrice", &[]));
m.insert("max".to_string(), self.safe_number_k(priceFilter.clone(), "maxPrice", &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), ternary(is_true(&linear), self.safe_number_k(lotSizeFilter.clone(), "minNotionalValue", &[]), Value::Null));
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer_k(market.clone(), "launchTime", &[]));
m.insert("info".to_string(), market.clone());
m
})]);
append_to_array(&mut result, parsedMarket.clone());
}
}
return result;
Value::Null
}
pub async fn fetch_option_markets(&mut self, mut params: Value) -> Value {
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), Value::Str("option".to_string()));
m
});
let mut usePrivateInstrumentsInfo: Value = self.handle_option(Value::Str("fetchMarkets".to_string()), Value::Str("usePrivateInstrumentsInfo".to_string()), &[Value::Bool(false)]);
let mut response: Value = Value::Null;
if is_equal(&usePrivateInstrumentsInfo, &Value::Bool(true)) {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_market_instruments_info(&[__ws_arg_2]).await;
} else {
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_v5_market_instruments_info(&[__ws_arg_3]).await;
}
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut markets: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
let mut loadAllOptions: Value = self.handle_option(Value::Str("fetchMarkets".to_string()), Value::Str("loadAllOptions".to_string()), &[]);
if is_equal(&loadAllOptions, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), Value::Int(1000));
let mut paginationCursor: Value = self.safe_string_k(data.clone(), "nextPageCursor", &[]);
if !is_equal(&paginationCursor, &Value::Null) {
while !is_equal(&paginationCursor, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("cursor".to_string()), paginationCursor.clone());
let mut responseInner: Value = Value::Null;
if is_equal(&usePrivateInstrumentsInfo, &Value::Bool(true)) {
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
responseInner = self.private_get_v5_market_instruments_info(&[__ws_arg_4]).await;
} else {
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
responseInner = self.public_get_v5_market_instruments_info(&[__ws_arg_5]).await;
}
let mut dataNew: Value = self.safe_dict_k(responseInner.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rawMarkets: Value = self.safe_list_k(dataNew.clone(), "list", &[Value::List(vec![])]);
let mut rawMarketsLength: Value = get_array_length(&rawMarkets);
if is_equal(&rawMarketsLength, &Value::Int(0)) {
break;
}
markets = self.array_concat(rawMarkets.clone(), markets.clone());
paginationCursor = self.safe_string_k(dataNew.clone(), "nextPageCursor", &[]);
}
}
}
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "category": "option",
// "nextPageCursor": "0%2C2",
// "list": [
// {
// "symbol": "BTC-29DEC23-80000-C",
// "status": "Trading",
// "baseCoin": "BTC",
// "quoteCoin": "USD",
// "settleCoin": "USDC",
// "optionsType": "Call",
// "launchTime": "1688630400000",
// "deliveryTime": "1703836800000",
// "deliveryFeeRate": "0.00015",
// "priceFilter": {
// "minPrice": "5",
// "maxPrice": "10000000",
// "tickSize": "5"
// },
// "lotSizeFilter": {
// "maxOrderQty": "500",
// "minOrderQty": "0.01",
// "qtyStep": "0.01"
// }
// },
// ]
// },
// "retExtInfo": {},
// "time": 1688873094448
// }
//
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_483: bool = true;
while { if !__for_first_483 { i = add(&i, &Value::Int(1)); } __for_first_483 = false; is_less_than(&i, &get_array_length(&markets)) } {
let mut market: Value = get_value(&markets, &i);
let mut market: Value = get_value(&markets, &i);
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCoin", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCoin", &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "settleCoin", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut lotSizeFilter: Value = self.safe_dict_k(market.clone(), "lotSizeFilter", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut priceFilter: Value = self.safe_dict_k(market.clone(), "priceFilter", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut status: Value = self.safe_string_k(market.clone(), "status", &[]);
let mut expiry: Value = self.safe_integer_k(market.clone(), "deliveryTime", &[]);
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" method() missing id".to_string()))));
}
let mut splitId: Value = split(&id, &Value::Str("-".to_string()));
let mut strike: Value = self.safe_string(splitId.clone(), Value::Int(2), &[]);
let mut optionLetter: Value = self.safe_string(splitId.clone(), Value::Int(3), &[]);
let mut isActive: Value = Value::Bool(is_equal(&status, &Value::Str("Trading".to_string())));
let mut isInverse: Value = Value::Bool(is_equal(&base, &settle));
let mut loadExpiredOptions: Value = self.handle_option(Value::Str("fetchMarkets".to_string()), Value::Str("loadExpiredOptions".to_string()), &[]);
if is_true(&isActive) || is_true(&(is_equal(&loadAllOptions, &Value::Bool(true)))) || is_true(&(is_equal(&loadExpiredOptions, &Value::Bool(true)))) {
append_to_array(&mut result, self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), add(&add(&add(&add(&add(&add(&add(&add(&add(&add(&base, &Value::Str("/".to_string())), "e), &Value::Str(":".to_string())), &settle), &Value::Str("-".to_string())), &self.yymmdd(expiry.clone(), &[])), &Value::Str("-".to_string())), &strike), &Value::Str("-".to_string())), &optionLetter));
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), settle.clone());
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), settleId.clone());
m.insert("type".to_string(), Value::Str("option".to_string()));
m.insert("subType".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(false));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(false));
m.insert("future".to_string(), Value::Bool(false));
m.insert("option".to_string(), Value::Bool(true));
m.insert("active".to_string(), isActive.clone());
m.insert("contract".to_string(), Value::Bool(true));
m.insert("linear".to_string(), Value::Bool(!is_true(&isInverse)));
m.insert("inverse".to_string(), isInverse.clone());
m.insert("taker".to_string(), self.safe_number_k(market.clone(), "takerFee", &[self.parse_number(Value::Str("0.0006".to_string()), &[])]));
m.insert("maker".to_string(), self.safe_number_k(market.clone(), "makerFee", &[self.parse_number(Value::Str("0.0001".to_string()), &[])]));
m.insert("contractSize".to_string(), self.parse_number(Value::Str("1".to_string()), &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), self.parse_number(strike.clone(), &[]));
m.insert("optionType".to_string(), self.safe_string_lower(market.clone(), Value::Str("optionsType".to_string()), &[]));
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.safe_number_k(lotSizeFilter.clone(), "qtyStep", &[]));
m.insert("price".to_string(), self.safe_number_k(priceFilter.clone(), "tickSize", &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(lotSizeFilter.clone(), "minOrderQty", &[]));
m.insert("max".to_string(), self.safe_number_k(lotSizeFilter.clone(), "maxOrderQty", &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(priceFilter.clone(), "minPrice", &[]));
m.insert("max".to_string(), self.safe_number_k(priceFilter.clone(), "maxPrice", &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), self.safe_integer_k(market.clone(), "launchTime", &[]));
m.insert("info".to_string(), market.clone());
m
})]));
}
}
}
return result;
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// spot
//
// {
// "symbol": "BTCUSDT",
// "bid1Price": "20517.96",
// "bid1Size": "2",
// "ask1Price": "20527.77",
// "ask1Size": "1.862172",
// "lastPrice": "20533.13",
// "prevPrice24h": "20393.48",
// "price24hPcnt": "0.0068",
// "highPrice24h": "21128.12",
// "lowPrice24h": "20318.89",
// "turnover24h": "243765620.65899866",
// "volume24h": "11801.27771",
// "usdIndexPrice": "20784.12009279"
// }
//
// linear/inverse
//
// {
// "symbol": "BTCUSD",
// "lastPrice": "16597.00",
// "indexPrice": "16598.54",
// "markPrice": "16596.00",
// "prevPrice24h": "16464.50",
// "price24hPcnt": "0.008047",
// "highPrice24h": "30912.50",
// "lowPrice24h": "15700.00",
// "prevPrice1h": "16595.50",
// "openInterest": "373504107",
// "openInterestValue": "22505.67",
// "turnover24h": "2352.94950046",
// "volume24h": "49337318",
// "fundingRate": "-0.001034",
// "nextFundingTime": "1672387200000",
// "predictedDeliveryPrice": "",
// "basisRate": "",
// "deliveryFeeRate": "",
// "deliveryTime": "0",
// "ask1Size": "1",
// "bid1Price": "16596.00",
// "ask1Price": "16597.50",
// "bid1Size": "1"
// }
//
// option
//
// {
// "symbol": "BTC-30DEC22-18000-C",
// "bid1Price": "0",
// "bid1Size": "0",
// "bid1Iv": "0",
// "ask1Price": "435",
// "ask1Size": "0.66",
// "ask1Iv": "5",
// "lastPrice": "435",
// "highPrice24h": "435",
// "lowPrice24h": "165",
// "markPrice": "0.00000009",
// "indexPrice": "16600.55",
// "markIv": "0.7567",
// "underlyingPrice": "16590.42",
// "openInterest": "6.3",
// "turnover24h": "2482.73",
// "volume24h": "0.15",
// "totalVolume": "99",
// "totalTurnover": "1967653",
// "delta": "0.00000001",
// "gamma": "0.00000001",
// "vega": "0.00000004",
// "theta": "-0.00000152",
// "predictedDeliveryPrice": "0",
// "change24h": "86"
// }
//
let mut isSpot: bool = is_equal(&self.safe_string_k(ticker.clone(), "openInterestValue", &[]), &Value::Null);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "time", &[]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
let mut type_var: Value = ternary(is_true(&isSpot), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, type_var.clone()]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, type_var.clone()]);
let mut last: Value = self.safe_string_k(ticker.clone(), "lastPrice", &[]);
let mut open: Value = self.safe_string_k(ticker.clone(), "prevPrice24h", &[]);
let mut percentage: Value = self.safe_string_k(ticker.clone(), "price24hPcnt", &[]);
percentage = crate::precise::Precise::stringMul(&percentage, &Value::Str("100".to_string()));
let mut quoteVolume: Value = self.safe_string_k(ticker.clone(), "turnover24h", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "volume24h", &[]);
let mut bid: Value = self.safe_string_k(ticker.clone(), "bid1Price", &[]);
let mut ask: Value = self.safe_string_k(ticker.clone(), "ask1Price", &[]);
let mut high: Value = self.safe_string_k(ticker.clone(), "highPrice24h", &[]);
let mut low: Value = self.safe_string_k(ticker.clone(), "lowPrice24h", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.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(), self.safe_string2(ticker.clone(), Value::Str("bidSize".to_string()), Value::Str("bid1Size".to_string()), &[]));
m.insert("ask".to_string(), ask.clone());
m.insert("askVolume".to_string(), self.safe_string2(ticker.clone(), Value::Str("askSize".to_string()), Value::Str("ask1Size".to_string()), &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), open.clone());
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), 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 bybit#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://bybit-exchange.github.io/docs/v5/market/tickers
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchTicker() 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 category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchTicker".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), category.clone());
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_tickers(&[__ws_arg_6]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "inverse",
// "list": [
// {
// "symbol": "BTCUSD",
// "lastPrice": "16597.00",
// "indexPrice": "16598.54",
// "markPrice": "16596.00",
// "prevPrice24h": "16464.50",
// "price24hPcnt": "0.008047",
// "highPrice24h": "30912.50",
// "lowPrice24h": "15700.00",
// "prevPrice1h": "16595.50",
// "openInterest": "373504107",
// "openInterestValue": "22505.67",
// "turnover24h": "2352.94950046",
// "volume24h": "49337318",
// "fundingRate": "-0.001034",
// "nextFundingTime": "1672387200000",
// "predictedDeliveryPrice": "",
// "basisRate": "",
// "deliveryFeeRate": "",
// "deliveryTime": "0",
// "ask1Size": "1",
// "bid1Price": "16596.00",
// "ask1Price": "16597.50",
// "bid1Size": "1"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672376496682
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut tickers: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut rawTicker: Value = self.safe_dict(tickers.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(rawTicker.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://bybit-exchange.github.io/docs/v5/market/tickers
* @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
* @param {string} [params.subType] *contract only* 'linear', 'inverse'
* @param {string} [params.baseCoin] *option only* base coin, default is 'BTC'
* @returns {object} an array 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 code: Value = self.safe_string_n(params.clone(), Value::List(vec![Value::Str("code".to_string()), Value::Str("currency".to_string()), Value::Str("baseCoin".to_string())]), &[]);
let mut market: Value = Value::Null;
let mut parsedSymbols: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
parsedSymbols = Value::List(vec![]);
let mut marketTypeInfo: Value = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[Value::Null, params.clone()]);
let mut defaultType: Value = get_value(&marketTypeInfo, &Value::Int(0)); // don't omit here
// we can't use marketSymbols here due to the conflicting ids between markets
let mut currentType: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_484: bool = true;
while { if !__for_first_484 { i = add(&i, &Value::Int(1)); } __for_first_484 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut symbol: Value = get_value(&symbols, &i);
let mut symbol: Value = get_value(&symbols, &i);
// using safeMarket here because if the user provides for instance BTCUSDT and "type": "spot" in params we should
// infer the market type from the type provided and not from the conflicting id (BTCUSDT might be swap or spot)
let mut isExchangeSpecificSymbol: bool = is_equal(&get_index_of(&symbol, &Value::Str("/".to_string())), &negate(&Value::Int(1)));
if is_true(&isExchangeSpecificSymbol) {
market = self.safe_market(&[symbol.clone(), Value::Null, Value::Null, defaultType.clone()]);
} else {
market = self.market(symbol.clone());
}
if is_equal(¤tType, &Value::Null) {
currentType = get_value(&market, &Value::Str("type".to_string()));
} else if !is_equal(&get_value(&market, &Value::Str("type".to_string())), ¤tType) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchTickers can only accept a list of symbols of the same type".to_string()))));
}
if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
if !is_equal(&code, &Value::Null) && !is_equal(&code, &get_value(&market, &Value::Str("base".to_string()))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchTickers the base currency must be the same for all symbols, this endpoint only supports one base currency at a time. Read more about it here: https://bybit-exchange.github.io/docs/v5/market/tickers".to_string()))));
}
if is_equal(&code, &Value::Null) {
code = get_value(&market, &Value::Str("base".to_string()));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("code".to_string()), Value::Str("currency".to_string())]), &[]);
}
append_to_array(&mut parsedSymbols, get_value(&market, &Value::Str("symbol".to_string())));
}
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchTickers".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), category.clone());
if is_equal(&category, &Value::Str("option".to_string())) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("option".to_string()));
if is_equal(&code, &Value::Null) {
code = Value::Str("BTC".to_string());
}
add_element_to_object(&mut request, &Value::Str("baseCoin".to_string()), code.clone());
}
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_tickers(&[__ws_arg_7]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "inverse",
// "list": [
// {
// "symbol": "BTCUSD",
// "lastPrice": "16597.00",
// "indexPrice": "16598.54",
// "markPrice": "16596.00",
// "prevPrice24h": "16464.50",
// "price24hPcnt": "0.008047",
// "highPrice24h": "30912.50",
// "lowPrice24h": "15700.00",
// "prevPrice1h": "16595.50",
// "openInterest": "373504107",
// "openInterestValue": "22505.67",
// "turnover24h": "2352.94950046",
// "volume24h": "49337318",
// "fundingRate": "-0.001034",
// "nextFundingTime": "1672387200000",
// "predictedDeliveryPrice": "",
// "basisRate": "",
// "deliveryFeeRate": "",
// "deliveryTime": "0",
// "ask1Size": "1",
// "bid1Price": "16596.00",
// "ask1Price": "16597.50",
// "bid1Size": "1"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672376496682
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut tickerList: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_tickers(tickerList.clone(), &[parsedSymbols.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchBidsAsks
* @description fetches the bid and ask price and volume for multiple markets
* @see https://bybit-exchange.github.io/docs/v5/market/tickers
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the bids and asks for, all markets are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] *contract only* 'linear', 'inverse'
* @param {string} [params.baseCoin] *option only* base coin, default is 'BTC'
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_bids_asks(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_tickers(&[symbols.clone(), params.clone()]).await;
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// "1621162800",
// "49592.43",
// "49644.91",
// "49342.37",
// "49349.42",
// "1451.59",
// "2.4343353100000003"
// ]
//
let mut isInverse: Value = self.safe_bool_k(market.clone(), "inverse", &[]);
let mut volumeIndex: Value = ternary(is_true(&(is_equal(&isInverse, &Value::Bool(true)))), Value::Int(6), Value::Int(5));
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(), volumeIndex.clone(), &[])]);
Value::Null
}
/*
* @method
* @name bybit#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://bybit-exchange.github.io/docs/v5/market/kline
* @see https://bybit-exchange.github.io/docs/v5/market/mark-kline
* @see https://bybit-exchange.github.io/docs/v5/market/index-kline
* @see https://bybit-exchange.github.io/docs/v5/market/preimum-index-kline
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch orders for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOHLCV() requires a symbol argument".to_string()))));
}
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("fetchOHLCV".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".to_string()), &[symbol.clone(), since.clone(), limit.clone(), timeframe.clone(), params.clone(), Value::Int(1000)]).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) {
limit = Value::Int(200); // default is 200 when requested with `since`
}
if !is_equal(&since, &Value::Null) {
// bybit returns the candle that contains `start`, whose timestamp is
// before a mid-interval `since` and gets dropped by the client-side
// since-filter, emptying a limit=1 request entirely, see issue
// https://github.com/ccxt/ccxt/issues/26736 - align the requested
// start up to the interval boundary so that the exchange returns
// candles from the first bucket at or after `since`
let mut duration: Value = multiply(&self.parse_timeframe(timeframe.clone()), &Value::Int(1000));
let mut rounded: Value = multiply(&self.parse_to_int(divide(&since, &duration)), &duration);
add_element_to_object(&mut request, &Value::Str("start".to_string()), ternary(is_true(&(is_equal(&rounded, &since))), since.clone(), self.sum(&[rounded.clone(), duration.clone()])));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // max 1000, default 1000
}
{ let __destr_tmp = self.handle_until_option(Value::Str("end".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("interval".to_string()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("spot".to_string()));
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_v5_market_kline(&[__ws_arg_8]).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(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("linear".to_string()));
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("inverse".to_string()));
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOHLCV() is not supported for option markets".to_string()))));
}
if is_equal(&price, &Value::Str("mark".to_string())) {
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_v5_market_mark_price_kline(&[__ws_arg_9]).await;
} else if is_equal(&price, &Value::Str("index".to_string())) {
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_v5_market_index_price_kline(&[__ws_arg_10]).await;
} else if is_equal(&price, &Value::Str("premiumIndex".to_string())) {
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_v5_market_premium_index_price_kline(&[__ws_arg_11]).await;
} else {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_v5_market_kline(&[__ws_arg_12]).await;
}
}
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "symbol": "BTCUSD",
// "category": "inverse",
// "list": [
// [
// "1670608800000",
// "17071",
// "17073",
// "17027",
// "17055.5",
// "268611",
// "15.74462667"
// ],
// [
// "1670605200000",
// "17071.5",
// "17071.5",
// "17061",
// "17071",
// "4177",
// "0.24469757"
// ],
// [
// "1670601600000",
// "17086.5",
// "17088",
// "16978",
// "17071.5",
// "6356",
// "0.37288112"
// ]
// ]
// },
// "retExtInfo": {},
// "time": 1672025956592
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ohlcvs: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_ohlc_vs(ohlcvs.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTCUSDT",
// "bidPrice": "19255",
// "askPrice": "19255.5",
// "lastPrice": "19255.50",
// "lastTickDirection": "ZeroPlusTick",
// "prevPrice24h": "18634.50",
// "price24hPcnt": "0.033325",
// "highPrice24h": "19675.00",
// "lowPrice24h": "18610.00",
// "prevPrice1h": "19278.00",
// "markPrice": "19255.00",
// "indexPrice": "19260.68",
// "openInterest": "48069.549",
// "turnover24h": "4686694853.047006",
// "volume24h": "243730.252",
// "fundingRate": "0.0001",
// "nextFundingTime": "1663689600000",
// "predictedDeliveryPrice": "",
// "basisRate": "",
// "deliveryFeeRate": "",
// "deliveryTime": "0"
// }
//
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "timestamp", &[]); // added artificially to avoid changing the signature
ticker = self.omit(ticker.clone(), Value::Str("timestamp".to_string()), &[]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("swap".to_string())]);
let mut fundingRate: Value = self.safe_number_k(ticker.clone(), "fundingRate", &[]);
let mut fundingTimestamp: Value = self.safe_integer_k(ticker.clone(), "nextFundingTime", &[]);
let mut markPrice: Value = self.safe_number_k(ticker.clone(), "markPrice", &[]);
let mut indexPrice: Value = self.safe_number_k(ticker.clone(), "indexPrice", &[]);
let mut info: Value = self.safe_dict(self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("swap".to_string())]), Value::Str("info".to_string()), &[]);
let mut fundingInterval: Value = self.safe_integer_k(info.clone(), "fundingInterval", &[]);
let mut intervalString: Value = Value::Null;
if !is_equal(&fundingInterval, &Value::Null) {
let mut interval: Value = self.parse_to_int(divide(&fundingInterval, &Value::Int(60)));
intervalString = add(&to_string_val(&interval), &Value::Str("h".to_string()));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), ticker.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("markPrice".to_string(), markPrice.clone());
m.insert("indexPrice".to_string(), indexPrice.clone());
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fundingRate".to_string(), fundingRate.clone());
m.insert("fundingTimestamp".to_string(), fundingTimestamp.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTimestamp.clone()));
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), Value::Null);
m.insert("nextFundingDatetime".to_string(), Value::Null);
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(), intervalString.clone());
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchFundingRates
* @description fetches funding rates for multiple markets
* @see https://bybit-exchange.github.io/docs/v5/market/tickers
* @param {string[]} symbols unified symbols of the markets to fetch the funding rates for, all market funding rates are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
symbols = self.market_symbols(&[symbols.clone()]);
market = self.market(get_value(&symbols, &Value::Int(0)));
let mut symbolsLength: Value = get_array_length(&symbols);
if is_equal(&symbolsLength, &Value::Int(1)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchFundingRates".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(&add(&add(&self.id, &Value::Str(" fetchFundingRates() does not support ".to_string())), &type_var), &Value::Str(" markets".to_string()))));
} else {
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchFundingRates".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)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), subType.clone());
}
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_tickers(&[__ws_arg_13]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "linear",
// "list": [
// {
// "symbol": "BTCUSDT",
// "bidPrice": "19255",
// "askPrice": "19255.5",
// "lastPrice": "19255.50",
// "lastTickDirection": "ZeroPlusTick",
// "prevPrice24h": "18634.50",
// "price24hPcnt": "0.033325",
// "highPrice24h": "19675.00",
// "lowPrice24h": "18610.00",
// "prevPrice1h": "19278.00",
// "markPrice": "19255.00",
// "indexPrice": "19260.68",
// "openInterest": "48069.549",
// "turnover24h": "4686694853.047006",
// "volume24h": "243730.252",
// "fundingRate": "0.0001",
// "nextFundingTime": "1663689600000",
// "predictedDeliveryPrice": "",
// "basisRate": "",
// "deliveryFeeRate": "",
// "deliveryTime": "0"
// }
// ]
// },
// "retExtInfo": null,
// "time": 1663670053454
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut tickerList: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
let mut timestamp: Value = self.safe_integer_k(response.clone(), "time", &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_485: bool = true;
while { if !__for_first_485 { i = add(&i, &Value::Int(1)); } __for_first_485 = false; is_less_than(&i, &get_array_length(&tickerList)) } {
add_element_to_object(get_value_mut(&mut tickerList, &i), &Value::Str("timestamp".to_string()), timestamp.clone()); // will be removed inside the parser
}
}
return self.parse_funding_rates(tickerList.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://bybit-exchange.github.io/docs/v5/market/history-fund-rate
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] timestamp in ms of the earliest funding rate to fetch
* @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-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 rate
* @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 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_dynamic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Int(200)]).await;
}
if is_equal(&limit, &Value::Null) {
limit = Value::Int(200);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), limit.clone());
m
});
let mut market: Value = self.market(symbol.clone());
let mut fundingTimeFrameMins: Value = self.safe_integer(get_value(&market, &Value::Str("info".to_string())), Value::Str("fundingInterval".to_string()), &[]);
symbol = get_value(&market, &Value::Str("symbol".to_string()));
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.get_bybit_type(Value::Str("fetchFundingRateHistory".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("option".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchFundingRateHistory() only support linear and inverse market".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]); // unified in milliseconds
let mut endTime: Value = self.safe_integer_k(params.clone(), "endTime", &[until.clone()]); // exchange-specific in milliseconds
params = self.omit(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("until".to_string())]), &[]);
if !is_equal(&endTime, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), endTime.clone());
} else {
if !is_equal(&since, &Value::Null) {
// end time is required when since is not empty
let mut fundingInterval: Value = multiply(&multiply(&multiply(&Value::Int(60), &Value::Int(60)), &Value::Int(8)), &Value::Int(1000));
if !is_equal(&fundingTimeFrameMins, &Value::Null) {
fundingInterval = multiply(&multiply(&fundingTimeFrameMins, &Value::Int(60)), &Value::Int(1000));
}
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), self.sum(&[since.clone(), multiply(&limit, &fundingInterval)]));
}
}
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_funding_history(&[__ws_arg_14]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "linear",
// "list": [
// {
// "symbol": "ETHPERP",
// "fundingRate": "0.0001",
// "fundingRateTimestamp": "1672041600000"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672051897447
// }
//
let mut rates: Value = Value::List(vec![]);
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
let mut resultList: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_486: bool = true;
while { if !__for_first_486 { i = add(&i, &Value::Int(1)); } __for_first_486 = false; is_less_than(&i, &get_array_length(&resultList)) } {
let mut entry: Value = get_value(&resultList, &i);
let mut entry: Value = get_value(&resultList, &i);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "fundingRateTimestamp", &[]);
append_to_array(&mut rates, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), self.safe_symbol(self.safe_string_k(entry.clone(), "symbol", &[]), &[Value::Null, Value::Null, Value::Str("swap".to_string())]));
m.insert("fundingRate".to_string(), self.safe_number_k(entry.clone(), "fundingRate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
}));
}
}
let mut sorted: Value = self.sort_by(rates.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.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);
//
// public https://bybit-exchange.github.io/docs/v5/market/recent-trade
//
// {
// "execId": "666042b4-50c6-58f3-bd9c-89b2088663ff",
// "symbol": "ETHUSD",
// "price": "1162.95",
// "size": "1",
// "side": "Sell",
// "time": "1669191277315",
// "isBlockTrade": false
// }
//
// private trades classic spot https://bybit-exchange.github.io/docs/v5/position/execution
//
// {
// "symbol": "QNTUSDT",
// "orderId": "1538686353240339712",
// "orderLinkId": "",
// "side": "Sell",
// "orderPrice": "",
// "orderQty": "",
// "leavesQty": "",
// "orderType": "Limit",
// "stopOrderType": "",
// "execFee": "0.040919",
// "execId": "2210000000097330907",
// "execPrice": "98.6",
// "execQty": "0.415",
// "execType": "",
// "execValue": "",
// "execTime": "1698161716634",
// "isMaker": true,
// "feeRate": "",
// "tradeIv": "",
// "markIv": "",
// "markPrice": "",
// "indexPrice": "",
// "underlyingPrice": "",
// "blockTradeId": ""
// }
//
// private trades unified https://bybit-exchange.github.io/docs/v5/position/execution
//
// {
// "symbol": "QNTUSDT",
// "orderType": "Limit",
// "underlyingPrice": "",
// "orderLinkId": "1549452573428424449",
// "orderId": "1549452573428424448",
// "stopOrderType": "",
// "execTime": "1699445151998",
// "feeRate": "0.00025",
// "tradeIv": "",
// "blockTradeId": "",
// "markPrice": "",
// "execPrice": "102.8",
// "markIv": "",
// "orderQty": "3.652",
// "orderPrice": "102.8",
// "execValue": "1.028",
// "closedSize": "",
// "execType": "Trade",
// "seq": "19157444346",
// "side": "Buy",
// "indexPrice": "",
// "leavesQty": "3.642",
// "isMaker": true,
// "execFee": "0.0000025",
// "execId": "2210000000101610464",
// "execQty": "0.01",
// "nextPageCursor": "267951%3A0%2C38567%3A0"
// },
//
// private USDC settled trades
//
// {
// "symbol": "ETHPERP",
// "orderLinkId": "",
// "side": "Buy",
// "orderId": "aad0ee44-ce12-4112-aeee-b7829f6c3a26",
// "execFee": "0.0210",
// "feeRate": "0.000600",
// "blockTradeId": "",
// "tradeTime": "1669196417930",
// "execPrice": "1162.15",
// "lastLiquidityInd": "TAKER",
// "execValue": "34.8645",
// "execType": "Trade",
// "execQty": "0.030",
// "tradeId": "0e94eaf5-b08e-5505-b43f-7f1f30b1ca80"
// }
//
// watchMyTrades execution.fast
//
// {
// "category": "linear",
// "symbol": "ICPUSDT",
// "execId": "3510f361-0add-5c7b-a2e7-9679810944fc",
// "execPrice": "12.015",
// "execQty": "3000",
// "orderId": "443d63fa-b4c3-4297-b7b1-23bca88b04dc",
// "isMaker": false,
// "orderLinkId": "test-00001",
// "side": "Sell",
// "execTime": "1716800399334",
// "seq": 34771365464
// }
//
// watchMyTrades execution
//
// {
// "category": "linear",
// "symbol": "BTCUSDT",
// "closedSize": "0",
// "execFee": "0.0679239",
// "execId": "135dbae5-cbed-5275-9290-3956bb2ed907",
// "execPrice": "123498",
// "execQty": "0.001",
// "execType": "Trade",
// "execValue": "123.498",
// "feeRate": "0.00055",
// "tradeIv": "",
// "markIv": "",
// "blockTradeId": "",
// "markPrice": "122392",
// "indexPrice": "",
// "underlyingPrice": "",
// "leavesQty": "0",
// "orderId": "aee7453a-a100-465f-857a-3db780e9329a",
// "orderLinkId": "",
// "orderPrice": "123615.9",
// "orderQty": "0.001",
// "orderType": "Market",
// "stopOrderType": "UNKNOWN",
// "side": "Buy",
// "execTime": "1757837580469",
// "isLeverage": "0",
// "isMaker": false,
// "seq": 9517074055,
// "marketUnit": "",
// "execPnl": "0",
// "createType": "CreateByUser",
// "extraFees": [],
// "feeCoin": "USDT"
// }
//
let mut id: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("execId".to_string()), Value::Str("id".to_string()), Value::Str("tradeId".to_string())]), &[]);
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
let mut marketType: Value = ternary(is_true(&(Value::Bool(in_op(&trade, &Value::Str("createType".to_string()))))), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
let mut category: Value = self.safe_string_k(trade.clone(), "category", &[]);
if !is_equal(&category, &Value::Null) {
marketType = ternary(is_true(&(is_equal(&category, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
}
if !is_equal(&market, &Value::Null) {
marketType = get_value(&market, &Value::Str("type".to_string()));
}
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut amountString: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("execQty".to_string()), Value::Str("orderQty".to_string()), Value::Str("size".to_string())]), &[]);
let mut priceString: Value = self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("execPrice".to_string()), Value::Str("orderPrice".to_string()), Value::Str("price".to_string())]), &[]);
let mut costString: Value = self.safe_string_k(trade.clone(), "execValue", &[]);
let mut timestamp: Value = self.safe_integer_n(trade.clone(), Value::List(vec![Value::Str("time".to_string()), Value::Str("execTime".to_string()), Value::Str("tradeTime".to_string())]), &[]);
let mut side: Value = self.safe_string_lower(trade.clone(), Value::Str("side".to_string()), &[]);
if is_equal(&side, &Value::Null) {
let mut isBuyer: Value = self.safe_integer_k(trade.clone(), "isBuyer", &[]);
if !is_equal(&isBuyer, &Value::Null) {
side = ternary(is_true(&(!is_equal(&isBuyer, &Value::Int(0)))), Value::Str("buy".to_string()), Value::Str("sell".to_string()));
}
}
let mut isMaker: Value = self.safe_bool_k(trade.clone(), "isMaker", &[]);
let mut takerOrMaker: Value = Value::Null;
if !is_equal(&isMaker, &Value::Null) {
takerOrMaker = ternary(is_true(&isMaker), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
} else {
let mut lastLiquidityInd: Value = self.safe_string_k(trade.clone(), "lastLiquidityInd", &[]);
if is_equal(&lastLiquidityInd, &Value::Str("UNKNOWN".to_string())) {
lastLiquidityInd = Value::Null;
}
if !is_equal(&lastLiquidityInd, &Value::Null) {
if is_true(&(is_equal(&lastLiquidityInd, &Value::Str("TAKER".to_string())))) || is_true(&(is_equal(&lastLiquidityInd, &Value::Str("MAKER".to_string())))) {
takerOrMaker = to_lower(&lastLiquidityInd);
} else {
takerOrMaker = ternary(is_true(&(is_equal(&lastLiquidityInd, &Value::Str("AddedLiquidity".to_string())))), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
}
}
let mut orderType: Value = self.safe_string_lower(trade.clone(), Value::Str("orderType".to_string()), &[]);
if is_equal(&orderType, &Value::Str("unknown".to_string())) {
orderType = Value::Null;
}
let mut feeCostString: Value = self.safe_string_k(trade.clone(), "execFee", &[]);
let mut fee: Value = Value::Null;
if !is_equal(&feeCostString, &Value::Null) {
let mut feeRateString: Value = self.safe_string_k(trade.clone(), "feeRate", &[]);
let mut feeCurrencyCode: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if is_true(&crate::precise::Precise::stringGt(&feeCostString, &Value::Str("0".to_string()))) {
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 {
if is_equal(&side, &Value::Str("buy".to_string())) {
feeCurrencyCode = get_value(&market, &Value::Str("quote".to_string()));
} else {
feeCurrencyCode = get_value(&market, &Value::Str("base".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("base".to_string())), get_value(&market, &Value::Str("settle".to_string())));
}
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostString.clone());
m.insert("currency".to_string(), self.safe_string_k(trade.clone(), "feeCoin", &[feeCurrencyCode.clone()]));
m.insert("rate".to_string(), feeRateString.clone());
m
});
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("type".to_string(), orderType.clone());
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), priceString.clone());
m.insert("amount".to_string(), amountString.clone());
m.insert("cost".to_string(), costString.clone());
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://bybit-exchange.github.io/docs/v5/market/recent-trade
* @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
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchTrades() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
// spot: [1,60], default: 60.
// others: [1,1000], default: 500
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchTrades".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_recent_trade(&[__ws_arg_15]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "spot",
// "list": [
// {
// "execId": "2100000000007764263",
// "symbol": "BTCUSDT",
// "price": "16618.49",
// "size": "0.00012",
// "side": "Buy",
// "time": "1672052955758",
// "isBlockTrade": false
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672053054358
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trades: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://bybit-exchange.github.io/docs/v5/market/orderbook
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrderBook() 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 defaultLimit: Value = Value::Int(25);
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
// limit: [1, 50]. Default: 1
defaultLimit = Value::Int(50);
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("spot".to_string()));
} else {
if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
// limit: [1, 25]. Default: 1
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("option".to_string()));
} else if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
// limit: [1, 500]. Default: 25
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("linear".to_string()));
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
// limit: [1, 500]. Default: 25
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("inverse".to_string()));
}
}
add_element_to_object(&mut request, &Value::Str("limit".to_string()), ternary(is_true(&(!is_equal(&limit, &Value::Null))), limit.clone(), defaultLimit.clone()));
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_orderbook(&[__ws_arg_16]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "s": "BTCUSDT",
// "a": [
// [
// "16638.64",
// "0.008479"
// ]
// ],
// "b": [
// [
// "16638.27",
// "0.305749"
// ]
// ],
// "ts": 1672765737733,
// "u": 5277055
// },
// "retExtInfo": {},
// "time": 1672765737734
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(result.clone(), "ts", &[]);
return self.parse_order_book(result.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("b".to_string()), Value::Str("a".to_string())]);
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
//
// cross
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "acctBalanceSum": "0.122995614474732872",
// "debtBalanceSum": "0.011734191124529754",
// "loanAccountList": [
// {
// "free": "0.001143855",
// "interest": "0",
// "loan": "0",
// "locked": "0",
// "tokenId": "BTC",
// "total": "0.001143855"
// },
// {
// "free": "200.00005568",
// "interest": "0.0008391",
// "loan": "200",
// "locked": "0",
// "tokenId": "USDT",
// "total": "200.00005568"
// },
// ],
// "riskRate": "0.0954",
// "status": 1
// },
// "retExtInfo": {},
// "time": 1669843584123
// }
//
// funding
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "memberId": "533285",
// "accountType": "FUND",
// "balance": [
// {
// "coin": "USDT",
// "transferBalance": "1010",
// "walletBalance": "1010",
// "bonus": ""
// },
// {
// "coin": "USDC",
// "transferBalance": "0",
// "walletBalance": "0",
// "bonus": ""
// }
// ]
// },
// "retExtInfo": {},
// "time": 1675865290069
// }
//
// spot & swap
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "totalEquity": "18070.32797922",
// "accountIMRate": "0.0101",
// "totalMarginBalance": "18070.32797922",
// "totalInitialMargin": "182.60183684",
// "accountType": "UNIFIED",
// "totalAvailableBalance": "17887.72614237",
// "accountMMRate": "0",
// "totalPerpUPL": "-0.11001349",
// "totalWalletBalance": "18070.43799271",
// "accountLTV": "0.017",
// "totalMaintenanceMargin": "0.38106773",
// "coin": [
// {
// "availableToBorrow": "2.5",
// "bonus": "0",
// "accruedInterest": "0",
// "availableToWithdraw": "0.805994",
// "totalOrderIM": "0",
// "equity": "0.805994",
// "totalPositionMM": "0",
// "usdValue": "12920.95352538",
// "unrealisedPnl": "0",
// "borrowAmount": "0",
// "totalPositionIM": "0",
// "walletBalance": "0.805994",
// "cumRealisedPnl": "0",
// "coin": "BTC"
// }
// ]
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672125441042
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "time", &[]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
let mut responseResult: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyList: Value = self.safe_list_n(responseResult.clone(), Value::List(vec![Value::Str("loanAccountList".to_string()), Value::Str("list".to_string()), Value::Str("balance".to_string())]), &[]);
if is_equal(¤cyList, &Value::Null) {
// usdc wallet
let mut code: Value = Value::Str("USDC".to_string());
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(responseResult.clone(), "availableBalance", &[]));
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(responseResult.clone(), "walletBalance", &[]));
add_element_to_object(&mut result, &code, account.clone());
} else {
{
let mut i: Value = Value::Int(0);
let mut __for_first_488: bool = true;
while { if !__for_first_488 { i = add(&i, &Value::Int(1)); } __for_first_488 = false; is_less_than(&i, &get_array_length(¤cyList)) } {
let mut entry: Value = get_value(¤cyList, &i);
let mut entry: Value = get_value(¤cyList, &i);
let mut accountType: Value = self.safe_string_k(entry.clone(), "accountType", &[]);
if is_equal(&accountType, &Value::Str("UNIFIED".to_string())) || is_equal(&accountType, &Value::Str("CONTRACT".to_string())) || is_equal(&accountType, &Value::Str("SPOT".to_string())) {
let mut coins: Value = self.safe_list_k(entry.clone(), "coin", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_487: bool = true;
while { if !__for_first_487 { j = add(&j, &Value::Int(1)); } __for_first_487 = false; is_less_than(&j, &get_array_length(&coins)) } {
let mut account: Value = self.account();
let mut coinEntry: Value = get_value(&coins, &j);
let mut coinEntry: Value = get_value(&coins, &j);
let mut loan: Value = self.safe_string_k(coinEntry.clone(), "borrowAmount", &[]);
let mut interest: Value = self.safe_string_k(coinEntry.clone(), "accruedInterest", &[]);
if is_true(&(!is_equal(&loan, &Value::Null))) && is_true(&(!is_equal(&interest, &Value::Null))) {
add_element_to_object(&mut account, &Value::Str("debt".to_string()), crate::precise::Precise::stringAdd(&loan, &interest));
}
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(coinEntry.clone(), "walletBalance", &[]));
let mut free: Value = self.safe_string2(coinEntry.clone(), Value::Str("availableToWithdraw".to_string()), Value::Str("free".to_string()), &[]);
if !is_equal(&free, &Value::Null) {
add_element_to_object(&mut account, &Value::Str("free".to_string()), free.clone());
} else {
let mut locked: Value = self.safe_string_k(coinEntry.clone(), "locked", &[Value::Str("0".to_string())]);
let mut totalPositionIm: Value = self.safe_string_k(coinEntry.clone(), "totalPositionIM", &[Value::Str("0".to_string())]);
let mut totalOrderIm: Value = self.safe_string_k(coinEntry.clone(), "totalOrderIM", &[Value::Str("0".to_string())]);
let mut totalUsed: Value = crate::precise::Precise::stringAdd(&locked, &totalPositionIm);
totalUsed = crate::precise::Precise::stringAdd(&totalUsed, &totalOrderIm);
add_element_to_object(&mut account, &Value::Str("used".to_string()), totalUsed.clone());
}
// account['used'] = this.safeString (coinEntry, 'locked');
let mut currencyId: Value = self.safe_string_k(coinEntry.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
} else {
let mut account: Value = self.account();
let mut loan: Value = self.safe_string_k(entry.clone(), "loan", &[]);
let mut interest: Value = self.safe_string_k(entry.clone(), "interest", &[]);
if is_true(&(!is_equal(&loan, &Value::Null))) && is_true(&(!is_equal(&interest, &Value::Null))) {
add_element_to_object(&mut account, &Value::Str("debt".to_string()), crate::precise::Precise::stringAdd(&loan, &interest));
}
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string2(entry.clone(), Value::Str("total".to_string()), Value::Str("walletBalance".to_string()), &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_n(entry.clone(), Value::List(vec![Value::Str("free".to_string()), Value::Str("availableBalanceWithoutConvert".to_string()), Value::Str("availableBalance".to_string()), Value::Str("transferBalance".to_string())]), &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(entry.clone(), "locked", &[]));
let mut currencyId: Value = self.safe_string_n(entry.clone(), Value::List(vec![Value::Str("tokenId".to_string()), Value::Str("coin".to_string()), Value::Str("currencyCoin".to_string())]), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
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 bybit#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://bybit-exchange.github.io/docs/v5/spot-margin-normal/account-info
* @see https://bybit-exchange.github.io/docs/v5/asset/all-balance
* @see https://bybit-exchange.github.io/docs/v5/account/wallet-balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] wallet type, ['spot', 'swap', 'funding']
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut enableUnifiedMarginenableUnifiedAccountVariable = self.is_unified_enabled(&[]).await;
let mut enableUnifiedMargin: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(0));
let mut enableUnifiedAccount: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(1));
let mut isUnifiedAccount: bool = is_true(&(is_equal(&enableUnifiedMargin, &Value::Bool(true)))) || is_true(&(is_equal(&enableUnifiedAccount, &Value::Bool(true))));
let mut type_var: Value = Value::Null;
// don't use getBybitType here
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut 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)); }
if is_true(&(is_equal(&type_var, &Value::Str("swap".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("future".to_string())))) {
type_var = subType.clone();
}
let mut lowercaseRawType: Value = ternary(is_true(&(!is_equal(&type_var, &Value::Null))), to_lower(&type_var), Value::Null);
let mut isSpot: bool = is_equal(&type_var, &Value::Str("spot".to_string()));
let mut isLinear: bool = is_equal(&type_var, &Value::Str("linear".to_string()));
let mut isInverse: bool = is_equal(&type_var, &Value::Str("inverse".to_string()));
let mut isFunding: bool = is_true(&(is_equal(&lowercaseRawType, &Value::Str("fund".to_string())))) || is_true(&(is_equal(&lowercaseRawType, &Value::Str("funding".to_string()))));
if is_true(&isUnifiedAccount) {
let mut unifiedMarginStatus: Value = self.safe_integer_k(self.options.clone(), "unifiedMarginStatus", &[Value::Int(6)]);
if is_less_than(&unifiedMarginStatus, &Value::Int(5)) {
// it's not uta.20 where inverse are unified
if is_true(&isInverse) {
type_var = Value::Str("contract".to_string());
} else {
type_var = Value::Str("unified".to_string());
}
} else {
type_var = Value::Str("unified".to_string()); // uta.20 where inverse are unified
}
} else {
if is_true(&isLinear) || is_true(&isInverse) {
type_var = Value::Str("contract".to_string());
}
}
let mut accountTypes: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut unifiedType: Value = self.safe_string_upper(accountTypes.clone(), type_var.clone(), &[type_var.clone()]);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBalance".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_true(&isSpot) && is_true(&(!is_equal(&marginMode, &Value::Null))) {
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_spot_cross_margin_trade_account(&[__ws_arg_17]).await;
} else if is_true(&isFunding) {
// use this endpoint only we have no other choice
// because it requires transfer permission
add_element_to_object(&mut request, &Value::Str("accountType".to_string()), Value::Str("FUND".to_string()));
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_asset_transfer_query_account_coins_balance(&[__ws_arg_18]).await;
} else {
add_element_to_object(&mut request, &Value::Str("accountType".to_string()), unifiedType.clone());
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_account_wallet_balance(&[__ws_arg_19]).await;
}
return self.parse_balance(response.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("PARTIALLY_FILLED".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("PENDING_CANCEL".to_string(), Value::Str("open".to_string()));
m.insert("PENDING_NEW".to_string(), Value::Str("open".to_string()));
m.insert("REJECTED".to_string(), Value::Str("rejected".to_string()));
m.insert("PARTIALLY_FILLED_CANCELLED".to_string(), Value::Str("closed".to_string()));
m.insert("Created".to_string(), Value::Str("open".to_string()));
m.insert("New".to_string(), Value::Str("open".to_string()));
m.insert("Rejected".to_string(), Value::Str("rejected".to_string()));
m.insert("PartiallyFilled".to_string(), Value::Str("open".to_string()));
m.insert("PartiallyFilledCanceled".to_string(), Value::Str("closed".to_string()));
m.insert("Filled".to_string(), Value::Str("closed".to_string()));
m.insert("PendingCancel".to_string(), Value::Str("open".to_string()));
m.insert("Cancelled".to_string(), Value::Str("canceled".to_string()));
m.insert("Untriggered".to_string(), Value::Str("open".to_string()));
m.insert("Deactivated".to_string(), Value::Str("canceled".to_string()));
m.insert("Triggered".to_string(), Value::Str("open".to_string()));
m.insert("Active".to_string(), Value::Str("open".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Value {
let mut timeInForces: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GoodTillCancel".to_string(), Value::Str("GTC".to_string()));
m.insert("ImmediateOrCancel".to_string(), Value::Str("IOC".to_string()));
m.insert("FillOrKill".to_string(), Value::Str("FOK".to_string()));
m.insert("PostOnly".to_string(), Value::Str("PO".to_string()));
m
});
return self.safe_string(timeInForces.clone(), timeInForce.clone(), &[timeInForce.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);
//
// v1 for usdc normal account
// {
// "symbol": "BTCPERP",
// "orderType": "Market",
// "orderLinkId": "",
// "orderId": "36190ad3-de08-4b83-9ad3-56942f684b79",
// "cancelType": "UNKNOWN",
// "stopOrderType": "UNKNOWN",
// "orderStatus": "Filled",
// "updateTimeStamp": "1692769133267",
// "takeProfit": "0.0000",
// "cumExecValue": "259.6830",
// "createdAt": "1692769133261",
// "blockTradeId": "",
// "orderPnl": "",
// "price": "24674.7",
// "tpTriggerBy": "UNKNOWN",
// "timeInForce": "ImmediateOrCancel",
// "updatedAt": "1692769133267",
// "basePrice": "0.0",
// "realisedPnl": "0.0000",
// "side": "Sell",
// "triggerPrice": "0.0",
// "cumExecFee": "0.1429",
// "leavesQty": "0.000",
// "cashFlow": "",
// "slTriggerBy": "UNKNOWN",
// "iv": "",
// "closeOnTrigger": "UNKNOWN",
// "cumExecQty": "0.010",
// "reduceOnly": 0,
// "qty": "0.010",
// "stopLoss": "0.0000",
// "triggerBy": "UNKNOWN",
// "orderIM": ""
// }
//
// v5
// {
// "symbol": "BTCUSDT",
// "orderType": "Market",
// "orderLinkId": "",
// "slLimitPrice": "0",
// "orderId": "f5f2d355-9a11-4af3-9b83-aa1d6ab6ddfe",
// "cancelType": "UNKNOWN",
// "avgPrice": "122529.9",
// "stopOrderType": "",
// "lastPriceOnCreated": "123747.9",
// "orderStatus": "Filled",
// "createType": "CreateByUser",
// "takeProfit": "",
// "cumExecValue": "122.5299",
// "tpslMode": "",
// "smpType": "None",
// "triggerDirection": 0,
// "blockTradeId": "",
// "cumFeeDetail": {
// "USDT": "0.06739145"
// },
// "rejectReason": "EC_NoError",
// "isLeverage": "",
// "price": "120518",
// "orderIv": "",
// "createdTime": "1757837618905",
// "tpTriggerBy": "",
// "positionIdx": 0,
// "timeInForce": "IOC",
// "leavesValue": "0",
// "updatedTime": "1757837618909",
// "side": "Sell",
// "smpGroup": 0,
// "triggerPrice": "",
// "tpLimitPrice": "0",
// "cumExecFee": "0.06739145",
// "slTriggerBy": "",
// "leavesQty": "0",
// "closeOnTrigger": false,
// "slippageToleranceType": "UNKNOWN",
// "placeType": "",
// "cumExecQty": "0.001",
// "reduceOnly": true,
// "qty": "0.001",
// "stopLoss": "",
// "smpOrderId": "",
// "slippageTolerance": "0",
// "triggerBy": "",
// "extraFees": ""
// }
//
// createOrders failed order
// {
// "category": "linear",
// "symbol": "LTCUSDT",
// "orderId": '',
// "orderLinkId": '',
// "createAt": '',
// "code": "10001",
// "msg": "The number of contracts exceeds maximum limit allowed: too large"
// }
//
let mut code: Value = self.safe_string_k(order.clone(), "code", &[]);
if !is_equal(&code, &Value::Null) {
if !is_equal(&code, &Value::Str("0".to_string())) {
let mut category: Value = self.safe_string_k(order.clone(), "category", &[]);
let mut inferredMarketType: Value = ternary(is_true(&(is_equal(&category, &Value::Str("spot".to_string())))), Value::Str("spot".to_string()), Value::Str("contract".to_string()));
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("status".to_string(), Value::Str("rejected".to_string()));
m.insert("id".to_string(), self.safe_string_k(order.clone(), "orderId", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "orderLinkId", &[]));
m.insert("symbol".to_string(), self.safe_symbol(self.safe_string_k(order.clone(), "symbol", &[]), &[Value::Null, Value::Null, inferredMarketType.clone()]));
m
}), &[]);
}
}
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut isContract: Value = (Value::Bool(in_op(&order, &Value::Str("tpslMode".to_string()))));
let mut marketType: Value = Value::Null;
if !is_equal(&market, &Value::Null) {
marketType = get_value(&market, &Value::Str("type".to_string()));
} else {
marketType = ternary(is_true(&isContract), Value::Str("contract".to_string()), Value::Str("spot".to_string()));
}
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer2(order.clone(), Value::Str("createdTime".to_string()), Value::Str("createdAt".to_string()), &[]);
let mut marketUnit: Value = self.safe_string_k(order.clone(), "marketUnit", &[]); // '' is filtered by safeString, do not force a default:
// bybit's spot Market Buy qty is quote-denominated unless marketUnit is explicitly 'baseCoin',
// see https://github.com/ccxt/ccxt/issues/27725
let mut id: Value = self.safe_string_k(order.clone(), "orderId", &[]);
let mut type_var: Value = self.safe_string_lower(order.clone(), Value::Str("orderType".to_string()), &[]);
let mut price: Value = self.safe_string_k(order.clone(), "price", &[]);
let mut side: Value = self.safe_string_lower(order.clone(), Value::Str("side".to_string()), &[]);
let mut amount: Value = Value::Null;
let mut cost: Value = Value::Null;
let mut qtyIsQuote: Value = Value::Bool(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_true(&(is_equal(&marketUnit, &Value::Str("quoteCoin".to_string())))) || is_true(&(is_true(&(is_equal(&marketUnit, &Value::Null))) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))))))));
if is_equal(&qtyIsQuote, &Value::Bool(true)) {
// qty is denominated in the quote currency, safeOrder derives amount from filled + remaining
cost = self.safe_string_k(order.clone(), "cumExecValue", &[]);
} else {
amount = self.safe_string_k(order.clone(), "qty", &[]);
cost = self.safe_string_k(order.clone(), "cumExecValue", &[]);
}
let mut filled: Value = self.safe_string_k(order.clone(), "cumExecQty", &[]);
let mut remaining: Value = self.safe_string_k(order.clone(), "leavesQty", &[]);
let mut lastTradeTimestamp: Value = self.safe_integer2(order.clone(), Value::Str("updatedTime".to_string()), Value::Str("updatedAt".to_string()), &[]);
let mut rawStatus: Value = self.safe_string_k(order.clone(), "orderStatus", &[]);
let mut status: Value = self.parse_order_status(rawStatus.clone());
let mut fee: Value = Value::Null;
let mut cumFeeDetail: Value = self.safe_dict_k(order.clone(), "cumFeeDetail", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut feeCoins: Value = object_keys(&cumFeeDetail);
let mut feeCoinId: Value = self.safe_string(feeCoins.clone(), Value::Int(0), &[]);
if !is_equal(&feeCoinId, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.safe_number(cumFeeDetail.clone(), feeCoinId.clone(), &[]));
m.insert("currency".to_string(), feeCoinId.clone());
m
});
}
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "orderLinkId", &[]);
if is_true(&(!is_equal(&clientOrderId, &Value::Null))) && is_true(&(is_less_than(&get_array_length(&clientOrderId), &Value::Int(1)))) {
clientOrderId = Value::Null;
}
let mut avgPrice: Value = self.omit_zero(self.safe_string_k(order.clone(), "avgPrice", &[]));
let mut rawTimeInForce: Value = self.safe_string_k(order.clone(), "timeInForce", &[]);
let mut timeInForce: Value = self.parse_time_in_force(rawTimeInForce.clone());
let mut triggerPrice: Value = self.omit_zero(self.safe_string_k(order.clone(), "triggerPrice", &[]));
let mut reduceOnly: Value = self.safe_bool_k(order.clone(), "reduceOnly", &[]);
let mut takeProfitPrice: Value = self.omit_zero(self.safe_string_k(order.clone(), "takeProfit", &[]));
let mut stopLossPrice: Value = self.omit_zero(self.safe_string_k(order.clone(), "stopLoss", &[]));
let mut triggerDirection: Value = self.safe_string_k(order.clone(), "triggerDirection", &[]);
let mut isAscending: bool = is_equal(&triggerDirection, &Value::Str("1".to_string()));
let mut isStopOrderType2: Value = Value::Bool(is_true(&(!is_equal(&triggerPrice, &Value::Null))) && is_true(&reduceOnly));
if is_true(&(is_equal(&stopLossPrice, &Value::Null))) && is_true(&(is_equal(&isStopOrderType2, &Value::Bool(true)))) {
// check if order is stop order type 2 - stopLossPrice
if is_true(&isAscending) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
// stopLoss order against short position
stopLossPrice = triggerPrice.clone();
}
if !is_true(&isAscending) && is_true(&(is_equal(&side, &Value::Str("sell".to_string())))) {
// stopLoss order against a long position
stopLossPrice = triggerPrice.clone();
}
}
if is_true(&(is_equal(&takeProfitPrice, &Value::Null))) && is_true(&(is_equal(&isStopOrderType2, &Value::Bool(true)))) {
// check if order is stop order type 2 - takeProfitPrice
if is_true(&isAscending) && is_true(&(is_equal(&side, &Value::Str("sell".to_string())))) {
// takeprofit order against a long position
takeProfitPrice = triggerPrice.clone();
}
if !is_true(&isAscending) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
// takeprofit order against a short position
takeProfitPrice = triggerPrice.clone();
}
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), lastTradeTimestamp.clone());
m.insert("lastUpdateTimestamp".to_string(), lastTradeTimestamp.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("timeInForce".to_string(), timeInForce.clone());
m.insert("postOnly".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), self.safe_bool_k(order.clone(), "reduceOnly", &[]));
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("triggerPrice".to_string(), triggerPrice.clone());
m.insert("takeProfitPrice".to_string(), takeProfitPrice.clone());
m.insert("stopLossPrice".to_string(), stopLossPrice.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("average".to_string(), avgPrice.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), remaining.clone());
m.insert("status".to_string(), status.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("trades".to_string(), Value::Null);
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @see https://bybit-exchange.github.io/docs/v5/order/create-order
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketBuyOrderWithCost() supports spot orders only".to_string()))));
}
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), cost.clone());
m
});
let __ws_arg_20 = self.extend(req.clone(), &[params.clone()]);
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), negate(&Value::Int(1)), &[Value::Null, __ws_arg_20]).await;
Value::Null
}
/*
* @method
* @name bybit#createMarkeSellOrderWithCost
* @description create a market sell order by providing the symbol and cost
* @see https://bybit-exchange.github.io/docs/v5/order/create-order
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut types: Value = self.is_unified_enabled(&[]).await;
let mut enableUnifiedAccount: Value = get_value(&types, &Value::Int(1));
if !is_equal(&enableUnifiedAccount, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketSellOrderWithCost() supports UTA accounts only".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
if !is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createMarketSellOrderWithCost() supports spot orders only".to_string()))));
}
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), cost.clone());
m
});
let __ws_arg_21 = self.extend(req.clone(), &[params.clone()]);
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("sell".to_string()), negate(&Value::Int(1)), &[Value::Null, __ws_arg_21]).await;
Value::Null
}
/*
* @method
* @name bybit#createOrder
* @description create a trade order
* @see https://bybit-exchange.github.io/docs/v5/order/create-order
* @see https://bybit-exchange.github.io/docs/v5/position/trading-stop
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.timeInForce] "GTC", "IOC", "FOK"
* @param {bool} [params.postOnly] true or false whether the order is post-only
* @param {bool} [params.reduceOnly] true or false whether the order is reduce-only
* @param {string} [params.positionIdx] *contracts only* 0 for one-way mode, 1 buy side of hedged mode, 2 sell side of hedged mode
* @param {bool} [params.hedged] *contracts only* true for hedged mode, false for one way mode, default is false
* @param {int} [params.isLeverage] *unified spot only* false then spot trading true then margin trading
* @param {string} [params.tpslMode] *contract only* 'Full' or 'Partial'
* @param {string} [params.mmp] *option only* market maker protection
* @param {string} [params.triggerDirection] *contract only* the direction for trigger orders, 'ascending' or 'descending'
* @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
* @param {float} [params.stopLossPrice] The price at which a stop loss order is triggered at
* @param {float} [params.stopLossLimitPrice] The limit price for a stoploss order (only when used in OCO with takeProfitPrice)
* @param {float} [params.takeProfitPrice] The price at which a take profit order is triggered at
* @param {float} [params.takeProfitLimitPrice] The limit price for a takeprofit order (only when used in OCO combination with stopLossPrice)
* @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 {string} [params.trailingAmount] the quote amount to trail away from the current market price
* @param {string} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
* @param {boolean} [params.tradingStopEndpoint] whether to enforce using the tradingStop (https://bybit-exchange.github.io/docs/v5/position/trading-stop) endpoint, makes difference when submitting single tp/sl order
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut parts: Value = self.is_unified_enabled(&[]).await;
let mut enableUnifiedAccount: Value = get_value(&parts, &Value::Int(1));
let mut isTrailingOrder: bool = !is_equal(&self.safe_string2(params.clone(), Value::Str("trailingAmount".to_string()), Value::Str("trailingStop".to_string()), &[]), &Value::Null);
let mut isStopLossOrder: bool = !is_equal(&self.safe_string_k(params.clone(), "stopLossPrice", &[]), &Value::Null);
let mut isTakeProfitOrder: bool = !is_equal(&self.safe_string_k(params.clone(), "takeProfitPrice", &[]), &Value::Null);
let mut orderRequest: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone(), enableUnifiedAccount.clone()]);
let mut switchToOco: Value = Value::Bool(is_true(&(is_true(&isStopLossOrder) && is_true(&isTakeProfitOrder))) || is_true(&self.safe_bool_k(params.clone(), "tradingStopEndpoint", &[Value::Bool(false)])));
let mut defaultMethod: Value = Value::Null;
if is_true(&(is_true(&isTrailingOrder) || is_true(&(is_equal(&switchToOco, &Value::Bool(true)))))) && is_true(&(!is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) {
defaultMethod = Value::Str("privatePostV5PositionTradingStop".to_string());
} else {
defaultMethod = Value::Str("privatePostV5OrderCreate".to_string());
}
let mut method: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("method".to_string()), &[defaultMethod.clone()]); method = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privatePostV5PositionTradingStop".to_string())) {
response = self.private_post_v5_position_trading_stop(&[orderRequest.clone()]).await;
} else {
response = self.private_post_v5_order_create(&[orderRequest.clone()]).await;
}
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "orderId": "1321003749386327552",
// "orderLinkId": "spot-test-postonly"
// },
// "retExtInfo": {},
// "time": 1672211918471
// }
//
let mut order: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
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
}));
let mut isUTA = get_arg(optional_args, 2, Value::Bool(true));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut lowerCaseType: Value = to_lower(&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
});
let mut hedged: Value = self.safe_bool_k(params.clone(), "hedged", &[Value::Bool(false)]);
let mut reduceOnly: Value = self.safe_bool_k(params.clone(), "reduceOnly", &[]);
let mut triggerPrice: Value = self.safe_value2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossTriggerPrice: Value = self.safe_value_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitTriggerPrice: Value = self.safe_value_k(params.clone(), "takeProfitPrice", &[]);
let mut stopLoss: Value = self.safe_value_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_value_k(params.clone(), "takeProfit", &[]);
let mut trailingTriggerPrice: Value = self.safe_string2(params.clone(), Value::Str("trailingTriggerPrice".to_string()), Value::Str("activePrice".to_string()), &[self.number_to_string(price.clone())]);
let mut trailingAmount: Value = self.safe_string2(params.clone(), Value::Str("trailingAmount".to_string()), Value::Str("trailingStop".to_string()), &[]);
let mut isTrailingOrder: bool = !is_equal(&trailingAmount, &Value::Null);
let mut isTriggerOrder: bool = !is_equal(&triggerPrice, &Value::Null);
let mut isStopLossOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
let mut isMarket: Value = Value::Bool(is_equal(&lowerCaseType, &Value::Str("market".to_string())));
let mut isLimit: bool = is_equal(&lowerCaseType, &Value::Str("limit".to_string()));
let mut isBuy: bool = is_equal(&side, &Value::Str("buy".to_string()));
let mut switchToOco: Value = Value::Bool(is_true(&(is_true(&isStopLossOrder) && is_true(&isTakeProfitOrder))) || is_true(&self.safe_bool_k(params.clone(), "tradingStopEndpoint", &[Value::Bool(false)])));
let mut defaultMethod: Value = Value::Null;
if is_true(&isTrailingOrder) || is_true(&(is_equal(&switchToOco, &Value::Bool(true)))) {
defaultMethod = Value::Str("privatePostV5PositionTradingStop".to_string());
} else {
defaultMethod = Value::Str("privatePostV5OrderCreate".to_string());
}
let mut method: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("method".to_string()), &[defaultMethod.clone()]); method = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut endpointIsTradingStop: bool = is_equal(&method, &Value::Str("privatePostV5PositionTradingStop".to_string()));
if is_true(&(is_equal(&price, &Value::Null))) && is_true(&(is_equal(&lowerCaseType, &Value::Str("limit".to_string())))) && !is_true(&endpointIsTradingStop) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrder requires a price argument for limit orders".to_string()))));
}
// workaround, bcz for some langs we have to allow 0.0 as input (bcz of type)
if !is_true(&crate::precise::Precise::stringGt(&self.number_to_string(amount.clone()), &Value::Str("0".to_string()))) {
amount = Value::Null;
}
let mut amountString: Value = ternary(is_true(&(!is_equal(&amount, &Value::Null))), self.get_amount(symbol.clone(), amount.clone()), Value::Null);
let mut priceString: Value = ternary(is_true(&(!is_equal(&price, &Value::Null))), self.get_price(symbol.clone(), self.number_to_string(price.clone())), Value::Null);
if is_true(&endpointIsTradingStop) {
if is_true(&hasStopLoss) || is_true(&hasTakeProfit) || is_true(&isTriggerOrder) || is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" the API endpoint used only supports contract trailingAmount, stopLossPrice and takeProfitPrice orders".to_string()))));
}
if is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder) {
let mut tpslModeSl: Value = Value::Null;
let mut tpslModeTp: Value = Value::Null;
if is_true(&isStopLossOrder) {
add_element_to_object(&mut request, &Value::Str("stopLoss".to_string()), self.get_price(symbol.clone(), stopLossTriggerPrice.clone()));
let mut stopLossLimitPrice: Value = self.safe_string2(params.clone(), Value::Str("stopLossLimitPrice".to_string()), Value::Str("slLimitPrice".to_string()), &[]);
if !is_equal(&stopLossLimitPrice, &Value::Null) {
tpslModeSl = Value::Str("Partial".to_string());
add_element_to_object(&mut request, &Value::Str("slOrderType".to_string()), Value::Str("Limit".to_string()));
add_element_to_object(&mut request, &Value::Str("slLimitPrice".to_string()), stopLossLimitPrice.clone());
add_element_to_object(&mut request, &Value::Str("slSize".to_string()), amountString.clone());
} else {
add_element_to_object(&mut request, &Value::Str("slOrderType".to_string()), Value::Str("Market".to_string()));
if !is_equal(&amountString, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("slSize".to_string()), amountString.clone());
tpslModeSl = Value::Str("Partial".to_string());
} else {
tpslModeSl = Value::Str("Full".to_string());
}
}
}
if is_true(&isTakeProfitOrder) {
add_element_to_object(&mut request, &Value::Str("takeProfit".to_string()), self.get_price(symbol.clone(), takeProfitTriggerPrice.clone()));
let mut takeProfitLimitPrice: Value = self.safe_string2(params.clone(), Value::Str("takeProfitLimitPrice".to_string()), Value::Str("tpLimitPrice".to_string()), &[]);
if !is_equal(&takeProfitLimitPrice, &Value::Null) {
tpslModeTp = Value::Str("Partial".to_string());
add_element_to_object(&mut request, &Value::Str("tpOrderType".to_string()), Value::Str("Limit".to_string()));
add_element_to_object(&mut request, &Value::Str("tpLimitPrice".to_string()), takeProfitLimitPrice.clone());
add_element_to_object(&mut request, &Value::Str("tpSize".to_string()), amountString.clone());
} else {
add_element_to_object(&mut request, &Value::Str("tpOrderType".to_string()), Value::Str("Market".to_string()));
if !is_equal(&amountString, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tpSize".to_string()), amountString.clone());
tpslModeTp = Value::Str("Partial".to_string());
} else {
tpslModeTp = Value::Str("Full".to_string());
}
}
}
if is_true(&isTakeProfitOrder) && is_true(&isStopLossOrder) && !is_equal(&tpslModeSl, &tpslModeTp) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires both stopLoss and takeProfit to be full or partial when using as OCO combination".to_string()))));
}
if !is_equal(&tpslModeSl, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tpslMode".to_string()), tpslModeSl.clone());
} else {
add_element_to_object(&mut request, &Value::Str("tpslMode".to_string()), tpslModeTp.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopLossLimitPrice".to_string()), Value::Str("takeProfitLimitPrice".to_string()), Value::Str("tradingStopEndpoint".to_string())]), &[]);
}
} else {
add_element_to_object(&mut request, &Value::Str("side".to_string()), self.capitalize(side.clone()));
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), self.capitalize(lowerCaseType.clone()));
let mut timeInForce: Value = self.safe_string_lower(params.clone(), Value::Str("timeInForce".to_string()), &[]); // this is same as exchange specific param
let mut postOnly: Value = Value::Null;
{ let __destr_tmp = self.handle_post_only(isMarket.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_equal(&postOnly, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), Value::Str("PostOnly".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()));
} else 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()));
} 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()));
}
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
// only works for spot market
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), Value::Str("StopOrder".to_string()));
} else if is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder) {
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), Value::Str("tpslOrder".to_string()));
}
}
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderLinkId".to_string()), clientOrderId.clone());
} else if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
// mandatory field for options
add_element_to_object(&mut request, &Value::Str("orderLinkId".to_string()), self.uuid16(&[]));
}
if is_true(&isLimit) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), priceString.clone());
}
}
let mut category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("createOrderRequest".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), category.clone());
let mut cost: Value = self.safe_string_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
// if the cost is inferable, let's keep the old logic and ignore marketUnit, to minimize the impact of the changes
let mut isMarketBuyAndCostInferable: bool = is_true(&(is_equal(&lowerCaseType, &Value::Str("market".to_string())))) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) && is_true(&(is_true(&(!is_equal(&price, &Value::Null))) || is_true(&(!is_equal(&cost, &Value::Null)))));
let mut isMarketOrder: bool = is_equal(&lowerCaseType, &Value::Str("market".to_string()));
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&isMarketOrder) && is_true(&isUTA) && !is_true(&isMarketBuyAndCostInferable) {
// UTA account can specify the cost of the order on both sides
if is_true(&(!is_equal(&cost, &Value::Null))) || is_true(&(!is_equal(&price, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("marketUnit".to_string()), Value::Str("quoteCoin".to_string()));
let mut orderCost: Value = Value::Null;
if !is_equal(&cost, &Value::Null) {
orderCost = cost.clone();
} else {
let mut quoteAmount: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
orderCost = quoteAmount.clone();
}
add_element_to_object(&mut request, &Value::Str("qty".to_string()), self.get_cost(symbol.clone(), orderCost.clone()));
} else {
add_element_to_object(&mut request, &Value::Str("marketUnit".to_string()), Value::Str("baseCoin".to_string()));
add_element_to_object(&mut request, &Value::Str("qty".to_string()), amountString.clone());
}
} else if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&isMarketOrder) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
// classic accounts
// for market buy it requires the amount of quote currency to spend
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("createMarketBuyOrderRequiresPrice".to_string()), &[]); createMarketBuyOrderRequiresPrice = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&createMarketBuyOrderRequiresPrice) {
if is_true(&(is_equal(&price, &Value::Null))) && is_true(&(is_equal(&cost, &Value::Null))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument".to_string()))));
} else {
let mut quoteAmount: Value = crate::precise::Precise::stringMul(&self.number_to_string(amount.clone()), &priceString);
let mut costRequest: Value = ternary(is_true(&(!is_equal(&cost, &Value::Null))), cost.clone(), quoteAmount.clone());
add_element_to_object(&mut request, &Value::Str("qty".to_string()), self.get_cost(symbol.clone(), costRequest.clone()));
}
} else {
if !is_equal(&cost, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("qty".to_string()), self.get_cost(symbol.clone(), self.number_to_string(cost.clone())));
} else if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("qty".to_string()), self.get_cost(symbol.clone(), crate::precise::Precise::stringMul(&amountString, &priceString)));
} else {
add_element_to_object(&mut request, &Value::Str("qty".to_string()), amountString.clone());
}
}
} else {
if !is_true(&isTrailingOrder) && !is_true(&endpointIsTradingStop) {
add_element_to_object(&mut request, &Value::Str("qty".to_string()), amountString.clone());
}
}
if is_true(&isTrailingOrder) {
if !is_equal(&trailingTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("activePrice".to_string()), self.get_price(symbol.clone(), trailingTriggerPrice.clone()));
}
add_element_to_object(&mut request, &Value::Str("trailingStop".to_string()), trailingAmount.clone());
} else if is_true(&isTriggerOrder) && !is_true(&endpointIsTradingStop) {
let mut triggerDirection: Value = self.safe_string_k(params.clone(), "triggerDirection", &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerDirection".to_string())]), &[]);
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
if !is_equal(&triggerDirection, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrder() : trigger order does not support triggerDirection for spot markets yet".to_string()))));
}
} else {
if is_equal(&triggerDirection, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" stop/trigger orders require a triggerDirection parameter, either \"ascending\" or \"descending\" to determine the direction of the trigger.".to_string()))));
}
let mut isAsending: bool = is_true(&(is_equal(&triggerDirection, &Value::Str("ascending".to_string())))) || is_true(&(is_equal(&triggerDirection, &Value::Str("above".to_string())))) || is_true(&(is_equal(&triggerDirection, &Value::Str("1".to_string()))));
add_element_to_object(&mut request, &Value::Str("triggerDirection".to_string()), ternary(is_true(&isAsending), Value::Int(1), Value::Int(2)));
}
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.get_price(symbol.clone(), triggerPrice.clone()));
} else if is_true(&(is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder))) && !is_true(&endpointIsTradingStop) {
if is_true(&isBuy) {
add_element_to_object(&mut request, &Value::Str("triggerDirection".to_string()), ternary(is_true(&isStopLossOrder), Value::Int(1), Value::Int(2)));
} else {
add_element_to_object(&mut request, &Value::Str("triggerDirection".to_string()), ternary(is_true(&isStopLossOrder), Value::Int(2), Value::Int(1)));
}
triggerPrice = ternary(is_true(&isStopLossOrder), stopLossTriggerPrice.clone(), takeProfitTriggerPrice.clone());
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.get_price(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("reduceOnly".to_string()), Value::Bool(true));
}
if is_true(&(is_true(&hasStopLoss) || is_true(&hasTakeProfit))) && !is_true(&endpointIsTradingStop) {
if is_true(&hasStopLoss) {
let mut slTriggerPrice: Value = self.safe_value2(stopLoss.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[stopLoss.clone()]);
add_element_to_object(&mut request, &Value::Str("stopLoss".to_string()), self.get_price(symbol.clone(), slTriggerPrice.clone()));
let mut slLimitPrice: Value = self.safe_value_k(stopLoss.clone(), "price", &[]);
if !is_equal(&slLimitPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tpslMode".to_string()), Value::Str("Partial".to_string()));
add_element_to_object(&mut request, &Value::Str("slOrderType".to_string()), Value::Str("Limit".to_string()));
add_element_to_object(&mut request, &Value::Str("slLimitPrice".to_string()), self.get_price(symbol.clone(), slLimitPrice.clone()));
} else {
// for spot market, we need to add this
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("slOrderType".to_string()), Value::Str("Market".to_string()));
}
}
// for spot market, we need to add this
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&isMarketOrder) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder(): attached stopLoss is not supported for spot market orders".to_string()))));
}
}
if is_true(&hasTakeProfit) {
let mut tpTriggerPrice: Value = self.safe_value2(takeProfit.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[takeProfit.clone()]);
add_element_to_object(&mut request, &Value::Str("takeProfit".to_string()), self.get_price(symbol.clone(), tpTriggerPrice.clone()));
let mut tpLimitPrice: Value = self.safe_value_k(takeProfit.clone(), "price", &[]);
if !is_equal(&tpLimitPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tpslMode".to_string()), Value::Str("Partial".to_string()));
add_element_to_object(&mut request, &Value::Str("tpOrderType".to_string()), Value::Str("Limit".to_string()));
add_element_to_object(&mut request, &Value::Str("tpLimitPrice".to_string()), self.get_price(symbol.clone(), tpLimitPrice.clone()));
} else {
// for spot market, we need to add this
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("tpOrderType".to_string()), Value::Str("Market".to_string()));
}
}
// for spot market, we need to add this
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&isMarketOrder) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder(): attached takeProfit is not supported for spot market orders".to_string()))));
}
}
}
if is_true(&(!is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) && is_true(&(is_equal(&hedged, &Value::Bool(true)))) {
if is_equal(&reduceOnly, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("reduceOnly".to_string()), &[]);
side = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Str("sell".to_string()), Value::Str("buy".to_string()));
}
add_element_to_object(&mut request, &Value::Str("positionIdx".to_string()), ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), Value::Int(1), Value::Int(2)));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("timeInForce".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("postOnly".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string()), Value::Str("trailingAmount".to_string()), Value::Str("trailingTriggerPrice".to_string()), Value::Str("hedged".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name bybit#createOrders
* @description create a list of trade orders
* @see https://bybit-exchange.github.io/docs/v5/order/batch-place
* @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
* @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_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 accounts: Value = self.is_unified_enabled(&[]).await;
let mut isUta: Value = get_value(&accounts, &Value::Int(1));
let mut ordersRequests: Value = Value::List(vec![]);
let mut orderSymbols: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_489: bool = true;
while { if !__for_first_489 { i = add(&i, &Value::Int(1)); } __for_first_489 = 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", &[]);
append_to_array(&mut orderSymbols, marketId.clone());
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_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(), isUta.clone()]);
remove(&mut orderRequest, &Value::Str("category".to_string()));
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut symbols: Value = self.market_symbols(&[orderSymbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
let mut unifiedMarginStatus: Value = self.safe_integer_k(self.options.clone(), "unifiedMarginStatus", &[Value::Int(6)]);
let mut category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("createOrders".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&category, &Value::Str("inverse".to_string())))) && is_true(&(is_less_than(&unifiedMarginStatus, &Value::Int(5)))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrders does not allow inverse orders for non UTA2.0 account".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), category.clone());
m.insert("request".to_string(), ordersRequests.clone());
m
});
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_order_create_batch(&[__ws_arg_22]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut retInfo: Value = self.safe_dict_k(response.clone(), "retExtInfo", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut codes: Value = self.safe_list_k(retInfo.clone(), "list", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_490: bool = true;
while { if !__for_first_490 { i = add(&i, &Value::Int(1)); } __for_first_490 = false; is_less_than(&i, &get_array_length(&codes)) } {
let mut code: Value = get_value(&codes, &i);
let mut code: Value = get_value(&codes, &i);
let mut retCode: Value = self.safe_integer_k(code.clone(), "code", &[]);
if !is_equal(&retCode, &Value::Int(0)) {
{ let __be_tmp = self.extend(get_value(&data, &i), &[code.clone()]); add_element_to_object(&mut data, &i, __be_tmp); };
}
}
}
return self.parse_orders(data.clone(), &[]);
Value::Null
}
pub fn edit_order_request(&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(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
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("orderLinkId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderLinkId".to_string()), clientOrderId.clone());
}
let mut category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("editOrderRequest".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), category.clone());
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("qty".to_string()), self.get_amount(symbol.clone(), amount.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("price".to_string()), self.get_price(symbol.clone(), self.number_to_string(price.clone())));
}
let mut triggerPrice: Value = self.safe_string2(params.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[]);
let mut stopLossTriggerPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut takeProfitTriggerPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut stopLoss: Value = self.safe_value_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_value_k(params.clone(), "takeProfit", &[]);
let mut isStopLossOrder: bool = !is_equal(&stopLossTriggerPrice, &Value::Null);
let mut isTakeProfitOrder: bool = !is_equal(&takeProfitTriggerPrice, &Value::Null);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
if is_true(&isStopLossOrder) || is_true(&isTakeProfitOrder) {
triggerPrice = ternary(is_true(&isStopLossOrder), stopLossTriggerPrice.clone(), takeProfitTriggerPrice.clone());
}
if !is_equal(&triggerPrice, &Value::Null) {
let mut triggerPriceRequest: Value = ternary(is_true(&(is_equal(&triggerPrice, &Value::Str("0".to_string())))), triggerPrice.clone(), self.get_price(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), triggerPriceRequest.clone());
let mut triggerBy: Value = self.safe_string_k(params.clone(), "triggerBy", &[Value::Str("LastPrice".to_string())]);
add_element_to_object(&mut request, &Value::Str("triggerBy".to_string()), triggerBy.clone());
}
if is_true(&hasStopLoss) || is_true(&hasTakeProfit) {
if is_true(&hasStopLoss) {
let mut slTriggerPrice: Value = self.safe_string2(stopLoss.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[stopLoss.clone()]);
let mut stopLossRequest: Value = ternary(is_true(&(is_equal(&slTriggerPrice, &Value::Str("0".to_string())))), slTriggerPrice.clone(), self.get_price(symbol.clone(), slTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("stopLoss".to_string()), stopLossRequest.clone());
let mut slTriggerBy: Value = self.safe_string_k(params.clone(), "slTriggerBy", &[Value::Str("LastPrice".to_string())]);
add_element_to_object(&mut request, &Value::Str("slTriggerBy".to_string()), slTriggerBy.clone());
}
if is_true(&hasTakeProfit) {
let mut tpTriggerPrice: Value = self.safe_string2(takeProfit.clone(), Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), &[takeProfit.clone()]);
let mut takeProfitRequest: Value = ternary(is_true(&(is_equal(&tpTriggerPrice, &Value::Str("0".to_string())))), tpTriggerPrice.clone(), self.get_price(symbol.clone(), tpTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("takeProfit".to_string()), takeProfitRequest.clone());
let mut tpTriggerBy: Value = self.safe_string_k(params.clone(), "tpTriggerBy", &[Value::Str("LastPrice".to_string())]);
add_element_to_object(&mut request, &Value::Str("tpTriggerBy".to_string()), tpTriggerBy.clone());
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string())]), &[]);
return request;
Value::Null
}
/*
* @method
* @name bybit#editOrder
* @description edit a trade order
* @see https://bybit-exchange.github.io/docs/v5/order/amend-order
* @see https://bybit-exchange.github.io/docs/derivatives/unified/replace-order
* @see https://bybit-exchange.github.io/docs/api-explorer/derivatives/trade/contract/replace-order
* @param {string} id cancel 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 currency you want to trade in units of base currency
* @param {float} price the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] unique client order id
* @param {float} [params.triggerPrice] The price that a trigger order is triggered at
* @param {float} [params.stopLossPrice] The price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] The price that a take profit order is triggered at
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice that 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 that the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {string} [params.triggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for triggerPrice
* @param {string} [params.slTriggerBy] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for stopLoss
* @param {string} [params.tpTriggerby] 'IndexPrice', 'MarkPrice' or 'LastPrice', default is 'LastPrice', required if no initial value for takeProfit
* @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;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires a symbol argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.edit_order_request(id.clone(), symbol.clone(), type_var.clone(), side.clone(), &[amount.clone(), price.clone(), params.clone()]);
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_order_amend(&[__ws_arg_23]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "orderId": "c6f055d9-7f21-4079-913d-e6523a9cfffa",
// "orderLinkId": "linear-004"
// },
// "retExtInfo": {},
// "time": 1672217093461
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("id".to_string(), self.safe_string_k(result.clone(), "orderId", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(result.clone(), "orderLinkId", &[]));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#editOrders
* @description edit a list of trade orders
* @see https://bybit-exchange.github.io/docs/v5/order/batch-amend
* @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
* @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 edit_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 orderSymbols: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_491: bool = true;
while { if !__for_first_491 { i = add(&i, &Value::Int(1)); } __for_first_491 = 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 symbol: Value = self.safe_string_k(rawOrder.clone(), "symbol", &[]);
append_to_array(&mut orderSymbols, symbol.clone());
let mut id: Value = self.safe_string_k(rawOrder.clone(), "id", &[]);
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[]);
let mut side: Value = self.safe_string_k(rawOrder.clone(), "side", &[]);
let mut amount: Value = self.safe_value_k(rawOrder.clone(), "amount", &[]);
let mut price: Value = self.safe_value_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.edit_order_request(id.clone(), symbol.clone(), type_var.clone(), side.clone(), &[amount.clone(), price.clone(), orderParams.clone()]);
remove(&mut orderRequest, &Value::Str("category".to_string()));
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
orderSymbols = self.market_symbols(&[orderSymbols.clone(), Value::Null, Value::Bool(false), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.market(get_value(&orderSymbols, &Value::Int(0)));
let mut unifiedMarginStatus: Value = self.safe_integer_k(self.options.clone(), "unifiedMarginStatus", &[Value::Int(6)]);
let mut category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("editOrders".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&category, &Value::Str("inverse".to_string())))) && is_true(&(is_less_than(&unifiedMarginStatus, &Value::Int(5)))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" editOrders does not allow inverse orders for non UTA2.0 account".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), category.clone());
m.insert("request".to_string(), ordersRequests.clone());
m
});
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_order_amend_batch(&[__ws_arg_24]).await;
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut retInfo: Value = self.safe_dict_k(response.clone(), "retExtInfo", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut codes: Value = self.safe_list_k(retInfo.clone(), "list", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_492: bool = true;
while { if !__for_first_492 { i = add(&i, &Value::Int(1)); } __for_first_492 = false; is_less_than(&i, &get_array_length(&codes)) } {
let mut code: Value = get_value(&codes, &i);
let mut code: Value = get_value(&codes, &i);
let mut retCode: Value = self.safe_integer_k(code.clone(), "code", &[]);
if !is_equal(&retCode, &Value::Int(0)) {
{ let __be_tmp = self.extend(get_value(&data, &i), &[code.clone()]); add_element_to_object(&mut data, &i, __be_tmp); };
}
}
}
return self.parse_orders(data.clone(), &[]);
Value::Null
}
pub fn cancel_order_request(&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
}));
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
// only works for spot market
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("StopOrder".to_string()), Value::Str("Order".to_string())));
}
if !is_equal(&id, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("cancelOrderRequest".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), category.clone());
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name bybit#cancelOrder
* @description cancels an open order
* @see https://bybit-exchange.github.io/docs/v5/order/cancel-order
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] *spot only* whether the order is a trigger order
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.orderFilter] *spot only* 'Order' or 'StopOrder' or 'tpslOrder'
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut requestExtended: Value = self.cancel_order_request(id.clone(), &[symbol.clone(), params.clone()]);
let mut response: Value = self.private_post_v5_order_cancel(&[requestExtended.clone()]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "orderId": "c6f055d9-7f21-4079-913d-e6523a9cfffa",
// "orderLinkId": "linear-004"
// },
// "retExtInfo": {},
// "time": 1672217377164
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(result.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#cancelOrders
* @description cancel multiple orders
* @see https://bybit-exchange.github.io/docs/v5/order/batch-cancel
* @param {string[]} ids order ids
* @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.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 types: Value = self.is_unified_enabled(&[]).await;
let mut enableUnifiedAccount: Value = get_value(&types, &Value::Int(1));
if !is_equal(&enableUnifiedAccount, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrders() supports UTA accounts only".to_string()))));
}
let mut category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("cancelOrders".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&category, &Value::Str("inverse".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrders does not allow inverse orders".to_string()))));
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut clientOrderIds: Value = self.safe_list2(params.clone(), Value::Str("clientOrderIds".to_string()), Value::Str("clientOids".to_string()), &[Value::List(vec![])]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderIds".to_string()), Value::Str("clientOids".to_string())]), &[]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_493: bool = true;
while { if !__for_first_493 { i = add(&i, &Value::Int(1)); } __for_first_493 = false; is_less_than(&i, &get_array_length(&clientOrderIds)) } {
append_to_array(&mut ordersRequests, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("orderLinkId".to_string(), self.safe_string(clientOrderIds.clone(), i.clone(), &[]));
m
}));
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_494: bool = true;
while { if !__for_first_494 { i = add(&i, &Value::Int(1)); } __for_first_494 = false; is_less_than(&i, &get_array_length(&ids)) } {
append_to_array(&mut ordersRequests, 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(), self.safe_string(ids.clone(), i.clone(), &[]));
m
}));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), category.clone());
m.insert("request".to_string(), ordersRequests.clone());
m
});
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_order_cancel_batch(&[__ws_arg_25]).await;
//
// {
// "retCode": "0",
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "category": "spot",
// "symbol": "BTCUSDT",
// "orderId": "1636282505818800896",
// "orderLinkId": "1636282505818800897"
// },
// {
// "category": "spot",
// "symbol": "BTCUSDT",
// "orderId": "1636282505818800898",
// "orderLinkId": "1636282505818800899"
// }
// ]
// },
// "retExtInfo": {
// "list": [
// {
// "code": "0",
// "msg": "OK"
// },
// {
// "code": "0",
// "msg": "OK"
// }
// ]
// },
// "time": "1709796158501"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut row: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_orders(row.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#cancelAllOrdersAfter
* @description dead man's switch, cancel all orders after the given timeout
* @see https://bybit-exchange.github.io/docs/v5/order/dcp
* @param {number} timeout time in milliseconds
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.product] OPTIONS, DERIVATIVES, SPOT, default is 'DERIVATIVES'
* @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;
}
if is_equal(&timeout, &Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" cancelAllOrdersAfter() missing timeout".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeWindow".to_string(), self.parse_to_int(divide(&timeout, &Value::Int(1000))));
m
});
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(), Value::Str("swap".to_string())]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut productMap: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot".to_string(), Value::Str("SPOT".to_string()));
m.insert("swap".to_string(), Value::Str("DERIVATIVES".to_string()));
m.insert("option".to_string(), Value::Str("OPTIONS".to_string()));
m
});
let mut product: Value = self.safe_string(productMap.clone(), type_var.clone(), &[type_var.clone()]);
add_element_to_object(&mut request, &Value::Str("product".to_string()), product.clone());
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_order_disconnected_cancel_all(&[__ws_arg_26]).await;
return response;
Value::Null
}
/*
* @method
* @name bybit#cancelOrdersForSymbols
* @description cancel multiple orders for multiple symbols
* @see https://bybit-exchange.github.io/docs/v5/order/batch-cancel
* @param {CancellationRequest[]} orders list of order ids with symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders_for_symbols(&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 types: Value = self.is_unified_enabled(&[]).await;
let mut enableUnifiedAccount: Value = get_value(&types, &Value::Int(1));
if !is_equal(&enableUnifiedAccount, &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrdersForSymbols() supports UTA accounts only".to_string()))));
}
let mut ordersRequests: Value = Value::List(vec![]);
let mut category: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_495: bool = true;
while { if !__for_first_495 { i = add(&i, &Value::Int(1)); } __for_first_495 = false; is_less_than(&i, &get_array_length(&orders)) } {
let mut order: Value = get_value(&orders, &i);
let mut order: Value = get_value(&orders, &i);
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut market: Value = self.market(symbol.clone());
let mut currentCategory: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("cancelOrders".to_string()), market.clone(), &[params.clone()]); currentCategory = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(¤tCategory, &Value::Str("inverse".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" cancelOrdersForSymbols does not allow inverse orders".to_string()))));
}
if is_true(&(!is_equal(&category, &Value::Null))) && is_true(&(!is_equal(&category, ¤tCategory))) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" cancelOrdersForSymbols requires all orders to be of the same category (linear, spot or option))".to_string()))));
}
category = currentCategory.clone();
let mut id: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "clientOrderId", &[]);
let mut idKey: Value = Value::Str("orderId".to_string());
if !is_equal(&clientOrderId, &Value::Null) {
idKey = Value::Str("orderLinkId".to_string());
}
let mut orderItem: 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 orderItem, &idKey, ternary(is_true(&(is_equal(&idKey, &Value::Str("orderId".to_string())))), id.clone(), clientOrderId.clone()));
append_to_array(&mut ordersRequests, orderItem.clone());
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), category.clone());
m.insert("request".to_string(), ordersRequests.clone());
m
});
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_order_cancel_batch(&[__ws_arg_27]).await;
//
// {
// "retCode": "0",
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "category": "spot",
// "symbol": "BTCUSDT",
// "orderId": "1636282505818800896",
// "orderLinkId": "1636282505818800897"
// },
// {
// "category": "spot",
// "symbol": "BTCUSDT",
// "orderId": "1636282505818800898",
// "orderLinkId": "1636282505818800899"
// }
// ]
// },
// "retExtInfo": {
// "list": [
// {
// "code": "0",
// "msg": "OK"
// },
// {
// "code": "0",
// "msg": "OK"
// }
// ]
// },
// "time": "1709796158501"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut row: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_orders(row.clone(), &[]);
Value::Null
}
/*
* @method
* @name bybit#cancelAllOrders
* @description cancel all open orders
* @see https://bybit-exchange.github.io/docs/v5/order/cancel-all
* @param {string} [symbol] unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] true if trigger order
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.baseCoin] Base coin. Supports linear, inverse & option
* @param {string} [params.settleCoin] Settle coin. Supports linear, inverse & option
* @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 enableUnifiedMarginenableUnifiedAccountVariable = self.is_unified_enabled(&[]).await;
let mut enableUnifiedMargin: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(0));
let mut enableUnifiedAccount: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(1));
let mut isUnifiedAccount: bool = is_true(&(is_equal(&enableUnifiedMargin, &Value::Bool(true)))) || is_true(&(is_equal(&enableUnifiedAccount, &Value::Bool(true))));
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 __destr_tmp = self.get_bybit_type(Value::Str("cancelAllOrders".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
if is_true(&(is_equal(&type_var, &Value::Str("option".to_string())))) && !is_true(&isUnifiedAccount) {
panic!("{}", crate::exchange_errors::not_supported(add(&add(&add(&self.id, &Value::Str(" cancelAllOrders() Normal Account not support ".to_string())), &type_var), &Value::Str(" market".to_string()))));
}
if is_true(&(is_equal(&type_var, &Value::Str("linear".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("inverse".to_string())))) {
let mut baseCoin: Value = self.safe_string_k(params.clone(), "baseCoin", &[]);
if is_equal(&symbol, &Value::Null) && is_equal(&baseCoin, &Value::Null) {
let mut defaultSettle: Value = self.safe_string_k(self.options.clone(), "defaultSettle", &[Value::Str("USDT".to_string())]);
add_element_to_object(&mut request, &Value::Str("settleCoin".to_string()), self.safe_string_k(params.clone(), "settleCoin", &[defaultSettle.clone()]));
}
}
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), Value::Str("StopOrder".to_string()));
}
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_order_cancel_all(&[__ws_arg_28]).await;
//
// linear / inverse / option
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "orderId": "f6a73e1f-39b5-4dee-af21-1460b2e3b27c",
// "orderLinkId": "a001"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672219780463
// }
//
// spot
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "success": "1"
// },
// "retExtInfo": {},
// "time": 1676962409398
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orders: Value = self.safe_list_k(result.clone(), "list", &[]);
if !is_true(&Value::Bool(is_array(&orders))) {
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[])]);
}
return self.parse_orders(orders.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchOrderClassic
* @description fetches information on an order made by the user *classic accounts only*
* @see https://bybit-exchange.github.io/docs/v5/order/order-list
* @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
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order_classic(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrder() is not supported for spot markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id.clone());
m
});
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
let mut result: Value = self.fetch_orders_classic(&[symbol.clone(), Value::Null, Value::Null, __ws_arg_29]).await;
let mut length: Value = get_array_length(&result);
if is_equal(&length, &Value::Int(0)) {
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
let mut extra: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("".to_string()), Value::Str(" If you are trying to fetch SL/TP conditional order, you might try setting params[\"trigger\"] = true".to_string()));
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&add(&Value::Str("Order ".to_string()), &to_string_val(&id)), &Value::Str(" was not found.".to_string())), &extra)));
}
if is_greater_than(&length, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" returned more than one order".to_string()))));
}
return self.safe_value(result.clone(), Value::Int(0), &[]);
Value::Null
}
/*
* @method
* @name bybit#fetchOrder
* @description *classic accounts only/ spot not supported* fetches information on an order made by the user *classic accounts only*
* @see https://bybit-exchange.github.io/docs/v5/order/order-list
* @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 {object} [params.acknowledged] to suppress the warning, set to true
* @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 enableUnifiedMarginenableUnifiedAccountVariable = self.is_unified_enabled(&[]).await;
let mut enableUnifiedMargin: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(0));
let mut enableUnifiedAccount: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(1));
let mut isUnifiedAccount: bool = is_true(&(is_equal(&enableUnifiedMargin, &Value::Bool(true)))) || is_true(&(is_equal(&enableUnifiedAccount, &Value::Bool(true))));
if !is_true(&isUnifiedAccount) {
return self.fetch_order_classic(id.clone(), &[symbol.clone(), params.clone()]).await;
}
let mut acknowledge: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrder".to_string()), Value::Str("acknowledged".to_string()), &[]); acknowledge = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_true(&acknowledge) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrder() can only access an order if it is in last 500 orders (of any status) for your account. Set params[\"acknowledged\"] = true to hide this warning. Alternatively, we suggest to use fetchOpenOrder or fetchClosedOrder".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchOrder".to_string()), market.clone(), &[params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut 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.insert("category".to_string(), marketType.clone());
m
});
let mut isTrigger: Value = Value::Null;
{ let __destr_tmp = self.handle_param_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]); isTrigger = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), Value::Str("StopOrder".to_string()));
}
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_order_realtime(&[__ws_arg_30]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "1321052653536515584%3A1672217748287%2C1321052653536515584%3A1672217748287",
// "category": "spot",
// "list": [
// {
// "symbol": "ETHUSDT",
// "orderType": "Limit",
// "orderLinkId": "1672217748277652",
// "orderId": "1321052653536515584",
// "cancelType": "UNKNOWN",
// "avgPrice": "",
// "stopOrderType": "tpslOrder",
// "lastPriceOnCreated": "",
// "orderStatus": "Cancelled",
// "takeProfit": "",
// "cumExecValue": "0",
// "triggerDirection": 0,
// "isLeverage": "0",
// "rejectReason": "",
// "price": "1000",
// "orderIv": "",
// "createdTime": "1672217748287",
// "tpTriggerBy": "",
// "positionIdx": 0,
// "timeInForce": "GTC",
// "leavesValue": "500",
// "updatedTime": "1672217748287",
// "side": "Buy",
// "triggerPrice": "1500",
// "cumExecFee": "0",
// "leavesQty": "0",
// "slTriggerBy": "",
// "closeOnTrigger": false,
// "cumExecQty": "0",
// "reduceOnly": false,
// "qty": "0.5",
// "stopLoss": "",
// "triggerBy": "1192.5"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672219526294
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut innerList: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
// the xLength idiom transpiles to count() in php, inline .length here mis-transpiled to strlen(),
// see https://github.com/ccxt/ccxt/pull/29602
let mut innerListLength: Value = get_array_length(&innerList);
if is_equal(&innerListLength, &Value::Int(0)) {
let mut extra: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("".to_string()), Value::Str(" If you are trying to fetch SL/TP conditional order, you might try setting params[\"trigger\"] = true".to_string()));
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&add(&Value::Str("Order ".to_string()), &to_string_val(&id)), &Value::Str(" was not found.".to_string())), &extra)));
}
let mut order: Value = self.safe_dict(innerList.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchOrdersClassic
* @description fetches information on multiple orders made by the user *classic accounts only*
* @see https://bybit-exchange.github.io/docs/v5/order/order-list
* @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 {boolean} [params.trigger] true if trigger order
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.orderFilter] 'Order' or 'StopOrder' or 'tpslOrder'
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders_classic(&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("fetchOrdersClassic".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_cursor(Value::Str("fetchOrdersClassic".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).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.get_bybit_type(Value::Str("fetchOrdersClassic".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchOrdersClassic() is not supported for spot markets".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), Value::Str("StopOrder".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 mut until: Value = self.safe_integer_k(params.clone(), "until", &[]); // unified in milliseconds
let mut endTime: Value = self.safe_integer_k(params.clone(), "endTime", &[until.clone()]); // exchange-specific in milliseconds
params = self.omit(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("until".to_string())]), &[]);
if !is_equal(&endTime, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), endTime.clone());
}
let __ws_arg_31 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_order_history(&[__ws_arg_31]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "03234de9-1332-41eb-b805-4a9f42c136a3%3A1672220109387%2C03234de9-1332-41eb-b805-4a9f42c136a3%3A1672220109387",
// "category": "linear",
// "list": [
// {
// "symbol": "BTCUSDT",
// "orderType": "Limit",
// "orderLinkId": "test-001",
// "orderId": "03234de9-1332-41eb-b805-4a9f42c136a3",
// "cancelType": "CancelByUser",
// "avgPrice": "0",
// "stopOrderType": "UNKNOWN",
// "lastPriceOnCreated": "16656.5",
// "orderStatus": "Cancelled",
// "takeProfit": "",
// "cumExecValue": "0",
// "triggerDirection": 0,
// "blockTradeId": "",
// "rejectReason": "EC_PerCancelRequest",
// "isLeverage": "",
// "price": "18000",
// "orderIv": "",
// "createdTime": "1672220109387",
// "tpTriggerBy": "UNKNOWN",
// "positionIdx": 0,
// "timeInForce": "GoodTillCancel",
// "leavesValue": "0",
// "updatedTime": "1672220114123",
// "side": "Sell",
// "triggerPrice": "",
// "cumExecFee": "0",
// "slTriggerBy": "UNKNOWN",
// "leavesQty": "0",
// "closeOnTrigger": false,
// "cumExecQty": "0",
// "reduceOnly": false,
// "qty": "0.1",
// "stopLoss": "",
// "triggerBy": "UNKNOWN"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672221263862
// }
//
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchClosedOrder
* @description fetches information on a closed order made by the user
* @see https://bybit-exchange.github.io/docs/v5/order/order-list
* @param {string} id order id
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true for fetching a closed trigger order
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.orderFilter] 'Order' or 'StopOrder' or 'tpslOrder'
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id.clone());
m
});
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
let mut result: Value = self.fetch_closed_orders(&[symbol.clone(), Value::Null, Value::Null, __ws_arg_32]).await;
let mut length: Value = get_array_length(&result);
if is_equal(&length, &Value::Int(0)) {
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
let mut extra: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("".to_string()), Value::Str(" If you are trying to fetch SL/TP conditional order, you might try setting params[\"trigger\"] = true".to_string()));
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&add(&Value::Str("Order ".to_string()), &to_string_val(&id)), &Value::Str(" was not found.".to_string())), &extra)));
}
if is_greater_than(&length, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" returned more than one order".to_string()))));
}
return self.safe_value(result.clone(), Value::Int(0), &[]);
Value::Null
}
/*
* @method
* @name bybit#fetchOpenOrder
* @description fetches information on an open order made by the user
* @see https://bybit-exchange.github.io/docs/v5/order/open-order
* @param {string} id order id
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true for fetching an open trigger order
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.baseCoin] Base coin. Supports linear, inverse & option
* @param {string} [params.settleCoin] Settle coin. Supports linear, inverse & option
* @param {string} [params.orderFilter] 'Order' or 'StopOrder' or 'tpslOrder'
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id.clone());
m
});
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
let mut result: Value = self.fetch_open_orders(&[symbol.clone(), Value::Null, Value::Null, __ws_arg_33]).await;
let mut length: Value = get_array_length(&result);
if is_equal(&length, &Value::Int(0)) {
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
let mut extra: Value = ternary(is_true(&(is_equal(&isTrigger, &Value::Bool(true)))), Value::Str("".to_string()), Value::Str(" If you are trying to fetch SL/TP conditional order, you might try setting params[\"trigger\"] = true".to_string()));
panic!("{}", crate::exchange_errors::order_not_found(add(&add(&add(&Value::Str("Order ".to_string()), &to_string_val(&id)), &Value::Str(" was not found.".to_string())), &extra)));
}
if is_greater_than(&length, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" returned more than one order".to_string()))));
}
return self.safe_value(result.clone(), Value::Int(0), &[]);
Value::Null
}
/*
* @method
* @name bybit#fetchCanceledAndClosedOrders
* @description fetches information on multiple canceled and closed orders made by the user
* @see https://bybit-exchange.github.io/docs/v5/order/order-list
* @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 {boolean} [params.trigger] set to true for fetching trigger orders
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.orderFilter] 'Order' or 'StopOrder' or 'tpslOrder'
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_and_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchCanceledAndClosedOrders".to_string()), Value::Str("paginate".to_string()), &[]); 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_cursor(Value::Str("fetchCanceledAndClosedOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).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.get_bybit_type(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)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("trigger".to_string()), Value::Str("stop".to_string())]), &[]);
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), Value::Str("StopOrder".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 mut until: Value = self.safe_integer_k(params.clone(), "until", &[]); // unified in milliseconds
let mut endTime: Value = self.safe_integer_k(params.clone(), "endTime", &[until.clone()]); // exchange-specific in milliseconds
params = self.omit(params.clone(), Value::List(vec![Value::Str("endTime".to_string()), Value::Str("until".to_string())]), &[]);
if !is_equal(&endTime, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), endTime.clone());
}
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_order_history(&[__ws_arg_34]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "f5f2d355-9a11-4af3-9b83-aa1d6ab6ddfe%3A1757837618905%2Caee7453a-a100-465f-857a-3db780e9329a%3A1757837580469",
// "category": "linear",
// "list": [
// {
// "symbol": "BTCUSDT",
// "orderType": "Market",
// "orderLinkId": "",
// "slLimitPrice": "0",
// "orderId": "f5f2d355-9a11-4af3-9b83-aa1d6ab6ddfe",
// "cancelType": "UNKNOWN",
// "avgPrice": "122529.9",
// "stopOrderType": "",
// "lastPriceOnCreated": "123747.9",
// "orderStatus": "Filled",
// "createType": "CreateByUser",
// "takeProfit": "",
// "cumExecValue": "122.5299",
// "tpslMode": "",
// "smpType": "None",
// "triggerDirection": 0,
// "blockTradeId": "",
// "cumFeeDetail": {
// "USDT": "0.06739145"
// },
// "rejectReason": "EC_NoError",
// "isLeverage": "",
// "price": "120518",
// "orderIv": "",
// "createdTime": "1757837618905",
// "tpTriggerBy": "",
// "positionIdx": 0,
// "timeInForce": "IOC",
// "leavesValue": "0",
// "updatedTime": "1757837618909",
// "side": "Sell",
// "smpGroup": 0,
// "triggerPrice": "",
// "tpLimitPrice": "0",
// "cumExecFee": "0.06739145",
// "slTriggerBy": "",
// "leavesQty": "0",
// "closeOnTrigger": false,
// "slippageToleranceType": "UNKNOWN",
// "placeType": "",
// "cumExecQty": "0.001",
// "reduceOnly": true,
// "qty": "0.001",
// "stopLoss": "",
// "smpOrderId": "",
// "slippageTolerance": "0",
// "triggerBy": "",
// "extraFees": ""
// },
// ]
// },
// "retExtInfo": {},
// "time": 1758187806376
// }
//
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://bybit-exchange.github.io/docs/v5/order/order-list
* @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 {boolean} [params.trigger] set to true for fetching closed trigger orders
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.orderFilter] 'Order' or 'StopOrder' or 'tpslOrder'
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderStatus".to_string(), Value::Str("Filled".to_string()));
m
});
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_canceled_and_closed_orders(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_35]).await;
Value::Null
}
/*
* @method
* @name bybit#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://bybit-exchange.github.io/docs/v5/order/order-list
* @param {string} [symbol] unified market symbol of the market orders were made in
* @param {int} [since] timestamp in ms of the earliest order, default is undefined
* @param {int} [limit] max number of orders to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] true if trigger order
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.orderFilter] 'Order' or 'StopOrder' or 'tpslOrder'
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderStatus".to_string(), Value::Str("Cancelled".to_string()));
m
});
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_canceled_and_closed_orders(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_36]).await;
Value::Null
}
/*
* @method
* @name bybit#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://bybit-exchange.github.io/docs/v5/order/open-order
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for
* @param {int} [limit] the maximum number of open orders structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] set to true for fetching open trigger orders
* @param {boolean} [params.stop] alias for trigger
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.baseCoin] Base coin. Supports linear, inverse & option
* @param {string} [params.settleCoin] Settle coin. Supports linear, inverse & option
* @param {string} [params.orderFilter] 'Order' or 'StopOrder' or 'tpslOrder'
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if 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("fetchOpenOrders".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_cursor(Value::Str("fetchOpenOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).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.get_bybit_type(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)); }
if is_equal(&type_var, &Value::Str("linear".to_string())) || is_equal(&type_var, &Value::Str("inverse".to_string())) {
let mut baseCoin: Value = self.safe_string_k(params.clone(), "baseCoin", &[]);
if is_equal(&symbol, &Value::Null) && is_equal(&baseCoin, &Value::Null) {
let mut defaultSettle: Value = self.safe_string_k(self.options.clone(), "defaultSettle", &[Value::Str("USDT".to_string())]);
let mut settleCoin: Value = self.safe_string_k(params.clone(), "settleCoin", &[defaultSettle.clone()]);
add_element_to_object(&mut request, &Value::Str("settleCoin".to_string()), settleCoin.clone());
}
}
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
let mut isTrigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[Value::Bool(false)]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
if is_equal(&isTrigger, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("orderFilter".to_string()), Value::Str("StopOrder".to_string()));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_order_realtime(&[__ws_arg_37]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "f5f2d355-9a11-4af3-9b83-aa1d6ab6ddfe%3A1757837618905%2Caee7453a-a100-465f-857a-3db780e9329a%3A1757837580469",
// "category": "linear",
// "list": [
// {
// "symbol": "BTCUSDT",
// "orderType": "Market",
// "orderLinkId": "",
// "slLimitPrice": "0",
// "orderId": "f5f2d355-9a11-4af3-9b83-aa1d6ab6ddfe",
// "cancelType": "UNKNOWN",
// "avgPrice": "122529.9",
// "stopOrderType": "",
// "lastPriceOnCreated": "123747.9",
// "orderStatus": "Filled",
// "createType": "CreateByUser",
// "takeProfit": "",
// "cumExecValue": "122.5299",
// "tpslMode": "",
// "smpType": "None",
// "triggerDirection": 0,
// "blockTradeId": "",
// "cumFeeDetail": {
// "USDT": "0.06739145"
// },
// "rejectReason": "EC_NoError",
// "isLeverage": "",
// "price": "120518",
// "orderIv": "",
// "createdTime": "1757837618905",
// "tpTriggerBy": "",
// "positionIdx": 0,
// "timeInForce": "IOC",
// "leavesValue": "0",
// "updatedTime": "1757837618909",
// "side": "Sell",
// "smpGroup": 0,
// "triggerPrice": "",
// "tpLimitPrice": "0",
// "cumExecFee": "0.06739145",
// "slTriggerBy": "",
// "leavesQty": "0",
// "closeOnTrigger": false,
// "slippageToleranceType": "UNKNOWN",
// "placeType": "",
// "cumExecQty": "0.001",
// "reduceOnly": true,
// "qty": "0.001",
// "stopLoss": "",
// "smpOrderId": "",
// "slippageTolerance": "0",
// "triggerBy": "",
// "extraFees": ""
// },
// ]
// },
// "retExtInfo": {},
// "time": 1758187806376
// }
//
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://bybit-exchange.github.io/docs/v5/position/execution
* @param {string} id order id
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clientOrderId".to_string()), Value::Str("orderLinkId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderLinkId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("clientOrderId".to_string()), Value::Str("orderLinkId".to_string())]), &[]);
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_my_trades(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_38]).await;
Value::Null
}
/*
* @method
* @name bybit#fetchMyTrades
* @description fetch all trades made by the user
* @see https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution
* @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 {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if 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("fetchMyTrades".to_string()), Value::Str("paginate".to_string()), &[]); paginate = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&paginate) {
return self.fetch_paginated_call_cursor(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(100)]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("execType".to_string(), Value::Str("Trade".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())));
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchMyTrades".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
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_39 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_execution_list(&[__ws_arg_39]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "132766%3A2%2C132766%3A2",
// "category": "linear",
// "list": [
// {
// "symbol": "ETHPERP",
// "orderType": "Market",
// "underlyingPrice": "",
// "orderLinkId": "",
// "side": "Buy",
// "indexPrice": "",
// "orderId": "8c065341-7b52-4ca9-ac2c-37e31ac55c94",
// "stopOrderType": "UNKNOWN",
// "leavesQty": "0",
// "execTime": "1672282722429",
// "isMaker": false,
// "execFee": "0.071409",
// "feeRate": "0.0006",
// "execId": "e0cbe81d-0f18-5866-9415-cf319b5dab3b",
// "tradeIv": "",
// "blockTradeId": "",
// "markPrice": "1183.54",
// "execPrice": "1190.15",
// "markIv": "",
// "orderQty": "0.1",
// "orderPrice": "1236.9",
// "execValue": "119.015",
// "execType": "Trade",
// "execQty": "0.1"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672283754510
// }
//
let mut trades: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_trades(trades.clone(), &[market.clone(), since.clone(), limit.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);
//
// {
// "chainType": "ERC20",
// "addressDeposit": "0xf56297c6717c1d1c42c30324468ed50a9b7402ee",
// "tagDeposit": '',
// "chain": "ETH"
// }
//
let mut address: Value = self.safe_string_k(depositAddress.clone(), "addressDeposit", &[]);
let mut tag: Value = self.safe_string_k(depositAddress.clone(), "tagDeposit", &[]);
let mut code: Value = self.safe_string_k(currency.clone(), "code", &[]);
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(), self.network_id_to_code(&[self.safe_string_k(depositAddress.clone(), "chain", &[]), code.clone()]));
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchDepositAddressesByNetwork
* @description fetch a dictionary of addresses for a currency, indexed by network
* @see https://bybit-exchange.github.io/docs/v5/asset/master-deposit-addr
* @param {string} code unified currency code of the currency for the deposit address
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let mut networkCode: Value = Value::Null;
{ let __destr_tmp = self.handle_network_code_and_params(params.clone()); networkCode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chainType".to_string()), self.network_code_to_id(networkCode.clone(), &[code.clone()]));
}
let __ws_arg_40 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_deposit_query_address(&[__ws_arg_40]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "coin": "USDT",
// "chains": [
// {
// "chainType": "ERC20",
// "addressDeposit": "0xd9e1cd77afa0e50b452a62fbb68a3340602286c3",
// "tagDeposit": "",
// "chain": "ETH"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672192792860
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut chains: Value = self.safe_list_k(result.clone(), "chains", &[Value::List(vec![])]);
let mut coin: Value = self.safe_string_k(result.clone(), "coin", &[]);
let mut currencyFromResponse: Value = self.currency(coin.clone());
let mut parsed: Value = self.parse_deposit_addresses(chains.clone(), &[Value::List(vec![get_value(¤cyFromResponse, &Value::Str("code".to_string()))]), Value::Bool(false), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cyFromResponse, &Value::Str("code".to_string())));
m
})]);
return self.index_by(parsed.clone(), Value::Str("network".to_string()));
Value::Null
}
/*
* @method
* @name bybit#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://bybit-exchange.github.io/docs/v5/asset/master-deposit-addr
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut networkCodeparamsOmitedVariable = self.handle_network_code_and_params(params.clone());
let mut networkCode: Value = get_value(&networkCodeparamsOmitedVariable, &Value::Int(0));
let mut paramsOmited: Value = get_value(&networkCodeparamsOmitedVariable, &Value::Int(1));
let mut indexedAddresses: Value = self.fetch_deposit_addresses_by_network(code.clone(), &[paramsOmited.clone()]).await;
let mut selectedNetworkCode: Value = self.select_network_code_from_unified_networks(get_value(¤cy, &Value::Str("code".to_string())), networkCode.clone(), indexedAddresses.clone());
return self.safe_value(indexedAddresses.clone(), selectedNetworkCode.clone(), &[]);
Value::Null
}
/*
* @method
* @name bybit#fetchDeposits
* @description fetch all deposits made to an account
* @see https://bybit-exchange.github.io/docs/v5/asset/deposit-record
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for, default = 30 days before the current time
* @param {int} [limit] the maximum number of deposits structures to retrieve, default = 50, max = 50
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch deposits for, default = 30 days after since
* EXCHANGE SPECIFIC PARAMETERS
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @param {string} [params.cursor] used for pagination
* @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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchDeposits".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_cursor(Value::Str("fetchDeposits".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).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()), 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_41 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_deposit_query_record(&[__ws_arg_41]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "rows": [
// {
// "coin": "USDT",
// "chain": "ETH",
// "amount": "10000",
// "txID": "skip-notification-scene-test-amount-202212270944-533285-USDT",
// "status": 3,
// "toAddress": "test-amount-address",
// "tag": "",
// "depositFee": "",
// "successAt": "1672134274000",
// "confirmations": "10000",
// "txIndex": "",
// "blockHash": ""
// }
// ],
// "nextPageCursor": "eyJtaW5JRCI6MTA0NjA0MywibWF4SUQiOjEwNDYwNDN9"
// },
// "retExtInfo": {},
// "time": 1672191992512
// }
//
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://bybit-exchange.github.io/docs/v5/asset/withdraw-record
* @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 entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchWithdrawals".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_cursor(Value::Str("fetchWithdrawals".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).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()), 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_42 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_withdraw_query_record(&[__ws_arg_42]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "rows": [
// {
// "coin": "USDT",
// "chain": "ETH",
// "amount": "77",
// "txID": "",
// "status": "SecurityCheck",
// "toAddress": "0x99ced129603abc771c0dabe935c326ff6c86645d",
// "tag": "",
// "withdrawFee": "10",
// "createTime": "1670922217000",
// "updateTime": "1670922217000",
// "withdrawId": "9976",
// "withdrawType": 0
// },
// {
// "coin": "USDT",
// "chain": "ETH",
// "amount": "26",
// "txID": "",
// "status": "success",
// "toAddress": "15638072681@163.com",
// "tag": "",
// "withdrawFee": "0",
// "createTime": "1669711121000",
// "updateTime": "1669711380000",
// "withdrawId": "9801",
// "withdrawType": 1
// }
// ],
// "nextPageCursor": "eyJtaW5JRCI6OTgwMSwibWF4SUQiOjk5NzZ9"
// },
// "retExtInfo": {},
// "time": 1672194949928
// }
//
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("0".to_string(), Value::Str("unknown".to_string()));
m.insert("1".to_string(), Value::Str("pending".to_string()));
m.insert("2".to_string(), Value::Str("processing".to_string()));
m.insert("3".to_string(), Value::Str("ok".to_string()));
m.insert("4".to_string(), Value::Str("fail".to_string()));
m.insert("SecurityCheck".to_string(), Value::Str("pending".to_string()));
m.insert("Pending".to_string(), Value::Str("pending".to_string()));
m.insert("success".to_string(), Value::Str("ok".to_string()));
m.insert("CancelByUser".to_string(), Value::Str("canceled".to_string()));
m.insert("Reject".to_string(), Value::Str("rejected".to_string()));
m.insert("Fail".to_string(), Value::Str("failed".to_string()));
m.insert("BlockchainConfirmed".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchWithdrawals
//
// {
// "coin": "USDT",
// "chain": "TRX",
// "amount": "12.34",
// "txID": "de5ea0a2f2e59dc9a714837dd3ddc6d5e151b56ec5d786d351c4f52336f80d3c",
// "status": "success",
// "toAddress": "TQdmFKUoe1Lk2iwZuwRJEHJreTUBoN3BAw",
// "tag": "",
// "withdrawFee": "0.5",
// "createTime": "1665144183000",
// "updateTime": "1665144256000",
// "withdrawId": "8839035"
// }
//
// fetchDeposits
//
// {
// "coin": "USDT",
// "chain": "TRX",
// "amount": "44",
// "txID": "0b038ea12fa1575e2d66693db3c346b700d4b28347afc39f80321cf089acc960",
// "status": "3",
// "toAddress": "TC6NCAC5WSVCCiaD3kWZXyW91ZKKhLm53b",
// "tag": "",
// "depositFee": "",
// "successAt": "1665142507000",
// "confirmations": "100",
// "txIndex": "0",
// "blockHash": "0000000002ac3b1064aee94bca1bd0b58c4c09c65813b084b87a2063d961129e"
// }
//
// withdraw
//
// {
// "id": "9377266"
// }
//
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "coin", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer2(transaction.clone(), Value::Str("createTime".to_string()), Value::Str("successAt".to_string()), &[]);
let mut updated: Value = self.safe_integer_k(transaction.clone(), "updateTime", &[]);
let mut status: Value = self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[]));
let mut feeCost: Value = self.safe_number2(transaction.clone(), Value::Str("depositFee".to_string()), Value::Str("withdrawFee".to_string()), &[]);
let mut type_var: Value = ternary(is_true(&(Value::Bool(in_op(&transaction, &Value::Str("depositFee".to_string()))))), Value::Str("deposit".to_string()), Value::Str("withdrawal".to_string()));
let mut fee: Value = Value::Null;
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), code.clone());
m
});
}
let mut toAddress: Value = self.safe_string_k(transaction.clone(), "toAddress", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string2(transaction.clone(), Value::Str("id".to_string()), Value::Str("withdrawId".to_string()), &[]));
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "txID", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("network".to_string(), self.network_id_to_code(&[self.safe_string_k(transaction.clone(), "chain", &[]), code.clone()]));
m.insert("address".to_string(), Value::Null);
m.insert("addressTo".to_string(), toAddress.clone());
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), self.safe_string_k(transaction.clone(), "tag", &[]));
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), type_var.clone());
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), status.clone());
m.insert("updated".to_string(), updated.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://bybit-exchange.github.io/docs/v5/account/transaction-log
* @see https://bybit-exchange.github.io/docs/v5/account/contract-transaction-log
* @param {string} [code] unified currency code, default is undefined
* @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
* @param {int} [limit] max number of ledger entries to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {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)
* @param {string} [params.subType] if inverse will use v5/account/contract-transaction-log
* @returns {object} a [ledger structure]{@link https://docs.ccxt.com/?id=ledger-entry-structure}
*/
pub async fn fetch_ledger(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLedger".to_string()), Value::Str("paginate".to_string()), &[]); 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_cursor(Value::Str("fetchLedger".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut enableUnified: Value = self.is_unified_enabled(&[]).await;
let mut currency: Value = Value::Null;
let mut currencyKey: Value = Value::Str("coin".to_string());
if is_equal(&get_value(&enableUnified, &Value::Int(1)), &Value::Bool(true)) {
currencyKey = Value::Str("currency".to_string());
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("start_date".to_string()), self.yyyymmdd(since.clone(), &[]));
}
}
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, ¤cyKey, get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, 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(&get_value(&enableUnified, &Value::Int(1)), &Value::Bool(true)) {
let mut unifiedMarginStatus: Value = self.safe_integer_k(self.options.clone(), "unifiedMarginStatus", &[Value::Int(5)]); // 3/4 uta 1.0, 5/6 uta 2.0
if is_equal(&subType, &Value::Str("inverse".to_string())) && is_true(&(is_less_than(&unifiedMarginStatus, &Value::Int(5)))) {
let __ws_arg_43 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_account_contract_transaction_log(&[__ws_arg_43]).await;
} else {
let __ws_arg_44 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_account_transaction_log(&[__ws_arg_44]).await;
}
} else {
let __ws_arg_45 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_account_contract_transaction_log(&[__ws_arg_45]).await;
}
//
// {
// "ret_code": 0,
// "ret_msg": "ok",
// "ext_code": "",
// "result": {
// "data": [
// {
// "id": 234467,
// "user_id": 1,
// "coin": "BTC",
// "wallet_id": 27913,
// "type": "Realized P&L",
// "amount": "-0.00000006",
// "tx_id": "",
// "address": "BTCUSD",
// "wallet_balance": "0.03000330",
// "exec_time": "2019-12-09T00:00:25.000Z",
// "cross_seq": 0
// }
// ]
// },
// "ext_info": null,
// "time_now": "1577481867.115552",
// "rate_limit_status": 119,
// "rate_limit_reset_ms": 1577481867122,
// "rate_limit": 120
// }
//
// v5 transaction log
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "21963%3A1%2C14954%3A1",
// "list": [
// {
// "symbol": "XRPUSDT",
// "side": "Buy",
// "funding": "-0.003676",
// "orderLinkId": "",
// "orderId": "1672128000-8-592324-1-2",
// "fee": "0.00000000",
// "change": "-0.003676",
// "cashFlow": "0",
// "transactionTime": "1672128000000",
// "type": "SETTLEMENT",
// "feeRate": "0.0001",
// "size": "100",
// "qty": "100",
// "cashBalance": "5086.55825002",
// "currency": "USDT",
// "category": "linear",
// "tradePrice": "0.3676",
// "tradeId": "534c0003-4bf7-486f-aa02-78cee36825e4"
// },
// {
// "symbol": "XRPUSDT",
// "side": "Buy",
// "funding": "",
// "orderLinkId": "linear-order",
// "orderId": "592b7e41-78fd-42e2-9aa3-91e1835ef3e1",
// "fee": "0.01908720",
// "change": "-0.0190872",
// "cashFlow": "0",
// "transactionTime": "1672121182224",
// "type": "TRADE",
// "feeRate": "0.0006",
// "size": "100",
// "qty": "88",
// "cashBalance": "5086.56192602",
// "currency": "USDT",
// "category": "linear",
// "tradePrice": "0.3615",
// "tradeId": "5184f079-88ec-54c7-8774-5173cafd2b4e"
// },
// {
// "symbol": "XRPUSDT",
// "side": "Buy",
// "funding": "",
// "orderLinkId": "linear-order",
// "orderId": "592b7e41-78fd-42e2-9aa3-91e1835ef3e1",
// "fee": "0.00260280",
// "change": "-0.0026028",
// "cashFlow": "0",
// "transactionTime": "1672121182224",
// "type": "TRADE",
// "feeRate": "0.0006",
// "size": "12",
// "qty": "12",
// "cashBalance": "5086.58101322",
// "currency": "USDT",
// "category": "linear",
// "tradePrice": "0.3615",
// "tradeId": "8569c10f-5061-5891-81c4-a54929847eb3"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672132481405
// }
//
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_ledger(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "id": 234467,
// "user_id": 1,
// "coin": "BTC",
// "wallet_id": 27913,
// "type": "Realized P&L",
// "amount": "-0.00000006",
// "tx_id": "",
// "address": "BTCUSD",
// "wallet_balance": "0.03000330",
// "exec_time": "2019-12-09T00:00:25.000Z",
// "cross_seq": 0
// }
//
// {
// "symbol": "XRPUSDT",
// "side": "Buy",
// "funding": "",
// "orderLinkId": "linear-order",
// "orderId": "592b7e41-78fd-42e2-9aa3-91e1835ef3e1",
// "fee": "0.00260280",
// "change": "-0.0026028",
// "cashFlow": "0",
// "transactionTime": "1672121182224",
// "type": "TRADE",
// "feeRate": "0.0006",
// "size": "12",
// "qty": "12",
// "cashBalance": "5086.58101322",
// "currency": "USDT",
// "category": "linear",
// "tradePrice": "0.3615",
// "tradeId": "8569c10f-5061-5891-81c4-a54929847eb3"
// }
//
let mut currencyId: Value = self.safe_string2(item.clone(), Value::Str("coin".to_string()), Value::Str("currency".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut amountString: Value = self.safe_string2(item.clone(), Value::Str("amount".to_string()), Value::Str("change".to_string()), &[]);
let mut afterString: Value = self.safe_string2(item.clone(), Value::Str("wallet_balance".to_string()), Value::Str("cashBalance".to_string()), &[]);
let mut direction: Value = ternary(is_true(&crate::precise::Precise::stringLt(&amountString, &Value::Str("0".to_string()))), Value::Str("out".to_string()), Value::Str("in".to_string()));
let mut before: Value = Value::Null;
let mut after: Value = Value::Null;
let mut amount: Value = Value::Null;
if !is_equal(&afterString, &Value::Null) && !is_equal(&amountString, &Value::Null) {
let mut difference: Value = ternary(is_true(&(is_equal(&direction, &Value::Str("out".to_string())))), amountString.clone(), crate::precise::Precise::stringNeg(&amountString));
before = self.parse_to_numeric(crate::precise::Precise::stringAdd(&afterString, &difference));
after = self.parse_to_numeric(afterString.clone());
amount = self.parse_to_numeric(crate::precise::Precise::stringAbs(&amountString));
}
let mut timestamp: Value = self.parse8601(self.safe_string_k(item.clone(), "exec_time", &[]));
if is_equal(×tamp, &Value::Null) {
timestamp = self.safe_integer_k(item.clone(), "transactionTime", &[]);
}
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string_k(item.clone(), "id", &[]));
m.insert("direction".to_string(), direction.clone());
m.insert("account".to_string(), self.safe_string_k(item.clone(), "wallet_id", &[]));
m.insert("referenceId".to_string(), self.safe_string_k(item.clone(), "tx_id", &[]));
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_ledger_entry_type(self.safe_string_k(item.clone(), "type", &[])));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("before".to_string(), before.clone());
m.insert("after".to_string(), after.clone());
m.insert("status".to_string(), Value::Str("ok".to_string()));
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(item.clone(), "fee", &[]));
m
}));
m
}), &[currency.clone()]);
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Deposit".to_string(), Value::Str("transaction".to_string()));
m.insert("Withdraw".to_string(), Value::Str("transaction".to_string()));
m.insert("RealisedPNL".to_string(), Value::Str("trade".to_string()));
m.insert("Commission".to_string(), Value::Str("fee".to_string()));
m.insert("Refund".to_string(), Value::Str("cashback".to_string()));
m.insert("Prize".to_string(), Value::Str("prize".to_string()));
m.insert("ExchangeOrderWithdraw".to_string(), Value::Str("transaction".to_string()));
m.insert("ExchangeOrderDeposit".to_string(), Value::Str("transaction".to_string()));
m.insert("TRANSFER_IN".to_string(), Value::Str("transaction".to_string()));
m.insert("TRANSFER_OUT".to_string(), Value::Str("transaction".to_string()));
m.insert("TRADE".to_string(), Value::Str("trade".to_string()));
m.insert("SETTLEMENT".to_string(), Value::Str("trade".to_string()));
m.insert("DELIVERY".to_string(), Value::Str("trade".to_string()));
m.insert("LIQUIDATION".to_string(), Value::Str("trade".to_string()));
m.insert("BONUS".to_string(), Value::Str("Prize".to_string()));
m.insert("FEE_REFUND".to_string(), Value::Str("cashback".to_string()));
m.insert("INTEREST".to_string(), Value::Str("transaction".to_string()));
m.insert("CURRENCY_BUY".to_string(), Value::Str("trade".to_string()));
m.insert("CURRENCY_SELL".to_string(), Value::Str("trade".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
/*
* @method
* @name bybit#withdraw
* @description make a withdrawal
* @see https://bybit-exchange.github.io/docs/v5/asset/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 {string} [params.accountType] 'UTA', 'FUND', 'FUND,UTA', and 'SPOT (for classic accounts only)
* @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)); }
let mut accountType: Value = Value::Null;
let mut accounts: Value = self.is_unified_enabled(&[]).await;
let mut isUta: Value = get_value(&accounts, &Value::Int(1));
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("withdraw".to_string()), Value::Str("accountType".to_string()), &[]); accountType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&accountType, &Value::Null) {
accountType = ternary(is_true(&(is_equal(&isUta, &Value::Bool(true)))), Value::Str("UTA".to_string()), Value::Str("SPOT".to_string()));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
self.check_address(&[address.clone()]);
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), self.number_to_string(amount.clone()));
m.insert("address".to_string(), address.clone());
m.insert("timestamp".to_string(), self.milliseconds());
m.insert("accountType".to_string(), accountType.clone());
m
});
if !is_equal(&tag, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tag".to_string()), tag.clone());
}
let mut networkCodequeryVariable = self.handle_network_code_and_params(params.clone());
let mut networkCode: Value = get_value(&networkCodequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&networkCodequeryVariable, &Value::Int(1));
let mut networkId: Value = self.network_code_to_id(networkCode.clone(), &[code.clone()]);
if !is_equal(&networkId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("chain".to_string()), to_upper(&networkId));
}
let __ws_arg_46 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.private_post_v5_asset_withdraw_create(&[__ws_arg_46]).await;
//
// {
// "retCode": "0",
// "retMsg": "success",
// "result": {
// "id": "9377266"
// },
// "retExtInfo": {},
// "time": "1666892894902"
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(result.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchPosition
* @description fetch data on a single open contract trade position
* @see https://bybit-exchange.github.io/docs/v5/position
* @param {string} symbol unified market symbol of the market the position is held in, default is undefined
* @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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchPosition() 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 response: Value = Value::Null;
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchPosition".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v5_position_list(&[__ws_arg_47]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "updateAt%3D1672279322668",
// "category": "linear",
// "list": [
// {
// "symbol": "XRPUSDT",
// "leverage": "10",
// "avgPrice": "0.3615",
// "liqPrice": "0.0001",
// "riskLimitValue": "200000",
// "takeProfit": "",
// "positionValue": "36.15",
// "tpslMode": "Full",
// "riskId": 41,
// "trailingStop": "0",
// "unrealisedPnl": "-1.83",
// "markPrice": "0.3432",
// "cumRealisedPnl": "0.48805876",
// "positionMM": "0.381021",
// "createdTime": "1672121182216",
// "positionIdx": 0,
// "positionIM": "3.634521",
// "updatedTime": "1672279322668",
// "side": "Buy",
// "bustPrice": "",
// "size": "100",
// "positionStatus": "Normal",
// "stopLoss": "",
// "tradeMode": 0
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672280219169
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positions: Value = self.safe_list2(result.clone(), Value::Str("list".to_string()), Value::Str("dataList".to_string()), &[Value::List(vec![])]);
let mut timestamp: Value = self.safe_integer_k(response.clone(), "time", &[]);
let mut first: Value = self.safe_dict(positions.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut position: Value = self.parse_position(first.clone(), &[market.clone()]);
add_element_to_object(&mut position, &Value::Str("timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut position, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
return position;
Value::Null
}
/*
* @method
* @name bybit#fetchPositions
* @description fetch all open positions
* @see https://bybit-exchange.github.io/docs/v5/position
* @param {string[]} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {string} [params.baseCoin] Base coin. Supports linear, inverse & option
* @param {string} [params.settleCoin] Settle coin. Supports linear, inverse & option
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchPositions".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_cursor(Value::Str("fetchPositions".to_string()), &[symbols.clone(), Value::Null, Value::Null, params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(200)]).await;
}
let mut symbol: Value = Value::Null;
if is_true(&(!is_equal(&symbols, &Value::Null))) && is_true(&Value::Bool(is_array(&symbols))) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(1)) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchPositions() does not accept an array with more than one symbol".to_string()))));
} else if is_equal(&symbolsLength, &Value::Int(1)) {
symbol = get_value(&symbols, &Value::Int(0));
}
symbols = self.market_symbols(&[symbols.clone()]);
} else if !is_equal(&symbols, &Value::Null) {
symbol = symbols.clone();
symbols = Value::List(vec![self.symbol(symbol.clone())]);
}
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());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
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.get_bybit_type(Value::Str("fetchPositions".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("linear".to_string())) || is_equal(&type_var, &Value::Str("inverse".to_string())) {
let mut baseCoin: Value = self.safe_string_k(params.clone(), "baseCoin", &[]);
if is_equal(&type_var, &Value::Str("linear".to_string())) {
if is_equal(&symbol, &Value::Null) && is_equal(&baseCoin, &Value::Null) {
let mut defaultSettle: Value = self.safe_string_k(self.options.clone(), "defaultSettle", &[Value::Str("USDT".to_string())]);
let mut settleCoin: Value = self.safe_string_k(params.clone(), "settleCoin", &[defaultSettle.clone()]);
add_element_to_object(&mut request, &Value::Str("settleCoin".to_string()), settleCoin.clone());
}
} else {
// inverse
if is_equal(&symbol, &Value::Null) && is_equal(&baseCoin, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("inverse".to_string()));
}
}
}
if is_equal(&self.safe_integer_k(params.clone(), "limit", &[]), &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), Value::Int(200)); // max limit
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("type".to_string())]), &[]);
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
let __ws_arg_48 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_position_list(&[__ws_arg_48]).await;
//
// {
// "retCode": 0,
// "retMsg": "Success",
// "result": {
// "nextPageCursor": "0%3A1657711949945%2C0%3A1657711949945",
// "category": "linear",
// "list": [
// {
// "symbol": "ETHUSDT",
// "leverage": "10",
// "updatedTime": 1657711949945,
// "side": "Buy",
// "positionValue": "536.92500000",
// "takeProfit": "",
// "tpslMode": "Full",
// "riskId": 11,
// "trailingStop": "",
// "entryPrice": "1073.85000000",
// "unrealisedPnl": "",
// "markPrice": "1080.65000000",
// "size": "0.5000",
// "positionStatus": "normal",
// "stopLoss": "",
// "cumRealisedPnl": "-0.32215500",
// "positionMM": "2.97456450",
// "createdTime": 1657711949928,
// "positionIdx": 0,
// "positionIM": "53.98243950"
// }
// ]
// },
// "time": 1657713693182
// }
//
let mut positions: Value = self.add_pagination_cursor_to_result(response.clone());
let mut results: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_496: bool = true;
while { if !__for_first_496 { i = add(&i, &Value::Int(1)); } __for_first_496 = false; is_less_than(&i, &get_array_length(&positions)) } {
let mut rawPosition: Value = get_value(&positions, &i);
let mut rawPosition: Value = get_value(&positions, &i);
if is_true(&(Value::Bool(in_op(&rawPosition, &Value::Str("data".to_string()))))) && is_true(&(Value::Bool(in_op(&rawPosition, &Value::Str("is_valid".to_string()))))) {
// futures only
rawPosition = self.safe_dict_k(rawPosition.clone(), "data", &[]);
}
append_to_array(&mut results, self.parse_position(rawPosition.clone(), &[]));
}
}
return self.filter_by_array_positions(results.clone(), Value::Str("symbol".to_string()), &[symbols.clone(), Value::Bool(false)]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// linear swap
//
// {
// "positionIdx": 0,
// "riskId": "11",
// "symbol": "ETHUSDT",
// "side": "Buy",
// "size": "0.10",
// "positionValue": "119.845",
// "entryPrice": "1198.45",
// "tradeMode": 1,
// "autoAddMargin": 0,
// "leverage": "4.2",
// "positionBalance": "28.58931118",
// "liqPrice": "919.10",
// "bustPrice": "913.15",
// "takeProfit": "0.00",
// "stopLoss": "0.00",
// "trailingStop": "0.00",
// "unrealisedPnl": "0.083",
// "createdTime": "1669097244192",
// "updatedTime": "1669413126190",
// "tpSlMode": "Full",
// "riskLimitValue": "900000",
// "activePrice": "0.00"
// }
//
// usdc
// {
// "symbol":"BTCPERP",
// "leverage":"1.00",
// "occClosingFee":"0.0000",
// "liqPrice":"",
// "positionValue":"30.8100",
// "takeProfit":"0.0",
// "riskId":"10001",
// "trailingStop":"0.0000",
// "unrealisedPnl":"0.0000",
// "createdAt":"1652451795305",
// "markPrice":"30809.41",
// "cumRealisedPnl":"0.0000",
// "positionMM":"0.1541",
// "positionIM":"30.8100",
// "updatedAt":"1652451795305",
// "tpSLMode":"UNKNOWN",
// "side":"Buy",
// "bustPrice":"",
// "deleverageIndicator":"0",
// "entryPrice":"30810.0",
// "size":"0.001",
// "sessionRPL":"0.0000",
// "positionStatus":"NORMAL",
// "sessionUPL":"-0.0006",
// "stopLoss":"0.0",
// "orderMargin":"0.0000",
// "sessionAvgPrice":"30810.0"
// }
//
// unified margin
//
// {
// "symbol": "ETHUSDT",
// "leverage": "10",
// "updatedTime": 1657711949945,
// "side": "Buy",
// "positionValue": "536.92500000",
// "takeProfit": "",
// "tpslMode": "Full",
// "riskId": 11,
// "trailingStop": "",
// "entryPrice": "1073.85000000",
// "unrealisedPnl": "",
// "markPrice": "1080.65000000",
// "size": "0.5000",
// "positionStatus": "normal",
// "stopLoss": "",
// "cumRealisedPnl": "-0.32215500",
// "positionMM": "2.97456450",
// "createdTime": 1657711949928,
// "positionIdx": 0,
// "positionIM": "53.98243950"
// }
//
// unified account
//
// {
// "symbol": "XRPUSDT",
// "leverage": "10",
// "avgPrice": "0.3615",
// "liqPrice": "0.0001",
// "riskLimitValue": "200000",
// "takeProfit": "",
// "positionValue": "36.15",
// "tpslMode": "Full",
// "riskId": 41,
// "trailingStop": "0",
// "unrealisedPnl": "-1.83",
// "markPrice": "0.3432",
// "cumRealisedPnl": "0.48805876",
// "positionMM": "0.381021",
// "createdTime": "1672121182216",
// "positionIdx": 0,
// "positionIM": "3.634521",
// "updatedTime": "1672279322668",
// "side": "Buy",
// "bustPrice": "",
// "size": "100",
// "positionStatus": "Normal",
// "stopLoss": "",
// "tradeMode": 0
// }
//
// fetchPositionsHistory
//
// {
// symbol: 'XRPUSDT',
// orderType: 'Market',
// leverage: '10',
// updatedTime: '1712717265572',
// side: 'Sell',
// orderId: '071749f3-a9fa-427b-b5ca-27b2f52b81de',
// closedPnl: '-0.00049568',
// avgEntryPrice: '0.6045',
// qty: '3',
// cumEntryValue: '1.8135',
// createdTime: '1712717265566',
// orderPrice: '0.5744',
// closedSize: '3',
// avgExitPrice: '0.605',
// execType: 'Trade',
// fillCount: '1',
// cumExitValue: '1.815'
// }
//
let mut closedSize: Value = self.safe_string_k(position.clone(), "closedSize", &[]);
let mut isHistory: bool = !is_equal(&closedSize, &Value::Null);
let mut contract: Value = self.safe_string_k(position.clone(), "symbol", &[]);
market = self.safe_market(&[contract.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut size: Value = crate::precise::Precise::stringAbs(&self.safe_string2(position.clone(), Value::Str("size".to_string()), Value::Str("qty".to_string()), &[]));
let mut side: Value = self.safe_string_k(position.clone(), "side", &[]);
let mut positionIdx: Value = self.safe_string_k(position.clone(), "positionIdx", &[]);
let mut hedged: Value = Value::Null;
if !is_equal(&positionIdx, &Value::Null) {
hedged = Value::Bool(!is_equal(&positionIdx, &Value::Str("0".to_string())));
}
if is_true(&(!is_equal(&hedged, &Value::Null))) && is_true(&hedged) {
side = ternary(is_true(&(is_equal(&positionIdx, &Value::Str("1".to_string())))), Value::Str("long".to_string()), Value::Str("short".to_string()));
} else if !is_equal(&side, &Value::Null) {
if is_equal(&side, &Value::Str("Buy".to_string())) {
side = ternary(is_true(&isHistory), Value::Str("short".to_string()), Value::Str("long".to_string()));
} else if is_equal(&side, &Value::Str("Sell".to_string())) {
side = ternary(is_true(&isHistory), Value::Str("long".to_string()), Value::Str("short".to_string()));
} else {
side = Value::Null;
}
}
let mut notional: Value = Value::Null;
let mut contractSize: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
let mut markPrice: Value = self.safe_string_k(position.clone(), "markPrice", &[]);
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
notional = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(&size, &contractSize), &markPrice);
} else {
notional = self.safe_string2(position.clone(), Value::Str("positionValue".to_string()), Value::Str("cumExitValue".to_string()), &[]);
}
let mut unrealisedPnl: Value = self.omit_zero(self.safe_string_k(position.clone(), "unrealisedPnl", &[]));
let mut initialMarginString: Value = self.safe_string2(position.clone(), Value::Str("positionIM".to_string()), Value::Str("cumEntryValue".to_string()), &[]);
let mut maintenanceMarginString: Value = self.safe_string_k(position.clone(), "positionMM", &[]);
let mut timestamp: Value = self.safe_integer2(position.clone(), Value::Str("createdTime".to_string()), Value::Str("createdAt".to_string()), &[]);
let mut lastUpdateTimestamp: Value = self.parse8601(self.safe_string_k(position.clone(), "updated_at", &[]));
if is_equal(&lastUpdateTimestamp, &Value::Null) {
lastUpdateTimestamp = self.safe_integer2(position.clone(), Value::Str("updatedTime".to_string()), Value::Str("updatedAt".to_string()), &[]);
}
let mut collateralString: Value = self.safe_string_k(position.clone(), "positionBalance", &[]);
let mut entryPrice: Value = self.omit_zero(self.safe_string_n(position.clone(), Value::List(vec![Value::Str("entryPrice".to_string()), Value::Str("avgPrice".to_string()), Value::Str("avgEntryPrice".to_string())]), &[]));
let mut liquidationPrice: Value = self.omit_zero(self.safe_string_k(position.clone(), "liqPrice", &[]));
let mut leverage: Value = self.safe_string_k(position.clone(), "leverage", &[]);
if !is_equal(&liquidationPrice, &Value::Null) {
if is_equal(&get_value(&market, &Value::Str("settle".to_string())), &Value::Str("USDC".to_string())) {
// (Entry price - Liq price) * Contracts + Maintenance Margin + (unrealised pnl) = Collateral
let mut useMarkPrice: Value = self.safe_bool_k(self.options.clone(), "useMarkPriceForPositionCollateral", &[Value::Bool(false)]);
let mut price: Value = ternary(is_true(&useMarkPrice), markPrice.clone(), entryPrice.clone());
let mut difference: Value = crate::precise::Precise::stringAbs(&crate::precise::Precise::stringSub(&price, &liquidationPrice));
collateralString = crate::precise::Precise::stringAdd(&crate::precise::Precise::stringAdd(&crate::precise::Precise::stringMul(&difference, &size), &maintenanceMarginString), &unrealisedPnl);
} else {
let mut bustPrice: Value = self.safe_string_k(position.clone(), "bustPrice", &[]);
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
// derived from the following formulas
// (Entry price - Bust price) * Contracts = Collateral
// (Entry price - Liq price) * Contracts = Collateral - Maintenance Margin
// Maintenance Margin = (Bust price - Liq price) x Contracts
let mut maintenanceMarginPriceDifference: Value = crate::precise::Precise::stringAbs(&crate::precise::Precise::stringSub(&liquidationPrice, &bustPrice));
maintenanceMarginString = crate::precise::Precise::stringMul(&maintenanceMarginPriceDifference, &size);
// Initial Margin = Contracts x Entry Price / Leverage
if is_true(&(!is_equal(&entryPrice, &Value::Null))) && is_true(&(is_equal(&initialMarginString, &Value::Null))) {
initialMarginString = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(&size, &entryPrice), &leverage);
}
} else {
// Contracts * (1 / Entry price - 1 / Bust price) = Collateral
// Contracts * (1 / Entry price - 1 / Liq price) = Collateral - Maintenance Margin
// Maintenance Margin = Contracts * (1 / Liq price - 1 / Bust price)
// Maintenance Margin = Contracts * (Bust price - Liq price) / (Liq price x Bust price)
let mut difference: Value = crate::precise::Precise::stringAbs(&crate::precise::Precise::stringSub(&bustPrice, &liquidationPrice));
let mut multiply: Value = crate::precise::Precise::stringMul(&bustPrice, &liquidationPrice);
maintenanceMarginString = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(&size, &difference), &multiply);
// Initial Margin = Leverage x Contracts / EntryPrice
if is_true(&(!is_equal(&entryPrice, &Value::Null))) && is_true(&(is_equal(&initialMarginString, &Value::Null))) {
initialMarginString = crate::precise::Precise::stringDiv(&size, &crate::precise::Precise::stringMul(&entryPrice, &leverage));
}
}
}
}
let mut maintenanceMarginPercentage: Value = crate::precise::Precise::stringDiv(&maintenanceMarginString, ¬ional);
let mut marginRatio: Value = crate::precise::Precise::stringDivPrec(&maintenanceMarginString, &collateralString, &Value::Int(4));
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.clone());
m.insert("initialMargin".to_string(), self.parse_number(initialMarginString.clone(), &[]));
m.insert("initialMarginPercentage".to_string(), self.parse_number(crate::precise::Precise::stringDiv(&initialMarginString, ¬ional), &[]));
m.insert("maintenanceMargin".to_string(), self.parse_number(maintenanceMarginString.clone(), &[]));
m.insert("maintenanceMarginPercentage".to_string(), self.parse_number(maintenanceMarginPercentage.clone(), &[]));
m.insert("entryPrice".to_string(), self.parse_number(entryPrice.clone(), &[]));
m.insert("notional".to_string(), self.parse_number(notional.clone(), &[]));
m.insert("leverage".to_string(), self.parse_number(leverage.clone(), &[]));
m.insert("unrealizedPnl".to_string(), self.parse_number(unrealisedPnl.clone(), &[]));
m.insert("realizedPnl".to_string(), self.safe_number2(position.clone(), Value::Str("curRealisedPnl".to_string()), Value::Str("closedPnl".to_string()), &[]));
m.insert("contracts".to_string(), self.parse_number(size.clone(), &[]));
m.insert("contractSize".to_string(), self.safe_number_k(market.clone(), "contractSize", &[]));
m.insert("marginRatio".to_string(), self.parse_number(marginRatio.clone(), &[]));
m.insert("liquidationPrice".to_string(), self.parse_number(liquidationPrice.clone(), &[]));
m.insert("markPrice".to_string(), self.parse_number(markPrice.clone(), &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "avgExitPrice", &[]));
m.insert("collateral".to_string(), self.parse_number(collateralString.clone(), &[]));
m.insert("marginMode".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("percentage".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), self.safe_number2(position.clone(), Value::Str("stop_loss".to_string()), Value::Str("stopLoss".to_string()), &[]));
m.insert("takeProfitPrice".to_string(), self.safe_number2(position.clone(), Value::Str("take_profit".to_string()), Value::Str("takeProfit".to_string()), &[]));
m.insert("hedged".to_string(), hedged.clone());
m
}));
Value::Null
}
/*
* @method
* @name bybit#fetchLeverage
* @description fetch the set leverage for a market
* @see https://bybit-exchange.github.io/docs/v5/position
* @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 position: Value = self.fetch_position(symbol.clone(), &[params.clone()]).await;
return self.parse_leverage(position.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = self.safe_string_k(leverage.clone(), "symbol", &[]);
let mut leverageValue: Value = self.safe_integer_k(leverage.clone(), "leverage", &[]);
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(), self.safe_string_lower(leverage.clone(), Value::Str("marginMode".to_string()), &[]));
m.insert("longLeverage".to_string(), leverageValue.clone());
m.insert("shortLeverage".to_string(), leverageValue.clone());
m
});
Value::Null
}
/*
* @method
* @name bybit#setMarginMode
* @description set margin mode (account) or trade mode (symbol)
* @see https://bybit-exchange.github.io/docs/v5/account/set-margin-mode
* @see https://bybit-exchange.github.io/docs/v5/position/cross-isolate
* @param {string} marginMode account mode must be either [isolated, cross, portfolio], trade mode must be either [isolated, cross]
* @param {string} symbol unified market symbol of the market the position is held in, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.leverage] the rate of leverage, is required if setting trade mode (symbol)
* @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(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut enableUnifiedMarginenableUnifiedAccountVariable = self.is_unified_enabled(&[]).await;
let mut enableUnifiedMargin: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(0));
let mut enableUnifiedAccount: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(1));
let mut isUnifiedAccount: bool = is_true(&(is_equal(&enableUnifiedMargin, &Value::Bool(true)))) || is_true(&(is_equal(&enableUnifiedAccount, &Value::Bool(true))));
let mut market: Value = Value::Null;
let mut response: Value = Value::Null;
if is_true(&isUnifiedAccount) {
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
marginMode = Value::Str("ISOLATED_MARGIN".to_string());
} else if is_equal(&marginMode, &Value::Str("cross".to_string())) {
marginMode = Value::Str("REGULAR_MARGIN".to_string());
} else if is_equal(&marginMode, &Value::Str("portfolio".to_string())) {
marginMode = Value::Str("PORTFOLIO_MARGIN".to_string());
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setMarginMode() marginMode must be either [isolated, cross, portfolio]".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("setMarginMode".to_string(), marginMode.clone());
m
});
let __ws_arg_49 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_v5_account_set_margin_mode(&[__ws_arg_49]).await;
} else {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a symbol parameter for non unified account".to_string()))));
}
market = self.market(symbol.clone());
let mut isUsdcSettled: bool = is_equal(&get_value(&market, &Value::Str("settle".to_string())), &Value::Str("USDC".to_string()));
if is_true(&isUsdcSettled) {
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
marginMode = Value::Str("REGULAR_MARGIN".to_string());
} else if is_equal(&marginMode, &Value::Str("portfolio".to_string())) {
marginMode = Value::Str("PORTFOLIO_MARGIN".to_string());
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setMarginMode() for usdc market marginMode must be either [cross, portfolio]".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("setMarginMode".to_string(), marginMode.clone());
m
});
let __ws_arg_50 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_v5_account_set_margin_mode(&[__ws_arg_50]).await;
} else {
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("setPositionMode".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 tradeMode: Value = Value::Null;
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
tradeMode = Value::Int(0);
} else if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
tradeMode = Value::Int(1);
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setMarginMode() with symbol marginMode must be either [isolated, cross]".to_string()))));
}
let mut sellLeverage: Value = Value::Null;
let mut buyLeverage: Value = Value::Null;
let mut leverage: Value = self.safe_string_k(params.clone(), "leverage", &[]);
if is_equal(&leverage, &Value::Null) {
sellLeverage = self.safe_string2(params.clone(), Value::Str("sell_leverage".to_string()), Value::Str("sellLeverage".to_string()), &[]);
buyLeverage = self.safe_string2(params.clone(), Value::Str("buy_leverage".to_string()), Value::Str("buyLeverage".to_string()), &[]);
if is_equal(&sellLeverage, &Value::Null) && is_equal(&buyLeverage, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a leverage parameter or sell_leverage and buy_leverage parameters".to_string()))));
}
if is_equal(&buyLeverage, &Value::Null) {
buyLeverage = sellLeverage.clone();
}
if is_equal(&sellLeverage, &Value::Null) {
sellLeverage = buyLeverage.clone();
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("buy_leverage".to_string()), Value::Str("sell_leverage".to_string()), Value::Str("sellLeverage".to_string()), Value::Str("buyLeverage".to_string())]), &[]);
} else {
sellLeverage = leverage.clone();
buyLeverage = leverage.clone();
params = self.omit(params.clone(), Value::Str("leverage".to_string()), &[]);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), type_var.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("tradeMode".to_string(), tradeMode.clone());
m.insert("buyLeverage".to_string(), buyLeverage.clone());
m.insert("sellLeverage".to_string(), sellLeverage.clone());
m
});
let __ws_arg_51 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_v5_position_switch_isolated(&[__ws_arg_51]).await;
}
}
return response;
Value::Null
}
/*
* @method
* @name bybit#setLeverage
* @description set the level of leverage for a market
* @see https://bybit-exchange.github.io/docs/v5/position/leverage
* @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.buyLeverage] leverage for buy side
* @param {string} [params.sellLeverage] leverage for sell side
* @returns {object} response from the exchange
*/
pub async fn set_leverage(&mut self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setLeverage() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
// WARNING: THIS WILL INCREASE LIQUIDATION PRICE FOR OPEN ISOLATED LONG POSITIONS
// AND DECREASE LIQUIDATION PRICE FOR OPEN ISOLATED SHORT POSITIONS
// engage in leverage setting
// we reuse the code here instead of having two methods
let mut leverageString: Value = self.number_to_string(leverage.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("buyLeverage".to_string(), leverageString.clone());
m.insert("sellLeverage".to_string(), leverageString.clone());
m
});
add_element_to_object(&mut request, &Value::Str("buyLeverage".to_string()), leverageString.clone());
add_element_to_object(&mut request, &Value::Str("sellLeverage".to_string()), leverageString.clone());
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("linear".to_string()));
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("inverse".to_string()));
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" setLeverage() only support linear and inverse market".to_string()))));
}
let __ws_arg_52 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_position_set_leverage(&[__ws_arg_52]).await;
return response;
Value::Null
}
/*
* @method
* @name bybit#setPositionMode
* @description set hedged to true or false for a market
* @see https://bybit-exchange.github.io/docs/v5/position/position-mode
* @param {bool} hedged
* @param {string} symbol used for unified account with inverse market
* @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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut mode: Value = Value::Null;
if is_true(&hedged) {
mode = Value::Int(3);
} else {
mode = Value::Int(0);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mode".to_string(), mode.clone());
m
});
if is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("coin".to_string()), Value::Str("USDT".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
if !is_equal(&symbol, &Value::Null) {
let mut isLinear: bool = is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true));
add_element_to_object(&mut request, &Value::Str("category".to_string()), ternary(is_true(&isLinear), Value::Str("linear".to_string()), Value::Str("inverse".to_string())));
} else {
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("setPositionMode".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
}
params = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
let __ws_arg_53 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_position_switch_mode(&[__ws_arg_53]).await;
return response;
Value::Null
}
pub async fn fetch_derivatives_open_interest_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1h".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 subType: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))), Value::Str("linear".to_string()), Value::Str("inverse".to_string()));
let mut category: Value = self.safe_string_k(params.clone(), "category", &[subType.clone()]);
let mut intervals: Value = self.safe_dict_k(self.options.clone(), "intervals", &[]);
let mut interval: Value = self.safe_string(intervals.clone(), timeframe.clone(), &[]); // 5min,15min,30min,1h,4h,1d
if is_equal(&interval, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&self.id, &Value::Str(" fetchOpenInterestHistory() cannot use the ".to_string())), &timeframe), &Value::Str(" timeframe".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("intervalTime".to_string(), interval.clone());
m.insert("category".to_string(), category.clone());
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]); // unified in milliseconds
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
} else if !is_equal(&since, &Value::Null) {
// the endpoint walks backwards from endTime and ignores a lone startTime
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut requestedLimit: Value = ternary(is_true(&(is_equal(&limit, &Value::Null))), Value::Int(50), limit.clone()); // exchange default
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), self.sum(&[since.clone(), multiply(&multiply(&duration, &requestedLimit), &Value::Int(1000))]));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_54 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_open_interest(&[__ws_arg_54]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "symbol": "BTCUSD",
// "category": "inverse",
// "list": [
// {
// "openInterest": "461134384.00000000",
// "timestamp": "1669571400000"
// },
// {
// "openInterest": "461134292.00000000",
// "timestamp": "1669571100000"
// }
// ],
// "nextPageCursor": ""
// },
// "retExtInfo": {},
// "time": 1672053548579
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
let mut id: Value = self.safe_string_k(result.clone(), "symbol", &[]);
let mut safeMarketObj: Value = self.safe_market(&[id.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
return self.parse_open_interests_history(data.clone(), &[safeMarketObj.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchOpenInterest
* @description Retrieves the open interest of a derivative trading pair
* @see https://bybit-exchange.github.io/docs/v5/market/open-interest
* @param {string} symbol Unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @param {string} [params.interval] 5m, 15m, 30m, 1h, 4h, 1d
* @param {string} [params.category] "linear" or "inverse"
* @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());
if !is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOpenInterest() supports contract markets only".to_string()))));
}
let mut timeframe: Value = self.safe_string_k(params.clone(), "interval", &[Value::Str("1h".to_string())]);
let mut intervals: Value = self.safe_dict_k(self.options.clone(), "intervals", &[]);
let mut interval: Value = self.safe_string(intervals.clone(), timeframe.clone(), &[]); // 5min,15min,30min,1h,4h,1d
if is_equal(&interval, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&self.id, &Value::Str(" fetchOpenInterest() cannot use the ".to_string())), &timeframe), &Value::Str(" timeframe".to_string()))));
}
let mut subType: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)))), Value::Str("linear".to_string()), Value::Str("inverse".to_string()));
let mut category: Value = self.safe_string_k(params.clone(), "category", &[subType.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("intervalTime".to_string(), interval.clone());
m.insert("category".to_string(), category.clone());
m
});
let __ws_arg_55 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_open_interest(&[__ws_arg_55]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "symbol": "BTCUSD",
// "category": "inverse",
// "list": [
// {
// "openInterest": "461134384.00000000",
// "timestamp": "1669571400000"
// },
// {
// "openInterest": "461134292.00000000",
// "timestamp": "1669571100000"
// }
// ],
// "nextPageCursor": ""
// },
// "retExtInfo": {},
// "time": 1672053548579
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut id: Value = self.safe_string_k(result.clone(), "symbol", &[]);
let mut safeMarketObj: Value = self.safe_market(&[id.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_open_interest(get_value(&data, &Value::Int(0)), &[safeMarketObj.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchOpenInterestHistory
* @description Gets the total amount of unsettled contracts. In other words, the total number of contracts held in open positions
* @see https://bybit-exchange.github.io/docs/v5/market/open-interest
* @param {string} symbol Unified market symbol
* @param {string} timeframe "5m", 15m, 30m, 1h, 4h, 1d
* @param {int} [since] Timestamp in ms of the earliest open interest to fetch
* @param {int} [limit] The number of open interest structures to return. Max 200, default 50
* @param {object} [params] Exchange specific parameters
* @param {int} [params.until] Timestamp in ms of the latest open interest 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 An array of open interest structures
*/
pub async fn fetch_open_interest_history(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1h".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(&timeframe, &Value::Str("1m".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOpenInterestHistory cannot use the 1m timeframe".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = self.safe_bool_k(params.clone(), "paginate", &[]);
if is_equal(&paginate, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("paginate".to_string()), &[]);
add_element_to_object(&mut params, &Value::Str("timeframe".to_string()), timeframe.clone());
return self.fetch_paginated_call_cursor(Value::Str("fetchOpenInterestHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(200)]).await;
}
let mut market: Value = self.market(symbol.clone());
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&self.id, &Value::Str(" fetchOpenInterestHistory() symbol does not support market ".to_string())), &symbol)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
return self.fetch_derivatives_open_interest_history(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), params.clone()]).await;
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);
//
// {
// "openInterest": 64757.62400000,
// "timestamp": 1665784800000,
// }
//
let mut timestamp: Value = self.safe_integer_k(interest.clone(), "timestamp", &[]);
let mut openInterest: Value = self.safe_number2(interest.clone(), Value::Str("open_interest".to_string()), Value::Str("openInterest".to_string()), &[]);
// the openInterest is in the base asset for linear and quote asset for inverse
let mut isLinear: bool = is_equal(&self.safe_bool_k(market.clone(), "linear", &[]), &Value::Bool(true));
let mut isInverse: bool = is_equal(&self.safe_bool_k(market.clone(), "inverse", &[]), &Value::Bool(true));
let mut amount: Value = ternary(is_true(&isLinear), openInterest.clone(), Value::Null);
let mut value: Value = ternary(is_true(&isInverse), openInterest.clone(), Value::Null);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("openInterestAmount".to_string(), amount.clone());
m.insert("openInterestValue".to_string(), value.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 bybit#fetchCrossBorrowRate
* @description fetch the rate of interest to borrow a currency for margin trading
* @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/vip-margin
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.vipLevel] the vip level to fetch the borrow rate for, defaults to 'No VIP'
* @returns {object} a [borrow rate structure]{@link https://docs.ccxt.com/?id=borrow-rate-structure}
*/
pub async fn fetch_cross_borrow_rate(&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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("vipLevel".to_string(), Value::Str("No VIP".to_string()));
m
});
let __ws_arg_56 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_spot_margin_trade_data(&[__ws_arg_56]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "vipCoinList": [
// {
// "list": [
// {
// "borrowable": true,
// "collateralRatio": "0.98",
// "currency": "BTC",
// "hourlyBorrowRate": "0.0000005030430000",
// "liquidationOrder": "3",
// "marginCollateral": true,
// "maxBorrowingAmount": "300"
// }
// ],
// "vipLevel": "No VIP"
// }
// ]
// },
// "retExtInfo": "{}",
// "time": 1786958191900
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "time", &[]);
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut vipCoinList: Value = self.safe_list_k(data.clone(), "vipCoinList", &[Value::List(vec![])]);
let mut firstVip: Value = self.safe_dict(vipCoinList.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut coins: Value = self.safe_list_k(firstVip.clone(), "list", &[Value::List(vec![])]);
let mut coin: Value = self.safe_dict(coins.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
add_element_to_object(&mut coin, &Value::Str("timestamp".to_string()), timestamp.clone());
return self.parse_borrow_rate(coin.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_borrow_rate(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchCrossBorrowRate
// {
// "borrowable": true,
// "collateralRatio": "0.98",
// "currency": "BTC",
// "hourlyBorrowRate": "0.0000005030430000",
// "liquidationOrder": "3",
// "marginCollateral": true,
// "maxBorrowingAmount": "300",
// "timestamp": 1786958191900
// }
//
// fetchBorrowRateHistory
// {
// "timestamp": 1721469600000,
// "currency": "USDC",
// "hourlyBorrowRate": "0.000014621596",
// "vipLevel": "No VIP"
// }
//
let mut timestamp: Value = self.safe_integer_k(info.clone(), "timestamp", &[]);
let mut currencyId: Value = self.safe_string2(info.clone(), Value::Str("coin".to_string()), Value::Str("currency".to_string()), &[]);
let mut hourlyBorrowRate: Value = self.safe_number_k(info.clone(), "hourlyBorrowRate", &[]);
let mut period: Value = ternary(is_true(&(!is_equal(&hourlyBorrowRate, &Value::Null))), Value::Int(3600000), Value::Int(86400000)); // 1h or 1d
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("rate".to_string(), self.safe_number_k(info.clone(), "interestRate", &[hourlyBorrowRate.clone()]));
m.insert("period".to_string(), period.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), info.clone());
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchBorrowInterest
* @description fetch the interest owed by the user for borrowing currency for margin trading
* @see https://bybit-exchange.github.io/docs/zh-TW/v5/spot-margin-normal/account-info
* @param {string} code unified currency code
* @param {string} symbol unified market symbol when fetch interest in isolated markets
* @param {number} [since] the earliest time in ms to fetch borrrow interest for
* @param {number} [limit] the maximum number of structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/?id=borrow-interest-structure}
*/
pub async fn fetch_borrow_interest(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut symbol = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, 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 __ws_arg_57 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_spot_cross_margin_trade_account(&[__ws_arg_57]).await;
//
// {
// "ret_code": 0,
// "ret_msg": "",
// "ext_code": null,
// "ext_info": null,
// "result": {
// "status": "1",
// "riskRate": "0",
// "acctBalanceSum": "0.000486213817680857",
// "debtBalanceSum": "0",
// "loanAccountList": [
// {
// "tokenId": "BTC",
// "total": "0.00048621",
// "locked": "0",
// "loan": "0",
// "interest": "0",
// "free": "0.00048621"
// },
// ...
// ]
// }
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rows: Value = self.safe_list_k(data.clone(), "loanAccountList", &[Value::List(vec![])]);
let mut interest: Value = self.parse_borrow_interests(rows.clone(), &[]);
return self.filter_by_currency_since_limit(interest.clone(), &[code.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchBorrowRateHistory
* @description retrieves a history of a currencies borrow interest rate at specific time slots
* @see https://bybit-exchange.github.io/docs/v5/spot-margin-uta/historical-interest
* @param {string} code unified currency code
* @param {int} [since] timestamp for the earliest borrow rate
* @param {int} [limit] the maximum number of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure} 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
* @returns {object[]} an array of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure}
*/
pub async fn fetch_borrow_rate_history(&mut self, mut code: 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 currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
if is_equal(&since, &Value::Null) {
since = subtract(&self.milliseconds(), &multiply(&Value::Int(86400000), &Value::Int(30))); // last 30 days
}
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
let mut endTime: Value = self.safe_integer2(params.clone(), Value::Str("until".to_string()), Value::Str("endTime".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
if is_equal(&endTime, &Value::Null) {
endTime = add(&since, &multiply(&Value::Int(86400000), &Value::Int(30))); // since + 30 days
}
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), endTime.clone());
let __ws_arg_58 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_spot_margin_trade_interest_rate_history(&[__ws_arg_58]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "timestamp": 1721469600000,
// "currency": "USDC",
// "hourlyBorrowRate": "0.000014621596",
// "vipLevel": "No VIP"
// }
// ]
// },
// "retExtInfo": "{}",
// "time": 1721899048991
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[]);
let mut rows: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
return self.parse_borrow_rate_history(rows.clone(), code.clone(), since.clone(), limit.clone());
Value::Null
}
pub fn parse_borrow_interest(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), Value::Null);
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(info.clone(), "tokenId", &[]), &[]));
m.insert("interest".to_string(), self.safe_number_k(info.clone(), "interest", &[]));
m.insert("interestRate".to_string(), Value::Null);
m.insert("amountBorrowed".to_string(), self.safe_number_k(info.clone(), "loan", &[]));
m.insert("marginMode".to_string(), Value::Str("cross".to_string()));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bybit#transfer
* @description transfer currency internally between wallets on the same account
* @see https://bybit-exchange.github.io/docs/v5/asset/create-inter-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.transferId] UUID, which is unique across the platform
* @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 transferId: Value = self.safe_string_k(params.clone(), "transferId", &[self.uuid(&[])]);
let mut accountTypes: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string(accountTypes.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountTypes.clone(), toAccount.clone(), &[toAccount.clone()]);
let mut currency: Value = self.currency(code.clone());
let mut amountToPrecision: Value = self.currency_to_precision(code.clone(), amount.clone(), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("transferId".to_string(), transferId.clone());
m.insert("fromAccountType".to_string(), fromId.clone());
m.insert("toAccountType".to_string(), toId.clone());
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), amountToPrecision.clone());
m
});
let __ws_arg_59 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_asset_transfer_inter_transfer(&[__ws_arg_59]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "transferId": "4244af44-f3b0-4cf6-a743-b56560e987bc"
// },
// "retExtInfo": {},
// "time": 1666875857205
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "time", &[]);
let mut transfer: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut statusRaw: Value = self.safe_string2(response.clone(), Value::Str("retCode".to_string()), Value::Str("retMsg".to_string()), &[]);
let mut status: Value = self.parse_transfer_status(statusRaw.clone());
let __ws_arg_60 = self.parse_transfer(transfer.clone(), &[currency.clone()]);
let __ws_arg_61 = self.iso8601(timestamp.clone());
let __ws_arg_62 = self.parse_number(amountToPrecision.clone(), &[]);
return self.extend(__ws_arg_60, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), __ws_arg_61);
m.insert("amount".to_string(), __ws_arg_62);
m.insert("fromAccount".to_string(), fromAccount.clone());
m.insert("toAccount".to_string(), toAccount.clone());
m.insert("status".to_string(), status.clone());
m
})]);
Value::Null
}
/*
* @method
* @name bybit#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://bybit-exchange.github.io/docs/v5/asset/inter-transfer-list
* @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 transfer structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch entries for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {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 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()), &[]); 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_cursor(Value::Str("fetchTransfers".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(50)]).await;
}
let mut currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&code, &Value::Null) {
currency = self.safe_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()), 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_63 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_transfer_query_inter_transfer_list(&[__ws_arg_63]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "list": [
// {
// "transferId": "selfTransfer_a1091cc7-9364-4b74-8de1-18f02c6f2d5c",
// "coin": "USDT",
// "amount": "5000",
// "fromAccountType": "SPOT",
// "toAccountType": "UNIFIED",
// "timestamp": "1667283263000",
// "status": "SUCCESS"
// }
// ],
// "nextPageCursor": "eyJtaW5JRCI6MTM1ODQ2OCwibWF4SUQiOjEzNTg0Njh9"
// },
// "retExtInfo": {},
// "time": 1670988271677
// }
//
let mut data: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_transfers(data.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#borrowCrossMargin
* @description create a loan to borrow margin
* @see https://bybit-exchange.github.io/docs/v5/account/borrow
* @param {string} code unified currency code of the currency to borrow
* @param {float} amount the amount to borrow
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn borrow_cross_margin(&mut self, mut code: 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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m
});
let __ws_arg_64 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_account_borrow(&[__ws_arg_64]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "coin": "BTC",
// "amount": "0.001"
// },
// "retExtInfo": {},
// "time": 1763194940073
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_loan(result.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name bybit#repayCrossMargin
* @description repay borrowed margin and interest
* @see https://bybit-exchange.github.io/docs/v5/account/no-convert-repay
* @param {string} code unified currency code of the currency to repay
* @param {float} amount the amount to repay
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn repay_cross_margin(&mut self, mut code: 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
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("coin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amount".to_string(), self.number_to_string(amount.clone()));
m
});
let __ws_arg_65 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_account_no_convert_repay(&[__ws_arg_65]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "resultStatus": "SU"
// },
// "retExtInfo": {},
// "time": 1763195201119
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut transaction: Value = self.parse_margin_loan(result.clone(), &[currency.clone()]);
return self.extend(transaction.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), amount.clone());
m
})]);
Value::Null
}
pub fn parse_margin_loan(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// borrowCrossMargin
//
// {
// "coin": "BTC",
// "amount": "0.001"
// }
//
// repayCrossMargin
//
// {
// "resultStatus": "SU"
// }
//
let mut currencyId: Value = self.safe_string_k(info.clone(), "coin", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Null);
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.clone()]));
m.insert("amount".to_string(), self.safe_number_k(info.clone(), "amount", &[]));
m.insert("symbol".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("info".to_string(), info.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("0".to_string(), Value::Str("ok".to_string()));
m.insert("OK".to_string(), Value::Str("ok".to_string()));
m.insert("SUCCESS".to_string(), Value::Str("ok".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.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);
//
// transfer
//
// {
// "transferId": "22c2bc11-ed5b-49a4-8647-c4e0f5f6f2b2"
// }
//
// fetchTransfers
//
// {
// "transferId": "e9c421c4-b010-4b16-abd6-106179f27702",
// "coin": "USDT",
// "amount": "8",
// "fromAccountType": "FUND",
// "toAccountType": "SPOT",
// "timestamp": "1666879426000",
// "status": "SUCCESS"
// }
//
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "coin", &[]);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "timestamp", &[]);
let mut fromAccountId: Value = self.safe_string_k(transfer.clone(), "fromAccountType", &[]);
let mut toAccountId: Value = self.safe_string_k(transfer.clone(), "toAccountType", &[]);
let mut accountIds: Value = self.safe_dict_k(self.options.clone(), "accountsById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromAccount: Value = self.safe_string(accountIds.clone(), fromAccountId.clone(), &[fromAccountId.clone()]);
let mut toAccount: Value = self.safe_string(accountIds.clone(), toAccountId.clone(), &[toAccountId.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "transferId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("currency".to_string(), self.safe_currency_code(currencyId.clone(), &[currency.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(self.safe_string_k(transfer.clone(), "status", &[])));
m
});
Value::Null
}
pub async fn fetch_derivatives_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());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("linear".to_string()));
} else if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("category".to_string()), Value::Str("inverse".to_string()));
}
let __ws_arg_66 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_risk_limit(&[__ws_arg_66]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "category": "inverse",
// "list": [
// {
// "id": 1,
// "symbol": "BTCUSD",
// "riskLimitValue": "150",
// "maintenanceMargin": "0.5",
// "initialMargin": "1",
// "isLowestRisk": 1,
// "maxLeverage": "100.00"
// },
// ....
// ]
// },
// "retExtInfo": {},
// "time": 1672054488010
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
let mut tiers: Value = self.safe_list_k(result.clone(), "list", &[]);
return self.parse_market_leverage_tiers(tiers.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchMarketLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
* @see https://bybit-exchange.github.io/docs/v5/market/risk-limit
* @param {string} symbol unified market symbol
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
market = self.market(symbol.clone());
if is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&self.id, &Value::Str(" fetchMarketLeverageTiers() symbol does not support market ".to_string())), &symbol)));
}
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
return self.fetch_derivatives_market_leverage_tiers(symbol.clone(), &[params.clone()]).await;
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);
//
// {
// "symbol": "ETHUSDT",
// "makerFeeRate": 0.001,
// "takerFeeRate": 0.001
// }
//
let mut marketId: Value = self.safe_string_k(fee.clone(), "symbol", &[]);
let mut defaultType: Value = ternary(is_true(&(!is_equal(&market, &Value::Null))), get_value(&market, &Value::Str("type".to_string())), Value::Str("contract".to_string()));
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, defaultType.clone()]);
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(), "makerFeeRate", &[]));
m.insert("taker".to_string(), self.safe_number_k(fee.clone(), "takerFeeRate", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://bybit-exchange.github.io/docs/v5/account/fee-rate
* @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 category: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchTradingFee".to_string()), market.clone(), &[params.clone()]); category = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), category.clone());
let __ws_arg_67 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_account_fee_rate(&[__ws_arg_67]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "symbol": "ETHUSDT",
// "takerFeeRate": "0.0006",
// "makerFeeRate": "0.0001"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1676360412576
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fees: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(fees.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(first.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://bybit-exchange.github.io/docs/v5/account/fee-rate
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTradingFees".to_string()), Value::Str("type".to_string()), &[Value::Str("future".to_string())]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTradingFees() is not supported for spot market".to_string()))));
}
let mut response: Value = self.private_get_v5_account_fee_rate(&[params.clone()]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "symbol": "ETHUSDT",
// "takerFeeRate": "0.0006",
// "makerFeeRate": "0.0001"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1676360412576
// }
//
let mut fees: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
fees = self.safe_list_k(fees.clone(), "list", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_497: bool = true;
while { if !__for_first_497 { i = add(&i, &Value::Int(1)); } __for_first_497 = false; is_less_than(&i, &get_array_length(&fees)) } {
let mut fee: Value = self.parse_trading_fee(get_value(&fees, &i), &[]);
let mut symbol: Value = get_value(&fee, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut result, &symbol, fee.clone());
}
}
}
return result;
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);
//
// {
// "name": "BTC",
// "coin": "BTC",
// "remainAmount": "150",
// "chains": [
// {
// "chainType": "BTC",
// "confirmation": "10000",
// "withdrawFee": "0.0005",
// "depositMin": "0.0005",
// "withdrawMin": "0.001",
// "chain": "BTC",
// "chainDeposit": "1",
// "chainWithdraw": "1",
// "minAccuracy": "8"
// }
// ]
// }
//
let mut chains: Value = self.safe_list_k(fee.clone(), "chains", &[Value::List(vec![])]);
let mut chainsLength: Value = get_array_length(&chains);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.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(&chainsLength, &Value::Int(0)) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_498: bool = true;
while { if !__for_first_498 { i = add(&i, &Value::Int(1)); } __for_first_498 = false; is_less_than(&i, &chainsLength) } {
let mut chain: Value = get_value(&chains, &i);
let mut chain: Value = get_value(&chains, &i);
let mut networkId: Value = self.safe_string_k(chain.clone(), "chain", &[]);
let mut currencyCode: Value = self.safe_string_k(currency.clone(), "code", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), currencyCode.clone()]);
if !is_equal(&networkCode, &Value::Null) {
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(chain.clone(), "withdrawFee", &[]));
m.insert("percentage".to_string(), Value::Bool(false));
m
}));
m
}));
}
if is_equal(&chainsLength, &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(chain.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 bybit#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees
* @see https://bybit-exchange.github.io/docs/v5/asset/coin-info
* @param {string[]} 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
}));
self.check_required_credentials(&[]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_v5_asset_coin_query_info(&[params.clone()]).await;
//
// {
// "retCode": 0,
// "retMsg": "",
// "result": {
// "rows": [
// {
// "name": "BTC",
// "coin": "BTC",
// "remainAmount": "150",
// "chains": [
// {
// "chainType": "BTC",
// "confirmation": "10000",
// "withdrawFee": "0.0005",
// "depositMin": "0.0005",
// "withdrawMin": "0.001",
// "chain": "BTC",
// "chainDeposit": "1",
// "chainWithdraw": "1",
// "minAccuracy": "8"
// }
// ]
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672194582264
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut rows: Value = self.safe_list_k(data.clone(), "rows", &[Value::List(vec![])]);
return self.parse_deposit_withdraw_fees(rows.clone(), &[codes.clone(), Value::Str("coin".to_string())]);
Value::Null
}
/*
* @method
* @name bybit#fetchSettlementHistory
* @description fetches historical settlement records
* @see https://bybit-exchange.github.io/docs/v5/market/delivery-price
* @param {string} symbol unified market symbol of the settlement history
* @param {int} [since] timestamp in ms
* @param {int} [limit] number of records
* @param {object} [params] exchange specific params
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @returns {object[]} a list of [settlement history objects]
*/
pub async fn fetch_settlement_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 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.get_bybit_type(Value::Str("fetchSettlementHistory".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchSettlementHistory() is not supported for spot market".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_68 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_delivery_price(&[__ws_arg_68]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "category": "option",
// "nextPageCursor": "0%2C3",
// "list": [
// {
// "symbol": "SOL-27JUN23-20-C",
// "deliveryPrice": "16.62258889",
// "deliveryTime": "1687852800000"
// },
// ]
// },
// "retExtInfo": {},
// "time": 1689043527231
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut settlements: Value = self.parse_settlements(data.clone(), market.clone());
let mut sorted: Value = self.sort_by(settlements.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[self.safe_string_k(market.clone(), "symbol", &[]), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchMySettlementHistory
* @description fetches historical settlement records of the user
* @see https://bybit-exchange.github.io/docs/v5/asset/delivery
* @param {string} symbol unified market symbol of the settlement history
* @param {int} [since] timestamp in ms
* @param {int} [limit] number of records
* @param {object} [params] exchange specific params
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @returns {object[]} a list of [settlement history objects]
*/
pub async fn fetch_my_settlement_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 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.get_bybit_type(Value::Str("fetchMySettlementHistory".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("spot".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchMySettlementHistory() is not supported for spot market".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_69 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_delivery_record(&[__ws_arg_69]).await;
//
// {
// "retCode": 0,
// "retMsg": "success",
// "result": {
// "category": "option",
// "nextPageCursor": "0%2C3",
// "list": [
// {
// "symbol": "SOL-27JUN23-20-C",
// "deliveryPrice": "16.62258889",
// "deliveryTime": "1687852800000",
// "side": "Buy",
// "strike": "20",
// "fee": "0.00000000",
// "position": "0.01",
// "deliveryRpl": "3.5"
// },
// ]
// },
// "retExtInfo": {},
// "time": 1689043527231
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut settlements: Value = self.parse_settlements(data.clone(), market.clone());
let mut sorted: Value = self.sort_by(settlements.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[self.safe_string_k(market.clone(), "symbol", &[]), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_settlement(&self, mut settlement: Value, mut market: Value) -> Value {
//
// fetchSettlementHistory
//
// {
// "symbol": "SOL-27JUN23-20-C",
// "deliveryPrice": "16.62258889",
// "deliveryTime": "1687852800000"
// }
//
// fetchMySettlementHistory
//
// {
// "symbol": "SOL-27JUN23-20-C",
// "deliveryPrice": "16.62258889",
// "deliveryTime": "1687852800000",
// "side": "Buy",
// "strike": "20",
// "fee": "0.00000000",
// "position": "0.01",
// "deliveryRpl": "3.5"
// }
//
let mut timestamp: Value = self.safe_integer_k(settlement.clone(), "deliveryTime", &[]);
let mut marketId: Value = self.safe_string_k(settlement.clone(), "symbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), settlement.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("price".to_string(), self.safe_number_k(settlement.clone(), "deliveryPrice", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
pub fn parse_settlements(&self, mut settlements: Value, mut market: Value) -> Value {
//
// fetchSettlementHistory
//
// [
// {
// "symbol": "SOL-27JUN23-20-C",
// "deliveryPrice": "16.62258889",
// "deliveryTime": "1687852800000"
// }
// ]
//
// fetchMySettlementHistory
//
// [
// {
// "symbol": "SOL-27JUN23-20-C",
// "deliveryPrice": "16.62258889",
// "deliveryTime": "1687852800000",
// "side": "Buy",
// "strike": "20",
// "fee": "0.00000000",
// "position": "0.01",
// "deliveryRpl": "3.5"
// }
// ]
//
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_499: bool = true;
while { if !__for_first_499 { i = add(&i, &Value::Int(1)); } __for_first_499 = false; is_less_than(&i, &get_array_length(&settlements)) } {
append_to_array(&mut result, self.parse_settlement(get_value(&settlements, &i), market.clone()));
}
}
return result;
Value::Null
}
/*
* @method
* @name bybit#fetchVolatilityHistory
* @description fetch the historical volatility of an option market based on an underlying asset
* @see https://bybit-exchange.github.io/docs/v5/market/iv
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.period] the period in days to fetch the volatility for: 7,14,21,30,60,90,180,270
* @returns {object[]} a list of [volatility history objects]{@link https://docs.ccxt.com/?id=volatility-structure}
*/
pub async fn fetch_volatility_history(&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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), Value::Str("option".to_string()));
m.insert("baseCoin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_70 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_historical_volatility(&[__ws_arg_70]).await;
//
// {
// "retCode": 0,
// "retMsg": "SUCCESS",
// "category": "option",
// "result": [
// {
// "period": 7,
// "value": "0.23854072",
// "time": "1690574400000"
// }
// ]
// }
//
let mut volatility: Value = self.safe_list_k(response.clone(), "result", &[Value::List(vec![])]);
return self.parse_volatility_history(volatility.clone());
Value::Null
}
pub fn parse_volatility_history(&self, mut volatility: Value) -> Value {
//
// {
// "period": 7,
// "value": "0.23854072",
// "time": "1690574400000"
// }
//
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_500: bool = true;
while { if !__for_first_500 { i = add(&i, &Value::Int(1)); } __for_first_500 = false; is_less_than(&i, &get_array_length(&volatility)) } {
let mut entry: Value = get_value(&volatility, &i);
let mut entry: Value = get_value(&volatility, &i);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "time", &[]);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), volatility.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("volatility".to_string(), self.safe_number_k(entry.clone(), "value", &[]));
m
}));
}
}
return result;
Value::Null
}
/*
* @method
* @name bybit#fetchGreeks
* @description fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
* @see https://bybit-exchange.github.io/docs/api-explorer/v5/market/tickers
* @param {string} symbol unified symbol of the market to fetch greeks for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [greeks structure]{@link https://docs.ccxt.com/?id=greeks-structure}
*/
pub async fn fetch_greeks(&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.insert("category".to_string(), Value::Str("option".to_string()));
m
});
let __ws_arg_71 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_tickers(&[__ws_arg_71]).await;
//
// {
// "retCode": 0,
// "retMsg": "SUCCESS",
// "result": {
// "category": "option",
// "list": [
// {
// "symbol": "BTC-26JAN24-39000-C",
// "bid1Price": "3205",
// "bid1Size": "7.1",
// "bid1Iv": "0.5478",
// "ask1Price": "3315",
// "ask1Size": "1.98",
// "ask1Iv": "0.5638",
// "lastPrice": "3230",
// "highPrice24h": "3255",
// "lowPrice24h": "3200",
// "markPrice": "3273.02263032",
// "indexPrice": "36790.96",
// "markIv": "0.5577",
// "underlyingPrice": "37649.67254894",
// "openInterest": "19.67",
// "turnover24h": "170140.33875912",
// "volume24h": "4.56",
// "totalVolume": "22",
// "totalTurnover": "789305",
// "delta": "0.49640971",
// "gamma": "0.00004131",
// "vega": "69.08651675",
// "theta": "-24.9443226",
// "predictedDeliveryPrice": "0",
// "change24h": "0.18532111"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1699584008326
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "time", &[]);
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut greeks: Value = self.parse_greeks(get_value(&data, &Value::Int(0)), &[market.clone()]);
let __ws_arg_72 = self.iso8601(timestamp.clone());
return self.extend(greeks.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), __ws_arg_72);
m
})]);
Value::Null
}
/*
* @method
* @name bybit#fetchAllGreeks
* @description fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
* @see https://bybit-exchange.github.io/docs/api-explorer/v5/market/tickers
* @param {string[]} [symbols] unified symbols of the markets to fetch greeks for, all markets are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.baseCoin] the baseCoin of the symbol, default is BTC
* @returns {object} a dictionary of [greeks structures]{@link https://docs.ccxt.com/?id=greeks-structure} indexed by market symbol
*/
pub async fn fetch_all_greeks(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut baseCoin: Value = self.safe_string_k(params.clone(), "baseCoin", &[Value::Str("BTC".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), Value::Str("option".to_string()));
m.insert("baseCoin".to_string(), baseCoin.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_equal(&symbolsLength, &Value::Int(1)) {
market = self.market(get_value(&symbols, &Value::Int(0)));
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let __ws_arg_73 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_tickers(&[__ws_arg_73]).await;
//
// {
// "retCode": 0,
// "retMsg": "SUCCESS",
// "result": {
// "category": "option",
// "list": [
// {
// "symbol": "BTC-26JAN24-39000-C",
// "bid1Price": "3205",
// "bid1Size": "7.1",
// "bid1Iv": "0.5478",
// "ask1Price": "3315",
// "ask1Size": "1.98",
// "ask1Iv": "0.5638",
// "lastPrice": "3230",
// "highPrice24h": "3255",
// "lowPrice24h": "3200",
// "markPrice": "3273.02263032",
// "indexPrice": "36790.96",
// "markIv": "0.5577",
// "underlyingPrice": "37649.67254894",
// "openInterest": "19.67",
// "turnover24h": "170140.33875912",
// "volume24h": "4.56",
// "totalVolume": "22",
// "totalTurnover": "789305",
// "delta": "0.49640971",
// "gamma": "0.00004131",
// "vega": "69.08651675",
// "theta": "-24.9443226",
// "predictedDeliveryPrice": "0",
// "change24h": "0.18532111"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1699584008326
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_all_greeks(data.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_greeks(&self, mut greeks: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTC-26JAN24-39000-C",
// "bid1Price": "3205",
// "bid1Size": "7.1",
// "bid1Iv": "0.5478",
// "ask1Price": "3315",
// "ask1Size": "1.98",
// "ask1Iv": "0.5638",
// "lastPrice": "3230",
// "highPrice24h": "3255",
// "lowPrice24h": "3200",
// "markPrice": "3273.02263032",
// "indexPrice": "36790.96",
// "markIv": "0.5577",
// "underlyingPrice": "37649.67254894",
// "openInterest": "19.67",
// "turnover24h": "170140.33875912",
// "volume24h": "4.56",
// "totalVolume": "22",
// "totalTurnover": "789305",
// "delta": "0.49640971",
// "gamma": "0.00004131",
// "vega": "69.08651675",
// "theta": "-24.9443226",
// "predictedDeliveryPrice": "0",
// "change24h": "0.18532111"
// }
//
let mut marketId: Value = self.safe_string_k(greeks.clone(), "symbol", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), symbol.clone());
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("delta".to_string(), self.safe_number_k(greeks.clone(), "delta", &[]));
m.insert("gamma".to_string(), self.safe_number_k(greeks.clone(), "gamma", &[]));
m.insert("theta".to_string(), self.safe_number_k(greeks.clone(), "theta", &[]));
m.insert("vega".to_string(), self.safe_number_k(greeks.clone(), "vega", &[]));
m.insert("rho".to_string(), Value::Null);
m.insert("bidSize".to_string(), self.safe_number_k(greeks.clone(), "bid1Size", &[]));
m.insert("askSize".to_string(), self.safe_number_k(greeks.clone(), "ask1Size", &[]));
m.insert("bidImpliedVolatility".to_string(), self.safe_number_k(greeks.clone(), "bid1Iv", &[]));
m.insert("askImpliedVolatility".to_string(), self.safe_number_k(greeks.clone(), "ask1Iv", &[]));
m.insert("markImpliedVolatility".to_string(), self.safe_number_k(greeks.clone(), "markIv", &[]));
m.insert("bidPrice".to_string(), self.safe_number_k(greeks.clone(), "bid1Price", &[]));
m.insert("askPrice".to_string(), self.safe_number_k(greeks.clone(), "ask1Price", &[]));
m.insert("markPrice".to_string(), self.safe_number_k(greeks.clone(), "markPrice", &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(greeks.clone(), "lastPrice", &[]));
m.insert("underlyingPrice".to_string(), self.safe_number_k(greeks.clone(), "underlyingPrice", &[]));
m.insert("info".to_string(), greeks.clone());
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchMyLiquidations
* @description retrieves the users liquidated positions
* @see https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution
* @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
* @param {object} [params] exchange specific parameters for the exchange API endpoint
* @param {string} [params.type] market type, ['swap', 'option', 'spot']
* @param {string} [params.subType] market subType, ['linear', 'inverse']
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} 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 paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchMyLiquidations".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_cursor(Value::Str("fetchMyLiquidations".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(100)]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("execType".to_string(), Value::Str("BustTrade".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())));
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchMyLiquidations".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
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_74 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_execution_list(&[__ws_arg_74]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "132766%3A2%2C132766%3A2",
// "category": "linear",
// "list": [
// {
// "symbol": "ETHPERP",
// "orderType": "Market",
// "underlyingPrice": "",
// "orderLinkId": "",
// "side": "Buy",
// "indexPrice": "",
// "orderId": "8c065341-7b52-4ca9-ac2c-37e31ac55c94",
// "stopOrderType": "UNKNOWN",
// "leavesQty": "0",
// "execTime": "1672282722429",
// "isMaker": false,
// "execFee": "0.071409",
// "feeRate": "0.0006",
// "execId": "e0cbe81d-0f18-5866-9415-cf319b5dab3b",
// "tradeIv": "",
// "blockTradeId": "",
// "markPrice": "1183.54",
// "execPrice": "1190.15",
// "markIv": "",
// "orderQty": "0.1",
// "orderPrice": "1236.9",
// "execValue": "119.015",
// "execType": "Trade",
// "execQty": "0.1"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1672283754510
// }
//
let mut liquidations: Value = self.add_pagination_cursor_to_result(response.clone());
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);
//
// {
// "symbol": "ETHPERP",
// "orderType": "Market",
// "underlyingPrice": "",
// "orderLinkId": "",
// "side": "Buy",
// "indexPrice": "",
// "orderId": "8c065341-7b52-4ca9-ac2c-37e31ac55c94",
// "stopOrderType": "UNKNOWN",
// "leavesQty": "0",
// "execTime": "1672282722429",
// "isMaker": false,
// "execFee": "0.071409",
// "feeRate": "0.0006",
// "execId": "e0cbe81d-0f18-5866-9415-cf319b5dab3b",
// "tradeIv": "",
// "blockTradeId": "",
// "markPrice": "1183.54",
// "execPrice": "1190.15",
// "markIv": "",
// "orderQty": "0.1",
// "orderPrice": "1236.9",
// "execValue": "119.015",
// "execType": "Trade",
// "execQty": "0.1"
// }
//
let mut marketId: Value = self.safe_string_k(liquidation.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(liquidation.clone(), "execTime", &[]);
let mut contractsString: Value = self.safe_string_k(liquidation.clone(), "execQty", &[]);
let mut contractSizeString: Value = self.safe_string_k(market.clone(), "contractSize", &[]);
let mut priceString: Value = self.safe_string_k(liquidation.clone(), "execPrice", &[]);
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(), Value::Null, Value::Str("contract".to_string())]));
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
}
pub async fn get_leverage_tiers_paginated(&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;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("getLeverageTiersPaginated".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_cursor(Value::Str("getLeverageTiersPaginated".to_string()), &[symbol.clone(), Value::Null, Value::Null, params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(100)]).await;
}
let mut subType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("getLeverageTiersPaginated".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("category".to_string(), subType.clone());
m
});
let __ws_arg_75 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_risk_limit(&[__ws_arg_75]).await;
let mut result: Value = self.add_pagination_cursor_to_result(response.clone());
let mut first: Value = self.safe_dict(result.clone(), Value::Int(0), &[]);
let mut total: Value = get_array_length(&result);
let mut lastIndex: Value = subtract(&total, &Value::Int(1));
let mut last: Value = self.safe_dict(result.clone(), lastIndex.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut cursorValue: Value = self.safe_string_k(first.clone(), "nextPageCursor", &[]);
add_element_to_object(&mut last, &Value::Str("info".to_string()), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("nextPageCursor".to_string(), cursorValue.clone());
m
}));
add_element_to_object(&mut result, &lastIndex, last.clone());
return result;
Value::Null
}
/*
* @method
* @name bybit#fetchLeverageTiers
* @description retrieve information on the maximum leverage, for different trade sizes
* @see https://bybit-exchange.github.io/docs/v5/market/risk-limit
* @param {string[]} [symbols] a list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.subType] market subType, ['linear', 'inverse'], default is 'linear'
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}, indexed by market symbols
*/
pub async fn fetch_leverage_tiers(&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;
let mut symbol: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
market = self.market(get_value(&symbols, &Value::Int(0)));
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLeverageTiers() is not supported for spot market".to_string()))));
}
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
let __ws_arg_76 = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("paginate".to_string(), Value::Bool(true));
m.insert("paginationCalls".to_string(), Value::Int(200));
m
}), &[params.clone()]);
let mut data: Value = self.get_leverage_tiers_paginated(&[symbol.clone(), __ws_arg_76]).await;
symbols = self.market_symbols(&[symbols.clone()]);
return self.parse_leverage_tiers(data.clone(), &[symbols.clone(), Value::Str("symbol".to_string())]);
Value::Null
}
pub fn parse_leverage_tiers(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut marketIdKey = get_arg(optional_args, 1, Value::Null);
//
// [
// {
// "id": 1,
// "symbol": "BTCUSD",
// "riskLimitValue": "150",
// "maintenanceMargin": "0.5",
// "initialMargin": "1",
// "isLowestRisk": 1,
// "maxLeverage": "100.00"
// }
// ]
//
let mut tiers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut marketIds: Value = self.market_ids(&[symbols.clone()]);
let mut idKey: Value = ternary(is_true(&(is_equal(&marketIdKey, &Value::Null))), Value::Str("symbol".to_string()), marketIdKey.clone());
let mut filteredResults: Value = self.filter_by_array(response.clone(), idKey.clone(), &[marketIds.clone(), Value::Bool(false)]);
let mut grouped: Value = self.group_by(filteredResults.clone(), idKey.clone(), &[]);
let mut keys: Value = object_keys(&grouped);
{
let mut i: Value = Value::Int(0);
let mut __for_first_502: bool = true;
while { if !__for_first_502 { i = add(&i, &Value::Int(1)); } __for_first_502 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut marketId: Value = get_value(&keys, &i);
let mut marketId: Value = get_value(&keys, &i);
let mut entry: Value = get_value(&grouped, &marketId);
let mut entry: Value = get_value(&grouped, &marketId);
{
let mut j: Value = Value::Int(0);
let mut __for_first_501: bool = true;
while { if !__for_first_501 { j = add(&j, &Value::Int(1)); } __for_first_501 = false; is_less_than(&j, &get_array_length(&entry)) } {
let mut id: Value = self.safe_integer_k(get_value(&entry, &j), "id", &[]);
add_element_to_object(get_value_mut(&mut entry, &j), &Value::Str("id".to_string()), id.clone());
}
}
let mut market: Value = self.safe_market(&[marketId.clone(), Value::Null, Value::Null, Value::Str("contract".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
add_element_to_object(&mut tiers, &symbol, self.parse_market_leverage_tiers(self.sort_by(entry.clone(), Value::Str("id".to_string()), &[]), &[market.clone()]));
}
}
return tiers;
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);
//
// [
// {
// "id": 1,
// "symbol": "BTCUSD",
// "riskLimitValue": "150",
// "maintenanceMargin": "0.5",
// "initialMargin": "1",
// "isLowestRisk": 1,
// "maxLeverage": "100.00"
// }
// ]
//
let mut tiers: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_503: bool = true;
while { if !__for_first_503 { i = add(&i, &Value::Int(1)); } __for_first_503 = false; is_less_than(&i, &get_array_length(&info)) } {
let mut tier: Value = get_value(&info, &i);
let mut tier: Value = get_value(&info, &i);
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone()]);
let mut minNotional: Value = self.parse_number(Value::Str("0".to_string()), &[]);
if !is_equal(&i, &Value::Int(0)) {
minNotional = self.safe_number(get_value(&info, &subtract(&i, &Value::Int(1))), Value::Str("riskLimitValue".to_string()), &[]);
}
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_integer_k(tier.clone(), "id", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("currency".to_string(), get_value(&market, &Value::Str("settle".to_string())));
m.insert("minNotional".to_string(), minNotional.clone());
m.insert("maxNotional".to_string(), self.safe_number_k(tier.clone(), "riskLimitValue", &[]));
m.insert("maintenanceMarginRate".to_string(), self.safe_number_k(tier.clone(), "maintenanceMargin", &[]));
m.insert("maxLeverage".to_string(), self.safe_number_k(tier.clone(), "maxLeverage", &[]));
m.insert("info".to_string(), tier.clone());
m
}));
}
}
return tiers;
Value::Null
}
/*
* @method
* @name bybit#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://bybit-exchange.github.io/docs/api-explorer/v5/position/execution
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch funding history for
* @param {int} [limit] the maximum number of funding history structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {object} a [funding history structure]{@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_cursor(Value::Str("fetchFundingHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("nextPageCursor".to_string()), Value::Str("cursor".to_string()), Value::Null, Value::Int(100)]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("execType".to_string(), Value::Str("Funding".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())));
}
let mut type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchFundingHistory".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("size".to_string()), limit.clone());
} else {
add_element_to_object(&mut request, &Value::Str("size".to_string()), Value::Int(100));
}
{ 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_77 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_execution_list(&[__ws_arg_77]).await;
let mut fundings: Value = self.add_pagination_cursor_to_result(response.clone());
return self.parse_incomes(fundings.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": "XMRUSDT",
// "orderType": "UNKNOWN",
// "underlyingPrice": "",
// "orderLinkId": "",
// "orderId": "a11e5fe2-1dbf-4bab-a9b2-af80a14efc5d",
// "stopOrderType": "UNKNOWN",
// "execTime": "1710950400000",
// "feeCurrency": "",
// "createType": "",
// "feeRate": "-0.000761",
// "tradeIv": "",
// "blockTradeId": "",
// "markPrice": "136.79",
// "execPrice": "137.11",
// "markIv": "",
// "orderQty": "0",
// "orderPrice": "0",
// "execValue": "134.3678",
// "closedSize": "0",
// "execType": "Funding",
// "seq": "28097658790",
// "side": "Sell",
// "indexPrice": "",
// "leavesQty": "0",
// "isMaker": false,
// "execFee": "-0.10232512",
// "execId": "8d1ef156-4ec6-4445-9a6c-1c0c24dbd046",
// "marketUnit": "",
// "execQty": "0.98",
// "nextPageCursor": "5774437%3A0%2C5771289%3A0"
// }
//
let mut marketId: Value = self.safe_string_k(income.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut code: Value = Value::Str("USDT".to_string());
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
code = get_value(&market, &Value::Str("quote".to_string()));
}
let mut timestamp: Value = self.safe_integer_k(income.clone(), "execTime", &[]);
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::Str("-".to_string()), Value::Str("swap".to_string())]));
m.insert("code".to_string(), code.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(), "execId", &[]));
m.insert("amount".to_string(), self.safe_number_k(income.clone(), "execFee", &[]));
m.insert("rate".to_string(), self.safe_number_k(income.clone(), "feeRate", &[]));
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchOption
* @description fetches option data that is commonly found in an option chain
* @see https://bybit-exchange.github.io/docs/v5/market/tickers
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [option chain structure]{@link https://docs.ccxt.com/?id=option-chain-structure}
*/
pub async fn fetch_option(&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("category".to_string(), Value::Str("option".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_78 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_tickers(&[__ws_arg_78]).await;
//
// {
// "retCode": 0,
// "retMsg": "SUCCESS",
// "result": {
// "category": "option",
// "list": [
// {
// "symbol": "BTC-27DEC24-55000-P",
// "bid1Price": "0",
// "bid1Size": "0",
// "bid1Iv": "0",
// "ask1Price": "0",
// "ask1Size": "0",
// "ask1Iv": "0",
// "lastPrice": "10980",
// "highPrice24h": "0",
// "lowPrice24h": "0",
// "markPrice": "11814.66756236",
// "indexPrice": "63838.92",
// "markIv": "0.8866",
// "underlyingPrice": "71690.55303594",
// "openInterest": "0.01",
// "turnover24h": "0",
// "volume24h": "0",
// "totalVolume": "2",
// "totalTurnover": "78719",
// "delta": "-0.23284954",
// "gamma": "0.0000055",
// "vega": "191.70757975",
// "theta": "-30.43617927",
// "predictedDeliveryPrice": "0",
// "change24h": "0"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1711162003672
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut resultList: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
let mut chain: Value = self.safe_dict(resultList.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_option(chain.clone(), &[Value::Null, market.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchOptionChain
* @description fetches data for an underlying asset that is commonly found in an option chain
* @see https://bybit-exchange.github.io/docs/v5/market/tickers
* @param {string} code base currency to fetch an option chain for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [option chain structures]{@link https://docs.ccxt.com/?id=option-chain-structure}
*/
pub async fn fetch_option_chain(&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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), Value::Str("option".to_string()));
m.insert("baseCoin".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_79 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_tickers(&[__ws_arg_79]).await;
//
// {
// "retCode": 0,
// "retMsg": "SUCCESS",
// "result": {
// "category": "option",
// "list": [
// {
// "symbol": "BTC-27DEC24-55000-P",
// "bid1Price": "0",
// "bid1Size": "0",
// "bid1Iv": "0",
// "ask1Price": "0",
// "ask1Size": "0",
// "ask1Iv": "0",
// "lastPrice": "10980",
// "highPrice24h": "0",
// "lowPrice24h": "0",
// "markPrice": "11814.66756236",
// "indexPrice": "63838.92",
// "markIv": "0.8866",
// "underlyingPrice": "71690.55303594",
// "openInterest": "0.01",
// "turnover24h": "0",
// "volume24h": "0",
// "totalVolume": "2",
// "totalTurnover": "78719",
// "delta": "-0.23284954",
// "gamma": "0.0000055",
// "vega": "191.70757975",
// "theta": "-30.43617927",
// "predictedDeliveryPrice": "0",
// "change24h": "0"
// },
// ]
// },
// "retExtInfo": {},
// "time": 1711162003672
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut resultList: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_option_chain(resultList.clone(), &[Value::Null, Value::Str("symbol".to_string())]);
Value::Null
}
pub fn parse_option(&self, mut chain: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut market = get_arg(optional_args, 1, Value::Null);
//
// {
// "symbol": "BTC-27DEC24-55000-P",
// "bid1Price": "0",
// "bid1Size": "0",
// "bid1Iv": "0",
// "ask1Price": "0",
// "ask1Size": "0",
// "ask1Iv": "0",
// "lastPrice": "10980",
// "highPrice24h": "0",
// "lowPrice24h": "0",
// "markPrice": "11814.66756236",
// "indexPrice": "63838.92",
// "markIv": "0.8866",
// "underlyingPrice": "71690.55303594",
// "openInterest": "0.01",
// "turnover24h": "0",
// "volume24h": "0",
// "totalVolume": "2",
// "totalTurnover": "78719",
// "delta": "-0.23284954",
// "gamma": "0.0000055",
// "vega": "191.70757975",
// "theta": "-30.43617927",
// "predictedDeliveryPrice": "0",
// "change24h": "0"
// }
//
let mut marketId: Value = self.safe_string_k(chain.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chain.clone());
m.insert("currency".to_string(), Value::Null);
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("impliedVolatility".to_string(), self.safe_number_k(chain.clone(), "markIv", &[]));
m.insert("openInterest".to_string(), self.safe_number_k(chain.clone(), "openInterest", &[]));
m.insert("bidPrice".to_string(), self.safe_number_k(chain.clone(), "bid1Price", &[]));
m.insert("askPrice".to_string(), self.safe_number_k(chain.clone(), "ask1Price", &[]));
m.insert("midPrice".to_string(), Value::Null);
m.insert("markPrice".to_string(), self.safe_number_k(chain.clone(), "markPrice", &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(chain.clone(), "lastPrice", &[]));
m.insert("underlyingPrice".to_string(), self.safe_number_k(chain.clone(), "underlyingPrice", &[]));
m.insert("change".to_string(), self.safe_number_k(chain.clone(), "change24h", &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_number_k(chain.clone(), "totalVolume", &[]));
m.insert("quoteVolume".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchPositionsHistory
* @description fetches historical positions
* @see https://bybit-exchange.github.io/docs/v5/position/close-pnl
* @param {string[]} symbols a list of unified market symbols
* @param {int} [since] timestamp in ms of the earliest position to fetch, params["until"] - since <= 7 days
* @param {int} [limit] the maximum amount of records to fetch, default=50, max=100
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest position to fetch, params["until"] - since <= 7 days
* @param {string} [params.subType] 'linear' or 'inverse'
* @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = 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 subType: Value = Value::Null;
let mut symbolsLength: Value = Value::Int(0);
if !is_equal(&symbols, &Value::Null) {
symbolsLength = get_array_length(&symbols);
if is_greater_than(&symbolsLength, &Value::Int(0)) {
market = self.market(get_value(&symbols, &Value::Int(0)));
}
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchPositionsHistory".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)); }
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("category".to_string(), subType.clone());
m
});
if is_true(&(!is_equal(&symbols, &Value::Null))) && is_true(&(is_equal(&symbolsLength, &Value::Int(1)))) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.safe_string_k(market.clone(), "id", &[]));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_80 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_position_closed_pnl(&[__ws_arg_80]).await;
//
// {
// retCode: '0',
// retMsg: 'OK',
// result: {
// nextPageCursor: '071749f3-a9fa-427b-b5ca-27b2f52b81de%3A1712717265566520788%2C071749f3-a9fa-427b-b5ca-27b2f52b81de%3A1712717265566520788',
// category: 'linear',
// list: [
// {
// symbol: 'XRPUSDT',
// orderType: 'Market',
// leverage: '10',
// updatedTime: '1712717265572',
// side: 'Sell',
// orderId: '071749f3-a9fa-427b-b5ca-27b2f52b81de',
// closedPnl: '-0.00049568',
// avgEntryPrice: '0.6045',
// qty: '3',
// cumEntryValue: '1.8135',
// createdTime: '1712717265566',
// orderPrice: '0.5744',
// closedSize: '3',
// avgExitPrice: '0.605',
// execType: 'Trade',
// fillCount: '1',
// cumExitValue: '1.815'
// }
// ]
// },
// retExtInfo: {},
// time: '1712717286073'
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[]);
let mut rawPositions: Value = self.safe_list_k(result.clone(), "list", &[]);
let mut rawPositionsList: Value = Value::List(vec![]);
if !is_equal(&rawPositions, &Value::Null) {
rawPositionsList = rawPositions.clone();
}
let mut positions: Value = self.parse_positions(rawPositionsList.clone(), &[symbols.clone(), params.clone()]);
return self.filter_by_since_limit(positions.clone(), &[since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchConvertCurrencies
* @description fetches all available currencies that can be converted
* @see https://bybit-exchange.github.io/docs/v5/asset/convert/convert-coin-list
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountType] eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_convert_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_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut accountType: Value = Value::Null;
let mut enableUnifiedMarginenableUnifiedAccountVariable = self.is_unified_enabled(&[]).await;
let mut enableUnifiedMargin: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(0));
let mut enableUnifiedAccount: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(1));
let mut isUnifiedAccount: bool = is_true(&(is_equal(&enableUnifiedMargin, &Value::Bool(true)))) || is_true(&(is_equal(&enableUnifiedAccount, &Value::Bool(true))));
let mut accountTypeDefault: Value = ternary(is_true(&isUnifiedAccount), Value::Str("eb_convert_uta".to_string()), Value::Str("eb_convert_spot".to_string()));
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchConvertCurrencies".to_string()), Value::Str("accountType".to_string()), &[accountTypeDefault.clone()]); accountType = 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("accountType".to_string(), accountType.clone());
m
});
let __ws_arg_81 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_exchange_query_coin_list(&[__ws_arg_81]).await;
//
// {
// "retCode": 0,
// "retMsg": "ok",
// "result": {
// "coins": [
// {
// "coin": "MATIC",
// "fullName": "MATIC",
// "icon": "https://s1.bycsi.com/app/assets/token/0552ae79c535c3095fa18f7b377dd2e9.svg",
// "iconNight": "https://t1.bycsi.com/app/assets/token/f59301aef2d6ac2165c4c4603e672fb4.svg",
// "accuracyLength": 8,
// "coinType": "crypto",
// "balance": "0",
// "uBalance": "0",
// "timePeriod": 0,
// "singleFromMinLimit": "1.1",
// "singleFromMaxLimit": "20001",
// "singleToMinLimit": "0",
// "singleToMaxLimit": "0",
// "dailyFromMinLimit": "0",
// "dailyFromMaxLimit": "0",
// "dailyToMinLimit": "0",
// "dailyToMaxLimit": "0",
// "disableFrom": false,
// "disableTo": false
// },
// ]
// },
// "retExtInfo": {},
// "time": 1727256416250
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut coins: Value = self.safe_list_k(data.clone(), "coins", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_504: bool = true;
while { if !__for_first_504 { i = add(&i, &Value::Int(1)); } __for_first_504 = false; is_less_than(&i, &get_array_length(&coins)) } {
let mut entry: Value = get_value(&coins, &i);
let mut entry: Value = get_value(&coins, &i);
let mut id: Value = self.safe_string_k(entry.clone(), "coin", &[]);
let mut disableFrom: Value = self.safe_bool_k(entry.clone(), "disableFrom", &[]);
let mut disableTo: Value = self.safe_bool_k(entry.clone(), "disableTo", &[]);
let mut inactive: bool = is_true(&(is_equal(&disableFrom, &Value::Bool(true)))) || is_true(&(is_equal(&disableTo, &Value::Bool(true))));
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("id".to_string(), id.clone());
m.insert("code".to_string(), code.clone());
m.insert("networks".to_string(), Value::Null);
m.insert("type".to_string(), self.safe_string_k(entry.clone(), "coinType", &[]));
m.insert("name".to_string(), self.safe_string_k(entry.clone(), "fullName", &[]));
m.insert("active".to_string(), Value::Bool(!is_true(&inactive)));
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), self.safe_number_k(entry.clone(), "balance", &[]));
m.insert("fee".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Null);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.safe_number_k(entry.clone(), "singleFromMinLimit", &[]));
m.insert("max".to_string(), self.safe_number_k(entry.clone(), "singleFromMaxLimit", &[]));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m
}));
}
}
}
return result;
Value::Null
}
/*
* @method
* @name bybit#fetchConvertQuote
* @description fetch a quote for converting from one currency to another
* @see https://bybit-exchange.github.io/docs/v5/asset/convert/apply-quote
* @param {string} fromCode the currency that you want to sell and convert from
* @param {string} toCode the currency that you want to buy and convert into
* @param {float} [amount] how much you want to trade in units of the from currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountType] eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
* @returns {object} a [conversion structure]{@link https://docs.ccxt.com/?id=conversion-structure}
*/
pub async fn fetch_convert_quote(&mut self, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> Value {
let mut amount = 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 accountType: Value = Value::Null;
let mut enableUnifiedMarginenableUnifiedAccountVariable = self.is_unified_enabled(&[]).await;
let mut enableUnifiedMargin: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(0));
let mut enableUnifiedAccount: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(1));
let mut isUnifiedAccount: bool = is_true(&(is_equal(&enableUnifiedMargin, &Value::Bool(true)))) || is_true(&(is_equal(&enableUnifiedAccount, &Value::Bool(true))));
let mut accountTypeDefault: Value = ternary(is_true(&isUnifiedAccount), Value::Str("eb_convert_uta".to_string()), Value::Str("eb_convert_spot".to_string()));
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchConvertQuote".to_string()), Value::Str("accountType".to_string()), &[accountTypeDefault.clone()]); accountType = 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("fromCoin".to_string(), fromCode.clone());
m.insert("toCoin".to_string(), toCode.clone());
m.insert("requestAmount".to_string(), self.number_to_string(amount.clone()));
m.insert("requestCoin".to_string(), fromCode.clone());
m.insert("accountType".to_string(), accountType.clone());
m
});
let __ws_arg_82 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_asset_exchange_quote_apply(&[__ws_arg_82]).await;
//
// {
// "retCode": 0,
// "retMsg": "ok",
// "result": {
// "quoteTxId": "1010020692439481682687668224",
// "exchangeRate": "0.000015330836780000",
// "fromCoin": "USDT",
// "fromCoinType": "crypto",
// "toCoin": "BTC",
// "toCoinType": "crypto",
// "fromAmount": "10",
// "toAmount": "0.000153308367800000",
// "expiredTime": "1727257413353",
// "requestId": ""
// },
// "retExtInfo": {},
// "time": 1727257398375
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromCurrencyId: Value = self.safe_string_k(data.clone(), "fromCoin", &[fromCode.clone()]);
let mut fromCurrency: Value = self.currency(fromCurrencyId.clone());
let mut toCurrencyId: Value = self.safe_string_k(data.clone(), "toCoin", &[toCode.clone()]);
let mut toCurrency: Value = self.currency(toCurrencyId.clone());
return self.parse_conversion(data.clone(), &[fromCurrency.clone(), toCurrency.clone()]);
Value::Null
}
/*
* @method
* @name bybit#createConvertTrade
* @description convert from one currency to another
* @see https://bybit-exchange.github.io/docs/v5/asset/convert/confirm-quote
* @param {string} id the id of the trade that you want to make
* @param {string} fromCode the currency that you want to sell and convert from
* @param {string} toCode the currency that you want to buy and convert into
* @param {float} amount how much you want to trade in units of the from currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [conversion structure]{@link https://docs.ccxt.com/?id=conversion-structure}
*/
pub async fn create_convert_trade(&mut self, mut id: Value, mut fromCode: Value, mut toCode: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("quoteTxId".to_string(), id.clone());
m
});
let __ws_arg_83 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_v5_asset_exchange_convert_execute(&[__ws_arg_83]).await;
//
// {
// "retCode": 0,
// "retMsg": "ok",
// "result": {
// "exchangeStatus": "processing",
// "quoteTxId": "1010020692439483803499737088"
// },
// "retExtInfo": {},
// "time": 1727257904969
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_conversion(data.clone(), &[]);
Value::Null
}
/*
* @method
* @name bybit#fetchConvertTrade
* @description fetch the data for a conversion trade
* @see https://bybit-exchange.github.io/docs/v5/asset/convert/get-convert-result
* @param {string} id the id of the trade that you want to fetch
* @param {string} [code] the unified currency code of the conversion trade
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountType] eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
* @returns {object} a [conversion structure]{@link https://docs.ccxt.com/?id=conversion-structure}
*/
pub async fn fetch_convert_trade(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut code = 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 accountType: Value = Value::Null;
let mut enableUnifiedMarginenableUnifiedAccountVariable = self.is_unified_enabled(&[]).await;
let mut enableUnifiedMargin: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(0));
let mut enableUnifiedAccount: Value = get_value(&enableUnifiedMarginenableUnifiedAccountVariable, &Value::Int(1));
let mut isUnifiedAccount: bool = is_true(&(is_equal(&enableUnifiedMargin, &Value::Bool(true)))) || is_true(&(is_equal(&enableUnifiedAccount, &Value::Bool(true))));
let mut accountTypeDefault: Value = ternary(is_true(&isUnifiedAccount), Value::Str("eb_convert_uta".to_string()), Value::Str("eb_convert_spot".to_string()));
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchConvertTrade".to_string()), Value::Str("accountType".to_string()), &[accountTypeDefault.clone()]); accountType = 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("quoteTxId".to_string(), id.clone());
m.insert("accountType".to_string(), accountType.clone());
m
});
let __ws_arg_84 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_exchange_convert_result_query(&[__ws_arg_84]).await;
//
// {
// "retCode": 0,
// "retMsg": "ok",
// "result": {
// "result": {
// "accountType": "eb_convert_uta",
// "exchangeTxId": "1010020692439483803499737088",
// "userId": "100406395",
// "fromCoin": "USDT",
// "fromCoinType": "crypto",
// "fromAmount": "10",
// "toCoin": "BTC",
// "toCoinType": "crypto",
// "toAmount": "0.00015344889",
// "exchangeStatus": "success",
// "extInfo": {},
// "convertRate": "0.000015344889",
// "createdAt": "1727257904726"
// }
// },
// "retExtInfo": {},
// "time": 1727258257216
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut result: Value = self.safe_dict_k(data.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromCurrencyId: Value = self.safe_string_k(result.clone(), "fromCoin", &[]);
let mut toCurrencyId: Value = self.safe_string_k(result.clone(), "toCoin", &[]);
let mut fromCurrency: Value = Value::Null;
let mut toCurrency: Value = Value::Null;
if !is_equal(&fromCurrencyId, &Value::Null) {
fromCurrency = self.currency(fromCurrencyId.clone());
}
if !is_equal(&toCurrencyId, &Value::Null) {
toCurrency = self.currency(toCurrencyId.clone());
}
return self.parse_conversion(result.clone(), &[fromCurrency.clone(), toCurrency.clone()]);
Value::Null
}
/*
* @method
* @name bybit#fetchConvertTradeHistory
* @description fetch the users history of conversion trades
* @see https://bybit-exchange.github.io/docs/v5/asset/convert/get-convert-history
* @param {string} [code] the unified currency code
* @param {int} [since] the earliest time in ms to fetch conversions for
* @param {int} [limit] the maximum number of conversion structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountType] eb_convert_uta, eb_convert_spot, eb_convert_funding, eb_convert_inverse, or eb_convert_contract
* @returns {object[]} a list of [conversion structures]{@link https://docs.ccxt.com/?id=conversion-structure}
*/
pub async fn fetch_convert_trade_history(&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
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_85 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_asset_exchange_query_convert_history(&[__ws_arg_85]).await;
//
// {
// "retCode": 0,
// "retMsg": "ok",
// "result": {
// "list": [
// {
// "accountType": "eb_convert_uta",
// "exchangeTxId": "1010020692439483803499737088",
// "userId": "100406395",
// "fromCoin": "USDT",
// "fromCoinType": "crypto",
// "fromAmount": "10",
// "toCoin": "BTC",
// "toCoinType": "crypto",
// "toAmount": "0.00015344889",
// "exchangeStatus": "success",
// "extInfo": {},
// "convertRate": "0.000015344889",
// "createdAt": "1727257904726"
// }
// ]
// },
// "retExtInfo": {},
// "time": 1727258761874
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut dataList: Value = self.safe_list_k(data.clone(), "list", &[Value::List(vec![])]);
return self.parse_conversions(dataList.clone(), &[code.clone(), Value::Str("fromCoin".to_string()), Value::Str("toCoin".to_string()), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_conversion(&self, mut conversion: Value, optional_args: &[Value]) -> Value {
let mut fromCurrency = get_arg(optional_args, 0, Value::Null);
let mut toCurrency = get_arg(optional_args, 1, Value::Null);
//
// fetchConvertQuote
//
// {
// "quoteTxId": "1010020692439481682687668224",
// "exchangeRate": "0.000015330836780000",
// "fromCoin": "USDT",
// "fromCoinType": "crypto",
// "toCoin": "BTC",
// "toCoinType": "crypto",
// "fromAmount": "10",
// "toAmount": "0.000153308367800000",
// "expiredTime": "1727257413353",
// "requestId": ""
// }
//
// createConvertTrade
//
// {
// "exchangeStatus": "processing",
// "quoteTxId": "1010020692439483803499737088"
// }
//
// fetchConvertTrade, fetchConvertTradeHistory
//
// {
// "accountType": "eb_convert_uta",
// "exchangeTxId": "1010020692439483803499737088",
// "userId": "100406395",
// "fromCoin": "USDT",
// "fromCoinType": "crypto",
// "fromAmount": "10",
// "toCoin": "BTC",
// "toCoinType": "crypto",
// "toAmount": "0.00015344889",
// "exchangeStatus": "success",
// "extInfo": {},
// "convertRate": "0.000015344889",
// "createdAt": "1727257904726"
// }
//
let mut timestamp: Value = self.safe_integer2(conversion.clone(), Value::Str("expiredTime".to_string()), Value::Str("createdAt".to_string()), &[]);
let mut fromCoin: Value = self.safe_string_k(conversion.clone(), "fromCoin", &[]);
let mut fromCode: Value = self.safe_currency_code(fromCoin.clone(), &[fromCurrency.clone()]);
let mut to: Value = self.safe_string_k(conversion.clone(), "toCoin", &[]);
let mut toCode: Value = self.safe_currency_code(to.clone(), &[toCurrency.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), conversion.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("id".to_string(), self.safe_string2(conversion.clone(), Value::Str("quoteTxId".to_string()), Value::Str("exchangeTxId".to_string()), &[]));
m.insert("fromCurrency".to_string(), fromCode.clone());
m.insert("fromAmount".to_string(), self.safe_number_k(conversion.clone(), "fromAmount", &[]));
m.insert("toCurrency".to_string(), toCode.clone());
m.insert("toAmount".to_string(), self.safe_number_k(conversion.clone(), "toAmount", &[]));
m.insert("price".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchLongShortRatioHistory
* @description fetches the long short ratio history for a unified market symbol
* @see https://bybit-exchange.github.io/docs/v5/market/long-short-ratio
* @param {string} symbol unified symbol of the market to fetch the long short ratio for
* @param {string} [timeframe] the period for the ratio, default is 24 hours
* @param {int} [since] the earliest time in ms to fetch ratios for
* @param {int} [limit] the maximum number of long short ratio structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of [long short ratio structures]{@link https://docs.ccxt.com/?id=long-short-ratio-structure}
*/
pub async fn fetch_long_short_ratio_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut timeframe = get_arg(optional_args, 1, Value::Null);
let mut since = get_arg(optional_args, 2, Value::Null);
let mut limit = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, 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 type_var: Value = Value::Null;
{ let __destr_tmp = self.get_bybit_type(Value::Str("fetchLongShortRatioHistory".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&type_var, &Value::Str("spot".to_string())) || is_equal(&type_var, &Value::Str("option".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchLongShortRatioHistory() only support linear and inverse markets".to_string()))));
}
if is_equal(&timeframe, &Value::Null) {
timeframe = Value::Str("1d".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("period".to_string(), timeframe.clone());
m.insert("category".to_string(), type_var.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_86 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_v5_market_account_ratio(&[__ws_arg_86]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "list": [
// {
// "symbol": "BTCUSDT",
// "buyRatio": "0.5707",
// "sellRatio": "0.4293",
// "timestamp": "1729123200000"
// },
// ]
// },
// "retExtInfo": {},
// "time": 1729147842516
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut data: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_long_short_ratio_history(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_long_short_ratio(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "BTCUSDT",
// "buyRatio": "0.5707",
// "sellRatio": "0.4293",
// "timestamp": "1729123200000"
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_omit_zero(info.clone(), Value::Str("timestamp".to_string()), &[]);
let mut longString: Value = self.safe_string_k(info.clone(), "buyRatio", &[]);
let mut shortString: Value = self.safe_string_k(info.clone(), "sellRatio", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("timeframe".to_string(), Value::Null);
m.insert("longShortRatio".to_string(), self.parse_to_numeric(crate::precise::Precise::stringDiv(&longString, &shortString)));
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchPositionsADLRank
* @description fetches the auto deleveraging rank and risk percentage for a list of symbols
* @see https://bybit-exchange.github.io/docs/v5/position#response-parameters
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of [auto de leverage structures]{@link https://docs.ccxt.com/?id=auto-de-leverage-structure}
*/
pub async fn fetch_positions_adl_rank(&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(&symbols, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchPositionsADLRank() requires a symbols argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&market, &Value::Null) {
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.get_bybit_type(Value::Str("fetchPositionsADLRank".to_string()), market.clone(), &[params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("category".to_string()), type_var.clone());
let __ws_arg_87 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_v5_position_list(&[__ws_arg_87]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "nextPageCursor": "BTCUSDT%2C1767085496112%2C0",
// "category": "linear",
// "list": [
// {
// "symbol": "BTCUSDT",
// "leverage": "",
// "autoAddMargin": 0,
// "avgPrice": "177489.6",
// "liqPrice": "",
// "riskLimitValue": "",
// "takeProfit": "",
// "positionValue": "1774.896",
// "isReduceOnly": false,
// "positionIMByMp": "",
// "tpslMode": "Full",
// "riskId": 0,
// "trailingStop": "0",
// "unrealisedPnl": "-3.016",
// "markPrice": "177188",
// "adlRankIndicator": 2,
// "cumRealisedPnl": "-9782.391468",
// "positionMM": "",
// "createdTime": "1699928551230",
// "positionIdx": 0,
// "positionIM": "",
// "positionMMByMp": "",
// "seq": 9558506126,
// "updatedTime": "1767085496112",
// "side": "Buy",
// "bustPrice": "",
// "positionBalance": "",
// "leverageSysUpdatedTime": "",
// "curRealisedPnl": "-0.9761928",
// "size": "0.01",
// "positionStatus": "Normal",
// "mmrSysUpdatedTime": "",
// "stopLoss": "",
// "tradeMode": 0,
// "sessionAvgPrice": ""
// }
// ]
// },
// "retExtInfo": {},
// "time": 1767085741416
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ranks: Value = self.safe_list_k(result.clone(), "list", &[Value::List(vec![])]);
return self.parse_adl_ranks(ranks.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_adl_rank(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchPositionsADLRank
//
// {
// "symbol": "BTCUSDT",
// "leverage": "",
// "autoAddMargin": 0,
// "avgPrice": "177489.6",
// "liqPrice": "",
// "riskLimitValue": "",
// "takeProfit": "",
// "positionValue": "1774.896",
// "isReduceOnly": false,
// "positionIMByMp": "",
// "tpslMode": "Full",
// "riskId": 0,
// "trailingStop": "0",
// "unrealisedPnl": "-3.016",
// "markPrice": "177188",
// "adlRankIndicator": 2,
// "cumRealisedPnl": "-9782.391468",
// "positionMM": "",
// "createdTime": "1699928551230",
// "positionIdx": 0,
// "positionIM": "",
// "positionMMByMp": "",
// "seq": 9558506126,
// "updatedTime": "1767085496112",
// "side": "Buy",
// "bustPrice": "",
// "positionBalance": "",
// "leverageSysUpdatedTime": "",
// "curRealisedPnl": "-0.9761928",
// "size": "0.01",
// "positionStatus": "Normal",
// "mmrSysUpdatedTime": "",
// "stopLoss": "",
// "tradeMode": 0,
// "sessionAvgPrice": ""
// }
//
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "updatedTime", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone(), Value::Null, Value::Str("contract".to_string())]));
m.insert("rank".to_string(), self.safe_integer_k(info.clone(), "adlRankIndicator", &[]));
m.insert("rating".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name bybit#fetchMarginMode
* @description fetches the margin mode of the trading pair
* @see https://bybit-exchange.github.io/docs/v5/account/account-info
* @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 response: Value = self.private_get_v5_account_info(&[params.clone()]).await;
//
// {
// "retCode": 0,
// "retMsg": "OK",
// "result": {
// "marginMode": "REGULAR_MARGIN",
// "updatedTime": "1723481446000",
// "unifiedMarginStatus": 5,
// "dcpStatus": "OFF",
// "timeWindow": 0,
// "smpGroup": 0,
// "isMasterTrader": false,
// "spotHedgingStatus": "OFF"
// }
// }
//
let mut result: Value = self.safe_dict_k(response.clone(), "result", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_mode(result.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 marginType: Value = self.safe_string_k(marginMode.clone(), "marginMode", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), marginMode.clone());
m.insert("symbol".to_string(), self.safe_symbol(Value::Null, &[market.clone()]));
m.insert("marginMode".to_string(), self.parse_margin_mode_type(marginType.clone()));
m
});
Value::Null
}
pub fn parse_margin_mode_type(&self, mut marginMode: Value) -> Value {
let mut marginModes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ISOLATED_MARGIN".to_string(), Value::Str("isolated".to_string()));
m.insert("REGULAR_MARGIN".to_string(), Value::Str("cross".to_string()));
m.insert("PORTFOLIO_MARGIN".to_string(), Value::Str("portfolio".to_string()));
m
});
return self.safe_string(marginModes.clone(), marginMode.clone(), &[marginMode.clone()]);
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::Str("public".to_string()));
let mut method = get_arg(optional_args, 1, Value::Str("GET".to_string()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut headers = get_arg(optional_args, 3, Value::Null);
let mut body = get_arg(optional_args, 4, Value::Null);
let mut url: Value = add(&add(&self.implode_hostname(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api)), &Value::Str("/".to_string())), &path);
if is_equal(&api, &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.rawencode(params.clone(), &[])));
}
} else if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut isOpenapi: bool = is_greater_than_or_equal(&get_index_of(&url, &Value::Str("openapi".to_string())), &Value::Int(0));
let mut isV3UnifiedMargin: bool = is_greater_than_or_equal(&get_index_of(&url, &Value::Str("unified/v3".to_string())), &Value::Int(0));
let mut isV3Contract: bool = is_greater_than_or_equal(&get_index_of(&url, &Value::Str("contract/v3".to_string())), &Value::Int(0));
let mut isV5UnifiedAccount: bool = is_greater_than_or_equal(&get_index_of(&url, &Value::Str("v5".to_string())), &Value::Int(0));
let mut timestamp: Value = to_string_val(&self.nonce());
if is_true(&isOpenapi) {
if is_greater_than(&get_array_length(&object_keys(¶ms)), &Value::Int(0)) {
body = self.json(params.clone());
} else {
// this fix for PHP is required otherwise it generates
// '[]' on empty arrays even when forced to use objects
body = Value::Str("{}".to_string());
}
let mut payload: Value = add(&add(×tamp, &self.apiKey), &body);
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("hex".to_string())]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m.insert("X-BAPI-API-KEY".to_string(), self.apiKey.clone());
m.insert("X-BAPI-TIMESTAMP".to_string(), timestamp.clone());
m.insert("X-BAPI-SIGN".to_string(), signature.clone());
m
});
} else if is_true(&isV3UnifiedMargin) || is_true(&isV3Contract) || is_true(&isV5UnifiedAccount) {
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m.insert("X-BAPI-API-KEY".to_string(), self.apiKey.clone());
m.insert("X-BAPI-TIMESTAMP".to_string(), timestamp.clone());
m.insert("X-BAPI-RECV-WINDOW".to_string(), to_string_val(&get_value(&self.options, &Value::Str("recvWindow".to_string()))));
m
});
if is_true(&isV3UnifiedMargin) || is_true(&isV3Contract) {
add_element_to_object(&mut headers, &Value::Str("X-BAPI-SIGN-TYPE".to_string()), Value::Str("2".to_string()));
}
let mut query: Value = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), &[params.clone()]);
let mut queryEncoded: Value = self.rawencode(query.clone(), &[]);
let mut auth_base: Value = add(&add(&to_string_val(×tamp), &self.apiKey), &to_string_val(&get_value(&self.options, &Value::Str("recvWindow".to_string()))));
let mut authFull: Value = Value::Null;
if is_equal(&method, &Value::Str("POST".to_string())) {
body = self.json(query.clone());
authFull = add(&auth_base, &body);
} else {
authFull = add(&auth_base, &queryEncoded);
url = add(&url, &add(&Value::Str("?".to_string()), &queryEncoded));
}
let mut signature: Value = Value::Null;
if is_greater_than(&get_index_of(&self.secret, &Value::Str("PRIVATE KEY".to_string())), &negate(&Value::Int(1))) {
signature = rsa(authFull.clone(), self.secret.clone(), Value::Str("sha256".to_string()));
} else {
signature = self.hmac(self.encode(authFull.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[]);
}
add_element_to_object(&mut headers, &Value::Str("X-BAPI-SIGN".to_string()), signature.clone());
} else {
let __ws_arg_88 = get_value(&self.options, &Value::Str("recvWindow".to_string()));
let mut query: Value = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api_key".to_string(), self.apiKey.clone());
m.insert("recv_window".to_string(), __ws_arg_88);
m.insert("timestamp".to_string(), timestamp.clone());
m
})]);
let mut sortedQuery: Value = self.keysort(query.clone(), &[]);
let mut auth: Value = self.rawencode(sortedQuery.clone(), &[Value::Bool(true)]);
let mut signature: Value = Value::Null;
if is_greater_than(&get_index_of(&self.secret, &Value::Str("PRIVATE KEY".to_string())), &negate(&Value::Int(1))) {
signature = rsa(auth.clone(), self.secret.clone(), Value::Str("sha256".to_string()));
} else {
signature = self.hmac(self.encode(auth.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[]);
}
if is_equal(&method, &Value::Str("POST".to_string())) {
let mut isSpot: bool = is_greater_than_or_equal(&get_index_of(&url, &Value::Str("spot".to_string())), &Value::Int(0));
let mut extendedQuery: Value = self.extend(query.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sign".to_string(), signature.clone());
m
})]);
if is_true(&isSpot) {
body = self.urlencode(extendedQuery.clone(), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/x-www-form-urlencoded".to_string()));
m
});
} else {
body = self.json(extendedQuery.clone());
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m
});
}
} else {
url = add(&url, &add(&Value::Str("?".to_string()), &self.rawencode(sortedQuery.clone(), &[Value::Bool(true)])));
url = add(&url, &add(&Value::Str("&sign=".to_string()), &signature));
}
}
}
if is_equal(&method, &Value::Str("POST".to_string())) {
let mut brokerId: Value = self.safe_string_k(self.options.clone(), "brokerId", &[]);
if !is_equal(&brokerId, &Value::Null) {
headers = ternary(is_true(&(is_equal(&headers, &Value::Null))), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), headers.clone());
add_element_to_object(&mut headers, &Value::Str("Referer".to_string()), brokerId.clone());
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url.clone());
m.insert("method".to_string(), method.clone());
m.insert("body".to_string(), body.clone());
m.insert("headers".to_string(), headers.clone());
m
});
Value::Null
}
pub fn handle_errors(&self, mut 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;
}
//
// {
// "ret_code": 10001,
// "ret_msg": "ReadMapCB: expect { or n, but found \u0000, error " +
// "found in #0 byte of ...||..., bigger context " +
// "...||...",
// "ext_code": '',
// "ext_info": '',
// "result": null,
// "time_now": "1583934106.590436"
// }
//
// {
// "retCode":10001,
// "retMsg":"symbol params err",
// "result":{"symbol":"","bid":"","bidIv":"","bidSize":"","ask":"","askIv":"","askSize":"","lastPrice":"","openInterest":"","indexPrice":"","markPrice":"","markPriceIv":"","change24h":"","high24h":"","low24h":"","volume24h":"","turnover24h":"","totalVolume":"","totalTurnover":"","fundingRate":"","predictedFundingRate":"","nextFundingTime":"","countdownHour":"0","predictedDeliveryPrice":"","underlyingPrice":"","delta":"","gamma":"","vega":"","theta":""}
// }
//
let mut errorCode: Value = self.safe_string2(response.clone(), Value::Str("ret_code".to_string()), Value::Str("retCode".to_string()), &[]);
if !is_equal(&errorCode, &Value::Str("0".to_string())) {
if is_equal(&errorCode, &Value::Str("30084".to_string())) {
return Value::Null;
}
let mut feedback: Value = Value::Null;
if is_equal(&errorCode, &Value::Str("10005".to_string())) && is_less_than(&get_index_of(&url, &Value::Str("order".to_string())), &Value::Int(0)) {
feedback = add(&add(&self.id, &Value::Str(" private api uses /user/v3/private/query-api to check if you have a unified account. The API key of user id must own one of permissions: \"Account Transfer\", \"Subaccount Transfer\", \"Withdrawal\" ".to_string())), &body);
} else {
feedback = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
}
if is_greater_than(&get_index_of(&body, &Value::Str("Withdraw address chain or destination tag are not equal".to_string())), &negate(&Value::Int(1))) {
feedback = add(&feedback, &Value::Str("; You might also need to ensure the address is whitelisted".to_string()));
}
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), body.clone(), feedback.clone());
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}