// 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 OkxCore {
pub exchange: crate::exchange::Exchange,
}
impl OkxCore {
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 = OkxCore::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 OkxCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::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 OkxCore.
OkxCore::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 OkxCore.
OkxCore::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 OkxCore.
OkxCore::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 OkxCore.
OkxCore::parse_transfer(self, transfer, &[currency.clone()])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_margin_modification(self, data, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::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 OkxCore.
OkxCore::parse_borrow_interest(self, info, &[market.clone()])
}
fn parse_greeks(&self, greeks: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::parse_greeks(self, greeks, &[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 OkxCore.
OkxCore::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 OkxCore.
OkxCore::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 OkxCore.
OkxCore::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 OkxCore.
OkxCore::parse_market_leverage_tiers(self, info, &[market.clone()])
}
fn create_expired_option_market(&self, symbol: crate::Value) -> crate::Value {
// Forward to the inherent method on OkxCore.
OkxCore::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 OkxCore.
OkxCore::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 OkxCore.
OkxCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for OkxCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"add_margin" => self.add_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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_after" => self.cancel_all_orders_after(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders" => self.cancel_orders(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"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,
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"convert_to_instrument_type" => self.convert_to_instrument_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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()[..]),
"fetch_accounts" => self.fetch_accounts(&args.get(0..).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_borrow_interest" => self.fetch_borrow_interest(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_borrow_rate_histories" => self.fetch_borrow_rate_histories(&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_orders" => self.fetch_canceled_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_cross_borrow_rates" => self.fetch_cross_borrow_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_currencies" => self.fetch_currencies(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit" => self.fetch_deposit(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_addresses_by_network" => self.fetch_deposit_addresses_by_network(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposit_withdraw_fees" => self.fetch_deposit_withdraw_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_history" => self.fetch_funding_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_interval" => self.fetch_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_long_short_ratio_history" => self.fetch_long_short_ratio_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_adjustment_history" => self.fetch_margin_adjustment_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_mark_price" => self.fetch_mark_price(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_mark_prices" => self.fetch_mark_prices(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_markets_by_type" => self.fetch_markets_by_type(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).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_interests" => self.fetch_open_interests(&args.get(0..).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_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position" => self.fetch_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_position_mode" => self.fetch_position_mode(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions" => self.fetch_positions(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_positions_for_symbol" => self.fetch_positions_for_symbol(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_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_transfer" => self.fetch_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_transfers" => self.fetch_transfers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_underlying_assets" => self.fetch_underlying_assets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawal" => self.fetch_withdrawal(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,
"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)),
"handle_market_type_and_params" => self.handle_market_type_and_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"modify_margin_helper" => self.modify_margin_helper(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args.get(3..).unwrap_or(&[]).to_vec()[..]).await,
"nonce" => self.nonce(),
"parse_balance_by_type" => self.parse_balance_by_type(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).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_borrow_rate_histories" => self.parse_borrow_rate_histories(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)),
"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_fees" => self.parse_deposit_withdraw_fees(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_balance" => self.parse_funding_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_interval" => self.parse_funding_interval(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_greeks" => self.parse_greeks(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ids" => self.parse_ids(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"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_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_modification" => self.parse_margin_modification(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_market_leverage_tiers" => self.parse_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_trading_balance" => self.parse_trading_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_trading_fee" => self.parse_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transaction_status" => self.parse_transaction_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_transfer_status" => self.parse_transfer_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"reduce_margin" => self.reduce_margin(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"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,
"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 OkxCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for OkxCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl OkxCore {
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("okx".to_string()));
m.insert("name".to_string(), Value::Str("OKX".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("CN".to_string()), Value::Str("US".to_string())]));
m.insert("version".to_string(), Value::Str("v5".to_string()));
m.insert("rateLimit".to_string(), multiply(&Value::Int(100), &Value::Float(1.1)));
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::Null);
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("addMargin".to_string(), Value::Bool(true));
m.insert("borrowCrossMargin".to_string(), Value::Bool(true));
m.insert("cancelAllOrders".to_string(), Value::Bool(false));
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(true));
m.insert("createConvertTrade".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
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("createTrailingPercentOrder".to_string(), Value::Bool(true));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("fetchAccounts".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::Null);
m.insert("fetchBorrowInterest".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(true));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrder".to_string(), Value::Null);
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(true));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposit".to_string(), Value::Bool(true));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(true));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(false));
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("fetchFundingInterval".to_string(), Value::Bool(true));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(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("fetchL3OrderBook".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Null);
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(true));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(true));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(true));
m.insert("fetchMarkPrice".to_string(), Value::Bool(true));
m.insert("fetchMarkPrices".to_string(), Value::Bool(true));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(true));
m.insert("fetchOpenInterests".to_string(), Value::Bool(true));
m.insert("fetchOpenOrder".to_string(), Value::Null);
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("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(true));
m.insert("fetchPositionHistory".to_string(), Value::Str("emulated".to_string()));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(true));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
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(false));
m.insert("fetchTradingLimits".to_string(), Value::Bool(false));
m.insert("fetchTransactionFee".to_string(), Value::Bool(false));
m.insert("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(true));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(true));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(true));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Bool(false));
m.insert("reduceMargin".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("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(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("1m".to_string()));
m.insert("3m".to_string(), Value::Str("3m".to_string()));
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("15m".to_string(), Value::Str("15m".to_string()));
m.insert("30m".to_string(), Value::Str("30m".to_string()));
m.insert("1h".to_string(), Value::Str("1H".to_string()));
m.insert("2h".to_string(), Value::Str("2H".to_string()));
m.insert("4h".to_string(), Value::Str("4H".to_string()));
m.insert("6h".to_string(), Value::Str("6H".to_string()));
m.insert("12h".to_string(), Value::Str("12H".to_string()));
m.insert("1d".to_string(), Value::Str("1D".to_string()));
m.insert("1w".to_string(), Value::Str("1W".to_string()));
m.insert("1M".to_string(), Value::Str("1M".to_string()));
m.insert("3M".to_string(), Value::Str("3M".to_string()));
m
}));
m.insert("hostname".to_string(), Value::Str("www.okx.com".to_string()));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://user-images.githubusercontent.com/1294454/152485636-38b19e4a-bece-4dec-979a-5982859ffc04.jpg".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("rest".to_string(), Value::Str("https://{hostname}".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.okx.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://www.okx.com/docs-v5/en/".to_string()));
m.insert("fees".to_string(), Value::Str("https://www.okx.com/pages/products/fees.html".to_string()));
m.insert("referral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), Value::Str("https://www.okx.com/join/CCXTCOM".to_string()));
m.insert("discount".to_string(), Value::Float(0.2));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("rest".to_string(), Value::Str("https://{hostname}".to_string()));
m
}));
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("market/tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/books".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(2)));
m
}));
m.insert("market/books-full".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("market/candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(2)));
m
}));
m.insert("market/history-candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(5)));
m
}));
m.insert("market/history-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("market/option/instrument-family-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/platform-24-volume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("market/call-auction-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/call-auction-details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/books-sbe".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("market/block-tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/block-ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/sprd-ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/sprd-candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(2)));
m
}));
m.insert("market/sprd-history-candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/index-tickers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/index-candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/history-index-candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("market/mark-price-candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/history-mark-price-candles".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/exchange-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("market/index-components".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("market/open-oracle".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("market/books-lite".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("public/option-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/block-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/estimated-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/delivery-exercise-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(2)));
m
}));
m.insert("public/estimated-settlement-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/settlement-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(2)));
m
}));
m.insert("public/funding-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/funding-rate-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/open-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/price-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/opt-summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/discount-rate-interest-free-quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("public/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/mark-price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/position-tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/interest-rate-loan-quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("public/underlying".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/insurance-fund".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/convert-contract-coin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("public/instrument-tick-bands".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("public/premium-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/economic-calendar".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("public/market-data-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("public/event-contract/events".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/event-contract/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/event-contract/series".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public/vip-interest-rate-loan-quota".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("rubik/stat/trading-data/support-coin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/contracts/open-interest-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("rubik/stat/taker-volume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/taker-volume-contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/margin/loan-ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/contracts/long-short-account-ratio-contract-top-trader".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/contracts/long-short-position-ratio-contract-top-trader".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/contracts/long-short-account-ratio-contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/contracts/long-short-account-ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/contracts/open-interest-volume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/option/open-interest-volume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/option/open-interest-volume-ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/option/open-interest-volume-expiry".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/option/open-interest-volume-strike".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rubik/stat/option/taker-block-volume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("system/status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("sprd/spreads".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/books".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/public-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/ticker".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/ai-param".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/min-investment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/public/rsi-back-testing".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/grid-quantity".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("asset/exchange-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/eth/apy-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/sol/apy-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/savings/lending-rate-summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/savings/lending-rate-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/fixed-loan/lending-offers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/fixed-loan/lending-apy-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/fixed-loan/pending-lending-volume".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/sfp/dcd/products".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(2), &Value::Int(3)));
m
}));
m.insert("copytrading/public-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-lead-traders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-weekly-pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-pnl".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-stats".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-preference-currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-current-subpositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-subpositions-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/public-copy-traders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("support/announcements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("support/announcements-types".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("support/announcement-types".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradingBot/grid/min-investment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("rfq/counterparties".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/maker-instrument-settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/mmp-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("rfq/quotes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("rfq/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/public-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("sprd/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/orders-pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("sprd/orders-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/orders-history-archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("trade/orders-pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("trade/orders-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(2)));
m
}));
m.insert("trade/orders-history-archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/fills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("trade/fills-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/fills-archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("trade/order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/orders-algo-pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/orders-algo-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/easy-convert-currency-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/easy-convert-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/one-click-repay-currency-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/one-click-repay-currency-list-v2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/one-click-repay-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/one-click-repay-history-v2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/account-rate-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/non-tradable-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/asset-valuation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("asset/transfer-state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/bills-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("asset/deposit-lightning".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("asset/deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/withdrawal-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/deposit-withdraw-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("asset/monthly-statement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("asset/convert/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/convert/currency-pair".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/convert/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("fiat/deposit-payment-methods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/withdrawal-payment-methods".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/deposit-order-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/deposit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/withdrawal-order-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/buy-sell/currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("fiat/buy-sell/currency-pair".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("fiat/buy-sell/history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("account/instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/positions-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/account-position-risk".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/bills-archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/bills-history-archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/subtypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/max-size".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/max-avail-size".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/leverage-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/adjust-leverage-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/max-loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/trade-fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/interest-accrued".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/interest-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/max-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/risk-state".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/interest-limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/spot-borrow-repay-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/greeks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/position-tiers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/set-account-switch-precheck".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/collateral-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/mmp-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/move-positions-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/precheck-set-delta-neutral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("account/quick-margin-borrow-repay-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/borrow-repay-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/vip-interest-accrued".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/vip-interest-deducted".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/vip-loan-order-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/vip-loan-order-detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/fixed-loan/borrowing-limit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/fixed-loan/borrowing-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/fixed-loan/borrowing-orders-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/spot-manual-borrow-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("account/set-auto-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("users/subaccount/list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/subaccount/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("asset/subaccount/balances".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("account/subaccount/max-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/subaccount/bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/subaccount/managed-subaccount-bills".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("users/entrust-subaccount-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/subaccount/interest-limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("users/subaccount/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("tradingBot/grid/orders-algo-pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/orders-algo-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/orders-algo-details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/sub-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/ai-param".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/signals".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/orders-algo-details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/orders-algo-pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/orders-algo-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/positions-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("tradingBot/signal/sub-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/event-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/orders-algo-pending".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/orders-algo-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/orders-algo-details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/sub-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/ongoing-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/history-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/position-details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/cycle-list".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("finance/savings/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/savings/lending-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/offers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/orders-active".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/orders-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/eth/product-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/eth/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/eth/purchase-redeem-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/sol/product-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/sol/balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/sol/purchase-redeem-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/flexible-loan/borrow-currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("finance/flexible-loan/collateral-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("finance/flexible-loan/max-collateral-redeem-amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("finance/flexible-loan/loan-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("finance/flexible-loan/loan-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("finance/flexible-loan/interest-accrued".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/current-subpositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("copytrading/subpositions-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("copytrading/instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/profit-sharing-details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/total-profit-sharing".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/unrealized-profit-sharing-details".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/total-unrealized-profit-sharing".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/copy-settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/current-lead-traders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/batch-leverage-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/lead-traders-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/dma/subaccount-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("broker/dma/subaccount-trade-fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("broker/dma/subaccount/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("broker/dma/rebate-per-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(300));
m
}));
m.insert("broker/fd/rebate-per-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(300));
m
}));
m.insert("broker/fd/if-rebate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("broker/nd/info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("broker/nd/subaccount-info".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("broker/nd/subaccount/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("asset/broker/nd/subaccount-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/broker/nd/subaccount-deposit-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("asset/broker/nd/subaccount-withdrawal-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/nd/rebate-daily".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("broker/nd/rebate-per-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(300));
m
}));
m.insert("finance/sfp/dcd/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("finance/sfp/dcd/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("finance/sfp/dcd/currency-pair".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("finance/sfp/dcd/order-status".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("finance/sfp/dcd/order-history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("affiliate/invitee/detail".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("users/partner/if-rebate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("support/announcements".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("rfq/create-rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/cancel-rfq".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/cancel-batch-rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("rfq/cancel-all-rfqs".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("rfq/execute-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("rfq/maker-instrument-settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/mmp-reset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("rfq/mmp-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(100));
m
}));
m.insert("rfq/create-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("rfq/cancel-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.4));
m
}));
m.insert("rfq/cancel-batch-quotes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("rfq/cancel-all-quotes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("rfq/cancel-all-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("sprd/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/mass-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/amend-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("sprd/cancel-all-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("trade/batch-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(15)));
m
}));
m.insert("trade/cancel-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("trade/cancel-batch-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(15)));
m
}));
m.insert("trade/amend-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(3)));
m
}));
m.insert("trade/amend-batch-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(150)));
m
}));
m.insert("trade/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/fills-archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(172800));
m
}));
m.insert("trade/cancel-advance-algos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/easy-convert".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/one-click-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/one-click-repay-v2".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("trade/mass-cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("trade/cancel-all-after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("trade/order-precheck".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("trade/order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/cancel-algos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("trade/amend-algos".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("asset/withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/withdrawal-lightning".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("asset/cancel-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("asset/convert-dust-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("asset/monthly-statement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1296000));
m
}));
m.insert("asset/convert/estimate-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("asset/convert/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("fiat/create-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/cancel-withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(10), &Value::Int(3)));
m
}));
m.insert("fiat/buy-sell/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("fiat/buy-sell/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("account/bills-history-archive".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(72000));
m
}));
m.insert("account/set-position-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/set-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/position/margin-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/set-fee-type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/set-greeks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/set-isolated-mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/spot-manual-borrow-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(30));
m
}));
m.insert("account/set-auto-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/quick-margin-borrow-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/borrow-repay".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("account/simulated_margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/position-builder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/position-builder-graph".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("account/set-riskOffset-type".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/set-riskOffset-amt".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(2));
m
}));
m.insert("account/activate-option".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/set-auto-loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/account-level-switch-preset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/set-account-level".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/set-collateral-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/mmp-reset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("account/mmp-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(50));
m
}));
m.insert("account/fixed-loan/borrowing-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/fixed-loan/amend-borrowing-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/fixed-loan/manual-reborrow".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/fixed-loan/repay-borrowing-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("account/move-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/set-auto-earn".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/set-settle-currency".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("account/set-trading-config".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("account/demo-adjust-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(20));
m
}));
m.insert("asset/subaccount/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("account/subaccount/set-loan-allocation".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("users/subaccount/create-subaccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("users/subaccount/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("users/subaccount/modify-apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("users/subaccount/subaccount-apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("users/subaccount/delete-apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("users/subaccount/set-transfer-out".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("tradingBot/grid/order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/copy-order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/amend-algo-basic-param".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/amend-order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/stop-order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/cancel-close-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/order-instant-trigger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/withdraw-income".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/compute-margin-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/margin-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/min-investment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/grid/adjust-investment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/create-signal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/stop-order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/margin-balance".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/amendTPSL".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/set-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/close-position".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/sub-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/signal/cancel-sub-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/amend-order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/stop-order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/create".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/amend-order-algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/stop".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/orders/manual-buy".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/settings/reinvestment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/settings/take-profit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/margin/add".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/dca/margin/reduce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/add-investment".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/amend-price-range".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/amend-recurring-amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/amend-recurring-time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/pause".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("tradingBot/recurring/restart".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("finance/savings/purchase-redempt".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/savings/set-lending-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("finance/staking-defi/purchase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/cancel".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/eth/purchase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/eth/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/eth/cancel-redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/sol/purchase".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/sol/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/staking-defi/sol/cancel-redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("finance/flexible-loan/max-loan".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("finance/flexible-loan/adjust-collateral".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/algo-order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("copytrading/close-subposition".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("copytrading/set-instruments".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/amend-profit-sharing-ratio".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/first-copy-settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/amend-copy-settings".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/stop-copy-trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("copytrading/batch-set-leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/nd/create-subaccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.25));
m
}));
m.insert("broker/nd/delete-subaccount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("broker/nd/subaccount/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.25));
m
}));
m.insert("broker/nd/subaccount/modify-apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("broker/nd/subaccount/delete-apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("broker/nd/set-subaccount-level".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/nd/set-subaccount-fee-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(4));
m
}));
m.insert("broker/nd/set-subaccount-assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.25));
m
}));
m.insert("asset/broker/nd/subaccount-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("asset/broker/nd/modify-subaccount-deposit-address".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(5), &Value::Int(3)));
m
}));
m.insert("broker/nd/rebate-per-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(36000));
m
}));
m.insert("finance/sfp/dcd/quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("finance/sfp/dcd/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("finance/sfp/dcd/trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("finance/sfp/dcd/redeem-quote".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("finance/sfp/dcd/redeem".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(10));
m
}));
m.insert("broker/nd/report-subaccount-ip".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Float(0.25));
m
}));
m.insert("broker/dma/subaccount/apikey".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), divide(&Value::Int(1), &Value::Int(4)));
m
}));
m.insert("broker/dma/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(36000));
m
}));
m.insert("broker/fd/rebate-per-orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(36000));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0015".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0010".to_string()), &[]));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0015".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0010".to_string()), &[]));
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0005".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("taker".to_string(), self.parse_number(Value::Str("0.00050".to_string()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.00020".to_string()), &[]));
m
}));
m
}));
m.insert("requiredCredentials".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("apiKey".to_string(), Value::Bool(true));
m.insert("secret".to_string(), Value::Bool(true));
m.insert("password".to_string(), Value::Bool(true));
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("1".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("2".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("4088".to_string(), Value::Str("ManualInteractionNeeded".to_string()).clone());
m.insert("50000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("50001".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("50002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("50004".to_string(), Value::Str("RequestTimeout".to_string()).clone());
m.insert("50005".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("50006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("50007".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("50008".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50009".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("50010".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50011".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("50012".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50013".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("50014".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("50015".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50016".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50017".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50018".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50019".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50020".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50021".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50022".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50023".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50024".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("50025".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50026".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("50027".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("50028".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50044".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("50061".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50062".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50100".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50101".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50102".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("50103".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50104".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50105".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50106".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50107".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50108".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50109".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("50110".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("50111".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50112".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50113".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50114".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("50115".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51001".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("51002".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("51003".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51006".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51007".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51008".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51009".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("51010".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("51011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51012".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("51014".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("51015".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("51016".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51017".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51018".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51019".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51020".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51021".to_string(), Value::Str("ContractUnavailable".to_string()).clone());
m.insert("51022".to_string(), Value::Str("ContractUnavailable".to_string()).clone());
m.insert("51023".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51024".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("51025".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51026".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("51027".to_string(), Value::Str("ContractUnavailable".to_string()).clone());
m.insert("51028".to_string(), Value::Str("ContractUnavailable".to_string()).clone());
m.insert("51029".to_string(), Value::Str("ContractUnavailable".to_string()).clone());
m.insert("51030".to_string(), Value::Str("ContractUnavailable".to_string()).clone());
m.insert("51031".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51046".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51047".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51051".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51072".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51073".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51074".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51090".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51091".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51092".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51093".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51094".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51095".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51096".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51098".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51099".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51100".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51101".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51102".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51103".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51104".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51105".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51106".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51107".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51108".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51109".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51110".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51111".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51112".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51113".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("51115".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51116".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51117".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51118".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51119".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51120".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51121".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51122".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51124".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51125".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51126".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51127".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51128".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51129".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51130".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("51131".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51132".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51133".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51134".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51135".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51136".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51137".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51138".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51139".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51155".to_string(), Value::Str("RestrictedLocation".to_string()).clone());
m.insert("51156".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51159".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51162".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51163".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51166".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51174".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51185".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51201".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51202".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51203".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51204".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51205".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51250".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51251".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51252".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51253".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51254".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51255".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51256".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51257".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51258".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51259".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51260".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51261".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51262".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51263".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51264".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51265".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51267".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51268".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51269".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51270".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51271".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51272".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51273".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51274".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51275".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51276".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51277".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51278".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51279".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51280".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51321".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51322".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51323".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51324".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51325".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51327".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51328".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51329".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51330".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51400".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("51401".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("51402".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("51403".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51404".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("51405".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51406".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51407".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51408".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51409".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51410".to_string(), Value::Str("CancelPending".to_string()).clone());
m.insert("51500".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51501".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51502".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51503".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51506".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51508".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51509".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51510".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51511".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51600".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51601".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51602".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51603".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("51732".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("51733".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("51734".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("51735".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51736".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51763".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("51764".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51765".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51766".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51767".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("51768".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51769".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51770".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51771".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("51772".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("51773".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("51774".to_string(), Value::Str("OnMaintenance".to_string()).clone());
m.insert("52000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("54000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("54001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("54008".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("54009".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("54011".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("54072".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("54073".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("54074".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("54094".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55100".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55101".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55102".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55103".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55104".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55111".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55112".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("55113".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("58000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("58002".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("58003".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58004".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("58005".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58006".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58007".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58100".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58101".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("58102".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("58103".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58104".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58105".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58106".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58107".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58108".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58109".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58110".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58111".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58112".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58114".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58115".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58116".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58117".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58125".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58126".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58127".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58128".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58200".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58201".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58202".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58203".to_string(), Value::Str("InvalidAddress".to_string()).clone());
m.insert("58204".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("58205".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58206".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58207".to_string(), Value::Str("InvalidAddress".to_string()).clone());
m.insert("58208".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58209".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58210".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58211".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58212".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58213".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("58221".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58222".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58224".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58227".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58228".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("58229".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("58300".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("58350".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("59000".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59001".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59100".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59101".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59102".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59103".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("59104".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59105".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59106".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59107".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59108".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("59109".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59113".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("59128".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("59200".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("59201".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("59216".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("59260".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("59262".to_string(), Value::Str("PermissionDenied".to_string()).clone());
m.insert("59300".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59301".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59313".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59401".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59410".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("59411".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("59412".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("59413".to_string(), Value::Str("OperationRejected".to_string()).clone());
m.insert("59414".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("59500".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59501".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59502".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59503".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59504".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59505".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59506".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59507".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59508".to_string(), Value::Str("AccountSuspended".to_string()).clone());
m.insert("59515".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59516".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59517".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59518".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59519".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59642".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("59643".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59683".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("59684".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("59686".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("60001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60003".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60004".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60005".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60006".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("60007".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60008".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60009".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60010".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60011".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60012".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("60013".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("60014".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("60015".to_string(), Value::Str("NetworkError".to_string()).clone());
m.insert("60016".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("60017".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("60018".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("60019".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("60020".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("60021".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("60022".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60023".to_string(), Value::Str("DDoSProtection".to_string()).clone());
m.insert("60024".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60025".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("60026".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60027".to_string(), Value::Str("ArgumentsRequired".to_string()).clone());
m.insert("60028".to_string(), Value::Str("NotSupported".to_string()).clone());
m.insert("60029".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("60030".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("60031".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("60032".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("63999".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("64000".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("64001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("64002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("64003".to_string(), Value::Str("AccountNotEnabled".to_string()).clone());
m.insert("64004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("64008".to_string(), Value::Str("NetworkError".to_string()).clone());
m.insert("70010".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70013".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70016".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70060".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70061".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70062".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70064".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70065".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70066".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("70067".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("1009".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("4001".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("4002".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("4003".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("4004".to_string(), Value::Str("NetworkError".to_string()).clone());
m.insert("4005".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("4006".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("4007".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("4008".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Internal Server Error".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("server error".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m
}));
m
}));
m.insert("httpExceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("429".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
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("sandboxMode".to_string(), Value::Bool(false));
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("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("BTC".to_string(), Value::Str("BTC".to_string()));
m.insert("USDT".to_string(), Value::Str("TRC20".to_string()));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BTC".to_string(), Value::Str("Bitcoin".to_string()));
m.insert("BTCLIGHTNING".to_string(), Value::Str("Lightning".to_string()));
m.insert("BSC".to_string(), Value::Str("BSC".to_string()));
m.insert("BEP20".to_string(), Value::Str("BSC".to_string()));
m.insert("BRC20".to_string(), Value::Str("BRC20".to_string()));
m.insert("ETH".to_string(), Value::Str("ERC20".to_string()));
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
m.insert("TRX".to_string(), Value::Str("TRC20".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRC20".to_string()));
m.insert("CRC20".to_string(), Value::Str("Crypto".to_string()));
m.insert("CRONOS".to_string(), Value::Str("Crypto".to_string()));
m.insert("ACA".to_string(), Value::Str("Acala".to_string()));
m.insert("ALGO".to_string(), Value::Str("Algorand".to_string()));
m.insert("APT".to_string(), Value::Str("Aptos".to_string()));
m.insert("SONIC".to_string(), Value::Str("Sonic".to_string()));
m.insert("SCROLL".to_string(), Value::Str("Scroll".to_string()));
m.insert("ARBITRUM".to_string(), Value::Str("Arbitrum One".to_string()));
m.insert("AVAXC".to_string(), Value::Str("Avalanche C-Chain".to_string()));
m.insert("AVAXX".to_string(), Value::Str("Avalanche X-Chain".to_string()));
m.insert("BASE".to_string(), Value::Str("Base".to_string()));
m.insert("SUI".to_string(), Value::Str("SUI".to_string()));
m.insert("ZKSYNCERA".to_string(), Value::Str("zkSync Era".to_string()));
m.insert("LINEA".to_string(), Value::Str("Linea".to_string()));
m.insert("VAULTA".to_string(), Value::Str("Vaulta".to_string()));
m.insert("AR".to_string(), Value::Str("Arweave".to_string()));
m.insert("ASTR".to_string(), Value::Str("Astar".to_string()));
m.insert("BCH".to_string(), Value::Str("BitcoinCash".to_string()));
m.insert("BSV".to_string(), Value::Str("Bitcoin SV".to_string()));
m.insert("ADA".to_string(), Value::Str("Cardano".to_string()));
m.insert("CSPR".to_string(), Value::Str("Casper".to_string()));
m.insert("CANTON".to_string(), Value::Str("Canton Network".to_string()));
m.insert("CELO".to_string(), Value::Str("CELO".to_string()));
m.insert("XCH".to_string(), Value::Str("Chia".to_string()));
m.insert("BABY".to_string(), Value::Str("Babylon".to_string()));
m.insert("ATOM".to_string(), Value::Str("Cosmos".to_string()));
m.insert("DGB".to_string(), Value::Str("Digibyte".to_string()));
m.insert("DOGE".to_string(), Value::Str("Dogecoin".to_string()));
m.insert("EGLD".to_string(), Value::Str("Elrond".to_string()));
m.insert("CFX".to_string(), Value::Str("Conflux".to_string()));
m.insert("EOS".to_string(), Value::Str("EOS".to_string()));
m.insert("CORE".to_string(), Value::Str("CORE".to_string()));
m.insert("ETC".to_string(), Value::Str("Ethereum Classic".to_string()));
m.insert("ETHW".to_string(), Value::Str("EthereumPow".to_string()));
m.insert("FIL".to_string(), Value::Str("Filecoin".to_string()));
m.insert("HBAR".to_string(), Value::Str("Hedera".to_string()));
m.insert("HYPER".to_string(), Value::Str("HyperEVM".to_string()));
m.insert("ICP".to_string(), Value::Str("Dfinity".to_string()));
m.insert("PI".to_string(), Value::Str("PI".to_string()));
m.insert("IOTA".to_string(), Value::Str("MIOTA".to_string()));
m.insert("KLAY".to_string(), Value::Str("Klaytn".to_string()));
m.insert("KSM".to_string(), Value::Str("Kusama".to_string()));
m.insert("LSK".to_string(), Value::Str("Lisk".to_string()));
m.insert("LTC".to_string(), Value::Str("Litecoin".to_string()));
m.insert("METIS".to_string(), Value::Str("Metis".to_string()));
m.insert("MINA".to_string(), Value::Str("Mina".to_string()));
m.insert("GLRM".to_string(), Value::Str("Moonbeam".to_string()));
m.insert("MOVR".to_string(), Value::Str("Moonriver".to_string()));
m.insert("NANO".to_string(), Value::Str("Nano".to_string()));
m.insert("NEAR".to_string(), Value::Str("NEAR".to_string()));
m.insert("NULS".to_string(), Value::Str("NULS".to_string()));
m.insert("OASYS".to_string(), Value::Str("OASYS".to_string()));
m.insert("ONT".to_string(), Value::Str("Ontology".to_string()));
m.insert("OP".to_string(), Value::Str("Optimism".to_string()));
m.insert("DOT".to_string(), Value::Str("Polkadot".to_string()));
m.insert("MATIC".to_string(), Value::Str("Polygon".to_string()));
m.insert("RVN".to_string(), Value::Str("Ravencoin".to_string()));
m.insert("XRP".to_string(), Value::Str("Ripple".to_string()));
m.insert("SC".to_string(), Value::Str("Siacoin".to_string()));
m.insert("SOL".to_string(), Value::Str("Solana".to_string()));
m.insert("STX".to_string(), Value::Str("l-Stacks".to_string()));
m.insert("XLM".to_string(), Value::Str("Stellar Lumens".to_string()));
m.insert("XTZ".to_string(), Value::Str("Tezos".to_string()));
m.insert("TON".to_string(), Value::Str("TON".to_string()));
m.insert("THETA".to_string(), Value::Str("Theta".to_string()));
m.insert("WAX".to_string(), Value::Str("Wax".to_string()));
m.insert("ZIL".to_string(), Value::Str("Zilliqa".to_string()));
m.insert("ZEC".to_string(), Value::Str("Zcash".to_string()));
m.insert("ZETA".to_string(), Value::Str("ZetaChain".to_string()));
m.insert("TIA".to_string(), Value::Str("Celestia".to_string()));
m.insert("SEI".to_string(), Value::Str("SEI".to_string()));
m.insert("QUANTUM".to_string(), Value::Str("Quantum".to_string()));
m.insert("PHAROS".to_string(), Value::Str("Pharos".to_string()));
m.insert("RONIN".to_string(), Value::Str("Ronin".to_string()));
m.insert("MEGAETH".to_string(), Value::Str("MegaETH".to_string()));
m.insert("INJ".to_string(), Value::Str("INJ".to_string()));
m.insert("FOGO".to_string(), Value::Str("Fogo".to_string()));
m.insert("FLR".to_string(), Value::Str("Flare".to_string()));
m.insert("FLOW".to_string(), Value::Str("FLOW".to_string()));
m.insert("DYDX".to_string(), Value::Str("DYDX".to_string()));
m.insert("AELF".to_string(), Value::Str("AELF".to_string()));
m.insert("BERA".to_string(), Value::Str("Berachain".to_string()));
m.insert("TEMPO".to_string(), Value::Str("Tempo".to_string()));
m.insert("MONAD".to_string(), Value::Str("Monad".to_string()));
m.insert("PLASMA".to_string(), Value::Str("Plasma".to_string()));
m
}));
m.insert("networksById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ERC20".to_string(), Value::Str("ERC20".to_string()));
m.insert("TRC20".to_string(), Value::Str("TRC20".to_string()));
m.insert("BEP20".to_string(), Value::Str("BEP20".to_string()));
m
}));
m.insert("fetchOpenInterestHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("5m".to_string(), Value::Str("5m".to_string()));
m.insert("1h".to_string(), Value::Str("1H".to_string()));
m.insert("8h".to_string(), Value::Str("8H".to_string()));
m.insert("1d".to_string(), Value::Str("1D".to_string()));
m.insert("5M".to_string(), Value::Str("5m".to_string()));
m.insert("1H".to_string(), Value::Str("1H".to_string()));
m.insert("8H".to_string(), Value::Str("8H".to_string()));
m.insert("1D".to_string(), Value::Str("1D".to_string()));
m
}));
m
}));
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timezone".to_string(), Value::Str("UTC".to_string()));
m
}));
m.insert("fetchPositions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("privateGetAccountPositions".to_string()));
m
}));
m.insert("createOrder".to_string(), Value::Str("privatePostTradeBatchOrders".to_string()));
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("types".to_string(), Value::List(vec![Value::Str("spot".to_string()), Value::Str("future".to_string()), Value::Str("swap".to_string()), Value::Str("option".to_string())]));
m
}));
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("defaultType".to_string(), Value::Str("spot".to_string()));
m.insert("fetchLedger".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("privateGetAccountBills".to_string()));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("privateGetTradeOrder".to_string()));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("privateGetTradeOrdersPending".to_string()));
m
}));
m.insert("cancelOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("privatePostTradeCancelBatchOrders".to_string()));
m
}));
m.insert("fetchCanceledOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("privateGetTradeOrdersHistory".to_string()));
m.insert("paginationDirection".to_string(), Value::Str("forward".to_string()));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("privateGetTradeOrdersHistory".to_string()));
m.insert("paginationDirection".to_string(), Value::Str("forward".to_string()));
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("password".to_string(), Value::Null);
m.insert("pwd".to_string(), Value::Null);
m
}));
m.insert("algoOrderTypes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("conditional".to_string(), Value::Bool(true));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("oco".to_string(), Value::Bool(true));
m.insert("move_order_stop".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(true));
m.insert("twap".to_string(), Value::Bool(true));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("funding".to_string(), Value::Str("6".to_string()));
m.insert("trading".to_string(), Value::Str("18".to_string()));
m.insert("spot".to_string(), Value::Str("18".to_string()));
m.insert("future".to_string(), Value::Str("18".to_string()));
m.insert("futures".to_string(), Value::Str("18".to_string()));
m.insert("margin".to_string(), Value::Str("18".to_string()));
m.insert("swap".to_string(), Value::Str("18".to_string()));
m.insert("option".to_string(), Value::Str("18".to_string()));
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("6".to_string(), Value::Str("funding".to_string()));
m.insert("18".to_string(), Value::Str("trading".to_string()));
m
}));
m.insert("exchangeType".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("MARGIN".to_string()));
m.insert("swap".to_string(), Value::Str("SWAP".to_string()));
m.insert("future".to_string(), Value::Str("FUTURES".to_string()));
m.insert("futures".to_string(), Value::Str("FUTURES".to_string()));
m.insert("option".to_string(), Value::Str("OPTION".to_string()));
m.insert("SPOT".to_string(), Value::Str("SPOT".to_string()));
m.insert("MARGIN".to_string(), Value::Str("MARGIN".to_string()));
m.insert("SWAP".to_string(), Value::Str("SWAP".to_string()));
m.insert("FUTURES".to_string(), Value::Str("FUTURES".to_string()));
m.insert("OPTION".to_string(), Value::Str("OPTION".to_string()));
m
}));
m.insert("brokerId".to_string(), Value::Str("6b9ad766b55dBCDE".to_string()));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(true));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("price".to_string(), Value::Bool(true));
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(true));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(true));
m.insert("marketBuyByCost".to_string(), Value::Bool(true));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("max".to_string(), Value::Int(20));
m
}));
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("limit".to_string(), Value::Int(100));
m.insert("untilDays".to_string(), Value::Int(10000));
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(true));
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(100));
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(true));
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(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("daysBackCanceled".to_string(), divide(&Value::Int(1), &Value::Int(12)));
m.insert("untilDays".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(true));
m.insert("trailing".to_string(), Value::Bool(true));
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(300));
m.insert("mark".to_string(), Value::Int(100));
m.insert("index".to_string(), Value::Int(100));
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
}));
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("currencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USD".to_string(), self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("USD".to_string()));
m.insert("code".to_string(), Value::Str("USD".to_string()));
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
m
})));
m.insert("EUR".to_string(), self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("EUR".to_string()));
m.insert("code".to_string(), Value::Str("EUR".to_string()));
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
m
})));
m.insert("AED".to_string(), self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("AED".to_string()));
m.insert("code".to_string(), Value::Str("AED".to_string()));
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
m
})));
m.insert("GBP".to_string(), self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("GBP".to_string()));
m.insert("code".to_string(), Value::Str("GBP".to_string()));
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
m
})));
m.insert("AUD".to_string(), self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), Value::Str("AUD".to_string()));
m.insert("code".to_string(), Value::Str("AUD".to_string()));
m.insert("precision".to_string(), self.parse_number(Value::Str("0.0001".to_string()), &[]));
m
})));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("AE".to_string(), Value::Str("AET".to_string()));
m
}));
m.insert("rollingWindowSize".to_string(), Value::Int(0));
m
})]);
Value::Null
}
pub fn handle_market_type_and_params(&self, mut methodName: Value, optional_args: &[Value]) -> Value {
let mut market = 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 defaultValue = get_arg(optional_args, 2, Value::Null);
let mut instType: Value = self.safe_string_k(params.clone(), "instType", &[]);
params = self.omit(params.clone(), Value::Str("instType".to_string()), &[]);
let mut type_var: Value = self.safe_string_k(params.clone(), "type", &[]);
if is_true(&(is_equal(&type_var, &Value::Null))) && is_true(&(!is_equal(&instType, &Value::Null))) {
add_element_to_object(&mut params, &Value::Str("type".to_string()), instType.clone());
}
return self.super_handle_market_type_and_params(methodName.clone(), market.clone(), params.clone(), defaultValue.clone());
Value::Null
}
pub fn convert_to_instrument_type(&self, mut type_var: Value) -> Value {
let mut exchangeTypes: Value = self.safe_dict_k(self.options.clone(), "exchangeType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_string(exchangeTypes.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn create_expired_option_market(&self, mut symbol: Value) -> Value {
// support expired option contracts
let mut quote: Value = Value::Str("USD".to_string());
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;
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), &[]);
} else {
base = self.safe_string(optionParts.clone(), Value::Int(0), &[]);
}
let mut settle: Value = base.clone();
let mut expiry: Value = self.safe_string(optionParts.clone(), Value::Int(2), &[]);
let mut strike: Value = self.safe_string(optionParts.clone(), Value::Int(3), &[]);
let mut optionType: Value = self.safe_string(optionParts.clone(), Value::Int(4), &[]);
let mut datetime: Value = ternary(is_true(&(is_equal(&expiry, &Value::Null))), Value::Null, self.convert_expire_date(expiry.clone()));
let mut timestamp: Value = self.parse8601(datetime.clone());
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), add(&add(&add(&add(&add(&add(&add(&add(&base, &Value::Str("-".to_string())), "e), &Value::Str("-".to_string())), &expiry), &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("linear".to_string(), Value::Null);
m.insert("inverse".to_string(), Value::Null);
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(), Value::Null);
m.insert("price".to_string(), Value::Null);
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 = false;
if !is_equal(&marketId, &Value::Null) {
let mut parts: Value = split(&marketId, &Value::Str("-".to_string()));
let mut partsLength: Value = get_array_length(&parts);
// a valid OKX option ends with the call/put flag and carries expiry+strike segments,
// e.g. the market id BTC-USD-220325-194000-P (5 parts) or the unified symbol
// BTC/USD:USD-260611-54000-C (4 parts). Requiring more than 3 dash-separated parts avoids
// misclassifying ordinary ids that merely contain "-C"/"-P" (such as a SPOT id like
// "PERFTESTA-PERFTESTB") as expired options, which would crash createExpiredOptionMarket
// on the missing expiry.
isOption = is_true(&(is_greater_than(&partsLength, &Value::Int(3)))) && is_true(&(is_true(&Value::Bool(ends_with(&marketId, &Value::Str("-C".to_string())))) || is_true(&Value::Bool(ends_with(&marketId, &Value::Str("-P".to_string()))))));
}
if is_true(&isOption) && is_true(&(!is_equal(&marketId, &Value::Null))) && 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
}
/*
* @method
* @name okx#fetchStatus
* @description the latest known information on the availability of the exchange API
* @see https://www.okx.com/docs-v5/en/#status-get-status
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [status structure]{@link https://docs.ccxt.com/?id=exchange-status-structure}
*/
pub async fn fetch_status(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_system_status(&[params.clone()]).await;
//
// Note, if there is no maintenance around, the 'data' array is empty
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "begin": "1621328400000",
// "end": "1621329000000",
// "href": "https://www.okx.com/support/hc/en-us/articles/360060882172",
// "scheDesc": "",
// "serviceType": "1", // 0 WebSocket, 1 Spot/Margin, 2 Futures, 3 Perpetual, 4 Options, 5 Trading service
// "state": "scheduled", // ongoing, completed, canceled
// "system": "classic", // classic, unified
// "title": "Classic Spot System Upgrade"
// },
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut dataLength: Value = get_array_length(&data);
let mut update: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("updated".to_string(), Value::Null);
m.insert("status".to_string(), ternary(is_true(&(is_equal(&dataLength, &Value::Int(0)))), Value::Str("ok".to_string()), Value::Str("maintenance".to_string())));
m.insert("eta".to_string(), Value::Null);
m.insert("url".to_string(), Value::Null);
m.insert("info".to_string(), response.clone());
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_982: bool = true;
while { if !__for_first_982 { i = add(&i, &Value::Int(1)); } __for_first_982 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut event: Value = get_value(&data, &i);
let mut event: Value = get_value(&data, &i);
let mut state: Value = self.safe_string_k(event.clone(), "state", &[]);
add_element_to_object(&mut update, &Value::Str("eta".to_string()), self.safe_integer_k(event.clone(), "end", &[]));
add_element_to_object(&mut update, &Value::Str("url".to_string()), self.safe_string_k(event.clone(), "href", &[]));
if is_equal(&state, &Value::Str("ongoing".to_string())) {
add_element_to_object(&mut update, &Value::Str("status".to_string()), Value::Str("maintenance".to_string()));
} else if is_equal(&state, &Value::Str("scheduled".to_string())) {
add_element_to_object(&mut update, &Value::Str("status".to_string()), Value::Str("ok".to_string()));
} else if is_equal(&state, &Value::Str("completed".to_string())) {
add_element_to_object(&mut update, &Value::Str("status".to_string()), Value::Str("ok".to_string()));
} else if is_equal(&state, &Value::Str("canceled".to_string())) {
add_element_to_object(&mut update, &Value::Str("status".to_string()), Value::Str("ok".to_string()));
}
}
}
return update;
Value::Null
}
/*
* @method
* @name okx#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-system-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_public_time(&[params.clone()]).await;
//
// {
// "code": "0",
// "data": [
// {"ts": "1621247923668"}
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.safe_integer_k(first.clone(), "ts", &[]);
Value::Null
}
/*
* @method
* @name okx#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/?id=account-structure} indexed by the account type
*/
pub async fn fetch_accounts(&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.private_get_account_config(&[params.clone()]).await;
//
// {
// "code": "0",
// "data": [
// {
// "acctLv": "2",
// "acctStpMode": "cancel_maker",
// "autoLoan": false,
// "ctIsoMode": "automatic",
// "enableSpotBorrow": false,
// "greeksType": "PA",
// "feeType": "0",
// "ip": "",
// "type": "0",
// "kycLv": "3",
// "label": "v5 test",
// "level": "Lv1",
// "levelTmp": "",
// "liquidationGear": "-1",
// "mainUid": "44705892343619584",
// "mgnIsoMode": "automatic",
// "opAuth": "1",
// "perm": "read_only,withdraw,trade",
// "posMode": "long_short_mode",
// "roleType": "0",
// "spotBorrowAutoRepay": false,
// "spotOffsetType": "",
// "spotRoleType": "0",
// "spotTraderInsts": [],
// "traderInsts": [],
// "uid": "44705892343619584",
// "settleCcy": "USDT",
// "settleCcyList": ["USD", "USDC", "USDG"],
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_983: bool = true;
while { if !__for_first_983 { i = add(&i, &Value::Int(1)); } __for_first_983 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut account: Value = get_value(&data, &i);
let mut account: Value = get_value(&data, &i);
let mut accountId: Value = self.safe_string_k(account.clone(), "uid", &[]);
let mut type_var: Value = self.safe_string_k(account.clone(), "acctLv", &[]);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), accountId.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("currency".to_string(), Value::Null);
m.insert("info".to_string(), account.clone());
m.insert("code".to_string(), Value::Null);
m
}));
}
}
return result;
Value::Null
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
/*
* @method
* @name okx#fetchMarkets
* @description retrieves data on all markets for okx
* @see https://www.okx.com/docs-v5/en/#rest-api-public-data-get-instruments
* @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 types: Value = Value::List(vec![Value::Str("spot".to_string()), Value::Str("future".to_string()), Value::Str("swap".to_string()), Value::Str("option".to_string())]);
let mut fetchMarketsOption: Value = self.safe_dict_k(self.options.clone(), "fetchMarkets", &[]);
if !is_equal(&fetchMarketsOption, &Value::Null) {
types = self.safe_list_k(fetchMarketsOption.clone(), "types", &[types.clone()]);
} else {
types = self.safe_list_k(self.options.clone(), "fetchMarkets", &[types.clone()]); // backward-support
}
let mut promises: Value = Value::List(vec![]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_984: bool = true;
while { if !__for_first_984 { i = add(&i, &Value::Int(1)); } __for_first_984 = false; is_less_than(&i, &get_array_length(&types)) } {
append_to_array(&mut promises, self.fetch_markets_by_type(get_value(&types, &i), &[params.clone()]).await);
}
}
promises = promise_all(&promises).await;
{
let mut i: Value = Value::Int(0);
let mut __for_first_985: bool = true;
while { if !__for_first_985 { i = add(&i, &Value::Int(1)); } __for_first_985 = false; is_less_than(&i, &get_array_length(&promises)) } {
result = self.array_concat(result.clone(), get_value(&promises, &i));
}
}
return result;
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
//
// {
// "alias": "", // this_week, next_week, quarter, next_quarter
// "baseCcy": "BTC",
// "category": "1",
// "ctMult": "",
// "ctType": "", // inverse, linear
// "ctVal": "",
// "ctValCcy": "",
// "expTime": "",
// "instId": "BTC-USDT", // BTC-USD-210521, CSPR-USDT-SWAP, BTC-USD-210517-44000-C
// "instType": "SPOT", // SPOT, FUTURES, SWAP, OPTION
// "lever": "10",
// "listTime": "1548133413000",
// "lotSz": "0.00000001",
// "minSz": "0.00001",
// "optType": "",
// "quoteCcy": "USDT",
// "settleCcy": "",
// "state": "live",
// "stk": "",
// "tickSz": "0.1",
// "uly": ""
// }
//
// {
// "alias": "",
// "baseCcy": "",
// "category": "1",
// "ctMult": "0.1",
// "ctType": "",
// "ctVal": "1",
// "ctValCcy": "BTC",
// "expTime": "1648195200000",
// "instId": "BTC-USD-220325-194000-P",
// "instType": "OPTION",
// "lever": "",
// "listTime": "1631262612280",
// "contTdSwTime": "1631262812280",
// "lotSz": "1",
// "minSz": "1",
// "optType": "P",
// "quoteCcy": "",
// "settleCcy": "BTC",
// "state": "live",
// "stk": "194000",
// "tickSz": "0.0005",
// "uly": "BTC-USD"
// }
//
// for swap "preopen" markets, only `instId` and `instType` are present
//
// instId: "ETH-USD_UM-SWAP",
// instType: "SWAP",
// state: "preopen",
//
let mut id: Value = self.safe_string_k(market.clone(), "instId", &[Value::Str("".to_string())]);
let mut type_var: Value = self.safe_string_lower(market.clone(), Value::Str("instType".to_string()), &[]);
if is_equal(&type_var, &Value::Str("futures".to_string())) {
type_var = Value::Str("future".to_string());
}
let mut spot: Value = Value::Bool(is_equal(&type_var, &Value::Str("spot".to_string())));
let mut future: Value = Value::Bool(is_equal(&type_var, &Value::Str("future".to_string())));
let mut swap: Value = Value::Bool(is_equal(&type_var, &Value::Str("swap".to_string())));
let mut option: Value = Value::Bool(is_equal(&type_var, &Value::Str("option".to_string())));
let mut contract: Value = Value::Bool(is_true(&swap) || is_true(&future) || is_true(&option));
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCcy", &[Value::Str("".to_string())]); // defaulting to '' because some weird preopen markets have empty baseId
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCcy", &[Value::Str("".to_string())]);
let mut settleId: Value = self.safe_string_k(market.clone(), "settleCcy", &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut underlying: Value = self.safe_string_k(market.clone(), "uly", &[]);
if is_true(&(!is_equal(&underlying, &Value::Null))) && !is_true(&spot) {
let mut parts: Value = split(&underlying, &Value::Str("-".to_string()));
baseId = self.safe_string(parts.clone(), Value::Int(0), &[Value::Str("".to_string())]);
quoteId = self.safe_string(parts.clone(), Value::Int(1), &[Value::Str("".to_string())]);
}
if is_true(&(is_true(&(is_equal(&baseId, &Value::Str("".to_string())))) || is_true(&(is_equal("eId, &Value::Str("".to_string())))))) && is_true(&spot) {
let mut instId: Value = self.safe_string_k(market.clone(), "instId", &[Value::Str("".to_string())]);
let mut parts: Value = split(&instId, &Value::Str("-".to_string()));
baseId = self.safe_string(parts.clone(), Value::Int(0), &[Value::Str("".to_string())]);
quoteId = self.safe_string(parts.clone(), Value::Int(1), &[Value::Str("".to_string())]);
}
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);
// handle preopen empty markets
if is_equal(&base, &Value::Str("".to_string())) || is_equal("e, &Value::Str("".to_string())) {
symbol = id.clone();
}
let mut expiry: Value = Value::Null;
let mut strikePrice: Value = Value::Null;
let mut optionType: Value = Value::Null;
if is_true(&contract) {
if !is_equal(&settle, &Value::Null) {
symbol = add(&add(&symbol, &Value::Str(":".to_string())), &settle);
}
if is_true(&future) {
expiry = self.safe_integer_k(market.clone(), "expTime", &[]);
if !is_equal(&expiry, &Value::Null) {
let mut ymd: Value = self.yymmdd(expiry.clone(), &[]);
symbol = add(&add(&symbol, &Value::Str("-".to_string())), &ymd);
}
} else if is_true(&option) {
expiry = self.safe_integer_k(market.clone(), "expTime", &[]);
strikePrice = self.safe_string_k(market.clone(), "stk", &[]);
optionType = self.safe_string_k(market.clone(), "optType", &[]);
if !is_equal(&expiry, &Value::Null) {
let mut ymd: Value = self.yymmdd(expiry.clone(), &[]);
symbol = add(&add(&add(&add(&add(&add(&symbol, &Value::Str("-".to_string())), &ymd), &Value::Str("-".to_string())), &strikePrice), &Value::Str("-".to_string())), &optionType);
optionType = ternary(is_true(&(is_equal(&optionType, &Value::Str("P".to_string())))), Value::Str("put".to_string()), Value::Str("call".to_string()));
}
}
}
let mut feesType: Value = ternary(is_true(&(is_equal(&type_var, &Value::Null))), Value::Str("".to_string()), type_var.clone());
let mut fees: Value = self.safe_dict2(self.fees.clone(), feesType.clone(), Value::Str("trading".to_string()), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut maxLeverage: Value = self.safe_string_k(market.clone(), "lever", &[Value::Str("1".to_string())]);
maxLeverage = crate::precise::Precise::stringMax(&maxLeverage, &Value::Str("1".to_string()));
let mut maxSpotCost: Value = self.safe_number_k(market.clone(), "maxMktSz", &[]);
let mut leverageAboveOne: Value = crate::precise::Precise::stringGt(&maxLeverage, &Value::Str("1".to_string()));
let mut quoteEqualSettle: Value = Value::Bool(is_equal("eId, &settleId));
let mut baseEqualSettle: Value = Value::Bool(is_equal(&baseId, &settleId));
let mut status: Value = self.safe_string_k(market.clone(), "state", &[]);
let mut instIdCode: Value = self.safe_integer_k(market.clone(), "instIdCode", &[]);
let __ws_arg_0 = self.safe_number_k(market.clone(), "ctVal", &[]);
let __ws_arg_1 = self.iso8601(expiry.clone());
let __ws_arg_2 = self.parse_number(strikePrice.clone(), &[]);
let __ws_arg_3 = self.safe_integer2(market.clone(), Value::Str("contTdSwTime".to_string()), Value::Str("listTime".to_string()), &[]);
let __ws_arg_4 = self.safe_number_k(market.clone(), "lotSz", &[]);
let __ws_arg_5 = self.safe_number_k(market.clone(), "tickSz", &[]);
let __ws_arg_6 = self.parse_number(Value::Str("1".to_string()), &[]);
let __ws_arg_7 = self.parse_number(maxLeverage.clone(), &[]);
let __ws_arg_8 = self.safe_number_k(market.clone(), "minSz", &[]);
let __ws_arg_9 = self.safe_number_k(market.clone(), "maxLmtSz", &[]);
return self.extend(fees.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("instIdCode".to_string(), instIdCode.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(), spot.clone());
m.insert("margin".to_string(), Value::Bool(is_true(&spot) && is_true(&leverageAboveOne)));
m.insert("swap".to_string(), swap.clone());
m.insert("future".to_string(), future.clone());
m.insert("option".to_string(), option.clone());
m.insert("active".to_string(), Value::Bool(is_equal(&status, &Value::Str("live".to_string()))));
m.insert("contract".to_string(), contract.clone());
m.insert("linear".to_string(), ternary(is_true(&contract), quoteEqualSettle.clone(), Value::Null));
m.insert("inverse".to_string(), ternary(is_true(&contract), baseEqualSettle.clone(), Value::Null));
m.insert("contractSize".to_string(), ternary(is_true(&contract), __ws_arg_0, Value::Null));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), __ws_arg_1);
m.insert("strike".to_string(), __ws_arg_2);
m.insert("optionType".to_string(), optionType.clone());
m.insert("created".to_string(), __ws_arg_3);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), __ws_arg_4);
m.insert("price".to_string(), __ws_arg_5);
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(), __ws_arg_6);
m.insert("max".to_string(), __ws_arg_7);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), __ws_arg_8);
m.insert("max".to_string(), __ws_arg_9);
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(), ternary(is_true(&contract), Value::Null, maxSpotCost.clone()));
m
}));
m
}));
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
pub async fn fetch_markets_by_type(&mut self, mut type_var: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), self.convert_to_instrument_type(type_var.clone()));
m
});
if is_equal(&type_var, &Value::Str("option".to_string())) {
let mut optionsUnderlying: Value = self.safe_list_k(self.options.clone(), "defaultUnderlying", &[Value::List(vec![Value::Str("BTC-USD".to_string()), Value::Str("ETH-USD".to_string())])]);
let mut promises: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_986: bool = true;
while { if !__for_first_986 { i = add(&i, &Value::Int(1)); } __for_first_986 = false; is_less_than(&i, &get_array_length(&optionsUnderlying)) } {
let mut underlying: Value = get_value(&optionsUnderlying, &i);
let mut underlying: Value = get_value(&optionsUnderlying, &i);
add_element_to_object(&mut request, &Value::Str("uly".to_string()), underlying.clone());
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
append_to_array(&mut promises, self.public_get_public_instruments(&[__ws_arg_10]).await);
}
}
let mut promisesResult: Value = promise_all(&promises).await;
let mut markets: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_987: bool = true;
while { if !__for_first_987 { i = add(&i, &Value::Int(1)); } __for_first_987 = false; is_less_than(&i, &get_array_length(&promisesResult)) } {
let mut res: Value = self.safe_dict(promisesResult.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut options: Value = self.safe_list_k(res.clone(), "data", &[Value::List(vec![])]);
markets = self.array_concat(markets.clone(), options.clone());
}
}
return self.parse_markets(markets.clone());
}
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_instruments(&[__ws_arg_11]).await;
//
// spot, future, swap, option
//
// {
// "code": "0",
// "data": [
// {
// "alias": "", // this_week, next_week, quarter, next_quarter
// "baseCcy": "BTC",
// "category": "1",
// "ctMult": "",
// "ctType": "", // inverse, linear
// "ctVal": "",
// "ctValCcy": "",
// "expTime": "",
// "instId": "BTC-USDT", // BTC-USD-210521, CSPR-USDT-SWAP, BTC-USD-210517-44000-C
// "instType": "SPOT", // SPOT, FUTURES, SWAP, OPTION
// "lever": "10",
// "listTime": "1548133413000",
// "lotSz": "0.00000001",
// "minSz": "0.00001",
// "optType": "",
// "quoteCcy": "USDT",
// "settleCcy": "",
// "state": "live",
// "stk": "",
// "tickSz": "0.1",
// "uly": ""
// }
// ],
// "msg": ""
// }
//
let mut dataResponse: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut marketsWithoutTest: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_988: bool = true;
while { if !__for_first_988 { i = add(&i, &Value::Int(1)); } __for_first_988 = false; is_less_than(&i, &get_array_length(&dataResponse)) } {
let mut data: Value = get_value(&dataResponse, &i);
let mut data: Value = get_value(&dataResponse, &i);
let mut instId: Value = self.safe_string_k(data.clone(), "instId", &[Value::Str("".to_string())]);
if is_equal(&instId, &Value::Str("".to_string())) {
continue;
}
if is_true(&self.isSandboxModeEnabled) {
let mut instFamily: Value = self.safe_string_k(data.clone(), "instFamily", &[Value::Str("".to_string())]);
if is_true(&Value::Bool(starts_with(&instFamily, &Value::Str("TEST".to_string())))) {
continue;
}
}
append_to_array(&mut marketsWithoutTest, data.clone());
}
}
return self.parse_markets(marketsWithoutTest.clone());
Value::Null
}
/*
* @method
* @name okx#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-get-currencies
* @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
}));
// this endpoint requires authentication
// while fetchCurrencies is a public API method by design
// therefore we check the keys here
// and fallback to generating the currencies from the markets
let mut isSandboxMode: Value = self.safe_bool_k(self.options.clone(), "sandboxMode", &[Value::Bool(false)]);
if !is_true(&self.check_required_credentials(&[Value::Bool(false)])) || is_true(&(is_equal(&isSandboxMode, &Value::Bool(true)))) {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
}
//
// has['fetchCurrencies'] is currently set to true, but an unauthorized request returns
//
// {"msg":"Request header “OK_ACCESS_KEY“ can't be empty.","code":"50103"}
//
let mut response: Value = self.private_get_asset_currencies(&[params.clone()]).await;
//
// {
// "code": "0",
// "data": [
// {
// "canDep": true,
// "canInternal": false,
// "canWd": true,
// "ccy": "USDT",
// "chain": "USDT-TRC20",
// "logoLink": "https://static.coinall.ltd/cdn/assets/imgs/221/5F74EB20302D7761.png",
// "mainNet": false,
// "maxFee": "1.6",
// "maxWd": "8852150",
// "minFee": "0.8",
// "minWd": "2",
// "name": "Tether",
// "usedWdQuota": "0",
// "wdQuota": "500",
// "wdTickSz": "3"
// },
// {
// "canDep": true,
// "canInternal": false,
// "canWd": true,
// "ccy": "USDT",
// "chain": "USDT-ERC20",
// "logoLink": "https://static.coinall.ltd/cdn/assets/imgs/221/5F74EB20302D7761.png",
// "mainNet": false,
// "maxFee": "16",
// "maxWd": "8852150",
// "minFee": "8",
// "minWd": "2",
// "name": "Tether",
// "usedWdQuota": "0",
// "wdQuota": "500",
// "wdTickSz": "3"
// },
// ...
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut dataByCurrencyId: Value = self.group_by(data.clone(), Value::Str("ccy".to_string()), &[]);
let mut currencies: Value = object_values(&dataByCurrencyId);
return self.parse_currencies(currencies.clone());
Value::Null
}
pub fn parse_currency(&self, mut currency: Value) -> Value {
let mut chains: Value = currency.clone();
// currencies are grouped by chain entries, so there is at least one entry
let mut firstChain: Value = self.safe_dict(chains.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut currencyId: Value = self.safe_string_k(firstChain.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut networks: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut type_var: Value = Value::Str("crypto".to_string());
let mut chainsLength: Value = get_array_length(&chains);
{
let mut j: Value = Value::Int(0);
let mut __for_first_989: bool = true;
while { if !__for_first_989 { j = add(&j, &Value::Int(1)); } __for_first_989 = false; is_less_than(&j, &chainsLength) } {
let mut chain: Value = get_value(&chains, &j);
let mut chain: Value = get_value(&chains, &j);
// allow empty string for rare fiat-currencies, e.g. TRY
let mut networkId: Value = self.safe_string_k(chain.clone(), "chain", &[Value::Str("".to_string())]); // USDT-BEP20, USDT-Avalance-C, etc
if is_equal(&networkId, &Value::Str("".to_string())) {
// only happens for fiat 'TRY' currency
type_var = Value::Str("fiat".to_string());
}
let mut idParts: Value = split(&networkId, &Value::Str("-".to_string()));
let mut parts: Value = self.array_slice(idParts.clone(), Value::Int(1), &[]);
let mut chainPart: Value = join(&parts, &Value::Str("-".to_string()));
let mut networkCode: Value = self.network_id_to_code(&[chainPart.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("id".to_string(), networkId.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), self.safe_bool_k(chain.clone(), "canDep", &[]));
m.insert("withdraw".to_string(), self.safe_bool_k(chain.clone(), "canWd", &[]));
m.insert("fee".to_string(), self.safe_number_k(chain.clone(), "fee", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[self.safe_string_k(chain.clone(), "wdTickSz", &[])]), &[]));
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(), "minWd", &[]));
m.insert("max".to_string(), self.safe_number_k(chain.clone(), "maxWd", &[]));
m
}));
m
}));
m.insert("info".to_string(), chain.clone());
m
}));
}
}
}
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), chains.clone());
m.insert("code".to_string(), code.clone());
m.insert("id".to_string(), currencyId.clone());
m.insert("name".to_string(), self.safe_string_k(firstChain.clone(), "name", &[]));
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
}));
m.insert("type".to_string(), type_var.clone());
m.insert("networks".to_string(), networks.clone());
m
}));
Value::Null
}
/*
* @method
* @name okx#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-order-book
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-full-order-book
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.method] 'publicGetMarketBooksFull' or 'publicGetMarketBooks' default is 'publicGetMarketBooks'
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut method: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOrderBook".to_string()), Value::Str("method".to_string()), &[Value::Str("publicGetMarketBooks".to_string())]); method = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&method, &Value::Str("publicGetMarketBooksFull".to_string())) && is_equal(&limit, &Value::Null) {
limit = Value::Int(5000);
}
limit = ternary(is_true(&(is_equal(&limit, &Value::Null))), Value::Int(100), limit.clone());
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("sz".to_string()), limit.clone()); // max 400
}
let mut response: Value = Value::Null;
if is_true(&(is_equal(&method, &Value::Str("publicGetMarketBooksFull".to_string())))) || is_true(&(is_greater_than(&limit, &Value::Int(400)))) {
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_books_full(&[__ws_arg_12]).await;
} else {
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_books(&[__ws_arg_13]).await;
}
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "asks": [
// ["0.07228","4.211619","0","2"], // price, amount, liquidated orders, total open orders
// ["0.0723","299.880364","0","2"],
// ["0.07231","3.72832","0","1"],
// ],
// "bids": [
// ["0.07221","18.5","0","1"],
// ["0.0722","18.5","0","1"],
// ["0.07219","0.505407","0","1"],
// ],
// "ts": "1621438475342"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(first.clone(), "ts", &[]);
return self.parse_order_book(first.clone(), symbol.clone(), &[timestamp.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "instType": "SPOT", // SPOT, SWAP, etc
// "instId": "ETH-BTC", // BTC-USDT, BTC-USDT-SWAP, etc..
// "last": "0.07319",
// "lastSz": "0.044378", // base size for spot, or contracts amount for derivatives
// "askPx": "0.07322",
// "askSz": "4.2",
// "bidPx": "0.0732",
// "bidSz": "6.050058",
// "open24h": "0.07801",
// "high24h": "0.07975",
// "low24h": "0.06019",
// "volCcy24h": "11788.887619", // note, for derivatives this is base-amount
// "vol24h": "167493.829229",
// "ts": "1621440583784",
// "sodUtc0": "0.07872",
// "sodUtc8": "0.07345"
// }
//
// {
// instId: 'LTC-USDT',
// idxPx: '65.74',
// open24h: '65.37',
// high24h: '66.15',
// low24h: '64.97',
// sodUtc0: '65.68',
// sodUtc8: '65.54',
// ts: '1728467346900'
// },
//
let mut instType: Value = self.safe_string_k(ticker.clone(), "instType", &[]);
let mut marketType: Value = Value::Null;
if !is_equal(&instType, &Value::Null) {
marketType = ternary(is_true(&(is_equal(&instType, &Value::Str("SPOT".to_string())))), Value::Str("spot".to_string()), Value::Str("swap".to_string()));
}
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "ts", &[]);
let mut marketId: Value = self.safe_string_k(ticker.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("-".to_string()), marketType.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut last: Value = self.safe_string_k(ticker.clone(), "last", &[]);
let mut open: Value = self.safe_string_k(ticker.clone(), "open24h", &[]);
let mut spot: Value = self.safe_bool_k(market.clone(), "spot", &[Value::Bool(false)]);
let mut quoteVolume: Value = ternary(is_true(&(is_equal(&spot, &Value::Bool(true)))), self.safe_string_k(ticker.clone(), "volCcy24h", &[]), Value::Null);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "vol24h", &[]);
let mut high: Value = self.safe_string_k(ticker.clone(), "high24h", &[]);
let mut low: Value = self.safe_string_k(ticker.clone(), "low24h", &[]);
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(), self.safe_string_k(ticker.clone(), "bidPx", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bidSz", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "askPx", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "askSz", &[]));
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(), Value::Null);
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(), "markPx", &[]));
m.insert("indexPrice".to_string(), self.safe_string_k(ticker.clone(), "idxPx", &[]));
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-ticker
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_market_ticker(&[__ws_arg_14]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "instType": "SPOT",
// "instId": "ETH-BTC",
// "last": "0.07319",
// "lastSz": "0.044378",
// "askPx": "0.07322",
// "askSz": "4.2",
// "bidPx": "0.0732",
// "bidSz": "6.050058",
// "open24h": "0.07801",
// "high24h": "0.07975",
// "low24h": "0.06019",
// "volCcy24h": "11788.887619",
// "vol24h": "167493.829229",
// "ts": "1621440583784",
// "sodUtc0": "0.07872",
// "sodUtc8": "0.07345"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_ticker(first.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchTickers
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-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
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTickers".to_string()), &[market.clone(), params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), self.convert_to_instrument_type(marketType.clone()));
m
});
if is_equal(&marketType, &Value::Str("option".to_string())) {
let mut defaultUnderlying: Value = self.safe_string_k(self.options.clone(), "defaultUnderlying", &[Value::Str("BTC-USD".to_string())]);
let mut currencyId: Value = self.safe_string2(params.clone(), Value::Str("uly".to_string()), Value::Str("marketId".to_string()), &[defaultUnderlying.clone()]);
if is_equal(¤cyId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchTickers() requires an underlying uly or marketId parameter for options markets".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("uly".to_string()), currencyId.clone());
}
}
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_market_tickers(&[__ws_arg_15]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "instType": "SPOT",
// "instId": "BCD-BTC",
// "last": "0.0000769",
// "lastSz": "5.4788",
// "askPx": "0.0000777",
// "askSz": "3.2197",
// "bidPx": "0.0000757",
// "bidSz": "4.7509",
// "open24h": "0.0000885",
// "high24h": "0.0000917",
// "low24h": "0.0000596",
// "volCcy24h": "9.2877",
// "vol24h": "124824.1985",
// "ts": "1621441741434",
// "sodUtc0": "0.0000905",
// "sodUtc8": "0.0000729"
// },
// ]
// }
//
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_tickers(tickers.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchMarkPrice
* @description fetches mark price for the market
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_mark_price(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_mark_price(&[__ws_arg_16]).await;
//
// {
// "code": "0",
// "data": [
// {
// "instId": "ETH-USDT",
// "instType": "MARGIN",
// "markPx": "2403.98",
// "ts": "1728578500703"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_ticker(self.safe_dict(data.clone(), Value::Int(0), &[]), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchMarkPrices
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-mark-price
* @param {string[]} [symbols] unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_mark_prices(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone()]);
let mut market: Value = self.get_market_from_symbols(&[symbols.clone()]);
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMarkPrices".to_string()), &[market.clone(), params.clone(), Value::Str("swap".to_string())]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), self.convert_to_instrument_type(marketType.clone()));
m
});
if is_equal(&marketType, &Value::Str("option".to_string())) {
let mut defaultUnderlying: Value = self.safe_string_k(self.options.clone(), "defaultUnderlying", &[Value::Str("BTC-USD".to_string())]);
let mut currencyId: Value = self.safe_string2(params.clone(), Value::Str("uly".to_string()), Value::Str("marketId".to_string()), &[defaultUnderlying.clone()]);
if is_equal(¤cyId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMarkPrices() requires an underlying uly or marketId parameter for options markets".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("uly".to_string()), currencyId.clone());
}
}
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_mark_price(&[__ws_arg_17]).await;
let mut tickers: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_tickers(tickers.clone(), &[symbols.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 fetchTrades
//
// {
// "instId": "ETH-BTC",
// "side": "sell",
// "sz": "0.119501",
// "px": "0.07065",
// "tradeId": "15826757",
// "ts": "1621446178316"
// }
//
// option: fetchTrades
//
// {
// "fillVol": "0.46387625976562497",
// "fwdPx": "26299.754935451125",
// "indexPx": "26309.7",
// "instFamily": "BTC-USD",
// "instId": "BTC-USD-230526-26000-C",
// "markPx": "0.042386283557554236",
// "optType": "C",
// "px": "0.0415",
// "side": "sell",
// "sz": "90",
// "tradeId": "112",
// "ts": "1683907480154"
// }
//
// private fetchMyTrades
//
// {
// "side": "buy",
// "fillSz": "0.007533",
// "fillPx": "2654.98",
// "fee": "-0.000007533",
// "ordId": "317321390244397056",
// "instType": "SPOT",
// "instId": "ETH-USDT",
// "clOrdId": "",
// "posSide": "net",
// "billId": "317321390265368576",
// "tag": "0",
// "execType": "T",
// "tradeId": "107601752",
// "feeCcy": "ETH",
// "ts": "1621927314985"
// }
//
let mut id: Value = self.safe_string_k(trade.clone(), "tradeId", &[]);
let mut marketId: Value = self.safe_string_k(trade.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Str("-".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "ts", &[]);
let mut price: Value = self.safe_string2(trade.clone(), Value::Str("fillPx".to_string()), Value::Str("px".to_string()), &[]);
let mut amount: Value = self.safe_string2(trade.clone(), Value::Str("fillSz".to_string()), Value::Str("sz".to_string()), &[]);
let mut side: Value = self.safe_string_k(trade.clone(), "side", &[]);
let mut orderId: Value = self.safe_string_k(trade.clone(), "ordId", &[]);
let mut feeCostString: Value = self.safe_string_k(trade.clone(), "fee", &[]);
let mut fee: Value = Value::Null;
if !is_equal(&feeCostString, &Value::Null) {
let mut feeCostSigned: Value = crate::precise::Precise::stringNeg(&feeCostString);
let mut feeCurrencyId: Value = self.safe_string_k(trade.clone(), "feeCcy", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCostSigned.clone());
m.insert("currency".to_string(), feeCurrencyCode.clone());
m
});
}
let mut takerOrMaker: Value = self.safe_string_k(trade.clone(), "execType", &[]);
if is_equal(&takerOrMaker, &Value::Str("T".to_string())) {
takerOrMaker = Value::Str("taker".to_string());
} else if is_equal(&takerOrMaker, &Value::Str("M".to_string())) {
takerOrMaker = Value::Str("maker".to_string());
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
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("id".to_string(), id.clone());
m.insert("order".to_string(), orderId.clone());
m.insert("type".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-trades
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-trades-history
* @see https://www.okx.com/docs-v5/en/#rest-api-public-data-get-option-trades
* @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.method] 'publicGetMarketTrades' or 'publicGetMarketHistoryTrades' default is 'publicGetMarketTrades'
* @param {boolean} [params.paginate] *only applies to publicGetMarketHistoryTrades* default false, when true will automatically paginate by calling this endpoint multiple times
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTrades".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("fetchTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), Value::Str("tradeId".to_string()), Value::Str("after".to_string()), Value::Null, Value::Int(100)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)) {
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_public_option_trades(&[__ws_arg_18]).await;
} else {
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 100
}
let mut method: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTrades".to_string()), Value::Str("method".to_string()), &[Value::Str("publicGetMarketTrades".to_string())]); method = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&method, &Value::Str("publicGetMarketTrades".to_string())) {
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_trades(&[__ws_arg_19]).await;
} else if is_equal(&method, &Value::Str("publicGetMarketHistoryTrades".to_string())) {
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_history_trades(&[__ws_arg_20]).await;
}
}
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {"instId":"ETH-BTC","side":"sell","sz":"0.119501","px":"0.07065","tradeId":"15826757","ts":"1621446178316"},
// {"instId":"ETH-BTC","side":"sell","sz":"0.03","px":"0.07068","tradeId":"15826756","ts":"1621446178066"},
// {"instId":"ETH-BTC","side":"buy","sz":"0.507","px":"0.07069","tradeId":"15826755","ts":"1621446175085"},
// ]
// }
//
// option
//
// {
// "code": "0",
// "data": [
// {
// "fillVol": "0.46387625976562497",
// "fwdPx": "26299.754935451125",
// "indexPx": "26309.7",
// "instFamily": "BTC-USD",
// "instId": "BTC-USD-230526-26000-C",
// "markPx": "0.042386283557554236",
// "optType": "C",
// "px": "0.0415",
// "side": "sell",
// "sz": "90",
// "tradeId": "112",
// "ts": "1683907480154"
// },
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// "1678928760000", // timestamp
// "24341.4", // open
// "24344", // high
// "24313.2", // low
// "24323", // close
// "628", // contract volume
// "2.5819", // base volume
// "62800", // quote volume
// "0" // candlestick state
// ]
//
let mut res: Value = self.handle_market_type_and_params(Value::Str("fetchOHLCV".to_string()), &[market.clone(), Value::Null]);
let mut type_var: Value = get_value(&res, &Value::Int(0));
let mut volumeIndex: Value = ternary(is_true(&(is_equal(&type_var, &Value::Str("spot".to_string())))), Value::Int(5), Value::Int(6));
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 okx#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-candlesticks
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-candlesticks-history
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-mark-price-candlesticks-history
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks
* @see https://www.okx.com/docs-v5/en/#rest-api-market-data-get-index-candlesticks-history
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-candlesticks-history
* @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 {string} [params.price] "mark" or "index" for mark price and index price candles
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @param {string} [params.type] "Candles" or "HistoryCandles", default is "Candles" for recent candles, "HistoryCandles" for older candles
* @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(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
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(200)]).await;
}
let mut priceType: Value = self.safe_string_k(params.clone(), "price", &[]);
let mut isMarkOrIndex: Value = self.in_array(priceType.clone(), Value::List(vec![Value::Str("mark".to_string()), Value::Str("index".to_string())]));
params = self.omit(params.clone(), Value::Str("price".to_string()), &[]);
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchOHLCV", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timezone: Value = self.safe_string_k(options.clone(), "timezone", &[Value::Str("UTC".to_string())]);
let mut limitIsUndefined: bool = is_equal(&limit, &Value::Null);
if is_equal(&limit, &Value::Null) {
limit = Value::Int(100); // default 100, max 300
} else {
let mut maxLimit: Value = ternary(is_true(&isMarkOrIndex), Value::Int(100), Value::Int(300)); // default 300, only 100 if 'mark' or 'index'
limit = crate::runtime::Math::min(&limit, &maxLimit);
}
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut bar: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
if is_true(&(is_equal(&timezone, &Value::Str("UTC".to_string())))) && is_true(&(is_greater_than_or_equal(&duration, &Value::Int(21600)))) {
bar = add(&bar, &to_lower(&timezone));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("bar".to_string(), bar.clone());
m.insert("limit".to_string(), limit.clone());
m
});
let mut defaultType: Value = Value::Str("Candles".to_string());
if !is_equal(&since, &Value::Null) {
let mut now: Value = self.milliseconds();
let mut durationInMilliseconds: Value = multiply(&duration, &Value::Int(1000));
// switch to history candles if since is past the cutoff for current candles
let mut historyBorder: Value = subtract(&now, &(multiply(&(subtract(&Value::Int(1440), &Value::Int(1))), &durationInMilliseconds)));
if is_less_than(&since, &historyBorder) {
defaultType = Value::Str("HistoryCandles".to_string());
let mut maxLimit: Value = ternary(is_true(&isMarkOrIndex), Value::Int(100), Value::Int(300));
limit = crate::runtime::Math::min(&limit, &maxLimit);
}
let mut startTime: Value = crate::runtime::Math::max(&subtract(&since, &Value::Int(1)), &Value::Int(0));
add_element_to_object(&mut request, &Value::Str("before".to_string()), startTime.clone());
add_element_to_object(&mut request, &Value::Str("after".to_string()), self.sum(&[since.clone(), multiply(&durationInMilliseconds, &limit)]));
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("after".to_string()), until.clone());
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
}
defaultType = self.safe_string_k(options.clone(), "type", &[defaultType.clone()]); // Candles or HistoryCandles
let mut type_var: Value = self.safe_string_k(params.clone(), "type", &[defaultType.clone()]);
params = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
let mut isHistoryCandles: bool = is_equal(&type_var, &Value::Str("HistoryCandles".to_string()));
let mut response: Value = Value::Null;
if is_equal(&priceType, &Value::Str("mark".to_string())) {
if is_true(&isHistoryCandles) {
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_history_mark_price_candles(&[__ws_arg_21]).await;
} else {
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_mark_price_candles(&[__ws_arg_22]).await;
}
} else if is_equal(&priceType, &Value::Str("index".to_string())) {
add_element_to_object(&mut request, &Value::Str("instId".to_string()), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("instFamily".to_string()))); // okx index candles require instFamily instead of instId
if is_true(&isHistoryCandles) {
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_history_index_candles(&[__ws_arg_23]).await;
} else {
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_index_candles(&[__ws_arg_24]).await;
}
} else {
if is_true(&isHistoryCandles) {
if is_true(&limitIsUndefined) && is_true(&(is_equal(&limit, &Value::Int(100)))) {
limit = Value::Int(300);
add_element_to_object(&mut request, &Value::Str("limit".to_string()), Value::Int(300)); // reassign to 300, but this whole logic needs to be simplified...
}
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_history_candles(&[__ws_arg_25]).await;
} else {
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_market_candles(&[__ws_arg_26]).await;
}
}
//
// {
// "code": "0",
// "msg": "",
// "data": [
// ["1678928760000","24341.4","24344","24313.2","24323","628","2.5819","62800","0"],
// ["1678928700000","24324.1","24347.6","24321.7","24341.4","2565","10.5401","256500","1"],
// ["1678928640000","24300.2","24324.1","24288","24324.1","3304","13.5937","330400","1"],
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate-history
* @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 {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_deterministic(Value::Str("fetchFundingRateHistory".to_string()), &[symbol.clone(), since.clone(), limit.clone(), Value::Str("8h".to_string()), params.clone(), Value::Int(100)]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), crate::runtime::Math::max(&subtract(&since, &Value::Int(1)), &Value::Int(0)));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_funding_rate_history(&[__ws_arg_27]).await;
//
// {
// "code":"0",
// "msg":"",
// "data":[
// {
// "instType":"SWAP",
// "instId":"BTC-USDT-SWAP",
// "fundingRate":"0.018",
// "realizedRate":"0.017",
// "fundingTime":"1597026383085"
// },
// {
// "instType":"SWAP",
// "instId":"BTC-USDT-SWAP",
// "fundingRate":"0.018",
// "realizedRate":"0.017",
// "fundingTime":"1597026383085"
// }
// ]
// }
//
let mut rates: Value = Value::List(vec![]);
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_990: bool = true;
while { if !__for_first_990 { i = add(&i, &Value::Int(1)); } __for_first_990 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rate: Value = get_value(&data, &i);
let mut rate: Value = get_value(&data, &i);
let mut timestamp: Value = self.safe_integer_k(rate.clone(), "fundingTime", &[]);
append_to_array(&mut rates, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), rate.clone());
m.insert("symbol".to_string(), self.safe_symbol(self.safe_string_k(rate.clone(), "instId", &[]), &[]));
m.insert("fundingRate".to_string(), self.safe_number_k(rate.clone(), "realizedRate", &[]));
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(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_balance_by_type(&self, mut type_var: Value, mut response: Value) -> Value {
if is_equal(&type_var, &Value::Str("funding".to_string())) {
return self.parse_funding_balance(response.clone());
} else {
return self.parse_trading_balance(response.clone());
}
Value::Null
}
pub fn parse_trading_balance(&self, mut response: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(first.clone(), "uTime", &[]);
let mut details: Value = self.safe_list_k(first.clone(), "details", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_991: bool = true;
while { if !__for_first_991 { i = add(&i, &Value::Int(1)); } __for_first_991 = false; is_less_than(&i, &get_array_length(&details)) } {
let mut balance: Value = get_value(&details, &i);
let mut balance: Value = get_value(&details, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
// it may be incorrect to use total, free and used for swap accounts
let mut eq: Value = self.safe_string_k(balance.clone(), "eq", &[]);
let mut availEq: Value = self.safe_string_k(balance.clone(), "availEq", &[]);
add_element_to_object(&mut account, &Value::Str("total".to_string()), eq.clone());
if is_equal(&availEq, &Value::Null) {
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "availBal", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "frozenBal", &[]));
} else {
add_element_to_object(&mut account, &Value::Str("free".to_string()), availEq.clone());
}
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
add_element_to_object(&mut result, &Value::Str("timestamp".to_string()), timestamp.clone());
add_element_to_object(&mut result, &Value::Str("datetime".to_string()), self.iso8601(timestamp.clone()));
return self.safe_balance(result.clone());
Value::Null
}
pub fn parse_funding_balance(&self, mut response: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_992: bool = true;
while { if !__for_first_992 { i = add(&i, &Value::Int(1)); } __for_first_992 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut balance: Value = get_value(&data, &i);
let mut balance: Value = get_value(&data, &i);
let mut currencyId: Value = self.safe_string_k(balance.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut account: Value = self.account();
// it may be incorrect to use total, free and used for swap accounts
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string_k(balance.clone(), "bal", &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string_k(balance.clone(), "availBal", &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string_k(balance.clone(), "frozenBal", &[]));
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut result, &code, account.clone());
}
}
}
return self.safe_balance(result.clone());
Value::Null
}
pub fn parse_trading_fee(&self, mut fee: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), fee.clone());
m.insert("symbol".to_string(), self.safe_symbol(Value::Null, &[market.clone()]));
m.insert("maker".to_string(), self.parse_number(crate::precise::Precise::stringNeg(&self.safe_string2(fee.clone(), Value::Str("maker".to_string()), Value::Str("makerU".to_string()), &[])), &[]));
m.insert("taker".to_string(), self.parse_number(crate::precise::Precise::stringNeg(&self.safe_string2(fee.clone(), Value::Str("taker".to_string()), Value::Str("takerU".to_string()), &[])), &[]));
m.insert("percentage".to_string(), Value::Null);
m.insert("tierBased".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name okx#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-fee-rates
* @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("instType".to_string(), self.convert_to_instrument_type(get_value(&market, &Value::Str("type".to_string()))));
m
});
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
} else if is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("option".to_string())), &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("uly".to_string()), add(&add(&get_value(&market, &Value::Str("baseId".to_string())), &Value::Str("-".to_string())), &get_value(&market, &Value::Str("quoteId".to_string()))));
} else {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchTradingFee() supports spot, swap, future or option markets only".to_string()))));
}
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_account_trade_fee(&[__ws_arg_28]).await;
//
// {
// "code": "0",
// "data": [
// {
// "category": "1",
// "delivery": "",
// "exercise": "",
// "instType": "SPOT",
// "level": "Lv1",
// "maker": "-0.0008",
// "taker": "-0.001",
// "ts": "1639043138472"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_trading_fee(first.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-balance
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] wallet type, ['funding' or 'trading'] default is 'trading'
* @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 marketTypequeryVariable = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone()]);
let mut marketType: Value = get_value(&marketTypequeryVariable, &Value::Int(0));
let mut query: Value = get_value(&marketTypequeryVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("funding".to_string())) {
let __ws_arg_29 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_asset_balances(&[__ws_arg_29]).await;
} else {
let __ws_arg_30 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_account_balance(&[__ws_arg_30]).await;
}
return self.parse_balance_by_type(marketType.clone(), response.clone());
Value::Null
}
/*
* @method
* @name okx#createMarketBuyOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-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 markets only".to_string()))));
}
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(false));
m.insert("tgtCcy".to_string(), Value::Str("quote_ccy".to_string()));
m
});
let __ws_arg_31 = self.extend(req.clone(), &[params.clone()]);
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("buy".to_string()), cost.clone(), &[Value::Null, __ws_arg_31]).await;
Value::Null
}
/*
* @method
* @name okx#createMarketSellOrderWithCost
* @description create a market buy order by providing the symbol and cost
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-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 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 markets only".to_string()))));
}
let mut req: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("createMarketBuyOrderRequiresPrice".to_string(), Value::Bool(false));
m.insert("tgtCcy".to_string(), Value::Str("quote_ccy".to_string()));
m
});
let __ws_arg_32 = self.extend(req.clone(), &[params.clone()]);
return self.create_order(symbol.clone(), Value::Str("market".to_string()), Value::Str("sell".to_string()), cost.clone(), &[Value::Null, __ws_arg_32]).await;
Value::Null
}
pub fn create_order_request(&self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a type argument".to_string()))));
}
if is_equal(&side, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" requires a side argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut takeProfitPrice: Value = self.safe_value2(params.clone(), Value::Str("takeProfitPrice".to_string()), Value::Str("tpTriggerPx".to_string()), &[]);
let mut stopLossPrice: Value = self.safe_value2(params.clone(), Value::Str("stopLossPrice".to_string()), Value::Str("slTriggerPx".to_string()), &[]);
let mut conditional: bool = is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("conditional".to_string()))));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("side".to_string(), side.clone());
m.insert("ordType".to_string(), type_var.clone());
m
});
let mut isConditionalOrOCO: bool = is_true(&conditional) || is_true(&(is_equal(&type_var, &Value::Str("oco".to_string()))));
let mut closeFraction: Value = self.safe_string_k(params.clone(), "closeFraction", &[]);
let mut shouldOmitSize: bool = is_true(&isConditionalOrOCO) && !is_equal(&closeFraction, &Value::Null);
if !is_true(&shouldOmitSize) {
add_element_to_object(&mut request, &Value::Str("sz".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
let mut spot: Value = get_value(&market, &Value::Str("spot".to_string()));
let mut contract: Value = get_value(&market, &Value::Str("contract".to_string()));
let mut triggerPrice: Value = self.safe_value_n(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerPx".to_string())]), &[]);
let mut timeInForce: Value = self.safe_string_k(params.clone(), "timeInForce", &[Value::Str("GTC".to_string())]);
// const takeProfitPrice = this.safeValue2 (params, 'takeProfitPrice', 'tpTriggerPx');
let mut tpOrdPx: Value = self.safe_number_k(params.clone(), "tpOrdPx", &[price.clone()]);
let mut tpTriggerPxType: Value = self.safe_string_k(params.clone(), "tpTriggerPxType", &[Value::Str("last".to_string())]);
// const stopLossPrice = this.safeValue2 (params, 'stopLossPrice', 'slTriggerPx');
let mut slOrdPx: Value = self.safe_number_k(params.clone(), "slOrdPx", &[price.clone()]);
let mut slTriggerPxType: Value = self.safe_string_k(params.clone(), "slTriggerPxType", &[Value::Str("last".to_string())]);
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut stopLoss: Value = self.safe_value_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_value_k(params.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
let mut trailingPercent: Value = self.safe_string2(params.clone(), Value::Str("trailingPercent".to_string()), Value::Str("callbackRatio".to_string()), &[]);
let mut isTrailingPercentOrder: bool = !is_equal(&trailingPercent, &Value::Null);
let mut trailingPrice: Value = self.safe_string2(params.clone(), Value::Str("trailingPrice".to_string()), Value::Str("callbackSpread".to_string()), &[]);
let mut isTrailingPriceOrder: bool = !is_equal(&trailingPrice, &Value::Null);
let mut trigger: bool = is_true(&(!is_equal(&triggerPrice, &Value::Null))) || is_true(&(is_equal(&type_var, &Value::Str("trigger".to_string()))));
let mut isReduceOnly: bool = is_true(&(is_equal(&self.safe_bool_k(params.clone(), "reduceOnly", &[Value::Bool(false)]), &Value::Bool(true)))) || is_true(&(!is_equal(&closeFraction, &Value::Null)));
let mut defaultMarginMode: Value = self.safe_string2(self.options.clone(), Value::Str("defaultMarginMode".to_string()), Value::Str("marginMode".to_string()), &[Value::Str("cross".to_string())]);
let mut marginMode: Value = self.safe_string2(params.clone(), Value::Str("marginMode".to_string()), Value::Str("tdMode".to_string()), &[]); // cross or isolated, tdMode not omitted so as to be extended into the request
let mut margin: Value = Value::Bool(false);
if is_true(&(!is_equal(&marginMode, &Value::Null))) && is_true(&(!is_equal(&marginMode, &Value::Str("cash".to_string())))) {
margin = Value::Bool(true);
} else {
marginMode = defaultMarginMode.clone();
margin = self.safe_bool_k(params.clone(), "margin", &[Value::Bool(false)]);
}
if is_equal(&spot, &Value::Bool(true)) {
if is_equal(&margin, &Value::Bool(true)) {
let mut defaultCurrency: Value = ternary(is_true(&(is_equal(&side, &Value::Str("buy".to_string())))), get_value(&market, &Value::Str("quote".to_string())), get_value(&market, &Value::Str("base".to_string())));
let mut currency: Value = self.safe_string_k(params.clone(), "ccy", &[defaultCurrency.clone()]);
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), self.safe_currency_code(currency.clone(), &[]));
}
let mut tradeMode: Value = ternary(is_true(&(is_equal(&margin, &Value::Bool(true)))), marginMode.clone(), Value::Str("cash".to_string()));
add_element_to_object(&mut request, &Value::Str("tdMode".to_string()), tradeMode.clone());
} else if is_equal(&contract, &Value::Bool(true)) {
if is_true(&(is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) || is_true(&(is_equal(&get_value(&market, &Value::Str("future".to_string())), &Value::Bool(true)))) {
let mut positionSide: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("positionSide".to_string()), &[]); positionSide = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&positionSide, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("posSide".to_string()), positionSide.clone());
} else {
let mut hedged: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("hedged".to_string()), &[]); hedged = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&hedged, &Value::Bool(true)) {
let mut isBuy: bool = is_equal(&side, &Value::Str("buy".to_string()));
let mut isProtective: bool = is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) || is_true(&(!is_equal(&stopLossPrice, &Value::Null))) || is_true(&isReduceOnly);
if is_true(&isProtective) {
// in case of protective orders, the posSide should be opposite of position side
// reduceOnly is emulated and not natively supported by the exchange
add_element_to_object(&mut request, &Value::Str("posSide".to_string()), ternary(is_true(&isBuy), Value::Str("short".to_string()), Value::Str("long".to_string())));
if is_true(&isReduceOnly) {
params = self.omit(params.clone(), Value::Str("reduceOnly".to_string()), &[]);
}
} else {
add_element_to_object(&mut request, &Value::Str("posSide".to_string()), ternary(is_true(&isBuy), Value::Str("long".to_string()), Value::Str("short".to_string())));
}
}
}
}
add_element_to_object(&mut request, &Value::Str("tdMode".to_string()), marginMode.clone());
}
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("market".to_string())));
let mut postOnly: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_post_only(isMarketOrder.clone(), Value::Bool(is_equal(&type_var, &Value::Str("post_only".to_string()))), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
params = self.omit(params.clone(), Value::List(vec![Value::Str("currency".to_string()), Value::Str("ccy".to_string()), Value::Str("marginMode".to_string()), Value::Str("timeInForce".to_string()), Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("slOrdPx".to_string()), Value::Str("tpOrdPx".to_string()), Value::Str("margin".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string()), Value::Str("trailingPercent".to_string())]), &[]);
let mut ioc: bool = is_true(&(is_equal(&timeInForce, &Value::Str("IOC".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("ioc".to_string()))));
let mut fok: bool = is_true(&(is_equal(&timeInForce, &Value::Str("FOK".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("fok".to_string()))));
// const conditional = (stopLossPrice !== undefined) || (takeProfitPrice !== undefined) || (type === 'conditional');
let mut marketIOC: bool = is_true(&(is_true(&isMarketOrder) && is_true(&ioc))) || is_true(&(is_equal(&type_var, &Value::Str("optimal_limit_ioc".to_string()))));
let mut defaultTgtCcy: Value = self.safe_string_k(self.options.clone(), "tgtCcy", &[Value::Str("base_ccy".to_string())]);
let mut tgtCcy: Value = self.safe_string_k(params.clone(), "tgtCcy", &[defaultTgtCcy.clone()]);
if is_true(&(!is_equal(&contract, &Value::Bool(true)))) && is_true(&(!is_equal(&margin, &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("tgtCcy".to_string()), tgtCcy.clone());
}
if is_true(&isMarketOrder) || is_true(&marketIOC) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("market".to_string()));
if is_true(&(is_equal(&spot, &Value::Bool(true)))) && is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
// spot market buy: "sz" can refer either to base currency units or to quote currency units
// see documentation: https://www.okx.com/docs-v5/en/#rest-api-trade-place-order
if is_equal(&tgtCcy, &Value::Str("quote_ccy".to_string())) {
// quote_ccy: sz refers to units of quote currency
let mut createMarketBuyOrderRequiresPrice: Value = Value::Bool(true);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("createMarketBuyOrderRequiresPrice".to_string()), &[Value::Bool(true)]); createMarketBuyOrderRequiresPrice = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut notional: Value = self.safe_number2(params.clone(), Value::Str("cost".to_string()), Value::Str("sz".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("cost".to_string()), Value::Str("sz".to_string())]), &[]);
if is_true(&createMarketBuyOrderRequiresPrice) {
if !is_equal(&price, &Value::Null) {
if is_equal(¬ional, &Value::Null) {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
let mut quoteAmount: Value = crate::precise::Precise::stringMul(&amountString, &priceString);
notional = self.parse_number(quoteAmount.clone(), &[]);
}
} else if is_equal(¬ional, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires the price argument with market buy orders to calculate total order cost (amount to spend), where cost = amount * price. Supply a price argument to createOrder() call if you want the cost to be calculated for you from price and amount, or, alternatively, add .options['createMarketBuyOrderRequiresPrice'] = false and supply the total cost value in the 'amount' argument or in the 'cost' unified extra parameter or in exchange-specific 'sz' extra parameter (the exchange-specific behaviour)".to_string()))));
}
} else {
notional = ternary(is_true(&(is_equal(¬ional, &Value::Null))), amount.clone(), notional.clone());
}
add_element_to_object(&mut request, &Value::Str("sz".to_string()), self.cost_to_precision(symbol.clone(), notional.clone()));
}
}
if is_true(&marketIOC) && is_true(&(is_equal(&contract, &Value::Bool(true)))) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("optimal_limit_ioc".to_string()));
}
} else {
if is_true(&(!is_true(&trigger))) && is_true(&(!is_true(&conditional))) {
add_element_to_object(&mut request, &Value::Str("px".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
}
if is_true(&postOnly) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("post_only".to_string()));
} else if is_true(&ioc) && !is_true(&marketIOC) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("ioc".to_string()));
} else if is_true(&fok) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("fok".to_string()));
}
if is_true(&isTrailingPercentOrder) {
let mut convertedTrailingPercent: Value = crate::precise::Precise::stringDiv(&trailingPercent, &Value::Str("100".to_string()));
add_element_to_object(&mut request, &Value::Str("callbackRatio".to_string()), convertedTrailingPercent.clone());
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("move_order_stop".to_string()));
} else if is_true(&isTrailingPriceOrder) {
add_element_to_object(&mut request, &Value::Str("callbackSpread".to_string()), trailingPrice.clone());
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("move_order_stop".to_string()));
} else if is_true(&hasStopLoss) || is_true(&hasTakeProfit) {
let mut attachAlgoOrd: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if is_true(&hasStopLoss) {
let mut stopLossTriggerPrice: Value = self.safe_value_n(stopLoss.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("slTriggerPx".to_string())]), &[]);
if is_equal(&stopLossTriggerPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires a trigger price in params[\"stopLoss\"][\"triggerPrice\"], or params[\"stopLoss\"][\"stopPrice\"], or params[\"stopLoss\"][\"slTriggerPx\"] for a stop loss order".to_string()))));
}
let mut slTriggerPx: Value = self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone());
let mut slOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut slOrder, &Value::Str("slTriggerPx".to_string()), slTriggerPx.clone());
let mut stopLossLimitPrice: Value = self.safe_value_n(stopLoss.clone(), Value::List(vec![Value::Str("price".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("slOrdPx".to_string())]), &[]);
let mut stopLossOrderType: Value = self.safe_string_k(stopLoss.clone(), "type", &[]);
if !is_equal(&stopLossOrderType, &Value::Null) {
let mut stopLossLimitOrderType: bool = is_equal(&stopLossOrderType, &Value::Str("limit".to_string()));
let mut stopLossMarketOrderType: bool = is_equal(&stopLossOrderType, &Value::Str("market".to_string()));
if is_true(&(!is_true(&stopLossLimitOrderType))) && is_true(&(!is_true(&stopLossMarketOrderType))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() params[\"stopLoss\"][\"type\"] must be either \"limit\" or \"market\"".to_string()))));
} else if is_true(&stopLossLimitOrderType) {
if is_equal(&stopLossLimitPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires a limit price in params[\"stopLoss\"][\"price\"] or params[\"stopLoss\"][\"slOrdPx\"] for a stop loss limit order".to_string()))));
} else {
add_element_to_object(&mut slOrder, &Value::Str("slOrdPx".to_string()), self.price_to_precision(symbol.clone(), stopLossLimitPrice.clone()));
}
} else if is_equal(&stopLossOrderType, &Value::Str("market".to_string())) {
add_element_to_object(&mut slOrder, &Value::Str("slOrdPx".to_string()), Value::Str("-1".to_string()));
}
} else if !is_equal(&stopLossLimitPrice, &Value::Null) {
add_element_to_object(&mut slOrder, &Value::Str("slOrdPx".to_string()), self.price_to_precision(symbol.clone(), stopLossLimitPrice.clone())); // limit sl order
} else {
add_element_to_object(&mut slOrder, &Value::Str("slOrdPx".to_string()), Value::Str("-1".to_string())); // market sl order
}
let mut stopLossTriggerPriceType: Value = self.safe_string2(stopLoss.clone(), Value::Str("triggerPriceType".to_string()), Value::Str("slTriggerPxType".to_string()), &[Value::Str("last".to_string())]);
if !is_equal(&stopLossTriggerPriceType, &Value::Null) {
if is_true(&(!is_equal(&stopLossTriggerPriceType, &Value::Str("last".to_string())))) && is_true(&(!is_equal(&stopLossTriggerPriceType, &Value::Str("index".to_string())))) && is_true(&(!is_equal(&stopLossTriggerPriceType, &Value::Str("mark".to_string())))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() stop loss trigger price type must be one of \"last\", \"index\" or \"mark\"".to_string()))));
}
add_element_to_object(&mut slOrder, &Value::Str("slTriggerPxType".to_string()), stopLossTriggerPriceType.clone());
}
attachAlgoOrd = self.extend(attachAlgoOrd.clone(), &[slOrder.clone()]);
}
if is_true(&hasTakeProfit) {
let mut takeProfitTriggerPrice: Value = self.safe_value_n(takeProfit.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("stopPrice".to_string()), Value::Str("tpTriggerPx".to_string())]), &[]);
if is_equal(&takeProfitTriggerPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires a trigger price in params[\"takeProfit\"][\"triggerPrice\"], or params[\"takeProfit\"][\"stopPrice\"], or params[\"takeProfit\"][\"tpTriggerPx\"] for a take profit order".to_string()))));
}
let mut tpOrder: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
add_element_to_object(&mut tpOrder, &Value::Str("tpTriggerPx".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
let mut takeProfitLimitPrice: Value = self.safe_value_n(takeProfit.clone(), Value::List(vec![Value::Str("price".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("tpOrdPx".to_string())]), &[]);
let mut takeProfitOrderType: Value = self.safe_string2(takeProfit.clone(), Value::Str("type".to_string()), Value::Str("tpOrdKind".to_string()), &[]);
if !is_equal(&takeProfitOrderType, &Value::Null) {
let mut takeProfitLimitOrderType: bool = is_equal(&takeProfitOrderType, &Value::Str("limit".to_string()));
let mut takeProfitMarketOrderType: bool = is_equal(&takeProfitOrderType, &Value::Str("market".to_string()));
if is_true(&(!is_true(&takeProfitLimitOrderType))) && is_true(&(!is_true(&takeProfitMarketOrderType))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() params[\"takeProfit\"][\"type\"] must be either \"limit\" or \"market\"".to_string()))));
} else if is_true(&takeProfitLimitOrderType) {
if is_equal(&takeProfitLimitPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires a limit price in params[\"takeProfit\"][\"price\"] or params[\"takeProfit\"][\"tpOrdPx\"] for a take profit limit order".to_string()))));
} else {
add_element_to_object(&mut tpOrder, &Value::Str("tpOrdKind".to_string()), takeProfitOrderType.clone());
add_element_to_object(&mut tpOrder, &Value::Str("tpOrdPx".to_string()), self.price_to_precision(symbol.clone(), takeProfitLimitPrice.clone()));
}
} else if is_equal(&takeProfitOrderType, &Value::Str("market".to_string())) {
add_element_to_object(&mut tpOrder, &Value::Str("tpOrdPx".to_string()), Value::Str("-1".to_string()));
}
} else if !is_equal(&takeProfitLimitPrice, &Value::Null) {
add_element_to_object(&mut tpOrder, &Value::Str("tpOrdKind".to_string()), Value::Str("limit".to_string()));
add_element_to_object(&mut tpOrder, &Value::Str("tpOrdPx".to_string()), self.price_to_precision(symbol.clone(), takeProfitLimitPrice.clone())); // limit tp order
} else {
add_element_to_object(&mut tpOrder, &Value::Str("tpOrdPx".to_string()), Value::Str("-1".to_string())); // market tp order
}
let mut takeProfitTriggerPriceType: Value = self.safe_string2(takeProfit.clone(), Value::Str("triggerPriceType".to_string()), Value::Str("tpTriggerPxType".to_string()), &[Value::Str("last".to_string())]);
if !is_equal(&takeProfitTriggerPriceType, &Value::Null) {
if is_true(&(!is_equal(&takeProfitTriggerPriceType, &Value::Str("last".to_string())))) && is_true(&(!is_equal(&takeProfitTriggerPriceType, &Value::Str("index".to_string())))) && is_true(&(!is_equal(&takeProfitTriggerPriceType, &Value::Str("mark".to_string())))) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() take profit trigger price type must be one of \"last\", \"index\" or \"mark\"".to_string()))));
}
add_element_to_object(&mut tpOrder, &Value::Str("tpTriggerPxType".to_string()), takeProfitTriggerPriceType.clone());
}
attachAlgoOrd = self.extend(attachAlgoOrd.clone(), &[tpOrder.clone()]);
}
let mut attachOrdKeys: Value = object_keys(&attachAlgoOrd);
let mut attachOrdLen: Value = get_array_length(&attachOrdKeys);
if is_greater_than(&attachOrdLen, &Value::Int(0)) {
add_element_to_object(&mut request, &Value::Str("attachAlgoOrds".to_string()), Value::List(vec![attachAlgoOrd.clone()]));
}
}
// algo order details
if is_true(&trigger) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("trigger".to_string()));
add_element_to_object(&mut request, &Value::Str("triggerPx".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("orderPx".to_string()), ternary(is_true(&isMarketOrder), Value::Str("-1".to_string()), self.price_to_precision(symbol.clone(), price.clone())));
} else if is_true(&conditional) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("conditional".to_string()));
let mut twoWayCondition: bool = is_true(&(!is_equal(&takeProfitPrice, &Value::Null))) && is_true(&(!is_equal(&stopLossPrice, &Value::Null)));
// if TP and SL are sent together
// as ordType 'conditional' only stop-loss order will be applied
// tpOrdKind is 'condition' which is the default
if is_true(&twoWayCondition) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("oco".to_string()));
}
if is_equal(&side, &Value::Str("sell".to_string())) {
request = self.omit(request.clone(), Value::Str("tgtCcy".to_string()), &[]);
}
if is_equal(&self.safe_string_k(request.clone(), "tdMode", &[]), &Value::Str("cash".to_string())) {
// for some reason tdMode = cash throws
// {"code":"1","data":[{"algoClOrdId":"","algoId":"","clOrdId":"","sCode":"51000","sMsg":"Parameter tdMode error ","tag":""}],"msg":""}
add_element_to_object(&mut request, &Value::Str("tdMode".to_string()), marginMode.clone());
}
if !is_equal(&takeProfitPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("tpTriggerPx".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone()));
let mut tpOrdPxReq: Value = Value::Str("-1".to_string());
if !is_equal(&tpOrdPx, &Value::Null) {
tpOrdPxReq = self.price_to_precision(symbol.clone(), tpOrdPx.clone());
}
add_element_to_object(&mut request, &Value::Str("tpOrdPx".to_string()), tpOrdPxReq.clone());
add_element_to_object(&mut request, &Value::Str("tpTriggerPxType".to_string()), tpTriggerPxType.clone());
}
if !is_equal(&stopLossPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("slTriggerPx".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone()));
let mut slOrdPxReq: Value = Value::Str("-1".to_string());
if !is_equal(&slOrdPx, &Value::Null) {
slOrdPxReq = self.price_to_precision(symbol.clone(), slOrdPx.clone());
}
add_element_to_object(&mut request, &Value::Str("slOrdPx".to_string()), slOrdPxReq.clone());
add_element_to_object(&mut request, &Value::Str("slTriggerPxType".to_string()), slTriggerPxType.clone());
}
}
if is_equal(&clientOrderId, &Value::Null) {
let mut brokerId: Value = self.safe_string_k(self.options.clone(), "brokerId", &[]);
if !is_equal(&brokerId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrdId".to_string()), add(&brokerId, &self.uuid16(&[])));
add_element_to_object(&mut request, &Value::Str("tag".to_string()), brokerId.clone());
}
} else {
add_element_to_object(&mut request, &Value::Str("clOrdId".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
}
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name okx#createOrder
* @description create a trade order
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-order
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-multiple-orders
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-place-algo-order
* @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 {bool} [params.reduceOnly] a mark to reduce the position size for margin, swap and future orders
* @param {bool} [params.postOnly] true to place a post only order
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered (perpetual swap markets only)
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {float} [params.takeProfit.price] used for take profit limit orders, not used for take profit market price orders
* @param {string} [params.takeProfit.type] 'market' or 'limit' used to specify the take profit price type
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered (perpetual swap markets only)
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {float} [params.stopLoss.price] used for stop loss limit orders, not used for stop loss market price orders
* @param {string} [params.stopLoss.type] 'market' or 'limit' used to specify the stop loss price type
* @param {string} [params.positionSide] if position mode is one-way: set to 'net', if position mode is hedge-mode: set to 'long' or 'short'
* @param {string} [params.trailingPercent] the percent to trail away from the current market price
* @param {string} [params.tpOrdKind] 'condition' or 'limit', the default is 'condition'
* @param {bool} [params.hedged] *swap and future only* true for hedged mode, false for one way mode
* @param {string} [params.marginMode] 'cross' or 'isolated', the default is 'cross'
* @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 request: Value = self.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut method: Value = self.safe_string_k(self.options.clone(), "createOrder", &[Value::Str("privatePostTradeBatchOrders".to_string())]);
let mut requestOrdType: Value = self.safe_string_k(request.clone(), "ordType", &[]);
if is_true(&(is_equal(&requestOrdType, &Value::Str("trigger".to_string())))) || is_true(&(is_equal(&requestOrdType, &Value::Str("conditional".to_string())))) || is_true(&(is_equal(&requestOrdType, &Value::Str("move_order_stop".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("move_order_stop".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("oco".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("iceberg".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("twap".to_string())))) {
method = Value::Str("privatePostTradeOrderAlgo".to_string());
}
if is_true(&(!is_equal(&method, &Value::Str("privatePostTradeOrder".to_string())))) && is_true(&(!is_equal(&method, &Value::Str("privatePostTradeOrderAlgo".to_string())))) && is_true(&(!is_equal(&method, &Value::Str("privatePostTradeBatchOrders".to_string())))) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" createOrder() this.options[\"createOrder\"] must be either privatePostTradeBatchOrders or privatePostTradeOrder or privatePostTradeOrderAlgo".to_string()))));
}
if is_equal(&method, &Value::Str("privatePostTradeBatchOrders".to_string())) {
// keep the request body the same
// submit a single order in an array to the batch order endpoint
// because it has a lower ratelimit
request = Value::List(vec![request.clone()]);
}
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privatePostTradeOrder".to_string())) {
response = self.private_post_trade_order(&[request.clone()]).await;
} else if is_equal(&method, &Value::Str("privatePostTradeOrderAlgo".to_string())) {
response = self.private_post_trade_order_algo(&[request.clone()]).await;
} else {
response = self.private_post_trade_batch_orders(&[request.clone()]).await;
}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(first.clone(), &[market.clone()]);
add_element_to_object(&mut order, &Value::Str("type".to_string()), type_var.clone());
add_element_to_object(&mut order, &Value::Str("side".to_string()), side.clone());
return order;
Value::Null
}
/*
* @method
* @name okx#createOrders
* @description create a list of trade orders
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-place-multiple-orders
* @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 ordersRequests: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_993: bool = true;
while { if !__for_first_993 { i = add(&i, &Value::Int(1)); } __for_first_993 = 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", &[]);
if is_equal(&marketId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" createOrders() requires a symbol for each order".to_string()))));
}
let mut type_var: Value = self.safe_string_k(rawOrder.clone(), "type", &[Value::Str("".to_string())]);
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 extendedParams: Value = self.extend(orderParams.clone(), &[params.clone()]); // the request does not accept extra params since it's a list, so we're extending each order with the common params
let mut orderRequest: Value = self.create_order_request(marketId.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), extendedParams.clone()]);
append_to_array(&mut ordersRequests, orderRequest.clone());
}
}
let mut response: Value = self.private_post_trade_batch_orders(&[ordersRequests.clone()]).await;
// {
// "code": "0",
// "data": [
// {
// "clOrdId": "e847386590ce4dBCc7f2a1b4c4509f82",
// "ordId": "636305438765568000",
// "sCode": "0",
// "sMsg": "Order placed",
// "tag": "e847386590ce4dBC"
// },
// {
// "clOrdId": "e847386590ce4dBC0b9993fe642d8f62",
// "ordId": "636305438765568001",
// "sCode": "0",
// "sMsg": "Order placed",
// "tag": "e847386590ce4dBC"
// }
// ],
// "inTime": "1697979038584486",
// "msg": "",
// "outTime": "1697979038586493"
// }
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
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
}));
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut isAlgoOrder: Value = Value::Null;
if is_true(&(is_equal(&type_var, &Value::Str("trigger".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("conditional".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("move_order_stop".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("oco".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("iceberg".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("twap".to_string())))) {
isAlgoOrder = Value::Bool(true);
}
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
if is_true(&isAlgoOrder) {
add_element_to_object(&mut request, &Value::Str("algoClOrdId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("clOrdId".to_string()), clientOrderId.clone());
}
} else {
if is_true(&isAlgoOrder) {
add_element_to_object(&mut request, &Value::Str("algoId".to_string()), id.clone());
} else {
add_element_to_object(&mut request, &Value::Str("ordId".to_string()), id.clone());
}
}
let mut stopLossTriggerPrice: Value = self.safe_number2(params.clone(), Value::Str("stopLossPrice".to_string()), Value::Str("newSlTriggerPx".to_string()), &[]);
let mut stopLossPrice: Value = self.safe_number_k(params.clone(), "newSlOrdPx", &[]);
let mut stopLossTriggerPriceType: Value = self.safe_string_k(params.clone(), "newSlTriggerPxType", &[Value::Str("last".to_string())]);
let mut takeProfitTriggerPrice: Value = self.safe_number2(params.clone(), Value::Str("takeProfitPrice".to_string()), Value::Str("newTpTriggerPx".to_string()), &[]);
let mut takeProfitPrice: Value = self.safe_number_k(params.clone(), "newTpOrdPx", &[]);
let mut takeProfitTriggerPriceType: Value = self.safe_string_k(params.clone(), "newTpTriggerPxType", &[Value::Str("last".to_string())]);
let mut stopLoss: Value = self.safe_value_k(params.clone(), "stopLoss", &[]);
let mut takeProfit: Value = self.safe_value_k(params.clone(), "takeProfit", &[]);
let mut hasStopLoss: bool = !is_equal(&stopLoss, &Value::Null);
let mut hasTakeProfit: bool = !is_equal(&takeProfit, &Value::Null);
if is_true(&isAlgoOrder) {
if is_true(&(is_equal(&stopLossTriggerPrice, &Value::Null))) && is_true(&(is_equal(&takeProfitTriggerPrice, &Value::Null))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" editOrder() requires a stopLossPrice or takeProfitPrice parameter for editing an algo order".to_string()))));
}
if !is_equal(&stopLossTriggerPrice, &Value::Null) {
if is_equal(&stopLossPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" editOrder() requires a newSlOrdPx parameter for editing an algo order".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("newSlTriggerPx".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("newSlOrdPx".to_string()), ternary(is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))), Value::Str("-1".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone())));
add_element_to_object(&mut request, &Value::Str("newSlTriggerPxType".to_string()), stopLossTriggerPriceType.clone());
}
if !is_equal(&takeProfitTriggerPrice, &Value::Null) {
if is_equal(&takeProfitPrice, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" editOrder() requires a newTpOrdPx parameter for editing an algo order".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("newTpTriggerPx".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("newTpOrdPx".to_string()), ternary(is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))), Value::Str("-1".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone())));
add_element_to_object(&mut request, &Value::Str("newTpTriggerPxType".to_string()), takeProfitTriggerPriceType.clone());
}
} else {
if !is_equal(&stopLossTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("newSlTriggerPx".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("newSlOrdPx".to_string()), ternary(is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))), Value::Str("-1".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone())));
add_element_to_object(&mut request, &Value::Str("newSlTriggerPxType".to_string()), stopLossTriggerPriceType.clone());
}
if !is_equal(&takeProfitTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("newTpTriggerPx".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("newTpOrdPx".to_string()), ternary(is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))), Value::Str("-1".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone())));
add_element_to_object(&mut request, &Value::Str("newTpTriggerPxType".to_string()), takeProfitTriggerPriceType.clone());
}
if is_true(&hasStopLoss) {
stopLossTriggerPrice = self.safe_number_k(stopLoss.clone(), "triggerPrice", &[]);
stopLossPrice = self.safe_number_k(stopLoss.clone(), "price", &[]);
let mut stopLossType: Value = self.safe_string_k(stopLoss.clone(), "type", &[]);
add_element_to_object(&mut request, &Value::Str("newSlTriggerPx".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("newSlOrdPx".to_string()), ternary(is_true(&(is_equal(&stopLossType, &Value::Str("market".to_string())))), Value::Str("-1".to_string()), self.price_to_precision(symbol.clone(), stopLossPrice.clone())));
add_element_to_object(&mut request, &Value::Str("newSlTriggerPxType".to_string()), stopLossTriggerPriceType.clone());
}
if is_true(&hasTakeProfit) {
takeProfitTriggerPrice = self.safe_number_k(takeProfit.clone(), "triggerPrice", &[]);
takeProfitPrice = self.safe_number_k(takeProfit.clone(), "price", &[]);
let mut takeProfitType: Value = self.safe_string_k(takeProfit.clone(), "type", &[]);
add_element_to_object(&mut request, &Value::Str("newTpOrdKind".to_string()), ternary(is_true(&(is_equal(&takeProfitType, &Value::Str("limit".to_string())))), takeProfitType.clone(), Value::Str("condition".to_string())));
add_element_to_object(&mut request, &Value::Str("newTpTriggerPx".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
add_element_to_object(&mut request, &Value::Str("newTpOrdPx".to_string()), ternary(is_true(&(is_equal(&takeProfitType, &Value::Str("market".to_string())))), Value::Str("-1".to_string()), self.price_to_precision(symbol.clone(), takeProfitPrice.clone())));
add_element_to_object(&mut request, &Value::Str("newTpTriggerPxType".to_string()), takeProfitTriggerPriceType.clone());
}
}
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("newSz".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_true(&isAlgoOrder) {
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("newPx".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("stopLoss".to_string()), Value::Str("takeProfit".to_string()), Value::Str("postOnly".to_string())]), &[]);
return self.extend(request.clone(), &[params.clone()]);
Value::Null
}
/*
* @method
* @name okx#editOrder
* @description edit a trade order
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-amend-order
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-amend-algo-order
* @param {string} id order id
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of the currency you want to trade in units of the base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client order id, uses id if not passed
* @param {float} [params.stopLossPrice] stop loss trigger price
* @param {float} [params.newSlOrdPx] the stop loss order price, set to stopLossPrice if the type is market
* @param {string} [params.newSlTriggerPxType] 'last', 'index' or 'mark' used to specify the stop loss trigger price type, default is 'last'
* @param {float} [params.takeProfitPrice] take profit trigger price
* @param {float} [params.newTpOrdPx] the take profit order price, set to takeProfitPrice if the type is market
* @param {string} [params.newTpTriggerPxType] 'last', 'index' or 'mark' used to specify the take profit trigger price type, default is 'last'
* @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 {float} [params.stopLoss.price] used for stop loss limit orders, not used for stop loss market price orders
* @param {string} [params.stopLoss.type] 'market' or 'limit' used to specify the stop loss price type
* @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 {float} [params.takeProfit.price] used for take profit limit orders, not used for take profit market price orders
* @param {string} [params.takeProfit.type] 'market' or 'limit' used to specify the take profit price type
* @param {string} [params.newTpOrdKind] 'condition' or 'limit', the default is 'condition'
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.edit_order_request(id.clone(), symbol.clone(), type_var.clone(), side.clone(), &[amount.clone(), price.clone(), params.clone()]);
let mut isAlgoOrder: Value = Value::Null;
if is_true(&(is_equal(&type_var, &Value::Str("trigger".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("conditional".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("move_order_stop".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("oco".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("iceberg".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("twap".to_string())))) {
isAlgoOrder = Value::Bool(true);
}
let mut response: Value = Value::Null;
if is_true(&isAlgoOrder) {
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_trade_amend_algos(&[__ws_arg_33]).await;
} else {
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_trade_amend_order(&[__ws_arg_34]).await;
}
//
// {
// "code": "0",
// "data": [
// {
// "clOrdId": "e847386590ce4dBCc1a045253497a547",
// "ordId": "559176536793178112",
// "reqId": "",
// "sCode": "0",
// "sMsg": ""
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut order: Value = self.parse_order(first.clone(), &[market.clone()]);
add_element_to_object(&mut order, &Value::Str("type".to_string()), type_var.clone());
add_element_to_object(&mut order, &Value::Str("side".to_string()), side.clone());
return order;
Value::Null
}
/*
* @method
* @name okx#cancelOrder
* @description cancels an open order
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-order
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-cancel-algo-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] true if trigger orders
* @param {boolean} [params.trailing] set to true if you want to cancel a trailing order
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires a symbol argument".to_string()))));
}
let mut trigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isTrigger: bool = is_true(&(!is_equal(&trigger, &Value::Null))) && is_true(&(!is_equal(&trigger, &Value::Bool(false))));
if is_true(&isTrigger) || is_true(&(is_equal(&trailing, &Value::Bool(true)))) {
let mut orderInner: Value = self.cancel_orders(Value::List(vec![id.clone()]), &[symbol.clone(), params.clone()]).await;
return self.safe_dict(orderInner.clone(), Value::Int(0), &[]);
}
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("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrdId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("ordId".to_string()), id.clone());
}
let mut query: Value = self.omit(params.clone(), Value::List(vec![Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let __ws_arg_35 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.private_post_trade_cancel_order(&[__ws_arg_35]).await;
// {"code":"0","data":[{"clOrdId":"","ordId":"317251910906576896","sCode":"0","sMsg":""}],"msg":""}
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut order: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_ids(&self, mut ids: Value) -> Value {
/*
* @ignore
* @method
* @name okx#parseIds
* @param {string[]|string} ids order ids
* @returns {string[]} list of order ids
*/
if is_true(&(!is_equal(&ids, &Value::Null))) && is_string(&ids) {
return split(&ids, &Value::Str(",".to_string()));
} else {
return ids;
}
Value::Null
}
/*
* @method
* @name okx#cancelOrders
* @description cancel multiple orders
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-multiple-orders
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-cancel-algo-order
* @param {string[]} ids order ids
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] whether the order is a stop/trigger order
* @param {boolean} [params.trailing] set to true if you want to cancel trailing orders
* @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
}));
// TODO : the original endpoint signature differs, according to that you can skip individual symbol and assign ids in batch. At this moment, `params` is not being used too.
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol argument".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::List(vec![]);
let mut options: Value = self.safe_dict_k(self.options.clone(), "cancelOrders", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options.clone(), "method", &[Value::Str("privatePostTradeCancelBatchOrders".to_string())]);
let mut method: Value = self.safe_string_k(params.clone(), "method", &[defaultMethod.clone()]);
let mut clientOrderIds: Value = self.parse_ids(self.safe_value2(params.clone(), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), &[]));
let mut algoIds: Value = self.parse_ids(self.safe_value_k(params.clone(), "algoId", &[]));
let mut trigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isTrigger: bool = is_true(&(!is_equal(&trigger, &Value::Null))) && is_true(&(!is_equal(&trigger, &Value::Bool(false))));
if is_true(&isTrigger) || is_true(&(is_equal(&trailing, &Value::Bool(true)))) {
method = Value::Str("privatePostTradeCancelAlgos".to_string());
}
if is_equal(&clientOrderIds, &Value::Null) {
ids = self.parse_ids(ids.clone());
if !is_equal(&algoIds, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_994: bool = true;
while { if !__for_first_994 { i = add(&i, &Value::Int(1)); } __for_first_994 = false; is_less_than(&i, &get_array_length(&algoIds)) } {
append_to_array(&mut request, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("algoId".to_string(), get_value(&algoIds, &i));
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
}));
}
}
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_995: bool = true;
while { if !__for_first_995 { i = add(&i, &Value::Int(1)); } __for_first_995 = false; is_less_than(&i, &get_array_length(&ids)) } {
if is_true(&(is_equal(&trailing, &Value::Bool(true)))) || is_true(&(!is_equal(&trigger, &Value::Null))) {
append_to_array(&mut request, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("algoId".to_string(), get_value(&ids, &i));
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
}));
} else {
append_to_array(&mut request, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ordId".to_string(), get_value(&ids, &i));
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
}));
}
}
}
} else {
{
let mut i: Value = Value::Int(0);
let mut __for_first_996: bool = true;
while { if !__for_first_996 { i = add(&i, &Value::Int(1)); } __for_first_996 = false; is_less_than(&i, &get_array_length(&clientOrderIds)) } {
if is_true(&(is_equal(&trailing, &Value::Bool(true)))) || is_true(&(!is_equal(&trigger, &Value::Null))) {
append_to_array(&mut request, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("algoClOrdId".to_string(), get_value(&clientOrderIds, &i));
m
}));
} else {
append_to_array(&mut request, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("clOrdId".to_string(), get_value(&clientOrderIds, &i));
m
}));
}
}
}
}
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privatePostTradeCancelAlgos".to_string())) {
response = self.private_post_trade_cancel_algos(&[request.clone()]).await; // * dont extend with params, otherwise ARRAY will be turned into OBJECT
} else {
response = self.private_post_trade_cancel_batch_orders(&[request.clone()]).await; // * dont extend with params, otherwise ARRAY will be turned into OBJECT
}
//
// {
// "code": "0",
// "data": [
// {
// "clOrdId": "e123456789ec4dBC1123456ba123b45e",
// "ordId": "405071912345641543",
// "sCode": "0",
// "sMsg": ""
// },
// ...
// ],
// "msg": ""
// }
//
// Algo order
//
// {
// "code": "0",
// "data": [
// {
// "algoId": "431375349042380800",
// "sCode": "0",
// "sMsg": ""
// }
// ],
// "msg": ""
// }
//
let mut ordersData: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
// the request-only keys must not be merged onto every parsed order: a clientOrderId[]
// request would otherwise come back as a list under the unified string field
let mut orderParams: Value = self.omit(params.clone(), Value::List(vec![Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("algoId".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), Value::Str("trailing".to_string()), Value::Str("method".to_string())]), &[]);
return self.parse_orders(ordersData.clone(), &[market.clone(), Value::Null, Value::Null, orderParams.clone()]);
Value::Null
}
/*
* @method
* @name okx#cancelOrdersForSymbols
* @description cancel multiple orders for multiple symbols
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-multiple-orders
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-post-cancel-algo-order
* @param {CancellationRequest[]} orders each order should contain the parameters required by cancelOrder namely id and symbol, example [{"id": "a", "symbol": "BTC/USDT"}, {"id": "b", "symbol": "ETH/USDT"}]
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean} [params.trigger] whether the order is a stop/trigger order
* @param {boolean} [params.trailing] set to true if you want to cancel trailing orders
* @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 request: Value = Value::List(vec![]);
let mut options: Value = self.safe_dict_k(self.options.clone(), "cancelOrders", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options.clone(), "method", &[Value::Str("privatePostTradeCancelBatchOrders".to_string())]);
let mut method: Value = self.safe_string_k(params.clone(), "method", &[defaultMethod.clone()]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isStopOrTrailing: Value = Value::Bool(is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_equal(&trailing, &Value::Bool(true)))));
if is_equal(&isStopOrTrailing, &Value::Bool(true)) {
method = Value::Str("privatePostTradeCancelAlgos".to_string());
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_997: bool = true;
while { if !__for_first_997 { i = add(&i, &Value::Int(1)); } __for_first_997 = 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 id: Value = self.safe_string_k(order.clone(), "id", &[]);
let mut clientOrderId: Value = self.safe_string2(order.clone(), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[]);
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrders() requires a symbol for each order".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut idKey: Value = Value::Str("ordId".to_string());
if is_equal(&isStopOrTrailing, &Value::Bool(true)) {
idKey = Value::Str("algoId".to_string());
} else if !is_equal(&clientOrderId, &Value::Null) {
idKey = Value::Str("clOrdId".to_string());
}
let mut requestItem: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
add_element_to_object(&mut requestItem, &idKey, ternary(is_true(&(!is_equal(&clientOrderId, &Value::Null))), clientOrderId.clone(), id.clone()));
append_to_array(&mut request, requestItem.clone());
}
}
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privatePostTradeCancelAlgos".to_string())) {
response = self.private_post_trade_cancel_algos(&[request.clone()]).await; // * dont extend with params, otherwise ARRAY will be turned into OBJECT
} else {
response = self.private_post_trade_cancel_batch_orders(&[request.clone()]).await; // * dont extend with params, otherwise ARRAY will be turned into OBJECT
}
//
// {
// "code": "0",
// "data": [
// {
// "clOrdId": "e123456789ec4dBC1123456ba123b45e",
// "ordId": "405071912345641543",
// "sCode": "0",
// "sMsg": ""
// },
// ...
// ],
// "msg": ""
// }
//
// Algo order
//
// {
// "code": "0",
// "data": [
// {
// "algoId": "431375349042380800",
// "sCode": "0",
// "sMsg": ""
// }
// ],
// "msg": ""
// }
//
let mut ordersData: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(ordersData.clone(), &[Value::Null, Value::Null, Value::Null, params.clone()]);
Value::Null
}
/*
* @method
* @name okx#cancelAllOrdersAfter
* @description dead man's switch, cancel all orders after the given timeout
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-cancel-all-after
* @param {number} timeout time in milliseconds, 0 represents cancel the timer
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} the api result
*/
pub async fn cancel_all_orders_after(&mut self, mut timeout: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut timeOut: Value = Value::Int(0);
if is_true(&(!is_equal(&timeout, &Value::Null))) && is_true(&(is_greater_than(&timeout, &Value::Int(0)))) {
timeOut = self.parse_to_int(divide(&timeout, &Value::Int(1000)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeOut".to_string(), timeOut.clone());
m
});
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_trade_cancel_all_after(&[__ws_arg_36]).await;
return response;
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("canceled".to_string(), Value::Str("canceled".to_string()));
m.insert("order_failed".to_string(), Value::Str("canceled".to_string()));
m.insert("live".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("effective".to_string(), Value::Str("closed".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder
//
// {
// "clOrdId": "oktswap6",
// "ordId": "312269865356374016",
// "tag": "",
// "sCode": "0",
// "sMsg": ""
// }
//
// editOrder
//
// {
// "clOrdId": "e847386590ce4dBCc1a045253497a547",
// "ordId": "559176536793178112",
// "reqId": "",
// "sCode": "0",
// "sMsg": ""
// }
//
// Spot and Swap fetchOrder, fetchOpenOrders
//
// {
// "accFillSz": "0",
// "avgPx": "",
// "cTime": "1621910749815",
// "category": "normal",
// "ccy": "",
// "clOrdId": "",
// "fee": "0",
// "feeCcy": "ETH",
// "fillPx": "",
// "fillSz": "0",
// "fillTime": "",
// "instId": "ETH-USDT",
// "instType": "SPOT",
// "lever": "",
// "ordId": "317251910906576896",
// "ordType": "limit",
// "pnl": "0",
// "posSide": "net",
// "px": "2000",
// "rebate": "0",
// "rebateCcy": "USDT",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "state": "live",
// "sz": "0.001",
// "tag": "",
// "tdMode": "cash",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tradeId": "",
// "uTime": "1621910749815"
// }
//
// watchOrders & fetchClosedOrders
//
// {
// "algoClOrdId": "",
// "algoId": "",
// "attachAlgoClOrdId": "",
// "attachAlgoOrds": [],
// "cancelSource": "",
// "cancelSourceReason": "", // not present in WS, but present in fetchClosedOrders
// "category": "normal",
// "ccy": "", // empty in WS, but eg. `USDT` in fetchClosedOrders
// "clOrdId": "",
// "cTime": "1751705801423",
// "feeCcy": "USDT",
// "instId": "LINK-USDT-SWAP",
// "instType": "SWAP",
// "isTpLimit": "false",
// "lever": "3",
// "linkedAlgoOrd": { "algoId": "" },
// "ordId": "2657625147249614848",
// "ordType": "limit",
// "posSide": "net",
// "px": "13.142",
// "pxType": "",
// "pxUsd": "",
// "pxVol": "",
// "quickMgnType": "",
// "rebate": "0",
// "rebateCcy": "USDT",
// "reduceOnly": "true",
// "side": "sell",
// "slOrdPx": "",
// "slTriggerPx": "",
// "slTriggerPxType": "",
// "source": "",
// "stpId": "",
// "stpMode": "cancel_maker",
// "sz": "0.1",
// "tag": "",
// "tdMode": "isolated",
// "tgtCcy": "",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tpTriggerPxType": "",
// "uTime": "1751705807467",
// "reqId": "", // field present only in WS
// "msg": "", // field present only in WS
// "amendResult": "", // field present only in WS
// "amendSource": "", // field present only in WS
// "code": "0", // field present only in WS
// "fillFwdPx": "", // field present only in WS
// "fillMarkVol": "", // field present only in WS
// "fillPxUsd": "", // field present only in WS
// "fillPxVol": "", // field present only in WS
// "lastPx": "13.142", // field present only in WS
// "notionalUsd": "1.314515408", // field present only in WS
//
// #### these below fields are empty on first omit from websocket, because of "creation" event. however, if order is executed, it also immediately sends another update with these fields filled ###
//
// "pnl": "-0.0001",
// "accFillSz": "0.1",
// "avgPx": "13.142",
// "state": "filled",
// "fee": "-0.00026284",
// "fillPx": "13.142",
// "tradeId": "293429690",
// "fillSz": "0.1",
// "fillTime": "1751705807467",
// "fillNotionalUsd": "1.314515408", // field present only in WS
// "fillPnl": "-0.0001", // field present only in WS
// "fillFee": "-0.00026284", // field present only in WS
// "fillFeeCcy": "USDT", // field present only in WS
// "execType": "M", // field present only in WS
// "fillMarkPx": "13.141", // field present only in WS
// "fillIdxPx": "13.147" // field present only in WS
// }
//
//
// Algo Order fetchOpenOrders, fetchCanceledOrders, fetchClosedOrders
//
// {
// "activePx": "",
// "activePxType": "",
// "actualPx": "",
// "actualSide": "buy",
// "actualSz": "0",
// "algoId": "431375349042380800",
// "cTime": "1649119897778",
// "callbackRatio": "",
// "callbackSpread": "",
// "ccy": "",
// "ctVal": "0.01",
// "instId": "BTC-USDT-SWAP",
// "instType": "SWAP",
// "last": "46538.9",
// "lever": "125",
// "moveTriggerPx": "",
// "notionalUsd": "467.059",
// "ordId": "",
// "ordPx": "50000",
// "ordType": "trigger",
// "posSide": "long",
// "pxLimit": "",
// "pxSpread": "",
// "pxVar": "",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "slTriggerPxType": "",
// "state": "live",
// "sz": "1",
// "szLimit": "",
// "tag": "",
// "tdMode": "isolated",
// "tgtCcy": "",
// "timeInterval": "",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tpTriggerPxType": "",
// "triggerPx": "50000",
// "triggerPxType": "last",
// "triggerTime": "",
// "uly": "BTC-USDT"
// }
//
let mut scode: Value = self.safe_string_k(order.clone(), "sCode", &[]);
if is_true(&(!is_equal(&scode, &Value::Null))) && is_true(&(!is_equal(&scode, &Value::Str("0".to_string())))) {
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(order.clone(), "ordId", &[]));
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "clOrdId", &[]));
m.insert("status".to_string(), Value::Str("rejected".to_string()));
m.insert("info".to_string(), order.clone());
m
}), &[]);
}
let mut id: Value = self.safe_string2(order.clone(), Value::Str("algoId".to_string()), Value::Str("ordId".to_string()), &[]);
let mut timestamp: Value = self.safe_integer_k(order.clone(), "cTime", &[]);
let mut lastUpdateTimestamp: Value = self.safe_integer_k(order.clone(), "uTime", &[]);
let mut lastTradeTimestamp: Value = self.safe_integer_k(order.clone(), "fillTime", &[]);
let mut side: Value = self.safe_string_k(order.clone(), "side", &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "ordType", &[]);
let mut postOnly: Value = Value::Null;
let mut timeInForce: Value = Value::Null;
if is_equal(&type_var, &Value::Str("post_only".to_string())) {
postOnly = Value::Bool(true);
type_var = Value::Str("limit".to_string());
} else if is_equal(&type_var, &Value::Str("fok".to_string())) {
timeInForce = Value::Str("FOK".to_string());
type_var = Value::Str("limit".to_string());
} else if is_equal(&type_var, &Value::Str("ioc".to_string())) {
timeInForce = Value::Str("IOC".to_string());
type_var = Value::Str("limit".to_string());
}
let mut marketId: Value = self.safe_string_k(order.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone(), Value::Str("-".to_string())]);
let mut filled: Value = self.safe_string_k(order.clone(), "accFillSz", &[]);
let mut price: Value = self.safe_string2(order.clone(), Value::Str("px".to_string()), Value::Str("ordPx".to_string()), &[]);
let mut average: Value = self.safe_string_k(order.clone(), "avgPx", &[]);
let mut status: Value = self.parse_order_status(self.safe_string_k(order.clone(), "state", &[]));
let mut feeCostString: Value = self.safe_string_k(order.clone(), "fee", &[]);
let mut amount: Value = Value::Null;
let mut cost: Value = Value::Null;
// spot market buy: "sz" can refer either to base currency units or to quote currency units
// see documentation: https://www.okx.com/docs-v5/en/#rest-api-trade-place-order
let mut defaultTgtCcy: Value = self.safe_string_k(self.options.clone(), "tgtCcy", &[Value::Str("base_ccy".to_string())]);
let mut tgtCcy: Value = self.safe_string_k(order.clone(), "tgtCcy", &[defaultTgtCcy.clone()]);
let mut instType: Value = self.safe_string_k(order.clone(), "instType", &[]);
if is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) && is_true(&(is_equal(&type_var, &Value::Str("market".to_string())))) && is_true(&(is_equal(&instType, &Value::Str("SPOT".to_string())))) && is_true(&(is_equal(&tgtCcy, &Value::Str("quote_ccy".to_string())))) {
// "sz" refers to the cost
cost = self.safe_string_k(order.clone(), "sz", &[]);
} else {
// "sz" refers to the trade currency amount
amount = self.safe_string_k(order.clone(), "sz", &[]);
}
let mut fee: Value = Value::Null;
if !is_equal(&feeCostString, &Value::Null) {
let mut feeCostSigned: Value = crate::precise::Precise::stringNeg(&feeCostString);
let mut feeCurrencyId: Value = self.safe_string_k(order.clone(), "feeCcy", &[]);
let mut feeCurrencyCode: Value = self.safe_currency_code(feeCurrencyId.clone(), &[]);
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(feeCostSigned.clone(), &[]));
m.insert("currency".to_string(), feeCurrencyCode.clone());
m
});
}
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "clOrdId", &[]);
if is_true(&(!is_equal(&clientOrderId, &Value::Null))) && is_true(&(is_less_than(&get_array_length(&clientOrderId), &Value::Int(1)))) {
clientOrderId = Value::Null; // fix empty clientOrderId string
}
let mut stopLossPrice: Value = self.safe_number2(order.clone(), Value::Str("slTriggerPx".to_string()), Value::Str("slOrdPx".to_string()), &[]);
let mut takeProfitPrice: Value = self.safe_number2(order.clone(), Value::Str("tpTriggerPx".to_string()), Value::Str("tpOrdPx".to_string()), &[]);
let mut reduceOnlyRaw: Value = self.safe_string_k(order.clone(), "reduceOnly", &[]);
let mut reduceOnly: Value = Value::Bool(false);
if !is_equal(&reduceOnly, &Value::Null) {
reduceOnly = Value::Bool(is_equal(&reduceOnlyRaw, &Value::Str("true".to_string())));
}
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), order.clone());
m.insert("id".to_string(), id.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), lastTradeTimestamp.clone());
m.insert("lastUpdateTimestamp".to_string(), lastUpdateTimestamp.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(), postOnly.clone());
m.insert("side".to_string(), side.clone());
m.insert("price".to_string(), price.clone());
m.insert("stopLossPrice".to_string(), stopLossPrice.clone());
m.insert("takeProfitPrice".to_string(), takeProfitPrice.clone());
m.insert("triggerPrice".to_string(), self.safe_number_n(order.clone(), Value::List(vec![Value::Str("triggerPx".to_string()), Value::Str("moveTriggerPx".to_string())]), &[]));
m.insert("average".to_string(), average.clone());
m.insert("cost".to_string(), cost.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("filled".to_string(), filled.clone());
m.insert("remaining".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("fee".to_string(), fee.clone());
m.insert("trades".to_string(), Value::Null);
m.insert("reduceOnly".to_string(), reduceOnly.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchOrder
* @description fetch an order by the id
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-details
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-details
* @param {string} id the order id
* @param {string} symbol unified market symbol
* @param {object} [params] extra and exchange specific parameters
* @param {boolean} [params.trigger] true if fetching trigger orders
* @returns [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(&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());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut clientOrderId: Value = self.safe_string2(params.clone(), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), &[]);
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options.clone(), "method", &[Value::Str("privateGetTradeOrder".to_string())]);
let mut method: Value = self.safe_string_k(params.clone(), "method", &[defaultMethod.clone()]);
let mut trigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut isTrigger: bool = is_true(&(!is_equal(&trigger, &Value::Null))) && is_true(&(!is_equal(&trigger, &Value::Bool(false))));
if is_true(&isTrigger) {
method = Value::Str("privateGetTradeOrderAlgo".to_string());
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("algoClOrdId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("algoId".to_string()), id.clone());
}
} else {
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrdId".to_string()), clientOrderId.clone());
} else {
add_element_to_object(&mut request, &Value::Str("ordId".to_string()), id.clone());
}
}
let mut query: Value = self.omit(params.clone(), Value::List(vec![Value::Str("method".to_string()), Value::Str("clOrdId".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privateGetTradeOrderAlgo".to_string())) {
let __ws_arg_37 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_trade_order_algo(&[__ws_arg_37]).await;
} else {
let __ws_arg_38 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_trade_order(&[__ws_arg_38]).await;
}
//
// Spot and Swap
//
// {
// "code": "0",
// "data": [
// {
// "accFillSz": "0",
// "avgPx": "",
// "cTime": "1621910749815",
// "category": "normal",
// "ccy": "",
// "clOrdId": "",
// "fee": "0",
// "feeCcy": "ETH",
// "fillPx": "",
// "fillSz": "0",
// "fillTime": "",
// "instId": "ETH-USDT",
// "instType": "SPOT",
// "lever": "",
// "ordId": "317251910906576896",
// "ordType": "limit",
// "pnl": "0",
// "posSide": "net",
// "px":"20 00",
// "rebate": "0",
// "rebateCcy": "USDT",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "state": "live",
// "sz":"0. 001",
// "tag": "",
// "tdMode": "cash",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tradeId": "",
// "uTime": "1621910749815"
// }
// ],
// "msg": ""
// }
//
// Algo order
// {
// "code":"0",
// "msg":"",
// "data":[
// {
// "instType":"FUTURES",
// "instId":"BTC-USD-200329",
// "ordId":"123445",
// "ccy":"BTC",
// "clOrdId":"",
// "algoId":"1234",
// "sz":"999",
// "closeFraction":"",
// "ordType":"oco",
// "side":"buy",
// "posSide":"long",
// "tdMode":"cross",
// "tgtCcy": "",
// "state":"effective",
// "lever":"20",
// "tpTriggerPx":"",
// "tpTriggerPxType":"",
// "tpOrdPx":"",
// "slTriggerPx":"",
// "slTriggerPxType":"",
// "triggerPx":"99",
// "triggerPxType":"last",
// "ordPx":"12",
// "actualSz":"",
// "actualPx":"",
// "actualSide":"",
// "pxVar":"",
// "pxSpread":"",
// "pxLimit":"",
// "szLimit":"",
// "tag": "adadadadad",
// "timeInterval":"",
// "callbackRatio":"",
// "callbackSpread":"",
// "activePx":"",
// "moveTriggerPx":"",
// "reduceOnly": "false",
// "triggerTime":"1597026383085",
// "last": "16012",
// "failCode": "",
// "algoClOrdId": "",
// "cTime":"1597026383000"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut order: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-list
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-list
* @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 {bool} [params.trigger] True if fetching trigger or conditional orders
* @param {string} [params.ordType] market, limit, post_only, fok, ioc and stop orders: conditional, oco, trigger, move_order_stop, iceberg, or twap
* @param {string} [params.algoId] Algo ID "'433845797218942976'"
* @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 {boolean} [params.trailing] set to true if you want to fetch trailing orders
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(100);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("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_dynamic(Value::Str("fetchOpenOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
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("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &maxLimit)); // default 100, max 100
}
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchOpenOrders", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut algoOrderTypes: Value = self.safe_dict_k(self.options.clone(), "algoOrderTypes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options.clone(), "method", &[Value::Str("privateGetTradeOrdersPending".to_string())]);
let mut method: Value = self.safe_string_k(params.clone(), "method", &[defaultMethod.clone()]);
let mut ordType: Value = self.safe_string_k(params.clone(), "ordType", &[]);
let mut trigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isTrigger: bool = is_true(&(!is_equal(&trigger, &Value::Null))) && is_true(&(!is_equal(&trigger, &Value::Bool(false))));
if is_true(&(is_equal(&trailing, &Value::Bool(true)))) || is_true(&isTrigger) || is_true(&(is_true(&(!is_equal(&ordType, &Value::Null))) && is_true(&(Value::Bool(in_op(&algoOrderTypes, &ordType)))))) {
method = Value::Str("privateGetTradeOrdersAlgoPending".to_string());
}
if is_equal(&trailing, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("move_order_stop".to_string()));
} else if is_true(&(!is_equal(&trigger, &Value::Null))) && is_true(&(is_equal(&ordType, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("trigger".to_string()));
}
let mut query: Value = self.omit(params.clone(), Value::List(vec![Value::Str("method".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), Value::Str("trailing".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privateGetTradeOrdersAlgoPending".to_string())) {
let __ws_arg_39 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_trade_orders_algo_pending(&[__ws_arg_39]).await;
} else {
let __ws_arg_40 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_trade_orders_pending(&[__ws_arg_40]).await;
}
//
// {
// "code": "0",
// "data": [
// {
// "accFillSz": "0",
// "avgPx": "",
// "cTime": "1621910749815",
// "category": "normal",
// "ccy": "",
// "clOrdId": "",
// "fee": "0",
// "feeCcy": "ETH",
// "fillPx": "",
// "fillSz": "0",
// "fillTime": "",
// "instId": "ETH-USDT",
// "instType": "SPOT",
// "lever": "",
// "ordId": "317251910906576896",
// "ordType": "limit",
// "pnl": "0",
// "posSide": "net",
// "px":"20 00",
// "rebate": "0",
// "rebateCcy": "USDT",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "state": "live",
// "sz":"0. 001",
// "tag": "",
// "tdMode": "cash",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tradeId": "",
// "uTime": "1621910749815"
// }
// ],
// "msg":""
// }
//
// Algo order
//
// {
// "code": "0",
// "data": [
// {
// "activePx": "",
// "activePxType": "",
// "actualPx": "",
// "actualSide": "buy",
// "actualSz": "0",
// "algoId": "431375349042380800",
// "cTime": "1649119897778",
// "callbackRatio": "",
// "callbackSpread": "",
// "ccy": "",
// "ctVal": "0.01",
// "instId": "BTC-USDT-SWAP",
// "instType": "SWAP",
// "last": "46538.9",
// "lever": "125",
// "moveTriggerPx": "",
// "notionalUsd": "467.059",
// "ordId": "",
// "ordPx": "50000",
// "ordType": "trigger",
// "posSide": "long",
// "pxLimit": "",
// "pxSpread": "",
// "pxVar": "",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "slTriggerPxType": "",
// "state": "live",
// "sz": "1",
// "szLimit": "",
// "tag": "",
// "tdMode": "isolated",
// "tgtCcy": "",
// "timeInterval": "",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tpTriggerPxType": "",
// "triggerPx": "50000",
// "triggerPxType": "last",
// "triggerTime": "",
// "uly": "BTC-USDT"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-7-days
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-history
* @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 {bool} [params.trigger] True if fetching trigger or conditional orders
* @param {string} [params.ordType] "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"
* @param {string} [params.algoId] Algo ID "'433845797218942976'"
* @param {int} [params.until] timestamp in ms to fetch orders for
* @param {boolean} [params.trailing] set to true if you want to fetch trailing orders
* @returns {object} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut 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("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut type_var: Value = Value::Null;
let mut query: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchCanceledOrders".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); query = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("instType".to_string()), self.convert_to_instrument_type(type_var.clone()));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 100, max 100
}
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("canceled".to_string()));
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchCanceledOrders", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut algoOrderTypes: Value = self.safe_dict_k(self.options.clone(), "algoOrderTypes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options.clone(), "method", &[Value::Str("privateGetTradeOrdersHistory".to_string())]);
let mut method: Value = self.safe_string_k(params.clone(), "method", &[defaultMethod.clone()]);
let mut ordType: Value = self.safe_string_k(params.clone(), "ordType", &[]);
let mut trigger: Value = self.safe_value2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
let mut isTrigger: bool = is_true(&(!is_equal(&trigger, &Value::Null))) && is_true(&(!is_equal(&trigger, &Value::Bool(false))));
if is_equal(&trailing, &Value::Bool(true)) {
method = Value::Str("privateGetTradeOrdersAlgoHistory".to_string());
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("move_order_stop".to_string()));
} else if is_true(&isTrigger) || is_true(&(is_true(&(!is_equal(&ordType, &Value::Null))) && is_true(&(Value::Bool(in_op(&algoOrderTypes, &ordType)))))) {
method = Value::Str("privateGetTradeOrdersAlgoHistory".to_string());
let mut algoId: Value = self.safe_string_k(params.clone(), "algoId", &[]);
if !is_equal(&algoId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("algoId".to_string()), algoId.clone());
params = self.omit(params.clone(), Value::Str("algoId".to_string()), &[]);
}
if is_true(&isTrigger) {
if is_equal(&ordType, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchCanceledOrders() requires an \"ordType\" string parameter, \"conditional\", \"oco\", \"trigger\", \"move_order_stop\", \"iceberg\", or \"twap\"".to_string()))));
}
}
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("begin".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(query.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end".to_string()), until.clone());
query = self.omit(query.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
}
}
let mut send: Value = self.omit(query.clone(), Value::List(vec![Value::Str("method".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), Value::Str("trailing".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privateGetTradeOrdersAlgoHistory".to_string())) {
let __ws_arg_41 = self.extend(request.clone(), &[send.clone()]);
response = self.private_get_trade_orders_algo_history(&[__ws_arg_41]).await;
} else {
let __ws_arg_42 = self.extend(request.clone(), &[send.clone()]);
response = self.private_get_trade_orders_history(&[__ws_arg_42]).await;
}
//
// {
// "code": "0",
// "data": [
// {
// "accFillSz": "0",
// "avgPx": "",
// "cTime": "1644037822494",
// "category": "normal",
// "ccy": "",
// "clOrdId": "",
// "fee": "0",
// "feeCcy": "BTC",
// "fillPx": "",
// "fillSz": "0",
// "fillTime": "",
// "instId": "BTC-USDT",
// "instType": "SPOT",
// "lever": "",
// "ordId": "410059580352409602",
// "ordType": "limit",
// "pnl": "0",
// "posSide": "net",
// "px": "30000",
// "rebate": "0",
// "rebateCcy": "USDT",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "slTriggerPxType": "",
// "source": "",
// "state": "canceled",
// "sz": "0.0005452",
// "tag": "",
// "tdMode": "cash",
// "tgtCcy": "",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tpTriggerPxType": "",
// "tradeId": "",
// "uTime": "1644038165667"
// }
// ],
// "msg": ""
// }
//
// Algo order
//
// {
// "code": "0",
// "data": [
// {
// "activePx": "",
// "activePxType": "",
// "actualPx": "",
// "actualSide": "buy",
// "actualSz": "0",
// "algoId": "433845797218942976",
// "cTime": "1649708898523",
// "callbackRatio": "",
// "callbackSpread": "",
// "ccy": "",
// "ctVal": "0.01",
// "instId": "BTC-USDT-SWAP",
// "instType": "SWAP",
// "last": "39950.4",
// "lever": "125",
// "moveTriggerPx": "",
// "notionalUsd": "1592.1760000000002",
// "ordId": "",
// "ordPx": "29000",
// "ordType": "trigger",
// "posSide": "long",
// "pxLimit": "",
// "pxSpread": "",
// "pxVar": "",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "slTriggerPxType": "",
// "state": "canceled",
// "sz": "4",
// "szLimit": "",
// "tag": "",
// "tdMode": "isolated",
// "tgtCcy": "",
// "timeInterval": "",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tpTriggerPxType": "",
// "triggerPx": "30000",
// "triggerPxType": "last",
// "triggerTime": "",
// "uly": "BTC-USDT"
// },
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-7-days
* @see https://www.okx.com/docs-v5/en/#order-book-trading-algo-trading-get-algo-order-history
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-history-last-3-months
* @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 {bool} [params.trigger] True if fetching trigger or conditional orders
* @param {string} [params.ordType] "conditional", "oco", "trigger", "move_order_stop", "iceberg", or "twap"
* @param {string} [params.algoId] Algo ID "'433845797218942976'"
* @param {int} [params.until] timestamp 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)
* @param {string} [params.method] method to be used, either 'privateGetTradeOrdersHistory', 'privateGetTradeOrdersHistoryArchive' or 'privateGetTradeOrdersAlgoHistory' default is 'privateGetTradeOrdersHistory'
* @param {boolean} [params.trailing] set to true if you want to fetch trailing orders
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(100);
let mut paginate: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchClosedOrders".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("fetchClosedOrders".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
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("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let mut type_var: Value = Value::Null;
let mut query: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchClosedOrders".to_string()), &[market.clone(), params.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); query = get_value(&__destr_tmp, &Value::Int(1)); }
add_element_to_object(&mut request, &Value::Str("instType".to_string()), self.convert_to_instrument_type(type_var.clone()));
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &maxLimit)); // default 100, max 100
}
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchClosedOrders", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut algoOrderTypes: Value = self.safe_dict_k(self.options.clone(), "algoOrderTypes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut defaultMethod: Value = self.safe_string_k(options.clone(), "method", &[Value::Str("privateGetTradeOrdersHistory".to_string())]);
let mut method: Value = self.safe_string_k(params.clone(), "method", &[defaultMethod.clone()]);
let mut ordType: Value = self.safe_string_k(params.clone(), "ordType", &[]);
let mut trigger: Value = self.safe_bool2(params.clone(), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), &[]);
let mut trailing: Value = self.safe_bool_k(params.clone(), "trailing", &[Value::Bool(false)]);
if is_true(&(is_equal(&trailing, &Value::Bool(true)))) || is_true(&(is_equal(&trigger, &Value::Bool(true)))) || is_true(&(is_true(&(!is_equal(&ordType, &Value::Null))) && is_true(&(Value::Bool(in_op(&algoOrderTypes, &ordType)))))) {
method = Value::Str("privateGetTradeOrdersAlgoHistory".to_string());
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("effective".to_string()));
}
if is_equal(&trailing, &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("move_order_stop".to_string()));
} else if is_equal(&trigger, &Value::Bool(true)) {
if is_equal(&ordType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("ordType".to_string()), Value::Str("trigger".to_string()));
}
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("begin".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(query.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end".to_string()), until.clone());
query = self.omit(query.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
}
add_element_to_object(&mut request, &Value::Str("state".to_string()), Value::Str("filled".to_string()));
}
let mut send: Value = self.omit(query.clone(), Value::List(vec![Value::Str("method".to_string()), Value::Str("stop".to_string()), Value::Str("trigger".to_string()), Value::Str("trailing".to_string())]), &[]);
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privateGetTradeOrdersAlgoHistory".to_string())) {
let __ws_arg_43 = self.extend(request.clone(), &[send.clone()]);
response = self.private_get_trade_orders_algo_history(&[__ws_arg_43]).await;
} else if is_equal(&method, &Value::Str("privateGetTradeOrdersHistoryArchive".to_string())) {
let __ws_arg_44 = self.extend(request.clone(), &[send.clone()]);
response = self.private_get_trade_orders_history_archive(&[__ws_arg_44]).await;
} else {
let __ws_arg_45 = self.extend(request.clone(), &[send.clone()]);
response = self.private_get_trade_orders_history(&[__ws_arg_45]).await;
}
//
// {
// "code": "0",
// "data": [
// {
// "accFillSz": "0",
// "avgPx": "",
// "cTime": "1621910749815",
// "category": "normal",
// "ccy": "",
// "clOrdId": "",
// "fee": "0",
// "feeCcy": "ETH",
// "fillPx": "",
// "fillSz": "0",
// "fillTime": "",
// "instId": "ETH-USDT",
// "instType": "SPOT",
// "lever": "",
// "ordId": "317251910906576896",
// "ordType": "limit",
// "pnl": "0",
// "posSide": "net",
// "px": "2000",
// "rebate": "0",
// "rebateCcy": "USDT",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "state": "live",
// "sz": "0.001",
// "tag": "",
// "tdMode": "cash",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tradeId": "",
// "uTime": "1621910749815"
// }
// ],
// "msg": ""
// }
//
// Algo order
//
// {
// "code": "0",
// "data": [
// {
// "activePx": "",
// "activePxType": "",
// "actualPx": "",
// "actualSide": "buy",
// "actualSz": "0",
// "algoId": "433845797218942976",
// "cTime": "1649708898523",
// "callbackRatio": "",
// "callbackSpread": "",
// "ccy": "",
// "ctVal": "0.01",
// "instId": "BTC-USDT-SWAP",
// "instType": "SWAP",
// "last": "39950.4",
// "lever": "125",
// "moveTriggerPx": "",
// "notionalUsd": "1592.1760000000002",
// "ordId": "",
// "ordPx": "29000",
// "ordType": "trigger",
// "posSide": "long",
// "pxLimit": "",
// "pxSpread": "",
// "pxVar": "",
// "side": "buy",
// "slOrdPx": "",
// "slTriggerPx": "",
// "slTriggerPxType": "",
// "state": "effective",
// "sz": "4",
// "szLimit": "",
// "tag": "",
// "tdMode": "isolated",
// "tgtCcy": "",
// "timeInterval": "",
// "tpOrdPx": "",
// "tpTriggerPx": "",
// "tpTriggerPxType": "",
// "triggerPx": "30000",
// "triggerPxType": "last",
// "triggerTime": "",
// "uly": "BTC-USDT"
// },
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_orders(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchMyTrades
* @description fetch all trades made by the user
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-transaction-details-last-3-months
* @param {string} symbol unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] Timestamp in ms of the latest time to retrieve trades for
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).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("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("begin".to_string()), since.clone());
}
{ 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)); }
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
add_element_to_object(&mut request, &Value::Str("instType".to_string()), self.convert_to_instrument_type(type_var.clone()));
if is_true(&(!is_equal(&limit, &Value::Null))) && is_true(&(is_equal(&since, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 100, max 100
}
let __ws_arg_46 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.private_get_trade_fills_history(&[__ws_arg_46]).await;
//
// {
// "code": "0",
// "data": [
// {
// "side": "buy",
// "fillSz": "0.007533",
// "fillPx": "2654.98",
// "fee": "-0.000007533",
// "ordId": "317321390244397056",
// "instType": "SPOT",
// "instId": "ETH-USDT",
// "clOrdId": "",
// "posSide": "net",
// "billId": "317321390265368576",
// "tag": "0",
// "execType": "T",
// "tradeId": "107601752",
// "feeCcy": "ETH",
// "ts": "1621927314985"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone(), query.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-transaction-details-last-3-months
* @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.insert("ordId".to_string(), id.clone());
m
});
let __ws_arg_47 = self.extend(request.clone(), &[params.clone()]);
return self.fetch_my_trades(&[symbol.clone(), since.clone(), limit.clone(), __ws_arg_47]).await;
Value::Null
}
/*
* @method
* @name okx#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered balance of the user
* @see https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-7-days
* @see https://www.okx.com/docs-v5/en/#rest-api-account-get-bills-details-last-3-months
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-asset-bills-details
* @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 {string} [params.marginMode] 'cross' or 'isolated'
* @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 [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_dynamic(Value::Str("fetchLedger".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchLedger", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut method: Value = self.safe_string_k(options.clone(), "method", &[]);
method = self.safe_string_k(params.clone(), "method", &[method.clone()]);
params = self.omit(params.clone(), Value::Str("method".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchLedger".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
marginMode = self.safe_string_k(params.clone(), "mgnMode", &[]);
}
if !is_equal(&method, &Value::Str("privateGetAssetBills".to_string())) {
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("mgnMode".to_string()), marginMode.clone());
}
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchLedger".to_string()), &[Value::Null, params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
if !is_equal(&type_var, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("instType".to_string()), self.convert_to_instrument_type(type_var.clone()));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
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("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
{ 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)); }
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privateGetAccountBillsArchive".to_string())) {
let __ws_arg_48 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_account_bills_archive(&[__ws_arg_48]).await;
} else if is_equal(&method, &Value::Str("privateGetAssetBills".to_string())) {
let __ws_arg_49 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_asset_bills(&[__ws_arg_49]).await;
} else {
let __ws_arg_50 = self.extend(request.clone(), &[query.clone()]);
response = self.private_get_account_bills(&[__ws_arg_50]).await;
}
//
// privateGetAccountBills, privateGetAccountBillsArchive
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "bal": "0.0000819307998198",
// "balChg": "-664.2679586599999802",
// "billId": "310394313544966151",
// "ccy": "USDT",
// "fee": "0",
// "from": "",
// "instId": "LTC-USDT",
// "instType": "SPOT",
// "mgnMode": "cross",
// "notes": "",
// "ordId": "310394313519800320",
// "pnl": "0",
// "posBal": "0",
// "posBalChg": "0",
// "subType": "2",
// "sz": "664.26795866",
// "to": "",
// "ts": "1620275771196",
// "type": "2"
// }
// ]
// }
//
// privateGetAssetBills
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "billId": "12344",
// "ccy": "BTC",
// "balChg": "2",
// "bal": "12",
// "type": "1",
// "ts": "1597026383085"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_ledger(data.clone(), &[currency.clone(), since.clone(), limit.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("1".to_string(), Value::Str("transfer".to_string()));
m.insert("2".to_string(), Value::Str("trade".to_string()));
m.insert("3".to_string(), Value::Str("trade".to_string()));
m.insert("4".to_string(), Value::Str("rebate".to_string()));
m.insert("5".to_string(), Value::Str("trade".to_string()));
m.insert("6".to_string(), Value::Str("transfer".to_string()));
m.insert("7".to_string(), Value::Str("trade".to_string()));
m.insert("8".to_string(), Value::Str("fee".to_string()));
m.insert("9".to_string(), Value::Str("trade".to_string()));
m.insert("10".to_string(), Value::Str("trade".to_string()));
m.insert("11".to_string(), Value::Str("trade".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.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);
//
// privateGetAccountBills, privateGetAccountBillsArchive
//
// {
// "bal": "0.0000819307998198",
// "balChg": "-664.2679586599999802",
// "billId": "310394313544966151",
// "ccy": "USDT",
// "fee": "0",
// "from": "",
// "instId": "LTC-USDT",
// "instType": "SPOT",
// "mgnMode": "cross",
// "notes": "",
// "ordId": "310394313519800320",
// "pnl": "0",
// "posBal": "0",
// "posBalChg": "0",
// "subType": "2",
// "sz": "664.26795866",
// "to": "",
// "ts": "1620275771196",
// "type": "2"
// }
//
// privateGetAssetBills
//
// {
// "billId": "12344",
// "ccy": "BTC",
// "balChg": "2",
// "bal": "12",
// "type": "1",
// "ts": "1597026383085"
// }
//
let mut currencyId: Value = self.safe_string_k(item.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer_k(item.clone(), "ts", &[]);
let mut feeCostString: Value = self.safe_string_k(item.clone(), "fee", &[]);
let mut fee: Value = Value::Null;
if !is_equal(&feeCostString, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), self.parse_number(crate::precise::Precise::stringNeg(&feeCostString), &[]));
m.insert("currency".to_string(), code.clone());
m
});
}
let mut marketId: Value = self.safe_string_k(item.clone(), "instId", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[Value::Null, Value::Str("-".to_string())]);
return self.safe_ledger_entry(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string_k(item.clone(), "billId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("account".to_string(), Value::Null);
m.insert("referenceId".to_string(), self.safe_string_k(item.clone(), "ordId", &[]));
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("symbol".to_string(), symbol.clone());
m.insert("amount".to_string(), self.safe_number_k(item.clone(), "balChg", &[]));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), self.safe_number_k(item.clone(), "bal", &[]));
m.insert("status".to_string(), Value::Str("ok".to_string()));
m.insert("fee".to_string(), fee.clone());
m
}), &[currency.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);
//
// {
// "addr": "okbtothemoon",
// "memo": "971668", // may be missing
// "tag":"52055", // may be missing
// "pmtId": "", // may be missing
// "ccy": "BTC",
// "to": "6", // 1 SPOT, 3 FUTURES, 6 FUNDING, 9 SWAP, 12 OPTION, 18 Unified account
// "selected": true
// }
//
// {
// "ccy":"usdt-erc20",
// "to":"6",
// "addr":"0x696abb81974a8793352cbd33aadcf78eda3cfdfa",
// "selected":true
// }
//
// {
// "chain": "ETH-OKExChain",
// "addrEx": { "comment": "6040348" }, // some currencies like TON may have this field,
// "ctAddr": "72315c",
// "ccy": "ETH",
// "to": "6",
// "addr": "0x1c9f2244d1ccaa060bd536827c18925db10db102",
// "selected": true
// }
//
let mut address: Value = self.safe_string_k(depositAddress.clone(), "addr", &[]);
let mut tag: Value = self.safe_string_n(depositAddress.clone(), Value::List(vec![Value::Str("tag".to_string()), Value::Str("pmtId".to_string()), Value::Str("memo".to_string())]), &[]);
if is_equal(&tag, &Value::Null) {
let mut addrEx: Value = self.safe_dict_k(depositAddress.clone(), "addrEx", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
tag = self.safe_string_k(addrEx.clone(), "comment", &[]);
}
let mut currencyId: Value = self.safe_string_k(depositAddress.clone(), "ccy", &[]);
currency = self.safe_currency(currencyId.clone(), &[currency.clone()]);
let mut code: Value = get_value(¤cy, &Value::Str("code".to_string()));
let mut chain: Value = self.safe_string_k(depositAddress.clone(), "chain", &[]);
let mut networks: Value = self.safe_dict_k(currency.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networksById: Value = self.index_by(networks.clone(), Value::Str("id".to_string()));
let mut networkData: Value = ternary(is_true(&(is_equal(&chain, &Value::Null))), Value::Null, self.safe_dict(networksById.clone(), chain.clone(), &[]));
// inconsistent naming responses from exchange
// with respect to network naming provided in currency info vs address chain-names and ids
//
// response from address endpoint:
// {
// "chain": "USDT-Polygon",
// "ctAddr": "",
// "ccy": "USDT",
// "to":"6" ,
// "addr": "0x1903441e386cc49d937f6302955b5feb4286dcfa",
// "selected": true
// }
// network information from currency['networks'] field:
// Polygon: {
// info: {
// canDep: false,
// canInternal: false,
// canWd: false,
// ccy: 'USDT',
// chain: 'USDT-Polygon-Bridge',
// mainNet: false,
// maxFee: '26.879528',
// minFee: '13.439764',
// minWd: '0.001',
// name: ''
// },
// id: 'USDT-Polygon-Bridge',
// network: 'Polygon',
// active: false,
// deposit: false,
// withdraw: false,
// fee: 13.439764,
// precision: undefined,
// limits: {
// withdraw: {
// min: 0.001,
// max: undefined
// }
// }
// },
//
if is_equal(&chain, &Value::Str("USDT-Polygon".to_string())) {
networkData = self.safe_dict2(networksById.clone(), Value::Str("USDT-Polygon-Bridge".to_string()), Value::Str("USDT-Polygon".to_string()), &[]);
}
let mut network: Value = self.safe_string_k(networkData.clone(), "network", &[]);
let mut networkCode: Value = self.network_id_to_code(&[network.clone(), code.clone()]);
self.check_address(&[address.clone()]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), networkCode.clone());
m.insert("address".to_string(), address.clone());
m.insert("tag".to_string(), tag.clone());
m
});
Value::Null
}
/*
* @method
* @name okx#fetchDepositAddressesByNetwork
* @description fetch a dictionary of addresses for a currency, indexed by network
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-deposit-address
* @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("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
let __ws_arg_51 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_deposit_address(&[__ws_arg_51]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "addr": "okbtothemoon",
// "memo": "971668", // may be missing
// "tag":"52055", // may be missing
// "pmtId": "", // may be missing
// "ccy": "BTC",
// "to": "6", // 1 SPOT, 3 FUTURES, 6 FUNDING, 9 SWAP, 12 OPTION, 18 Unified account
// "selected": true
// },
// // {"ccy":"usdt-erc20","to":"6","addr":"0x696abb81974a8793352cbd33aadcf78eda3cfdfa","selected":true},
// // {"ccy":"usdt-trc20","to":"6","addr":"TRrd5SiSZrfQVRKm4e9SRSbn2LNTYqCjqx","selected":true},
// // {"ccy":"usdt_okexchain","to":"6","addr":"0x696abb81974a8793352cbd33aadcf78eda3cfdfa","selected":true},
// // {"ccy":"usdt_kip20","to":"6","addr":"0x696abb81974a8793352cbd33aadcf78eda3cfdfa","selected":true},
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut filtered: Value = self.filter_by(data.clone(), Value::Str("selected".to_string()), Value::Bool(true), &[]);
let mut parsed: Value = self.parse_deposit_addresses(filtered.clone(), &[Value::List(vec![get_value(¤cy, &Value::Str("code".to_string()))]), Value::Bool(false)]);
return self.index_by(parsed.clone(), Value::Str("network".to_string()));
Value::Null
}
/*
* @method
* @name okx#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-deposit-address
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] the network name for the deposit address
* @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 rawNetwork: Value = self.safe_string_k(params.clone(), "network", &[]); // some networks are like "Dora Vota Mainnet"
params = self.omit(params.clone(), Value::Str("network".to_string()), &[]);
code = self.safe_currency_code(code.clone(), &[]);
let mut network: Value = self.network_id_to_code(&[rawNetwork.clone(), code.clone()]);
let mut responseRaw: Value = self.fetch_deposit_addresses_by_network(code.clone(), &[params.clone()]).await;
let mut response: Value = responseRaw.clone();
if !is_equal(&network, &Value::Null) {
let mut result: Value = self.safe_dict(response.clone(), network.clone(), &[]);
if is_equal(&result, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_address(add(&add(&add(&add(&self.id, &Value::Str(" fetchDepositAddress() cannot find ".to_string())), &network), &Value::Str(" deposit address for ".to_string())), &code)));
}
return result;
}
let mut codeNetwork: Value = self.network_id_to_code(&[code.clone(), code.clone()]);
if is_true(&(!is_equal(&codeNetwork, &Value::Null))) && is_true(&(Value::Bool(in_op(&response, &codeNetwork)))) {
return get_value(&response, &codeNetwork);
}
// if the network is not specified, return the first address
let mut keys: Value = object_keys(&response);
let mut first: Value = self.safe_string(keys.clone(), Value::Int(0), &[Value::Str("".to_string())]);
return self.safe_dict(response.clone(), first.clone(), &[]);
Value::Null
}
/*
* @method
* @name okx#withdraw
* @description make a withdrawal
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-withdrawal
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {string} tag
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut tag = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
{ let __destr_tmp = self.handle_withdraw_tag_and_params(tag.clone(), params.clone()); tag = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
self.check_address(&[address.clone()]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
if is_true(&(!is_equal(&tag, &Value::Null))) && is_true(&(is_greater_than(&get_array_length(&tag), &Value::Int(0)))) {
address = add(&add(&address, &Value::Str(":".to_string())), &tag);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("toAddr".to_string(), address.clone());
m.insert("dest".to_string(), Value::Str("4".to_string()));
m.insert("amt".to_string(), self.number_to_string(amount.clone()));
m
});
let mut network: Value = self.safe_string_k(params.clone(), "network", &[]); // this line allows the user to specify either ERC20 or ETH
if !is_equal(&network, &Value::Null) {
let mut networks: Value = self.safe_dict_k(self.options.clone(), "networks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
network = self.safe_string(networks.clone(), to_upper(&network), &[network.clone()]); // handle ETH>ERC20 alias
add_element_to_object(&mut request, &Value::Str("chain".to_string()), add(&add(&get_value(¤cy, &Value::Str("id".to_string())), &Value::Str("-".to_string())), &network));
params = self.omit(params.clone(), Value::Str("network".to_string()), &[]);
}
let mut fee: Value = self.safe_string_k(params.clone(), "fee", &[]);
if is_equal(&fee, &Value::Null) {
let mut currencies: Value = self.fetch_currencies(&[]).await;
{ let __t = self.map_to_safe_map(self.deep_extend(self.currencies.clone(), &[currencies.clone()])); self.currencies = __t; }
let mut networkCodeResolved: Value = self.network_id_to_code(&[network.clone(), get_value(¤cy, &Value::Str("code".to_string()))]);
let mut targetNetwork: Value = ternary(is_true(&(is_equal(&networkCodeResolved, &Value::Null))), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), self.safe_dict(get_value(¤cy, &Value::Str("networks".to_string())), networkCodeResolved.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]));
fee = self.safe_string_k(targetNetwork.clone(), "fee", &[]);
if is_equal(&fee, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" withdraw() requires a \"fee\" string parameter, network transaction fee must be ≥ 0. Withdrawals to OKCoin or OKX are fee-free, please set \"0\". Withdrawing to external digital asset address requires network transaction fee.".to_string()))));
}
}
add_element_to_object(&mut request, &Value::Str("fee".to_string()), self.number_to_string(fee.clone())); // withdrawals to OKCoin or OKX are fee-free, please set 0
let mut query: Value = self.omit(params.clone(), Value::List(vec![Value::Str("fee".to_string())]), &[]);
let __ws_arg_52 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.private_post_asset_withdrawal(&[__ws_arg_52]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "amt": "0.1",
// "wdId": "67485",
// "ccy": "BTC"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut transaction: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
return self.parse_transaction(transaction.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchDeposits
* @description fetch all deposits made to an account
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-get-deposit-history
* @param {string} code unified currency code
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of deposits structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch 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_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_dynamic(Value::Str("fetchDeposits".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).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("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), crate::runtime::Math::max(&subtract(&since, &Value::Int(1)), &Value::Int(0)));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 100, max 100
}
{ let __destr_tmp = self.handle_until_option(Value::Str("after".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_53 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_deposit_history(&[__ws_arg_53]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "amt": "0.01044408",
// "txId": "1915737_3_0_0_asset",
// "ccy": "BTC",
// "from": "13801825426",
// "to": "",
// "ts": "1597026383085",
// "state": "2",
// "depId": "4703879"
// },
// {
// "amt": "491.6784211",
// "txId": "1744594_3_184_0_asset",
// "ccy": "OKB",
// "from": "",
// "to": "",
// "ts": "1597026383085",
// "state": "2",
// "depId": "4703809"
// },
// {
// "amt": "223.18782496",
// "txId": "6d892c669225b1092c780bf0da0c6f912fc7dc8f6b8cc53b003288624c",
// "ccy": "USDT",
// "from": "",
// "to": "39kK4XvgEuM7rX9frgyHoZkWqx4iKu1spD",
// "ts": "1597026383085",
// "state": "2",
// "depId": "4703779"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchDeposit
* @description fetch data on a currency deposit via the deposit id
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-get-deposit-history
* @param {string} id deposit id
* @param {string} code filter by currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_deposit(&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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("depId".to_string(), id.clone());
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("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let __ws_arg_54 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_deposit_history(&[__ws_arg_54]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
let mut deposit: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(deposit.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-get-withdrawal-history
* @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_dynamic(Value::Str("fetchWithdrawals".to_string()), &[code.clone(), since.clone(), limit.clone(), params.clone()]).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("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), crate::runtime::Math::max(&subtract(&since, &Value::Int(1)), &Value::Int(0)));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone()); // default 100, max 100
}
{ let __destr_tmp = self.handle_until_option(Value::Str("after".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_55 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_withdrawal_history(&[__ws_arg_55]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "amt": "0.094",
// "wdId": "4703879",
// "fee": "0.01000000eth",
// "txId": "0x62477bac6509a04512819bb1455e923a60dea5966c7caeaa0b24eb8fb0432b85",
// "ccy": "ETH",
// "from": "13426335357",
// "to": "0xA41446125D0B5b6785f6898c9D67874D763A1519",
// "ts": "1597026383085",
// "state": "2"
// },
// {
// "amt": "0.01",
// "wdId": "4703879",
// "fee": "0.00000000btc",
// "txId": "",
// "ccy": "BTC",
// "from": "13426335357",
// "to": "13426335357",
// "ts": "1597026383085",
// "state": "2"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_transactions(data.clone(), &[currency.clone(), since.clone(), limit.clone(), params.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchWithdrawal
* @description fetch data on a currency withdrawal via the withdrawal id
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-get-withdrawal-history
* @param {string} id withdrawal id
* @param {string} code unified currency code of the currency withdrawn, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn fetch_withdrawal(&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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("wdId".to_string(), id.clone());
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("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let __ws_arg_56 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_withdrawal_history(&[__ws_arg_56]).await;
//
// {
// "code": "0",
// "data": [
// {
// "chain": "USDT-TRC20",
// "clientId": '',
// "fee": "0.8",
// "ccy": "USDT",
// "amt": "54.561",
// "txId": "00cff6ec7fa7c7d7d184bd84e82b9ff36863f07c0421188607f87dfa94e06b70",
// "from": "example@email.com",
// "to": "TEY6qjnKDyyq5jDc3DJizWLCdUySrpQ4yp",
// "state": "2",
// "ts": "1641376485000",
// "wdId": "25147041"
// }
// ],
// "msg": ''
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut withdrawal: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transaction(withdrawal.clone(), &[]);
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
//
// deposit statuses
//
// {
// "0": "waiting for confirmation",
// "1": "deposit credited",
// "2": "deposit successful"
// }
//
// withdrawal statuses
//
// {
// '-3': "pending cancel",
// "-2": "canceled",
// "-1": "failed",
// "0": "pending",
// "1": "sending",
// "2": "sent",
// "3": "awaiting email verification",
// "4": "awaiting manual verification",
// "5": "awaiting identity verification"
// }
//
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("-3".to_string(), Value::Str("pending".to_string()));
m.insert("-2".to_string(), Value::Str("canceled".to_string()));
m.insert("-1".to_string(), Value::Str("failed".to_string()));
m.insert("0".to_string(), Value::Str("pending".to_string()));
m.insert("1".to_string(), Value::Str("pending".to_string()));
m.insert("2".to_string(), Value::Str("ok".to_string()));
m.insert("3".to_string(), Value::Str("pending".to_string()));
m.insert("4".to_string(), Value::Str("pending".to_string()));
m.insert("5".to_string(), Value::Str("pending".to_string()));
m.insert("6".to_string(), Value::Str("pending".to_string()));
m.insert("7".to_string(), Value::Str("pending".to_string()));
m.insert("8".to_string(), Value::Str("pending".to_string()));
m.insert("9".to_string(), Value::Str("pending".to_string()));
m.insert("10".to_string(), Value::Str("pending".to_string()));
m.insert("12".to_string(), Value::Str("pending".to_string()));
m.insert("15".to_string(), Value::Str("pending".to_string()));
m.insert("16".to_string(), Value::Str("pending".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
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);
//
// withdraw
//
// {
// "amt": "0.1",
// "wdId": "67485",
// "ccy": "BTC"
// }
//
// fetchWithdrawals
//
// {
// "amt": "0.094",
// "wdId": "4703879",
// "fee": "0.01000000eth",
// "txId": "0x62477bac6509a04512819bb1455e923a60dea5966c7caeaa0b24eb8fb0432b85",
// "ccy": "ETH",
// "from": "13426335357",
// "to": "0xA41446125D0B5b6785f6898c9D67874D763A1519",
// "tag",
// "pmtId",
// "memo",
// "ts": "1597026383085",
// "state": "2"
// }
//
// fetchDeposits
//
// {
// "amt": "0.01044408",
// "txId": "1915737_3_0_0_asset",
// "ccy": "BTC",
// "from": "13801825426",
// "to": "",
// "ts": "1597026383085",
// "state": "2",
// "depId": "4703879"
// }
//
let mut type_var: Value = Value::Null;
let mut id: Value = Value::Null;
let mut withdrawalId: Value = self.safe_string_k(transaction.clone(), "wdId", &[]);
let mut addressFrom: Value = self.safe_string_k(transaction.clone(), "from", &[]);
let mut addressTo: Value = self.safe_string_k(transaction.clone(), "to", &[]);
let mut address: Value = addressTo.clone();
let mut tagTo: Value = self.safe_string2(transaction.clone(), Value::Str("tag".to_string()), Value::Str("memo".to_string()), &[]);
tagTo = ternary(is_true(&(is_equal(&tagTo, &Value::Null))), self.safe_string_k(transaction.clone(), "pmtId", &[]), self.safe_string2(transaction.clone(), Value::Str("pmtId".to_string()), tagTo.clone(), &[]));
if !is_equal(&withdrawalId, &Value::Null) {
type_var = Value::Str("withdrawal".to_string());
id = withdrawalId.clone();
} else {
// the payment_id will appear on new deposits but appears to be removed from the response after 2 months
id = self.safe_string_k(transaction.clone(), "depId", &[]);
type_var = Value::Str("deposit".to_string());
}
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut network: Value = Value::Null;
let mut chain: Value = self.safe_string_k(transaction.clone(), "chain", &[]);
if !is_equal(&chain, &Value::Null) {
let mut chainParts: Value = split(&chain, &Value::Str("-".to_string()));
let mut networkParts: Value = self.array_slice(chainParts.clone(), Value::Int(1), &[]);
let mut networkId: Value = join(&networkParts, &Value::Str("-".to_string()));
if !is_equal(&networkId, &Value::Null) {
network = self.network_id_to_code(&[networkId.clone(), code.clone()]);
}
}
let mut amount: Value = self.safe_number_k(transaction.clone(), "amt", &[]);
let mut status: Value = self.parse_transaction_status(self.safe_string_k(transaction.clone(), "state", &[]));
let mut txid: Value = self.safe_string_k(transaction.clone(), "txId", &[]);
let mut timestamp: Value = self.safe_integer_k(transaction.clone(), "ts", &[]);
let mut feeCost: Value = Value::Null;
if is_equal(&type_var, &Value::Str("deposit".to_string())) {
feeCost = Value::Int(0);
} else {
feeCost = self.safe_number_k(transaction.clone(), "fee", &[]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), id.clone());
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("network".to_string(), network.clone());
m.insert("addressFrom".to_string(), addressFrom.clone());
m.insert("addressTo".to_string(), addressTo.clone());
m.insert("address".to_string(), address.clone());
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tagTo".to_string(), tagTo.clone());
m.insert("tag".to_string(), tagTo.clone());
m.insert("status".to_string(), status.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("updated".to_string(), Value::Null);
m.insert("txid".to_string(), txid.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("cost".to_string(), feeCost.clone());
m
}));
m
});
Value::Null
}
/*
* @method
* @name okx#fetchLeverage
* @description fetch the set leverage for a market
* @see https://www.okx.com/docs-v5/en/#rest-api-account-get-leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] 'cross' or 'isolated'
* @returns {object} 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 marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchLeverage".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
marginMode = self.safe_string_k(params.clone(), "mgnMode", &[Value::Str("cross".to_string())]); // cross as default marginMode
}
if is_true(&(!is_equal(&marginMode, &Value::Str("cross".to_string())))) && is_true(&(!is_equal(&marginMode, &Value::Str("isolated".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchLeverage() requires a marginMode parameter that must be either cross or isolated".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("mgnMode".to_string(), marginMode.clone());
m
});
let __ws_arg_57 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_account_leverage_info(&[__ws_arg_57]).await;
//
// {
// "code": "0",
// "data": [
// {
// "instId": "BTC-USDT-SWAP",
// "lever": "5.00000000",
// "mgnMode": "isolated",
// "posSide": "net"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_leverage(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_leverage(&self, mut leverage: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
let mut marketId: Value = Value::Null;
let mut marginMode: Value = Value::Null;
let mut longLeverage: Value = Value::Null;
let mut shortLeverage: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_998: bool = true;
while { if !__for_first_998 { i = add(&i, &Value::Int(1)); } __for_first_998 = false; is_less_than(&i, &get_array_length(&leverage)) } {
let mut entry: Value = get_value(&leverage, &i);
let mut entry: Value = get_value(&leverage, &i);
marginMode = self.safe_string_lower(entry.clone(), Value::Str("mgnMode".to_string()), &[]);
marketId = self.safe_string_k(entry.clone(), "instId", &[]);
let mut positionSide: Value = self.safe_string_lower(entry.clone(), Value::Str("posSide".to_string()), &[]);
if is_equal(&positionSide, &Value::Str("long".to_string())) {
longLeverage = self.safe_integer_k(entry.clone(), "lever", &[]);
} else if is_equal(&positionSide, &Value::Str("short".to_string())) {
shortLeverage = self.safe_integer_k(entry.clone(), "lever", &[]);
} else {
longLeverage = self.safe_integer_k(entry.clone(), "lever", &[]);
shortLeverage = self.safe_integer_k(entry.clone(), "lever", &[]);
}
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), leverage.clone());
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("longLeverage".to_string(), longLeverage.clone());
m.insert("shortLeverage".to_string(), shortLeverage.clone());
m
});
Value::Null
}
/*
* @method
* @name okx#fetchPosition
* @description fetch data on a single open contract trade position
* @see https://www.okx.com/docs-v5/en/#rest-api-account-get-positions
* @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.instType] MARGIN, SWAP, FUTURES, OPTION
* @returns {object} a [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchPosition".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&type_var, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("instType".to_string()), self.convert_to_instrument_type(type_var.clone()));
}
let __ws_arg_58 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.private_get_account_positions(&[__ws_arg_58]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "adl": "1",
// "availPos": "1",
// "avgPx": "2566.31",
// "cTime": "1619507758793",
// "ccy": "ETH",
// "deltaBS": "",
// "deltaPA": "",
// "gammaBS": "",
// "gammaPA": "",
// "imr": "",
// "instId": "ETH-USD-210430",
// "instType": "FUTURES",
// "interest": "0",
// "last": "2566.22",
// "lever": "10",
// "liab": "",
// "liabCcy": "",
// "liqPx": "2352.8496681818233",
// "margin": "0.0003896645377994",
// "mgnMode": "isolated",
// "mgnRatio": "11.731726509588816",
// "mmr": "0.0000311811092368",
// "optVal": "",
// "pTime": "1619507761462",
// "pos": "1",
// "posCcy": "",
// "posId": "307173036051017730",
// "posSide": "long",
// "thetaBS": "",
// "thetaPA": "",
// "tradeId": "109844",
// "uTime": "1619507761462",
// "upl": "-0.0000009932766034",
// "uplRatio": "-0.0025490556801078",
// "vegaBS": "",
// "vegaPA": ""
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut position: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
if is_equal(&position, &Value::Null) {
panic!("{}", crate::exchange_errors::null_response(add(&add(&self.id, &Value::Str(" fetchPosition() could not find a position for ".to_string())), &symbol)));
}
return self.parse_position(position.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchPositions
* @see https://www.okx.com/docs-v5/en/#rest-api-account-get-positions
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions-history history
* @description fetch all open positions
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.instType] MARGIN, SWAP, FUTURES, OPTION
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut marketIds: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_999: bool = true;
while { if !__for_first_999 { i = add(&i, &Value::Int(1)); } __for_first_999 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut entry: Value = get_value(&symbols, &i);
let mut entry: Value = get_value(&symbols, &i);
let mut market: Value = self.market(entry.clone());
append_to_array(&mut marketIds, get_value(&market, &Value::Str("id".to_string())));
}
}
let mut marketIdsLength: Value = get_array_length(&marketIds);
if is_greater_than(&marketIdsLength, &Value::Int(0)) {
add_element_to_object(&mut request, &Value::Str("instId".to_string()), join(&marketIds, &Value::Str(",".to_string())));
}
}
let mut fetchPositionsOptions: Value = self.safe_dict_k(self.options.clone(), "fetchPositions", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut method: Value = self.safe_string_k(fetchPositionsOptions.clone(), "method", &[Value::Str("privateGetAccountPositions".to_string())]);
let mut response: Value = Value::Null;
if is_equal(&method, &Value::Str("privateGetAccountPositionsHistory".to_string())) {
let __ws_arg_59 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_account_positions_history(&[__ws_arg_59]).await;
} else {
let __ws_arg_60 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_account_positions(&[__ws_arg_60]).await;
}
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "adl": "1",
// "availPos": "1",
// "avgPx": "2566.31",
// "cTime": "1619507758793",
// "ccy": "ETH",
// "deltaBS": "",
// "deltaPA": "",
// "gammaBS": "",
// "gammaPA": "",
// "imr": "",
// "instId": "ETH-USD-210430",
// "instType": "FUTURES",
// "interest": "0",
// "last": "2566.22",
// "lever": "10",
// "liab": "",
// "liabCcy": "",
// "liqPx": "2352.8496681818233",
// "margin": "0.0003896645377994",
// "mgnMode": "isolated",
// "mgnRatio": "11.731726509588816",
// "mmr": "0.0000311811092368",
// "optVal": "",
// "pTime": "1619507761462",
// "pos": "1",
// "posCcy": "",
// "posId": "307173036051017730",
// "posSide": "long",
// "thetaBS": "",
// "thetaPA": "",
// "tradeId": "109844",
// "uTime": "1619507761462",
// "upl": "-0.0000009932766034",
// "uplRatio": "-0.0025490556801078",
// "vegaBS": "",
// "vegaPA": ""
// }
// ]
// }
//
let mut positions: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1000: bool = true;
while { if !__for_first_1000 { i = add(&i, &Value::Int(1)); } __for_first_1000 = false; is_less_than(&i, &get_array_length(&positions)) } {
append_to_array(&mut result, self.parse_position(get_value(&positions, &i), &[]));
}
}
return self.filter_by_array_positions(result.clone(), Value::Str("symbol".to_string()), &[self.market_symbols(&[symbols.clone()]), Value::Bool(false)]);
Value::Null
}
/*
* @method
* @name okx#fetchPositionsForSymbol
* @see https://www.okx.com/docs-v5/en/#rest-api-account-get-positions
* @description fetch all open positions for specific symbol
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.instType] MARGIN (if needed)
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions_for_symbol(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.fetch_positions(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "adl": "3",
// "availPos": "1",
// "avgPx": "34131.1",
// "cTime": "1627227626502",
// "ccy": "USDT",
// "deltaBS": "",
// "deltaPA": "",
// "gammaBS": "",
// "gammaPA": "",
// "imr": "170.66093041794787",
// "instId": "BTC-USDT-SWAP",
// "instType": "SWAP",
// "interest": "0",
// "last": "34134.4",
// "lever": "2",
// "liab": "",
// "liabCcy": "",
// "liqPx": "12608.959083877446",
// "markPx": "4786.459271773621",
// "margin": "",
// "mgnMode": "cross",
// "mgnRatio": "140.49930117599155",
// "mmr": "1.3652874433435829",
// "notionalUsd": "341.5130010779638",
// "optVal": "",
// "pos": "1",
// "posCcy": "",
// "posId": "339552508062380036",
// "posSide": "long",
// "thetaBS": "",
// "thetaPA": "",
// "tradeId": "98617799",
// "uTime": "1627227626502",
// "upl": "0.0108608358957281",
// "uplRatio": "0.0000636418743944",
// "vegaBS": "",
// "vegaPA": ""
// }
// history
// {
// "cTime":"1708351230102",
// "ccy":"USDT",
// "closeAvgPx":"1.2567",
// "closeTotalPos":"40",
// "direction":"short",
// "fee":"-0.0351036",
// "fundingFee":"0",
// "instId":"SUSHI-USDT-SWAP",
// "instType":"SWAP",
// "lever":"10.0",
// "liqPenalty":"0",
// "mgnMode":"isolated",
// "openAvgPx":"1.2462",
// "openMaxPos":"40",
// "pnl":"-0.42",
// "pnlRatio":"-0.0912982667308618",
// "posId":"666159086676836352",
// "realizedPnl":"-0.4551036",
// "triggerPx":"",
// "type":"2",
// "uTime":"1708354805699",
// "uly":"SUSHI-USDT"
// }
//
let mut marketId: Value = self.safe_string_k(position.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone(), Value::Null, Value::Str("contract".to_string())]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut pos: Value = self.safe_string_k(position.clone(), "pos", &[]); // 'pos' field: One way mode: 0 if position is not open, 1 if open | Two way (hedge) mode: -1 if short, 1 if long, 0 if position is not open
let mut contractsAbs: Value = crate::precise::Precise::stringAbs(&pos);
let mut side: Value = self.safe_string2(position.clone(), Value::Str("posSide".to_string()), Value::Str("direction".to_string()), &[]);
let mut hedged: Value = Value::Bool(!is_equal(&side, &Value::Str("net".to_string())));
let mut contracts: Value = self.parse_number(contractsAbs.clone(), &[]);
if is_equal(&get_value(&market, &Value::Str("margin".to_string())), &Value::Bool(true)) {
// margin position
if is_equal(&side, &Value::Str("net".to_string())) {
let mut posCcy: Value = self.safe_string_k(position.clone(), "posCcy", &[]);
let mut parsedCurrency: Value = self.safe_currency_code(posCcy.clone(), &[]);
if !is_equal(&parsedCurrency, &Value::Null) {
side = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("base".to_string())), &parsedCurrency))), Value::Str("long".to_string()), Value::Str("short".to_string()));
}
}
if is_equal(&side, &Value::Null) {
side = self.safe_string_k(position.clone(), "direction", &[]);
}
} else {
if !is_equal(&pos, &Value::Null) {
if is_equal(&side, &Value::Str("net".to_string())) {
if is_true(&crate::precise::Precise::stringGt(&pos, &Value::Str("0".to_string()))) {
side = Value::Str("long".to_string());
} else if is_true(&crate::precise::Precise::stringLt(&pos, &Value::Str("0".to_string()))) {
side = Value::Str("short".to_string());
} else {
side = Value::Null;
}
}
}
}
let mut contractSize: Value = self.safe_number_k(market.clone(), "contractSize", &[]);
let mut contractSizeString: Value = self.number_to_string(contractSize.clone());
let mut markPriceString: Value = self.safe_string_k(position.clone(), "markPx", &[]);
let mut notionalString: Value = self.safe_string_k(position.clone(), "notionalUsd", &[]);
if is_equal(&get_value(&market, &Value::Str("inverse".to_string())), &Value::Bool(true)) {
notionalString = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(&contractsAbs, &contractSizeString), &markPriceString);
}
let mut notional: Value = self.parse_number(notionalString.clone(), &[]);
let mut marginMode: Value = self.safe_string_k(position.clone(), "mgnMode", &[]);
let mut initialMarginString: Value = Value::Null;
let mut entryPriceString: Value = self.safe_string2(position.clone(), Value::Str("avgPx".to_string()), Value::Str("openAvgPx".to_string()), &[]);
let mut unrealizedPnlString: Value = self.safe_string_k(position.clone(), "upl", &[]);
let mut leverageString: Value = self.safe_string_k(position.clone(), "lever", &[]);
let mut initialMarginPercentage: Value = Value::Null;
let mut collateralString: Value = Value::Null;
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
initialMarginString = self.safe_string_k(position.clone(), "imr", &[]);
collateralString = crate::precise::Precise::stringAdd(&initialMarginString, &unrealizedPnlString);
} else if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
initialMarginPercentage = crate::precise::Precise::stringDiv(&Value::Str("1".to_string()), &leverageString);
collateralString = self.safe_string_k(position.clone(), "margin", &[]);
}
let mut maintenanceMarginString: Value = self.safe_string_k(position.clone(), "mmr", &[]);
let mut maintenanceMargin: Value = self.parse_number(maintenanceMarginString.clone(), &[]);
let mut maintenanceMarginPercentageString: Value = crate::precise::Precise::stringDiv(&maintenanceMarginString, ¬ionalString);
if is_equal(&initialMarginPercentage, &Value::Null) {
initialMarginPercentage = self.parse_number(crate::precise::Precise::stringDivPrec(&initialMarginString, ¬ionalString, &Value::Int(4)), &[]);
} else if is_equal(&initialMarginString, &Value::Null) {
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
let mut initialMarginPercentageString: Value = self.number_to_string(initialMarginPercentage.clone());
initialMarginString = crate::precise::Precise::stringMul(&initialMarginPercentageString, ¬ionalString);
} else {
initialMarginString = crate::precise::Precise::stringDiv(&crate::precise::Precise::stringDiv(&crate::precise::Precise::stringMul(&contractsAbs, &contractSizeString), &entryPriceString), &leverageString);
}
}
let mut rounder: Value = Value::Str("0.00005".to_string()); // round to closest 0.01%
let mut maintenanceMarginPercentage: Value = self.parse_number(crate::precise::Precise::stringDivPrec(&crate::precise::Precise::stringAdd(&maintenanceMarginPercentageString, &rounder), &Value::Str("1".to_string()), &Value::Int(4)), &[]);
let mut liquidationPrice: Value = self.safe_number_k(position.clone(), "liqPx", &[]);
let mut percentageString: Value = self.safe_string_k(position.clone(), "uplRatio", &[]);
let mut percentage: Value = self.parse_number(crate::precise::Precise::stringMul(&percentageString, &Value::Str("100".to_string())), &[]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "cTime", &[]);
let mut marginRatio: Value = self.parse_number(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(), self.safe_string_k(position.clone(), "posId", &[]));
m.insert("symbol".to_string(), symbol.clone());
m.insert("notional".to_string(), notional.clone());
m.insert("marginMode".to_string(), marginMode.clone());
m.insert("liquidationPrice".to_string(), liquidationPrice.clone());
m.insert("entryPrice".to_string(), self.parse_number(entryPriceString.clone(), &[]));
m.insert("unrealizedPnl".to_string(), self.parse_number(unrealizedPnlString.clone(), &[]));
m.insert("realizedPnl".to_string(), self.safe_number_k(position.clone(), "realizedPnl", &[]));
m.insert("percentage".to_string(), percentage.clone());
m.insert("contracts".to_string(), contracts.clone());
m.insert("contractSize".to_string(), contractSize.clone());
m.insert("markPrice".to_string(), self.parse_number(markPriceString.clone(), &[]));
m.insert("lastPrice".to_string(), self.safe_number_k(position.clone(), "closeAvgPx", &[]));
m.insert("side".to_string(), side.clone());
m.insert("hedged".to_string(), hedged.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "uTime", &[]));
m.insert("maintenanceMargin".to_string(), maintenanceMargin.clone());
m.insert("maintenanceMarginPercentage".to_string(), maintenanceMarginPercentage.clone());
m.insert("collateral".to_string(), self.parse_number(collateralString.clone(), &[]));
m.insert("initialMargin".to_string(), self.parse_number(initialMarginString.clone(), &[]));
m.insert("initialMarginPercentage".to_string(), self.parse_number(initialMarginPercentage.clone(), &[]));
m.insert("leverage".to_string(), self.parse_number(leverageString.clone(), &[]));
m.insert("marginRatio".to_string(), marginRatio.clone());
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
/*
* @method
* @name okx#transfer
* @description transfer currency internally between wallets on the same account
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-funds-transfer
* @param {string} code unified currency code
* @param {float} amount amount to transfer
* @param {string} fromAccount account to transfer from
* @param {string} toAccount account to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut currency: Value = self.currency(code.clone());
let mut accountsByType: Value = self.safe_dict_k(self.options.clone(), "accountsByType", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromId: Value = self.safe_string(accountsByType.clone(), fromAccount.clone(), &[fromAccount.clone()]);
let mut toId: Value = self.safe_string(accountsByType.clone(), toAccount.clone(), &[toAccount.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amt".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("type".to_string(), Value::Str("0".to_string()));
m.insert("from".to_string(), fromId.clone());
m.insert("to".to_string(), toId.clone());
m
});
if is_equal(&fromId, &Value::Str("master".to_string())) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("1".to_string()));
add_element_to_object(&mut request, &Value::Str("subAcct".to_string()), toId.clone());
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.safe_string_k(params.clone(), "from", &[Value::Str("6".to_string())]));
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.safe_string_k(params.clone(), "to", &[Value::Str("6".to_string())]));
} else if is_equal(&toId, &Value::Str("master".to_string())) {
add_element_to_object(&mut request, &Value::Str("type".to_string()), Value::Str("2".to_string()));
add_element_to_object(&mut request, &Value::Str("subAcct".to_string()), fromId.clone());
add_element_to_object(&mut request, &Value::Str("from".to_string()), self.safe_string_k(params.clone(), "from", &[Value::Str("6".to_string())]));
add_element_to_object(&mut request, &Value::Str("to".to_string()), self.safe_string_k(params.clone(), "to", &[Value::Str("6".to_string())]));
}
let __ws_arg_61 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_asset_transfer(&[__ws_arg_61]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "transId": "754147",
// "ccy": "USDT",
// "from": "6",
// "amt": "0.1",
// "to": "18"
// }
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rawTransfer: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_transfer(rawTransfer.clone(), &[currency.clone()]);
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// transfer
//
// {
// "transId": "754147",
// "ccy": "USDT",
// "from": "6",
// "amt": "0.1",
// "to": "18"
// }
//
// fetchTransfer
//
// {
// "amt": "5",
// "ccy": "USDT",
// "from": "18",
// "instId": "",
// "state": "success",
// "subAcct": "",
// "to": "6",
// "toInstId": "",
// "transId": "464424732",
// "type": "0"
// }
//
// fetchTransfers
//
// {
// "bal": "70.6874353780312913",
// "balChg": "-4.0000000000000000", // negative means "to funding", positive meand "from funding"
// "billId": "588900695232225299",
// "ccy": "USDT",
// "execType": "",
// "fee": "",
// "from": "18",
// "instId": "",
// "instType": "",
// "mgnMode": "",
// "notes": "To Funding Account",
// "ordId": "",
// "pnl": "",
// "posBal": "",
// "posBalChg": "",
// "price": "0",
// "subType": "12",
// "sz": "-4",
// "to": "6",
// "ts": "1686676866989",
// "type": "1"
// }
//
let mut id: Value = self.safe_string2(transfer.clone(), Value::Str("transId".to_string()), Value::Str("billId".to_string()), &[]);
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut amount: Value = self.safe_number_k(transfer.clone(), "amt", &[]);
let mut fromAccountId: Value = self.safe_string_k(transfer.clone(), "from", &[]);
let mut toAccountId: Value = self.safe_string_k(transfer.clone(), "to", &[]);
let mut accountsById: Value = self.safe_dict_k(self.options.clone(), "accountsById", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "ts", &[]);
let mut balanceChange: Value = self.safe_string_k(transfer.clone(), "sz", &[]);
if !is_equal(&balanceChange, &Value::Null) {
amount = self.parse_number(crate::precise::Precise::stringAbs(&balanceChange), &[]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transfer.clone());
m.insert("id".to_string(), id.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("fromAccount".to_string(), ternary(is_true(&(is_equal(&fromAccountId, &Value::Null))), Value::Null, self.safe_string(accountsById.clone(), fromAccountId.clone(), &[])));
m.insert("toAccount".to_string(), ternary(is_true(&(is_equal(&toAccountId, &Value::Null))), Value::Null, self.safe_string(accountsById.clone(), toAccountId.clone(), &[])));
m.insert("status".to_string(), self.parse_transfer_status(self.safe_string_k(transfer.clone(), "state", &[])));
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("success".to_string(), Value::Str("ok".to_string()));
m
});
if is_equal(&status, &Value::Null) {
return Value::Null;
}
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchTransfer
* @description fetch a transfer
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-funds-transfer-state
* @param {string} id transfer id
* @param {string} [code] unified currency code of the currency transferred
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn fetch_transfer(&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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("transId".to_string(), id.clone());
m
});
let __ws_arg_62 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_transfer_state(&[__ws_arg_62]).await;
//
// {
// "code": "0",
// "data": [
// {
// "amt": "5",
// "ccy": "USDT",
// "from": "18",
// "instId": "",
// "state": "success",
// "subAcct": "",
// "to": "6",
// "toInstId": "",
// "transId": "464424732",
// "type": "0"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut transfer: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
return self.parse_transfer(transfer.clone(), &[]);
Value::Null
}
/*
* @method
* @name okx#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months
* @param {string} code unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfers structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 currency: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("1".to_string()));
m
});
if !is_equal(&code, &Value::Null) {
currency = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("begin".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_63 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_account_bills_archive(&[__ws_arg_63]).await;
//
// {
// "code": "0",
// "data": [
// {
// "bal": "70.6874353780312913",
// "balChg": "-4.0000000000000000",
// "billId": "588900695232225299",
// "ccy": "USDT",
// "execType": "",
// "fee": "",
// "from": "18",
// "instId": "",
// "instType": "",
// "mgnMode": "",
// "notes": "To Funding Account",
// "ordId": "",
// "pnl": "",
// "posBal": "",
// "posBalChg": "",
// "price": "0",
// "subType": "12",
// "sz": "-4",
// "to": "6",
// "ts": "1686676866989",
// "type": "1"
// },
// ...
// ],
// "msg": ""
// }
//
let mut transfers: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_transfers(transfers.clone(), &[currency.clone(), since.clone(), limit.clone(), params.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 isArray: bool = is_array(¶ms);
let mut request: Value = add(&add(&add(&Value::Str("/api/".to_string()), &self.version), &Value::Str("/".to_string())), &self.implode_params(path.clone(), params.clone()));
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut url: Value = add(&self.implode_hostname(get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &Value::Str("rest".to_string()))), &request);
// const type = this.getPathAuthenticationType (path);
if is_equal(&api, &Value::Str("public".to_string())) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
url = add(&url, &add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[])));
}
} else if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
// inject id in implicit api call
if is_equal(&method, &Value::Str("POST".to_string())) && is_true(&(is_equal(&path, &Value::Str("trade/batch-orders".to_string())) || is_equal(&path, &Value::Str("trade/order-algo".to_string())) || is_equal(&path, &Value::Str("trade/order".to_string())))) {
let mut brokerId: Value = self.safe_string_k(self.options.clone(), "brokerId", &[Value::Str("6b9ad766b55dBCDE".to_string())]);
if is_true(&Value::Bool(is_array(¶ms))) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_1001: bool = true;
while { if !__for_first_1001 { i = add(&i, &Value::Int(1)); } __for_first_1001 = false; is_less_than(&i, &get_array_length(¶ms)) } {
let mut entry: Value = get_value(¶ms, &i);
let mut entry: Value = get_value(¶ms, &i);
let mut clientOrderId: Value = self.safe_string_k(entry.clone(), "clOrdId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut entry, &Value::Str("clOrdId".to_string()), add(&brokerId, &self.uuid16(&[])));
add_element_to_object(&mut entry, &Value::Str("tag".to_string()), brokerId.clone());
add_element_to_object(&mut params, &i, entry.clone());
}
}
}
} else {
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clOrdId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut params, &Value::Str("clOrdId".to_string()), add(&brokerId, &self.uuid16(&[])));
add_element_to_object(&mut params, &Value::Str("tag".to_string()), brokerId.clone());
}
}
}
let mut timestamp: Value = self.iso8601(self.nonce());
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("OK-ACCESS-KEY".to_string(), self.apiKey.clone());
m.insert("OK-ACCESS-PASSPHRASE".to_string(), self.password.clone());
m.insert("OK-ACCESS-TIMESTAMP".to_string(), timestamp.clone());
m
});
let mut auth: Value = add(&add(×tamp, &method), &request);
if is_equal(&method, &Value::Str("GET".to_string())) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
let mut urlencodedQuery: Value = add(&Value::Str("?".to_string()), &self.urlencode(query.clone(), &[]));
url = add(&url, &urlencodedQuery);
auth = add(&auth, &urlencodedQuery);
}
} else {
if is_true(&isArray) || is_true(&(is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)))) {
body = self.json(query.clone());
auth = add(&auth, &body);
}
add_element_to_object(&mut headers, &Value::Str("Content-Type".to_string()), Value::Str("application/json".to_string()));
}
let mut signature: Value = self.hmac(self.encode(auth.clone()), self.encode(self.secret.clone()), Value::Str("sha256".to_string()), &[Value::Str("base64".to_string())]);
add_element_to_object(&mut headers, &Value::Str("OK-ACCESS-SIGN".to_string()), signature.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 parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "fundingRate": "0.00027815",
// "fundingTime": "1634256000000",
// "instId": "BTC-USD-SWAP",
// "instType": "SWAP",
// "nextFundingRate": "0.00017",
// "nextFundingTime": "1634284800000"
// }
// ws
// {
// "fundingRate":"0.0001875391284828",
// "fundingTime":"1700726400000",
// "instId":"BTC-USD-SWAP",
// "instType":"SWAP",
// "method": "next_period",
// "maxFundingRate":"0.00375",
// "minFundingRate":"-0.00375",
// "nextFundingRate":"0.0002608059239328",
// "nextFundingTime":"1700755200000",
// "premium": "0.0001233824646391",
// "settFundingRate":"0.0001699799259033",
// "settState":"settled",
// "ts":"1700724675402"
// }
//
// in the response above nextFundingRate is actually two funding rates from now
//
let mut nextFundingRateTimestamp: Value = self.safe_integer_k(contract.clone(), "nextFundingTime", &[]);
let mut marketId: Value = self.safe_string_k(contract.clone(), "instId", &[]);
let mut symbol: Value = self.safe_symbol(marketId.clone(), &[market.clone()]);
let mut nextFundingRate: Value = self.safe_number_k(contract.clone(), "nextFundingRate", &[]);
let mut fundingTime: Value = self.safe_integer_k(contract.clone(), "fundingTime", &[]);
let mut fundingTimeString: Value = self.safe_string_k(contract.clone(), "fundingTime", &[]);
let mut nextFundingTimeString: Value = self.safe_string_k(contract.clone(), "nextFundingTime", &[]);
let mut millisecondsInterval: Value = crate::precise::Precise::stringSub(&nextFundingTimeString, &fundingTimeString);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), self.parse_number(Value::Str("0".to_string()), &[]));
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "fundingRate", &[]));
m.insert("fundingTimestamp".to_string(), fundingTime.clone());
m.insert("fundingDatetime".to_string(), self.iso8601(fundingTime.clone()));
m.insert("nextFundingRate".to_string(), nextFundingRate.clone());
m.insert("nextFundingTimestamp".to_string(), nextFundingRateTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingRateTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), self.parse_funding_interval(millisecondsInterval.clone()));
m
});
Value::Null
}
pub fn parse_funding_interval(&self, mut interval: Value) -> Value {
let mut intervals: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("3600000".to_string(), Value::Str("1h".to_string()));
m.insert("7200000".to_string(), Value::Str("2h".to_string()));
m.insert("14400000".to_string(), Value::Str("4h".to_string()));
m.insert("28800000".to_string(), Value::Str("8h".to_string()));
m.insert("57600000".to_string(), Value::Str("16h".to_string()));
m.insert("86400000".to_string(), Value::Str("24h".to_string()));
m
});
return self.safe_string(intervals.clone(), interval.clone(), &[interval.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchFundingInterval
* @description fetch the current funding rate interval
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_interval(&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
}));
return self.fetch_funding_rate(symbol.clone(), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name okx#fetchFundingRate
* @description fetch the current funding rate
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/?id=funding-rate-structure}
*/
pub async fn fetch_funding_rate(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut marketInfo: Value = self.safe_dict_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ruleType: Value = self.safe_string_k(marketInfo.clone(), "ruleType", &[]);
let mut isExtendedPerpetual: bool = is_equal(&ruleType, &Value::Str("xperp".to_string())); // long-dated futures that still pay funding, e.g. ETH-USD_UM_XPERP-310404
if is_true(&(!is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) && !is_true(&isExtendedPerpetual) {
panic!("{}", crate::exchange_errors::exchange_error(add(&self.id, &Value::Str(" fetchFundingRate() is only valid for swap markets or XPERP futures".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_64 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_funding_rate(&[__ws_arg_64]).await;
//
// {
// "code": "0",
// "data": [
// {
// "fundingRate": "0.00027815",
// "fundingTime": "1634256000000",
// "instId": "BTC-USD-SWAP",
// "instType": "SWAP",
// "nextFundingRate": "0.00017",
// "nextFundingTime": "1634284800000"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut entry: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_funding_rate(entry.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchFundingRates
* @description fetches the current funding rates for multiple symbols
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-funding-rate
* @param {string[]} symbols unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [funding rates structure]{@link https://docs.ccxt.com/?id=funding-rates-structure}
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true)]);
if !is_equal(&symbols, &Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_1002: bool = true;
while { if !__for_first_1002 { i = add(&i, &Value::Int(1)); } __for_first_1002 = false; is_less_than(&i, &get_array_length(&symbols)) } {
let mut market: Value = self.market(get_value(&symbols, &i));
let mut marketInfo: Value = self.safe_dict_k(market.clone(), "info", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ruleType: Value = self.safe_string_k(marketInfo.clone(), "ruleType", &[]);
let mut isExtendedPerpetual: bool = is_equal(&ruleType, &Value::Str("xperp".to_string())); // long-dated futures that still pay funding, e.g. ETH-USD_UM_XPERP-310404
if is_true(&(!is_equal(&get_value(&market, &Value::Str("swap".to_string())), &Value::Bool(true)))) && !is_true(&isExtendedPerpetual) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&add(&self.id, &Value::Str(" fetchFundingRates() symbols must be swap markets or XPERP futures, ".to_string())), &get_value(&symbols, &i)), &Value::Str(" is not".to_string()))));
}
}
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), Value::Str("ANY".to_string()));
m
});
let __ws_arg_65 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_funding_rate(&[__ws_arg_65]).await;
//
// {
// "code": "0",
// "data": [
// {
// "fundingRate": "0.00027815",
// "fundingTime": "1634256000000",
// "instId": "BTC-USD-SWAP",
// "instType": "SWAP",
// "nextFundingRate": "0.00017",
// "nextFundingTime": "1634284800000"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_funding_rates(data.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchFundingHistory
* @description fetch the history of funding payments paid and received on this account
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months
* @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
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("type".to_string(), Value::Str("8".to_string()));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), to_string_val(&limit)); // default 100, max 100
}
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()));
if is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)) {
if is_equal(&get_value(&market, &Value::Str("linear".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("ctType".to_string()), Value::Str("linear".to_string()));
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), get_value(&market, &Value::Str("quoteId".to_string())));
} else {
add_element_to_object(&mut request, &Value::Str("ctType".to_string()), Value::Str("inverse".to_string()));
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), get_value(&market, &Value::Str("baseId".to_string())));
}
}
}
let mut type_varqueryVariable = self.handle_market_type_and_params(Value::Str("fetchFundingHistory".to_string()), &[market.clone(), params.clone()]);
let mut type_var: Value = get_value(&type_varqueryVariable, &Value::Int(0));
let mut query: Value = get_value(&type_varqueryVariable, &Value::Int(1));
if is_equal(&type_var, &Value::Str("swap".to_string())) {
add_element_to_object(&mut request, &Value::Str("instType".to_string()), self.convert_to_instrument_type(type_var.clone()));
}
// AccountBillsArchive has the same cost as AccountBills but supports three months of data
let __ws_arg_66 = self.extend(request.clone(), &[query.clone()]);
let mut response: Value = self.private_get_account_bills_archive(&[__ws_arg_66]).await;
//
// {
// "bal": "0.0242946200998573",
// "balChg": "0.0000148752712240",
// "billId": "377970609204146187",
// "ccy": "ETH",
// "execType": "",
// "fee": "0",
// "from": "",
// "instId": "ETH-USD-SWAP",
// "instType": "SWAP",
// "mgnMode": "isolated",
// "notes": "",
// "ordId": "",
// "pnl": "0.000014875271224",
// "posBal": "0",
// "posBalChg": "0",
// "subType": "174",
// "sz": "9",
// "to": "",
// "ts": "1636387215588",
// "type": "8"
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1003: bool = true;
while { if !__for_first_1003 { i = add(&i, &Value::Int(1)); } __for_first_1003 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "ts", &[]);
let mut instId: Value = self.safe_string_k(entry.clone(), "instId", &[]);
let mut marketInner: Value = self.safe_market(&[instId.clone()]);
let mut currencyId: Value = self.safe_string_k(entry.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
let mut balanceChange: Value = self.safe_string_k(entry.clone(), "balChg", &[]);
let mut positionBalanceChange: Value = self.safe_string_k(entry.clone(), "posBalChg", &[]);
let mut amount: Value = Value::Null;
if is_true(&(!is_equal(&balanceChange, &Value::Null))) && is_true(&(!is_true(&crate::precise::Precise::stringEq(&balanceChange, &Value::Str("0".to_string()))))) {
amount = balanceChange.clone();
} else {
amount = positionBalanceChange.clone();
}
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), get_value(&marketInner, &Value::Str("symbol".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(entry.clone(), "billId", &[]));
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m
}));
}
}
let mut sorted: Value = self.sort_by(result.clone(), Value::Str("timestamp".to_string()), &[]);
return self.filter_by_symbol_since_limit(sorted.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name okx#setLeverage
* @description set the level of leverage for a market
* @see https://www.okx.com/docs-v5/en/#rest-api-account-set-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.marginMode] 'cross' or 'isolated'
* @param {string} [params.posSide] 'long' or 'short' or 'net' for isolated margin long/short mode on futures and swap markets, default is 'net'
* @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()))));
}
// WARNING: THIS WILL INCREASE LIQUIDATION PRICE FOR OPEN ISOLATED LONG POSITIONS
// AND DECREASE LIQUIDATION PRICE FOR OPEN ISOLATED SHORT POSITIONS
if is_true(&(is_less_than(&leverage, &Value::Int(1)))) || is_true(&(is_greater_than(&leverage, &Value::Int(125)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setLeverage() leverage should be between 1 and 125".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setLeverage".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
marginMode = self.safe_string_k(params.clone(), "mgnMode", &[Value::Str("cross".to_string())]); // cross as default marginMode
}
if is_true(&(!is_equal(&marginMode, &Value::Str("cross".to_string())))) && is_true(&(!is_equal(&marginMode, &Value::Str("isolated".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setLeverage() requires a marginMode parameter that must be either cross or isolated".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("lever".to_string(), leverage.clone());
m.insert("mgnMode".to_string(), marginMode.clone());
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut posSide: Value = self.safe_string_k(params.clone(), "posSide", &[Value::Str("net".to_string())]);
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
if !is_equal(&posSide, &Value::Str("long".to_string())) && !is_equal(&posSide, &Value::Str("short".to_string())) && !is_equal(&posSide, &Value::Str("net".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setLeverage() requires the posSide argument to be either \"long\", \"short\" or \"net\"".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("posSide".to_string()), posSide.clone());
}
let __ws_arg_67 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_set_leverage(&[__ws_arg_67]).await;
return response;
Value::Null
}
/*
* @method
* @name okx#fetchPositionMode
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-account-configuration
* @description fetchs the position mode, hedged or one way, hedged for binance is set identically for all linear markets or all inverse markets
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.accountId] if you have multiple accounts, you must specify the account id to fetch the position mode
* @returns {object} an object detailing whether the market is in hedged or one-way mode
*/
pub async fn fetch_position_mode(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut accounts: Value = self.fetch_accounts(&[]).await;
let mut length: Value = get_array_length(&accounts);
let mut selectedAccount: Value = Value::Null;
if is_greater_than(&length, &Value::Int(1)) {
let mut accountId: Value = self.safe_string_k(params.clone(), "accountId", &[]);
if is_equal(&accountId, &Value::Null) {
let mut accountIds: Value = self.get_list_from_object_values(accounts.clone(), Value::Str("id".to_string()));
panic!("{}", crate::exchange_errors::exchange_error(add(&add(&self.id, &Value::Str(" fetchPositionMode() can not detect position mode, because you have multiple accounts. Set params[\"accountId\"] to desired id from: ".to_string())), &join(&accountIds, &Value::Str(", ".to_string())))));
} else {
let mut accountsById: Value = self.index_by(accounts.clone(), Value::Str("id".to_string()));
selectedAccount = self.safe_dict(accountsById.clone(), accountId.clone(), &[]);
}
} else {
selectedAccount = get_value(&accounts, &Value::Int(0));
}
let mut mainAccount: Value = get_value(&selectedAccount, &Value::Str("info".to_string()));
let mut posMode: Value = self.safe_string_k(mainAccount.clone(), "posMode", &[]); // long_short_mode, net_mode
let mut isHedged: Value = Value::Bool(is_equal(&posMode, &Value::Str("long_short_mode".to_string())));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), mainAccount.clone());
m.insert("hedged".to_string(), isHedged.clone());
m
});
Value::Null
}
/*
* @method
* @name okx#setPositionMode
* @description set hedged to true or false for a market
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-position-mode
* @param {bool} hedged set to true to use long_short_mode, false for net_mode
* @param {string} symbol not used by okx setPositionMode
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} response from the exchange
*/
pub async fn set_position_mode(&mut self, mut hedged: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut hedgeMode: Value = Value::Null;
if is_true(&hedged) {
hedgeMode = Value::Str("long_short_mode".to_string());
} else {
hedgeMode = Value::Str("net_mode".to_string());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("posMode".to_string(), hedgeMode.clone());
m
});
let __ws_arg_68 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_set_position_mode(&[__ws_arg_68]).await;
return response;
Value::Null
}
/*
* @method
* @name okx#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-set-leverage
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.leverage] leverage
* @returns {object} response from the exchange
*/
pub async fn set_margin_mode(&mut self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a symbol argument".to_string()))));
}
// WARNING: THIS WILL INCREASE LIQUIDATION PRICE FOR OPEN ISOLATED LONG POSITIONS
// AND DECREASE LIQUIDATION PRICE FOR OPEN ISOLATED SHORT POSITIONS
marginMode = to_lower(&marginMode);
if is_true(&(!is_equal(&marginMode, &Value::Str("cross".to_string())))) && is_true(&(!is_equal(&marginMode, &Value::Str("isolated".to_string())))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setMarginMode() marginMode must be either cross or isolated".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut lever: Value = self.safe_integer2(params.clone(), Value::Str("lever".to_string()), Value::Str("leverage".to_string()), &[]);
if is_true(&(is_equal(&lever, &Value::Null))) || is_true(&(is_less_than(&lever, &Value::Int(1)))) || is_true(&(is_greater_than(&lever, &Value::Int(125)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setMarginMode() params[\"lever\"] should be between 1 and 125".to_string()))));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("leverage".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("lever".to_string(), lever.clone());
m.insert("mgnMode".to_string(), marginMode.clone());
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_69 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_set_leverage(&[__ws_arg_69]).await;
return response;
Value::Null
}
/*
* @method
* @name okx#fetchCrossBorrowRates
* @description fetch the borrow interest rates of all currencies
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-interest-rate
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure}
*/
pub async fn fetch_cross_borrow_rates(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut response: Value = self.private_get_account_interest_rate(&[params.clone()]).await;
//
// {
// "code": "0",
// "data": [
// {
// "ccy": "BTC",
// "interestRate": "0.00000833"
// }
// ...
// ],
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
// code-keyed dict (CrossBorrowRates); base fetchCrossBorrowRate looks up by code
let mut rates: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1004: bool = true;
while { if !__for_first_1004 { i = add(&i, &Value::Int(1)); } __for_first_1004 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rate: Value = self.parse_borrow_rate(get_value(&data, &i), &[]);
let mut code: Value = self.safe_string_k(rate.clone(), "currency", &[]);
if !is_equal(&code, &Value::Null) {
add_element_to_object(&mut rates, &code, rate.clone());
}
}
}
return rates;
Value::Null
}
/*
* @method
* @name okx#fetchCrossBorrowRate
* @description fetch the rate of interest to borrow a currency for margin trading
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-interest-rate
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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("ccy".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.private_get_account_interest_rate(&[__ws_arg_70]).await;
//
// {
// "code": "0",
// "data": [
// {
// "ccy": "USDT",
// "interestRate": "0.00002065"
// }
// ...
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rate: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_borrow_rate(rate.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);
//
// {
// "amt": "992.10341195",
// "ccy": "BTC",
// "rate": "0.01",
// "ts": "1643954400000"
// }
//
let mut ccy: Value = self.safe_string_k(info.clone(), "ccy", &[]);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "ts", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(ccy.clone(), &[]));
m.insert("rate".to_string(), self.safe_number2(info.clone(), Value::Str("interestRate".to_string()), Value::Str("rate".to_string()), &[]));
m.insert("period".to_string(), Value::Int(3600000));
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
}
pub fn parse_borrow_rate_histories(&self, mut response: Value, mut codes: Value, mut since: Value, mut limit: Value) -> Value {
//
// [
// {
// "amt": "992.10341195",
// "ccy": "BTC",
// "rate": "0.01",
// "ts": "1643954400000"
// },
// ...
// ]
//
let mut borrowRateHistories: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_1005: bool = true;
while { if !__for_first_1005 { i = add(&i, &Value::Int(1)); } __for_first_1005 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut item: Value = get_value(&response, &i);
let mut item: Value = get_value(&response, &i);
let mut code: Value = self.safe_currency_code(self.safe_string_k(item.clone(), "ccy", &[]), &[]);
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(is_equal(&codes, &Value::Null) || is_true(&self.in_array(code.clone(), codes.clone())))) {
if !is_true(&(Value::Bool(in_op(&borrowRateHistories, &code)))) {
add_element_to_object(&mut borrowRateHistories, &code, Value::List(vec![]));
}
let mut borrowRateStructure: Value = self.parse_borrow_rate(item.clone(), &[]);
// GET /api/v5/finance/savings/lending-rate-history returns annualized rates, unlike the hourly cross-margin endpoint
add_element_to_object(&mut borrowRateStructure, &Value::Str("period".to_string()), Value::Int(31536000000));
let mut borrrowRateCode: Value = get_value(&borrowRateHistories, &code);
append_to_array(&mut borrrowRateCode, borrowRateStructure.clone());
crate::set_value(&mut borrowRateHistories, &code, borrrowRateCode.clone());
}
}
}
let mut keys: Value = object_keys(&borrowRateHistories);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1006: bool = true;
while { if !__for_first_1006 { i = add(&i, &Value::Int(1)); } __for_first_1006 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut code: Value = get_value(&keys, &i);
let mut code: Value = get_value(&keys, &i);
{ let __be_tmp = self.filter_by_currency_since_limit(get_value(&borrowRateHistories, &code), &[code.clone(), since.clone(), limit.clone()]); add_element_to_object(&mut borrowRateHistories, &code, __be_tmp); };
}
}
return borrowRateHistories;
Value::Null
}
/*
* @method
* @name okx#fetchBorrowRateHistories
* @description retrieves a history of a multiple currencies borrow interest rate at specific time slots, returns all currencies if no symbols passed, default is undefined
* @see https://www.okx.com/docs-v5/en/#financial-product-savings-get-public-borrow-history-public
* @param {string[]|undefined} codes list of unified currency codes, default is undefined
* @param {int} [since] timestamp in ms of the earliest borrowRate, default is undefined
* @param {int} [limit] max number of borrow rate prices to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure} indexed by the market symbol
*/
pub async fn fetch_borrow_rate_histories(&mut self, optional_args: &[Value]) -> Value {
let mut codes = 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(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_71 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_finance_savings_lending_rate_history(&[__ws_arg_71]).await;
//
// {
// "code": "0",
// "data": [
// {
// "amt": "992.10341195",
// "ccy": "BTC",
// "rate": "0.01",
// "ts": "1643954400000"
// },
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_borrow_rate_histories(data.clone(), codes.clone(), since.clone(), limit.clone());
Value::Null
}
/*
* @method
* @name okx#fetchBorrowRateHistory
* @description retrieves a history of a currencies borrow interest rate at specific time slots
* @see https://www.okx.com/docs-v5/en/#financial-product-savings-get-public-borrow-history-public
* @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
* @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("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_72 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_finance_savings_lending_rate_history(&[__ws_arg_72]).await;
//
// {
// "code": "0",
// "data": [
// {
// "amt": "992.10341195",
// "ccy": "BTC",
// "rate": "0.01",
// "ts": "1643954400000"
// },
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_borrow_rate_history(data.clone(), code.clone(), since.clone(), limit.clone());
Value::Null
}
pub async fn modify_margin_helper(&mut self, mut symbol: Value, mut amount: Value, mut type_var: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut posSide: Value = self.safe_string_k(params.clone(), "posSide", &[Value::Str("net".to_string())]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("posSide".to_string())]), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("amt".to_string(), amount.clone());
m.insert("type".to_string(), type_var.clone());
m.insert("posSide".to_string(), posSide.clone());
m
});
let __ws_arg_73 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_position_margin_balance(&[__ws_arg_73]).await;
//
// {
// "code": "0",
// "data": [
// {
// "amt": "0.01",
// "instId": "ETH-USD-SWAP",
// "posSide": "net",
// "type": "reduce"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut entry: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut errorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
let __ws_arg_74 = self.parse_margin_modification(entry.clone(), &[market.clone()]);
return self.extend(__ws_arg_74, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), ternary(is_true(&(is_equal(&errorCode, &Value::Str("0".to_string())))), Value::Str("ok".to_string()), Value::Str("failed".to_string())));
m
})]);
Value::Null
}
pub fn parse_margin_modification(&self, mut data: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// addMargin/reduceMargin
//
// {
// "amt": "0.01",
// "instId": "ETH-USD-SWAP",
// "posSide": "net",
// "type": "reduce"
// }
//
// fetchMarginAdjustmentHistory
//
// {
// bal: '67621.4325135010619812',
// balChg: '-10.0000000000000000',
// billId: '691293628710342659',
// ccy: 'USDT',
// clOrdId: '',
// execType: '',
// fee: '0',
// fillFwdPx: '',
// fillIdxPx: '',
// fillMarkPx: '',
// fillMarkVol: '',
// fillPxUsd: '',
// fillPxVol: '',
// fillTime: '1711089244850',
// from: '',
// instId: 'XRP-USDT-SWAP',
// instType: 'SWAP',
// interest: '0',
// mgnMode: 'isolated',
// notes: '',
// ordId: '',
// pnl: '0',
// posBal: '73.12',
// posBalChg: '10.00',
// px: '',
// subType: '160',
// sz: '10',
// tag: '',
// to: '',
// tradeId: '0',
// ts: '1711089244699',
// type: '6'
// }
//
let mut amountRaw: Value = self.safe_string2(data.clone(), Value::Str("amt".to_string()), Value::Str("posBalChg".to_string()), &[]);
let mut typeRaw: Value = self.safe_string_k(data.clone(), "type", &[]);
// ledger uses numeric '6' (+/- amount); addMargin/reduceMargin already send 'add'/'reduce'
let mut type_var: Value = Value::Null;
if is_equal(&typeRaw, &Value::Str("6".to_string())) {
type_var = ternary(is_true(&crate::precise::Precise::stringGt(&amountRaw, &Value::Str("0".to_string()))), Value::Str("add".to_string()), Value::Str("reduce".to_string()));
} else {
type_var = typeRaw.clone();
}
let mut amount: Value = crate::precise::Precise::stringAbs(&amountRaw);
let mut marketId: Value = self.safe_string_k(data.clone(), "instId", &[]);
let mut responseMarket: Value = self.safe_market(&[marketId.clone(), market.clone()]);
let mut code: Value = ternary(is_true(&(is_equal(&get_value(&responseMarket, &Value::Str("inverse".to_string())), &Value::Bool(true)))), get_value(&responseMarket, &Value::Str("base".to_string())), get_value(&responseMarket, &Value::Str("quote".to_string())));
let mut timestamp: Value = self.safe_integer_k(data.clone(), "ts", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("symbol".to_string(), get_value(&responseMarket, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), type_var.clone());
m.insert("marginMode".to_string(), Value::Str("isolated".to_string()));
m.insert("amount".to_string(), self.parse_number(amount.clone(), &[]));
m.insert("code".to_string(), code.clone());
m.insert("total".to_string(), Value::Null);
m.insert("status".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 okx#reduceMargin
* @description remove margin from a position
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-increase-decrease-margin
* @param {string} symbol unified market symbol
* @param {float} amount the amount of margin to remove
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn reduce_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Str("reduce".to_string()), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name okx#addMargin
* @description add margin
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-increase-decrease-margin
* @param {string} symbol unified market symbol
* @param {float} amount amount of margin to add
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin structure]{@link https://docs.ccxt.com/?id=margin-structure}
*/
pub async fn add_margin(&mut self, mut symbol: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
return self.modify_margin_helper(symbol.clone(), amount.clone(), Value::Str("add".to_string()), &[params.clone()]).await;
Value::Null
}
/*
* @method
* @name okx#fetchMarketLeverageTiers
* @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes for a single market
* @see https://www.okx.com/docs-v5/en/#rest-api-public-data-get-position-tiers
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] 'cross' or 'isolated'
* @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
*/
pub async fn fetch_market_leverage_tiers(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut type_var: Value = ternary(is_true(&(is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)))), Value::Str("MARGIN".to_string()), self.convert_to_instrument_type(get_value(&market, &Value::Str("type".to_string()))));
let mut uly: Value = self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("uly".to_string()), &[]);
if is_true(&(is_equal(&uly, &Value::Null))) || is_true(&(is_equal(&uly, &Value::Str("".to_string())))) {
if !is_equal(&type_var, &Value::Str("MARGIN".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&self.id, &Value::Str(" fetchMarketLeverageTiers() cannot fetch leverage tiers for ".to_string())), &symbol)));
}
}
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchMarketLeverageTiers".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
marginMode = self.safe_string_k(params.clone(), "tdMode", &[Value::Str("cross".to_string())]); // cross as default marginMode
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), type_var.clone());
m.insert("tdMode".to_string(), marginMode.clone());
m.insert("uly".to_string(), uly.clone());
m
});
if is_equal(&type_var, &Value::Str("MARGIN".to_string())) {
add_element_to_object(&mut request, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_75 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_position_tiers(&[__ws_arg_75]).await;
//
// {
// "code": "0",
// "data": [
// {
// "baseMaxLoan": "500",
// "imr": "0.1",
// "instId": "ETH-USDT",
// "maxLever": "10",
// "maxSz": "500",
// "minSz": "0",
// "mmr": "0.03",
// "optMgnFactor": "0",
// "quoteMaxLoan": "200000",
// "tier": "1",
// "uly": ""
// },
// ...
// ]
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_market_leverage_tiers(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_market_leverage_tiers(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
/*
* @ignore
* @method
* @param {object} info Exchange response for 1 market
* @param {object} market CCXT market
*/
//
// [
// {
// "baseMaxLoan": "500",
// "imr": "0.1",
// "instId": "ETH-USDT",
// "maxLever": "10",
// "maxSz": "500",
// "minSz": "0",
// "mmr": "0.03",
// "optMgnFactor": "0",
// "quoteMaxLoan": "200000",
// "tier": "1",
// "uly": ""
// },
// ...
// ]
//
let mut tiers: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1007: bool = true;
while { if !__for_first_1007 { i = add(&i, &Value::Int(1)); } __for_first_1007 = 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(tier.clone(), "instId", &[]);
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_integer_k(tier.clone(), "tier", &[]));
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("currency".to_string(), self.safe_string_k(market.clone(), "quote", &[]));
m.insert("minNotional".to_string(), self.safe_number_k(tier.clone(), "minSz", &[]));
m.insert("maxNotional".to_string(), self.safe_number_k(tier.clone(), "maxSz", &[]));
m.insert("maintenanceMarginRate".to_string(), self.safe_number_k(tier.clone(), "mmr", &[]));
m.insert("maxLeverage".to_string(), self.safe_number_k(tier.clone(), "maxLever", &[]));
m.insert("info".to_string(), tier.clone());
m
}));
}
}
return tiers;
Value::Null
}
/*
* @method
* @name okx#fetchBorrowInterest
* @description fetch the interest owed b the user for borrowing currency for margin trading
* @see https://www.okx.com/docs-v5/en/#rest-api-account-get-interest-accrued-data
* @param {string} code the unified currency code for the currency of the interest
* @param {string} symbol the market symbol of an isolated margin market, if undefined, the interest for cross margin markets is returned
* @param {int} [since] timestamp in ms of the earliest time to receive interest records for
* @param {int} [limit] the number of [borrow interest structures]{@link https://docs.ccxt.com/?id=borrow-interest-structure} to retrieve
* @param {object} [params] exchange specific parameters
* @param {int} [params.type] Loan type 1 - VIP loans 2 - Market loans *Default is Market loans*
* @param {string} [params.marginMode] 'cross' or 'isolated'
* @returns {object[]} An 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 marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("fetchBorrowInterest".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Null) {
marginMode = self.safe_string_k(params.clone(), "mgnMode", &[Value::Str("cross".to_string())]); // cross as default marginMode
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mgnMode".to_string(), marginMode.clone());
m
});
let mut market: Value = Value::Null;
if !is_equal(&code, &Value::Null) {
let mut currency: Value = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), subtract(&since, &Value::Int(1)));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_76 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_account_interest_accrued(&[__ws_arg_76]).await;
//
// {
// "code": "0",
// "data": [
// {
// "ccy": "USDT",
// "instId": "",
// "interest": "0.0003960833333334",
// "interestRate": "0.0000040833333333",
// "liab": "97",
// "mgnMode": "",
// "ts": "1637312400000",
// "type": "1"
// },
// ...
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut interest: Value = self.parse_borrow_interests(data.clone(), &[]);
return self.filter_by_currency_since_limit(interest.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);
let mut instId: Value = self.safe_string_k(info.clone(), "instId", &[]);
if !is_equal(&instId, &Value::Null) {
market = self.safe_market(&[instId.clone(), market.clone()]);
}
let mut timestamp: Value = self.safe_integer_k(info.clone(), "ts", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(info.clone(), "ccy", &[]), &[]));
m.insert("interest".to_string(), self.safe_number_k(info.clone(), "interest", &[]));
m.insert("interestRate".to_string(), self.safe_number_k(info.clone(), "interestRate", &[]));
m.insert("amountBorrowed".to_string(), self.safe_number_k(info.clone(), "liab", &[]));
m.insert("marginMode".to_string(), self.safe_string_k(info.clone(), "mgnMode", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name okx#borrowCrossMargin
* @description create a loan to borrow margin (need to be VIP 5 and above)
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-vip-loans-borrow-and-repay
* @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("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amt".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("side".to_string(), Value::Str("borrow".to_string()));
m
});
let __ws_arg_77 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_borrow_repay(&[__ws_arg_77]).await;
//
// {
// "code": "0",
// "data": [
// {
// "amt": "102",
// "ccy": "USDT",
// "ordId": "544199684697214976",
// "side": "borrow",
// "state": "1"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut loan: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_loan(loan.clone(), &[currency.clone()]);
Value::Null
}
/*
* @method
* @name okx#repayCrossMargin
* @description repay borrowed margin and interest
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-vip-loans-borrow-and-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
* @param {string} [params.id] the order ID of borrowing, it is necessary while repaying
* @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 id: Value = self.safe_string2(params.clone(), Value::Str("id".to_string()), Value::Str("ordId".to_string()), &[]);
params = self.omit(params.clone(), Value::Str("id".to_string()), &[]);
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" repayCrossMargin() requires an id parameter".to_string()))));
}
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), get_value(¤cy, &Value::Str("id".to_string())));
m.insert("amt".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("side".to_string(), Value::Str("repay".to_string()));
m.insert("ordId".to_string(), id.clone());
m
});
let __ws_arg_78 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_account_borrow_repay(&[__ws_arg_78]).await;
//
// {
// "code": "0",
// "data": [
// {
// "amt": "102",
// "ccy": "USDT",
// "ordId": "544199684697214976",
// "side": "repay",
// "state": "1"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut loan: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_loan(loan.clone(), &[currency.clone()]);
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);
//
// {
// "amt": "102",
// "availLoan": "97",
// "ccy": "USDT",
// "loanQuota": "6000000",
// "posLoan": "0",
// "side": "repay",
// "usedLoan": "97"
// }
//
let mut currencyId: Value = self.safe_string_k(info.clone(), "ccy", &[]);
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(), "amt", &[]));
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
}
/*
* @method
* @name okx#fetchOpenInterest
* @description Retrieves the open interest of a currency
* @see https://www.okx.com/docs-v5/en/#rest-api-public-data-get-open-interest
* @param {string} symbol Unified CCXT market symbol
* @param {object} [params] exchange specific parameters
* @returns {object} an open interest structure{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
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 type_var: Value = self.convert_to_instrument_type(get_value(&market, &Value::Str("type".to_string())));
let mut uly: Value = self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("uly".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), type_var.clone());
m.insert("uly".to_string(), uly.clone());
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_79 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_open_interest(&[__ws_arg_79]).await;
//
// {
// "code": "0",
// "data": [
// {
// "instId": "BTC-USDT-SWAP",
// "instType": "SWAP",
// "oi": "2125419",
// "oiCcy": "21254.19",
// "ts": "1664005108969"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_open_interest(get_value(&data, &Value::Int(0)), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchOpenInterests
* @description Retrieves the open interests of some currencies
* @see https://www.okx.com/docs-v5/en/#rest-api-public-data-get-open-interest
* @param {string[]} symbols Unified CCXT market symbols
* @param {object} [params] exchange specific parameters
* @param {string} params.instType Instrument type, options: 'SWAP', 'FUTURES', 'OPTION', default to 'SWAP'
* @param {string} params.uly Underlying, Applicable to FUTURES/SWAP/OPTION, if instType is 'OPTION', either uly or instFamily is required
* @param {string} params.instFamily Instrument family, Applicable to FUTURES/SWAP/OPTION, if instType is 'OPTION', either uly or instFamily is required
* @returns {object} an dictionary of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
pub async fn fetch_open_interests(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true)]);
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
market = self.market(get_value(&symbols, &Value::Int(0)));
}
let mut marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_sub_type_and_params(Value::Str("fetchOpenInterests".to_string()), &[market.clone(), params.clone(), Value::Str("swap".to_string())]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut instType: Value = Value::Str("SWAP".to_string());
if is_equal(&marketType, &Value::Str("future".to_string())) {
instType = Value::Str("FUTURES".to_string());
} else if is_equal(&instType, &Value::Str("option".to_string())) {
instType = Value::Str("OPTION".to_string());
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), instType.clone());
m
});
let mut uly: Value = self.safe_string_k(params.clone(), "uly", &[]);
if !is_equal(&uly, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("uly".to_string()), uly.clone());
}
let mut instFamily: Value = self.safe_string_k(params.clone(), "instFamily", &[]);
if !is_equal(&instFamily, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("instFamily".to_string()), instFamily.clone());
}
if is_equal(&instType, &Value::Str("OPTION".to_string())) && is_equal(&uly, &Value::Null) && is_equal(&instFamily, &Value::Null) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOpenInterests() requires either uly or instFamily parameter for OPTION markets".to_string()))));
}
let __ws_arg_80 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_open_interest(&[__ws_arg_80]).await;
//
// {
// "code": "0",
// "data": [
// {
// "instId": "BTC-USDT-SWAP",
// "instType": "SWAP",
// "oi": "2125419",
// "oiCcy": "21254.19",
// "ts": "1664005108969"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_open_interests(data.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchOpenInterestHistory
* @description Retrieves the open interest history of a currency
* @see https://www.okx.com/docs-v5/en/#rest-api-trading-data-get-contracts-open-interest-and-volume
* @see https://www.okx.com/docs-v5/en/#rest-api-trading-data-get-options-open-interest-and-volume
* @param {string} symbol Unified CCXT currency code or unified symbol
* @param {string} timeframe "5m", "1h", or "1d" for option only "1d" or "8h"
* @param {int} [since] The time in ms of the earliest record to retrieve as a unix timestamp
* @param {int} [limit] Not used by okx, but parsed internally by CCXT
* @param {object} [params] Exchange specific parameters
* @param {int} [params.until] The time in ms of the latest record to retrieve as a unix timestamp
* @returns An array of [open interest structures]{@link https://docs.ccxt.com/?id=open-interest-structure}
*/
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("1d".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
}));
let mut options: Value = self.safe_dict_k(self.options.clone(), "fetchOpenInterestHistory", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timeframes: Value = self.safe_dict_k(options.clone(), "timeframes", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
timeframe = self.safe_string(timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
if !is_equal(&timeframe, &Value::Str("5m".to_string())) && !is_equal(&timeframe, &Value::Str("1H".to_string())) && !is_equal(&timeframe, &Value::Str("1D".to_string())) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchOpenInterestHistory cannot only use the 5m, 1h, and 1d timeframe".to_string()))));
}
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
// handle unified currency code or symbol
let mut currencyId: Value = Value::Null;
let mut market: Value = Value::Null;
if is_true(&(is_true(&(!is_equal(&self.markets, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.markets, &symbol)))))) || is_true(&(is_true(&(!is_equal(&self.markets_by_id, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.markets_by_id, &symbol)))))) {
market = self.market(symbol.clone());
currencyId = get_value(&market, &Value::Str("baseId".to_string()));
} else {
let mut currency: Value = self.currency(symbol.clone());
currencyId = get_value(¤cy, &Value::Str("id".to_string()));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ccy".to_string(), currencyId.clone());
m.insert("period".to_string(), timeframe.clone());
m
});
let mut type_var: Value = Value::Null;
let mut response: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenInterestHistory".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("option".to_string())) {
let __ws_arg_81 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_rubik_stat_option_open_interest_volume(&[__ws_arg_81]).await;
} else {
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("begin".to_string()), since.clone());
}
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end".to_string()), until.clone());
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string())]), &[]);
}
let __ws_arg_82 = self.extend(request.clone(), &[params.clone()]);
response = self.public_get_rubik_stat_contracts_open_interest_volume(&[__ws_arg_82]).await;
}
//
// {
// "code": "0",
// "data": [
// [
// "1648221300000", // timestamp
// "2183354317.945", // open interest (USD)
// "74285877.617", // volume (USD)
// ],
// ...
// ],
// "msg": ''
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_open_interests_history(data.clone(), &[Value::Null, since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_open_interest(&self, mut interest: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchOpenInterestHistory
//
// [
// "1648221300000", // timestamp
// "2183354317.945", // open interest (USD) - (coin) for options
// "74285877.617", // volume (USD) - (coin) for options
// ]
//
// fetchOpenInterest
//
// {
// "instId": "BTC-USD-230520-25500-P",
// "instType": "OPTION",
// "oi": "300",
// "oiCcy": "3",
// "oiUsd": "3",
// "ts": "1684551166251"
// }
//
let mut id: Value = self.safe_string_k(interest.clone(), "instId", &[]);
market = self.safe_market(&[id.clone(), market.clone()]);
let mut time: Value = self.safe_integer_k(interest.clone(), "ts", &[]);
let mut timestamp: Value = self.safe_integer(interest.clone(), Value::Int(0), &[time.clone()]);
let mut baseVolume: Value = Value::Null;
let mut quoteVolume: Value = Value::Null;
let mut openInterestAmount: Value = Value::Null;
let mut openInterestValue: Value = Value::Null;
let mut type_var: Value = self.safe_string_k(self.options.clone(), "defaultType", &[]);
if is_true(&Value::Bool(is_array(&interest))) {
if is_equal(&type_var, &Value::Str("option".to_string())) {
openInterestAmount = self.safe_number(interest.clone(), Value::Int(1), &[]);
baseVolume = self.safe_number(interest.clone(), Value::Int(2), &[]);
} else {
openInterestValue = self.safe_number(interest.clone(), Value::Int(1), &[]);
quoteVolume = self.safe_number(interest.clone(), Value::Int(2), &[]);
}
} else {
baseVolume = self.safe_number_k(interest.clone(), "oiCcy", &[]);
openInterestAmount = self.safe_number_k(interest.clone(), "oi", &[]);
openInterestValue = self.safe_number_k(interest.clone(), "oiUsd", &[]);
}
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(id.clone(), &[]));
m.insert("baseVolume".to_string(), baseVolume.clone());
m.insert("quoteVolume".to_string(), quoteVolume.clone());
m.insert("openInterestAmount".to_string(), openInterestAmount.clone());
m.insert("openInterestValue".to_string(), openInterestValue.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
pub fn set_sandbox_mode(&mut self, mut enable: Value) {
self.super_set_sandbox_mode(enable.clone());
add_element_to_object(&mut self.options, &Value::Str("sandboxMode".to_string()), enable.clone());
if is_true(&enable) {
add_element_to_object(&mut self.headers, &Value::Str("x-simulated-trading".to_string()), Value::Str("1".to_string()));
} else if is_true(&Value::Bool(in_op(&self.headers, &Value::Str("x-simulated-trading".to_string())))) {
{ let __t = self.omit(self.headers.clone(), Value::Str("x-simulated-trading".to_string()), &[]); self.headers = __t; }
}
}
/*
* @method
* @name okx#fetchDepositWithdrawFees
* @description fetch deposit and withdraw fees
* @see https://www.okx.com/docs-v5/en/#rest-api-funding-get-currencies
* @param {string[]|undefined} codes list of unified currency codes
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [fees structures]{@link https://docs.ccxt.com/?id=fee-structure}
*/
pub async fn fetch_deposit_withdraw_fees(&mut self, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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(&codes, &Value::Null) {
let mut ids: Value = self.currency_ids(&[codes.clone()]);
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), join(&ids, &Value::Str(",".to_string())));
}
let __ws_arg_83 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_currencies(&[__ws_arg_83]).await;
//
// {
// "code": "0",
// "data": [
// {
// "canDep": true,
// "canInternal": false,
// "canWd": true,
// "ccy": "USDT",
// "chain": "USDT-TRC20",
// "logoLink": "https://static.coinall.ltd/cdn/assets/imgs/221/5F74EB20302D7761.png",
// "mainNet": false,
// "maxFee": "1.6",
// "maxWd": "8852150",
// "minFee": "0.8",
// "minWd": "2",
// "name": "Tether",
// "usedWdQuota": "0",
// "wdQuota": "500",
// "wdTickSz": "3"
// },
// {
// "canDep": true,
// "canInternal": false,
// "canWd": true,
// "ccy": "USDT",
// "chain": "USDT-ERC20",
// "logoLink": "https://static.coinall.ltd/cdn/assets/imgs/221/5F74EB20302D7761.png",
// "mainNet": false,
// "maxFee": "16",
// "maxWd": "8852150",
// "minFee": "8",
// "minWd": "2",
// "name": "Tether",
// "usedWdQuota": "0",
// "wdQuota": "500",
// "wdTickSz": "3"
// },
// ...
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
return self.parse_deposit_withdraw_fees(data.clone(), &[codes.clone()]);
Value::Null
}
pub fn parse_deposit_withdraw_fees(&self, mut response: Value, optional_args: &[Value]) -> Value {
let mut codes = get_arg(optional_args, 0, Value::Null);
let mut currencyIdKey = get_arg(optional_args, 1, Value::Null);
//
// [
// {
// "canDep": true,
// "canInternal": false,
// "canWd": true,
// "ccy": "USDT",
// "chain": "USDT-TRC20",
// "logoLink": "https://static.coinall.ltd/cdn/assets/imgs/221/5F74EB20302D7761.png",
// "mainNet": false,
// "maxFee": "1.6",
// "maxWd": "8852150",
// "minFee": "0.8",
// "minWd": "2",
// "name": "Tether",
// "usedWdQuota": "0",
// "wdQuota": "500",
// "wdTickSz": "3"
// }
// ]
//
let mut depositWithdrawFees: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
codes = self.market_codes(&[codes.clone()]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1008: bool = true;
while { if !__for_first_1008 { i = add(&i, &Value::Int(1)); } __for_first_1008 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut feeInfo: Value = get_value(&response, &i);
let mut feeInfo: Value = get_value(&response, &i);
let mut currencyId: Value = self.safe_string_k(feeInfo.clone(), "ccy", &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[]);
if is_true(&(!is_equal(&code, &Value::Null))) && is_true(&(is_true(&(is_equal(&codes, &Value::Null))) || is_true(&(self.in_array(code.clone(), codes.clone()))))) {
let mut depositWithdrawFee: Value = self.safe_dict(depositWithdrawFees.clone(), code.clone(), &[]);
if is_equal(&depositWithdrawFee, &Value::Null) {
add_element_to_object(&mut depositWithdrawFees, &code, self.deposit_withdraw_fee(Value::Map({
let mut m = indexmap::IndexMap::new();
m
})));
}
if !is_equal(¤cyId, &Value::Null) {
add_element_to_object(get_value_mut(get_value_mut(&mut depositWithdrawFees, &code), &Value::Str("info".to_string())), ¤cyId, feeInfo.clone());
}
let mut chain: Value = self.safe_string_k(feeInfo.clone(), "chain", &[]);
if is_equal(&chain, &Value::Null) {
continue;
}
let mut chainSplit: Value = split(&chain, &Value::Str("-".to_string()));
let mut networkId: Value = self.safe_string(chainSplit.clone(), Value::Int(1), &[]);
let mut withdrawFee: Value = self.safe_number_k(feeInfo.clone(), "fee", &[]);
let mut withdrawResult: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), withdrawFee.clone());
m.insert("percentage".to_string(), ternary(is_true(&(!is_equal(&withdrawFee, &Value::Null))), Value::Bool(false), Value::Null));
m
});
let mut depositResult: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("fee".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m
});
let mut networkCode: Value = self.network_id_to_code(&[networkId.clone(), code.clone()]);
if !is_equal(&networkCode, &Value::Null) {
add_element_to_object(get_value_mut(get_value_mut(&mut depositWithdrawFees, &code), &Value::Str("networks".to_string())), &networkCode, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("withdraw".to_string(), withdrawResult.clone());
m.insert("deposit".to_string(), depositResult.clone());
m
}));
}
}
}
}
let mut depositWithdrawCodes: Value = object_keys(&depositWithdrawFees);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1009: bool = true;
while { if !__for_first_1009 { i = add(&i, &Value::Int(1)); } __for_first_1009 = false; is_less_than(&i, &get_array_length(&depositWithdrawCodes)) } {
let mut code: Value = get_value(&depositWithdrawCodes, &i);
let mut code: Value = get_value(&depositWithdrawCodes, &i);
let mut currency: Value = self.currency(code.clone());
{ let __be_tmp = self.assign_default_deposit_withdraw_fees(get_value(&depositWithdrawFees, &code), &[currency.clone()]); add_element_to_object(&mut depositWithdrawFees, &code, __be_tmp); };
}
}
return depositWithdrawFees;
Value::Null
}
/*
* @method
* @name okx#fetchSettlementHistory
* @description fetches historical settlement records
* @see https://www.okx.com/docs-v5/en/#rest-api-public-data-get-delivery-exercise-history
* @param {string} symbol unified market symbol to fetch the settlement history for
* @param {int} [since] timestamp in ms
* @param {int} [limit] number of records
* @param {object} [params] exchange specific params
* @returns {object[]} a list of [settlement history objects]{@link https://docs.ccxt.com/?id=settlement-history-structure}
*/
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(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchSettlementHistory() 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 type_var: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(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("future".to_string())) && !is_equal(&type_var, &Value::Str("option".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchSettlementHistory() supports futures and options markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), self.convert_to_instrument_type(type_var.clone()));
m.insert("uly".to_string(), add(&add(&get_value(&market, &Value::Str("baseId".to_string())), &Value::Str("-".to_string())), &get_value(&market, &Value::Str("quoteId".to_string()))));
m
});
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), subtract(&since, &Value::Int(1)));
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_84 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_delivery_exercise_history(&[__ws_arg_84]).await;
//
// {
// "code": "0",
// "data": [
// {
// "details": [
// {
// "insId": "BTC-USD-230523-25750-C",
// "px": "27290.1486867000556483",
// "type": "exercised"
// },
// ],
// "ts":"1684656000000"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[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(), &[get_value(&market, &Value::Str("symbol".to_string())), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_settlement(&self, mut settlement: Value, mut market: Value) -> Value {
//
// {
// "insId": "BTC-USD-230521-28500-P",
// "px": "27081.2007345984751516",
// "type": "exercised"
// }
//
let mut marketId: Value = self.safe_string_k(settlement.clone(), "insId", &[]);
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(), "px", &[]));
m.insert("timestamp".to_string(), Value::Null);
m.insert("datetime".to_string(), Value::Null);
m
});
Value::Null
}
pub fn parse_settlements(&self, mut settlements: Value, mut market: Value) -> Value {
//
// {
// "details": [
// {
// "insId": "BTC-USD-230523-25750-C",
// "px": "27290.1486867000556483",
// "type": "exercised"
// },
// ],
// "ts":"1684656000000"
// }
//
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1011: bool = true;
while { if !__for_first_1011 { i = add(&i, &Value::Int(1)); } __for_first_1011 = false; is_less_than(&i, &get_array_length(&settlements)) } {
let mut entry: Value = get_value(&settlements, &i);
let mut entry: Value = get_value(&settlements, &i);
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "ts", &[]);
let mut details: Value = self.safe_list_k(entry.clone(), "details", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_1010: bool = true;
while { if !__for_first_1010 { j = add(&j, &Value::Int(1)); } __for_first_1010 = false; is_less_than(&j, &get_array_length(&details)) } {
let mut settlement: Value = self.parse_settlement(get_value(&details, &j), market.clone());
let __ws_arg_85 = self.iso8601(timestamp.clone());
append_to_array(&mut result, self.extend(settlement.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), __ws_arg_85);
m
})]));
}
}
}
}
return result;
Value::Null
}
/*
* @method
* @name okx#fetchUnderlyingAssets
* @description fetches the market ids of underlying assets for a specific contract market type
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-underlying
* @param {object} [params] exchange specific params
* @param {string} [params.type] the contract market type, 'option', 'swap' or 'future', the default is 'option'
* @returns {object[]} a list of [underlying assets]{@link https://docs.ccxt.com/?id=underlying-assets-structure}
*/
pub async fn fetch_underlying_assets(&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 marketType: Value = Value::Null;
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchUnderlyingAssets".to_string()), &[Value::Null, params.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_true(&(is_equal(&marketType, &Value::Null))) || is_true(&(is_equal(&marketType, &Value::Str("spot".to_string())))) {
marketType = Value::Str("option".to_string());
}
if is_true(&(!is_equal(&marketType, &Value::Str("option".to_string())))) && is_true(&(!is_equal(&marketType, &Value::Str("swap".to_string())))) && is_true(&(!is_equal(&marketType, &Value::Str("future".to_string())))) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" fetchUnderlyingAssets() supports contract markets only".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instType".to_string(), self.convert_to_instrument_type(marketType.clone()));
m
});
let __ws_arg_86 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_underlying(&[__ws_arg_86]).await;
//
// {
// "code": "0",
// "data": [
// [
// "BTC-USD",
// "ETH-USD"
// ]
// ],
// "msg": ""
// }
//
let mut underlyings: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return get_value(&underlyings, &Value::Int(0));
Value::Null
}
/*
* @method
* @name okx#fetchGreeks
* @description fetches an option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-option-market-data
* @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 marketId: Value = self.safe_string_k(market.clone(), "id", &[Value::Str("".to_string())]);
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("uly".to_string(), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("uly".to_string())));
m.insert("instFamily".to_string(), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("instFamily".to_string())));
m.insert("expTime".to_string(), self.safe_string(optionParts.clone(), Value::Int(2), &[]));
m
});
let __ws_arg_87 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_opt_summary(&[__ws_arg_87]).await;
//
// {
// "code": "0",
// "data": [
// {
// "askVol": "0",
// "bidVol": "0",
// "delta": "0.5105464486882039",
// "deltaBS": "0.7325502184143025",
// "fwdPx": "37675.80158694987186",
// "gamma": "-0.13183515090501083",
// "gammaBS": "0.000024139685826358558",
// "instId": "BTC-USD-240329-32000-C",
// "instType": "OPTION",
// "lever": "4.504428015946619",
// "markVol": "0.5916253554539876",
// "realVol": "0",
// "theta": "-0.0004202992014012855",
// "thetaBS": "-18.52354631567909",
// "ts": "1699586421976",
// "uly": "BTC-USD",
// "vega": "0.0020207455080045846",
// "vegaBS": "74.44022302387287",
// "volLv": "0.5948549730405797"
// },
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1012: bool = true;
while { if !__for_first_1012 { i = add(&i, &Value::Int(1)); } __for_first_1012 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut entryMarketId: Value = self.safe_string_k(entry.clone(), "instId", &[]);
if is_equal(&entryMarketId, &marketId) {
return self.parse_greeks(entry.clone(), &[market.clone()]);
}
}
}
panic!("{}", crate::exchange_errors::null_response(add(&add(&self.id, &Value::Str(" fetchGreeks() could not find greeks for ".to_string())), &symbol)));
Value::Null
}
/*
* @method
* @name okx#fetchAllGreeks
* @description fetches all option contracts greeks, financial metrics used to measure the factors that affect the price of an options contract
* @see https://www.okx.com/docs-v5/en/#public-data-rest-api-get-option-market-data
* @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.uly Underlying, either uly or instFamily is required
* @param {string} params.instFamily Instrument family, either uly or instFamily is required
* @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;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true), Value::Bool(true)]);
let mut symbolsLength: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
symbolsLength = get_array_length(&symbols);
}
if is_true(&(is_equal(&symbols, &Value::Null))) || is_true(&(!is_equal(&symbolsLength, &Value::Int(1)))) {
let mut uly: Value = self.safe_string_k(params.clone(), "uly", &[]);
if !is_equal(&uly, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("uly".to_string()), uly.clone());
}
let mut instFamily: Value = self.safe_string_k(params.clone(), "instFamily", &[]);
if !is_equal(&instFamily, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("instFamily".to_string()), instFamily.clone());
}
if is_true(&(is_equal(&uly, &Value::Null))) && is_true(&(is_equal(&instFamily, &Value::Null))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchAllGreeks() requires either a uly or instFamily parameter".to_string()))));
}
}
let mut market: Value = Value::Null;
if !is_equal(&symbols, &Value::Null) {
if is_equal(&symbolsLength, &Value::Int(1)) {
market = self.market(get_value(&symbols, &Value::Int(0)));
let mut marketId: Value = self.safe_string_k(market.clone(), "id", &[Value::Str("".to_string())]);
let mut optionParts: Value = split(&marketId, &Value::Str("-".to_string()));
add_element_to_object(&mut request, &Value::Str("uly".to_string()), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("uly".to_string())));
add_element_to_object(&mut request, &Value::Str("instFamily".to_string()), get_value(&get_value(&market, &Value::Str("info".to_string())), &Value::Str("instFamily".to_string())));
add_element_to_object(&mut request, &Value::Str("expTime".to_string()), self.safe_string(optionParts.clone(), Value::Int(2), &[]));
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("uly".to_string()), Value::Str("instFamily".to_string())]), &[]);
let __ws_arg_88 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_opt_summary(&[__ws_arg_88]).await;
//
// {
// "code": "0",
// "data": [
// {
// "askVol": "0",
// "bidVol": "0",
// "delta": "0.5105464486882039",
// "deltaBS": "0.7325502184143025",
// "fwdPx": "37675.80158694987186",
// "gamma": "-0.13183515090501083",
// "gammaBS": "0.000024139685826358558",
// "instId": "BTC-USD-240329-32000-C",
// "instType": "OPTION",
// "lever": "4.504428015946619",
// "markVol": "0.5916253554539876",
// "realVol": "0",
// "theta": "-0.0004202992014012855",
// "thetaBS": "-18.52354631567909",
// "ts": "1699586421976",
// "uly": "BTC-USD",
// "vega": "0.0020207455080045846",
// "vegaBS": "74.44022302387287",
// "volLv": "0.5948549730405797"
// },
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[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);
//
// {
// "askVol": "0",
// "bidVol": "0",
// "delta": "0.5105464486882039",
// "deltaBS": "0.7325502184143025",
// "fwdPx": "37675.80158694987186",
// "gamma": "-0.13183515090501083",
// "gammaBS": "0.000024139685826358558",
// "instId": "BTC-USD-240329-32000-C",
// "instType": "OPTION",
// "lever": "4.504428015946619",
// "markVol": "0.5916253554539876",
// "realVol": "0",
// "theta": "-0.0004202992014012855",
// "thetaBS": "-18.52354631567909",
// "ts": "1699586421976",
// "uly": "BTC-USD",
// "vega": "0.0020207455080045846",
// "vegaBS": "74.44022302387287",
// "volLv": "0.5948549730405797"
// }
//
let mut timestamp: Value = self.safe_integer_k(greeks.clone(), "ts", &[]);
let mut marketId: Value = self.safe_string_k(greeks.clone(), "instId", &[]);
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(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
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(), Value::Null);
m.insert("askSize".to_string(), Value::Null);
m.insert("bidImpliedVolatility".to_string(), self.safe_number_k(greeks.clone(), "bidVol", &[]));
m.insert("askImpliedVolatility".to_string(), self.safe_number_k(greeks.clone(), "askVol", &[]));
m.insert("markImpliedVolatility".to_string(), self.safe_number_k(greeks.clone(), "markVol", &[]));
m.insert("bidPrice".to_string(), Value::Null);
m.insert("askPrice".to_string(), Value::Null);
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), Value::Null);
m.insert("underlyingPrice".to_string(), Value::Null);
m.insert("info".to_string(), greeks.clone());
m
});
Value::Null
}
/*
* @method
* @name okx#closePosition
* @description closes open positions for a market
* @see https://www.okx.com/docs-v5/en/#order-book-trading-trade-post-close-positions
* @param {string} symbol Unified CCXT market symbol
* @param {string} [side] 'buy' or 'sell', leave as undefined in net mode
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique identifier for the order
* @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross;
* @param {string} [params.code] *required in the case of closing cross MARGIN position for Single-currency margin* margin currency
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {boolean} [params.autoCxl] whether any pending orders for closing out needs to be automatically canceled when close position via a market order. false or true, the default is false
* @param {string} [params.tag] order tag a combination of case-sensitive alphanumerics, all numbers, or all letters of up to 16 characters
* @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
let mut code: Value = self.safe_string_k(params.clone(), "code", &[]);
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("closePosition".to_string()), &[params.clone(), Value::Str("cross".to_string())]); marginMode = 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("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("mgnMode".to_string(), marginMode.clone());
m
});
if !is_equal(&side, &Value::Null) {
if is_true(&(is_equal(&side, &Value::Str("buy".to_string())))) {
add_element_to_object(&mut request, &Value::Str("posSide".to_string()), Value::Str("long".to_string()));
} else if is_equal(&side, &Value::Str("sell".to_string())) {
add_element_to_object(&mut request, &Value::Str("posSide".to_string()), Value::Str("short".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("posSide".to_string()), side.clone());
}
}
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrdId".to_string()), clientOrderId.clone());
}
if !is_equal(&code, &Value::Null) {
let mut currency: Value = self.currency(code.clone());
add_element_to_object(&mut request, &Value::Str("ccy".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
}
let __ws_arg_89 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_trade_close_position(&[__ws_arg_89]).await;
//
// {
// "code": "1",
// "data": [
// {
// "clOrdId":"e847386590ce4dBCe903bbc394dc88bf",
// "ordId":"",
// "sCode":"51000",
// "sMsg":"Parameter posSide error ",
// "tag":"e847386590ce4dBC"
// }
// ],
// "inTime": "1701877077101064",
// "msg": "All operations failed",
// "outTime": "1701877077102579"
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut order: Value = self.safe_dict(data.clone(), Value::Int(0), &[]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchOption
* @description fetches option data that is commonly found in an option chain
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-ticker
* @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("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_90 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_market_ticker(&[__ws_arg_90]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "instType": "OPTION",
// "instId": "BTC-USD-241227-60000-P",
// "last": "",
// "lastSz": "0",
// "askPx": "",
// "askSz": "0",
// "bidPx": "",
// "bidSz": "0",
// "open24h": "",
// "high24h": "",
// "low24h": "",
// "volCcy24h": "0",
// "vol24h": "0",
// "ts": "1711176035035",
// "sodUtc0": "",
// "sodUtc8": ""
// }
// ]
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut chain: Value = self.safe_dict(result.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 okx#fetchOptionChain
* @description fetches data for an underlying asset that is commonly found in an option chain
* @see https://www.okx.com/docs-v5/en/#order-book-trading-market-data-get-tickers
* @param {string} code base currency to fetch an option chain for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.uly] the underlying asset, can be obtained from fetchUnderlyingAssets ()
* @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("uly".to_string(), add(&get_value(¤cy, &Value::Str("code".to_string())), &Value::Str("-USD".to_string())));
m.insert("instType".to_string(), Value::Str("OPTION".to_string()));
m
});
let __ws_arg_91 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_market_tickers(&[__ws_arg_91]).await;
//
// {
// "code": "0",
// "msg": "",
// "data": [
// {
// "instType": "OPTION",
// "instId": "BTC-USD-240323-52000-C",
// "last": "",
// "lastSz": "0",
// "askPx": "",
// "askSz": "0",
// "bidPx": "",
// "bidSz": "0",
// "open24h": "",
// "high24h": "",
// "low24h": "",
// "volCcy24h": "0",
// "vol24h": "0",
// "ts": "1711176207008",
// "sodUtc0": "",
// "sodUtc8": ""
// },
// ]
// }
//
let mut result: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_option_chain(result.clone(), &[Value::Null, Value::Str("instId".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);
//
// {
// "instType": "OPTION",
// "instId": "BTC-USD-241227-60000-P",
// "last": "",
// "lastSz": "0",
// "askPx": "",
// "askSz": "0",
// "bidPx": "",
// "bidSz": "0",
// "open24h": "",
// "high24h": "",
// "low24h": "",
// "volCcy24h": "0",
// "vol24h": "0",
// "ts": "1711176035035",
// "sodUtc0": "",
// "sodUtc8": ""
// }
//
let mut marketId: Value = self.safe_string_k(chain.clone(), "instId", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(chain.clone(), "ts", &[]);
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(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("impliedVolatility".to_string(), Value::Null);
m.insert("openInterest".to_string(), Value::Null);
m.insert("bidPrice".to_string(), self.safe_number_k(chain.clone(), "bidPx", &[]));
m.insert("askPrice".to_string(), self.safe_number_k(chain.clone(), "askPx", &[]));
m.insert("midPrice".to_string(), Value::Null);
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), self.safe_number_k(chain.clone(), "last", &[]));
m.insert("underlyingPrice".to_string(), Value::Null);
m.insert("change".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("baseVolume".to_string(), self.safe_number_k(chain.clone(), "volCcy24h", &[]));
m.insert("quoteVolume".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name okx#fetchConvertQuote
* @description fetch a quote for converting from one currency to another
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-estimate-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
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("baseCcy".to_string(), to_upper(&fromCode));
m.insert("quoteCcy".to_string(), to_upper(&toCode));
m.insert("rfqSzCcy".to_string(), to_upper(&fromCode));
m.insert("rfqSz".to_string(), self.number_to_string(amount.clone()));
m.insert("side".to_string(), Value::Str("sell".to_string()));
m
});
let __ws_arg_92 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_asset_convert_estimate_quote(&[__ws_arg_92]).await;
//
// {
// "code": "0",
// "data": [
// {
// "baseCcy": "ETH",
// "baseSz": "0.01023052",
// "clQReqId": "",
// "cnvtPx": "2932.40104429",
// "origRfqSz": "30",
// "quoteCcy": "USDT",
// "quoteId": "quoterETH-USDT16461885104612381",
// "quoteSz": "30",
// "quoteTime": "1646188510461",
// "rfqSz": "30",
// "rfqSzCcy": "USDT",
// "side": "buy",
// "ttlMs": "10000"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromCurrencyId: Value = self.safe_string_k(result.clone(), "baseCcy", &[fromCode.clone()]);
let mut fromCurrency: Value = self.currency(fromCurrencyId.clone());
let mut toCurrencyId: Value = self.safe_string_k(result.clone(), "quoteCcy", &[toCode.clone()]);
let mut toCurrency: Value = self.currency(toCurrencyId.clone());
return self.parse_conversion(result.clone(), &[fromCurrency.clone(), toCurrency.clone()]);
Value::Null
}
/*
* @method
* @name okx#createConvertTrade
* @description convert from one currency to another
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-convert-trade
* @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("quoteId".to_string(), id.clone());
m.insert("baseCcy".to_string(), fromCode.clone());
m.insert("quoteCcy".to_string(), toCode.clone());
m.insert("szCcy".to_string(), fromCode.clone());
m.insert("sz".to_string(), self.number_to_string(amount.clone()));
m.insert("side".to_string(), Value::Str("sell".to_string()));
m
});
let __ws_arg_93 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_asset_convert_trade(&[__ws_arg_93]).await;
//
// {
// "code": "0",
// "data": [
// {
// "baseCcy": "ETH",
// "clTReqId": "",
// "fillBaseSz": "0.01023052",
// "fillPx": "2932.40104429",
// "fillQuoteSz": "30",
// "instId": "ETH-USDT",
// "quoteCcy": "USDT",
// "quoteId": "quoterETH-USDT16461885104612381",
// "side": "buy",
// "state": "fullyFilled",
// "tradeId": "trader16461885203381437",
// "ts": "1646188520338"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromCurrencyId: Value = self.safe_string_k(result.clone(), "baseCcy", &[fromCode.clone()]);
let mut fromCurrency: Value = self.currency(fromCurrencyId.clone());
let mut toCurrencyId: Value = self.safe_string_k(result.clone(), "quoteCcy", &[toCode.clone()]);
let mut toCurrency: Value = self.currency(toCurrencyId.clone());
return self.parse_conversion(result.clone(), &[fromCurrency.clone(), toCurrency.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchConvertTrade
* @description fetch the data for a conversion trade
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-convert-history
* @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
* @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 request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clTReqId".to_string(), id.clone());
m
});
let __ws_arg_94 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_convert_history(&[__ws_arg_94]).await;
//
// {
// "code": "0",
// "data": [
// {
// "clTReqId": "",
// "instId": "ETH-USDT",
// "side": "buy",
// "fillPx": "2932.401044",
// "baseCcy": "ETH",
// "quoteCcy": "USDT",
// "fillBaseSz": "0.01023052",
// "state": "fullyFilled",
// "tradeId": "trader16461885203381437",
// "fillQuoteSz": "30",
// "ts": "1646188520000"
// }
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = self.safe_dict(data.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fromCurrencyId: Value = self.safe_string_k(result.clone(), "baseCcy", &[]);
let mut toCurrencyId: Value = self.safe_string_k(result.clone(), "quoteCcy", &[]);
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 okx#fetchConvertTradeHistory
* @description fetch the users history of conversion trades
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-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 {int} [params.until] timestamp in ms of the latest conversion to fetch
* @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
});
{ let __destr_tmp = self.handle_until_option(Value::Str("after".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("before".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_95 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_asset_convert_history(&[__ws_arg_95]).await;
//
// {
// "code": "0",
// "data": [
// {
// "clTReqId": "",
// "instId": "ETH-USDT",
// "side": "buy",
// "fillPx": "2932.401044",
// "baseCcy": "ETH",
// "quoteCcy": "USDT",
// "fillBaseSz": "0.01023052",
// "state": "fullyFilled",
// "tradeId": "trader16461885203381437",
// "fillQuoteSz": "30",
// "ts": "1646188520000"
// }
// ],
// "msg": ""
// }
//
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_conversions(rows.clone(), &[code.clone(), Value::Str("baseCcy".to_string()), Value::Str("quoteCcy".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
//
// {
// "baseCcy": "ETH",
// "baseSz": "0.01023052",
// "clQReqId": "",
// "cnvtPx": "2932.40104429",
// "origRfqSz": "30",
// "quoteCcy": "USDT",
// "quoteId": "quoterETH-USDT16461885104612381",
// "quoteSz": "30",
// "quoteTime": "1646188510461",
// "rfqSz": "30",
// "rfqSzCcy": "USDT",
// "side": "buy",
// "ttlMs": "10000"
// }
//
// createConvertTrade
//
// {
// "baseCcy": "ETH",
// "clTReqId": "",
// "fillBaseSz": "0.01023052",
// "fillPx": "2932.40104429",
// "fillQuoteSz": "30",
// "instId": "ETH-USDT",
// "quoteCcy": "USDT",
// "quoteId": "quoterETH-USDT16461885104612381",
// "side": "buy",
// "state": "fullyFilled",
// "tradeId": "trader16461885203381437",
// "ts": "1646188520338"
// }
//
// fetchConvertTrade, fetchConvertTradeHistory
//
// {
// "clTReqId": "",
// "instId": "ETH-USDT",
// "side": "buy",
// "fillPx": "2932.401044",
// "baseCcy": "ETH",
// "quoteCcy": "USDT",
// "fillBaseSz": "0.01023052",
// "state": "fullyFilled",
// "tradeId": "trader16461885203381437",
// "fillQuoteSz": "30",
// "ts": "1646188520000"
// }
//
let mut timestamp: Value = self.safe_integer2(conversion.clone(), Value::Str("quoteTime".to_string()), Value::Str("ts".to_string()), &[]);
let mut fromCoin: Value = self.safe_string_k(conversion.clone(), "baseCcy", &[]);
let mut fromCode: Value = self.safe_currency_code(fromCoin.clone(), &[fromCurrency.clone()]);
let mut to: Value = self.safe_string_k(conversion.clone(), "quoteCcy", &[]);
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_string_n(conversion.clone(), Value::List(vec![Value::Str("clQReqId".to_string()), Value::Str("tradeId".to_string()), Value::Str("quoteId".to_string())]), &[]));
m.insert("fromCurrency".to_string(), fromCode.clone());
m.insert("fromAmount".to_string(), self.safe_number2(conversion.clone(), Value::Str("baseSz".to_string()), Value::Str("fillBaseSz".to_string()), &[]));
m.insert("toCurrency".to_string(), toCode.clone());
m.insert("toAmount".to_string(), self.safe_number2(conversion.clone(), Value::Str("quoteSz".to_string()), Value::Str("fillQuoteSz".to_string()), &[]));
m.insert("price".to_string(), self.safe_number2(conversion.clone(), Value::Str("cnvtPx".to_string()), Value::Str("fillPx".to_string()), &[]));
m.insert("fee".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name okx#fetchConvertCurrencies
* @description fetches all available currencies that can be converted
* @see https://www.okx.com/docs-v5/en/#funding-account-rest-api-get-convert-currencies
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @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 response: Value = self.private_get_asset_convert_currencies(&[params.clone()]).await;
//
// {
// "code": "0",
// "data": [
// {
// "ccy": "BTC",
// "max": "",
// "min": ""
// },
// ],
// "msg": ""
// }
//
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1013: bool = true;
while { if !__for_first_1013 { i = add(&i, &Value::Int(1)); } __for_first_1013 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
let mut id: Value = self.safe_string_k(entry.clone(), "ccy", &[]);
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(), Value::Null);
m.insert("name".to_string(), Value::Null);
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(), self.safe_number_k(entry.clone(), "min", &[]));
m.insert("max".to_string(), self.safe_number_k(entry.clone(), "max", &[]));
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
}
pub fn handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_equal(&response, &Value::Null) {
return Value::Null;
}
//
// {
// "code": "1",
// "data": [
// {
// "clOrdId": "",
// "ordId": "",
// "sCode": "51119",
// "sMsg": "Order placement failed due to insufficient balance. ",
// "tag": ""
// }
// ],
// "msg": ""
// },
// {
// "code": "58001",
// "data": [],
// "msg": "Incorrect trade password"
// }
//
let mut code: Value = self.safe_string_k(response.clone(), "code", &[]);
if is_true(&(!is_equal(&code, &Value::Str("0".to_string())))) && is_true(&(!is_equal(&code, &Value::Str("2".to_string())))) {
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1014: bool = true;
while { if !__for_first_1014 { i = add(&i, &Value::Int(1)); } __for_first_1014 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut error: Value = get_value(&data, &i);
let mut error: Value = get_value(&data, &i);
let mut errorCode: Value = self.safe_string_k(error.clone(), "sCode", &[]);
let mut message: Value = self.safe_string_k(error.clone(), "sMsg", &[]);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
}
}
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), code.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
/*
* @method
* @name okx#fetchMarginAdjustmentHistory
* @description fetches the history of margin added or reduced from contract isolated positions
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-7-days
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-bills-details-last-3-months
* @param {string} [symbol] not used by okx fetchMarginAdjustmentHistory
* @param {string} [type] "add" or "reduce"
* @param {int} [since] the earliest time in ms to fetch margin adjustment history for
* @param {int} [limit] the maximum number of entries to retrieve
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {boolean} [params.auto] true if fetching auto margin increases
* @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/?id=margin-loan-structure}
*/
pub async fn fetch_margin_adjustment_history(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut type_var = 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 auto: Value = self.safe_bool_k(params.clone(), "auto", &[]);
if is_equal(&type_var, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMarginAdjustmentHistory () requires a type argument".to_string()))));
}
let mut isAdd: bool = is_equal(&type_var, &Value::Str("add".to_string()));
let mut subType: Value = ternary(is_true(&isAdd), Value::Str("160".to_string()), Value::Str("161".to_string()));
if is_equal(&auto, &Value::Bool(true)) {
if is_true(&isAdd) {
subType = Value::Str("162".to_string());
} else {
panic!("{}", crate::exchange_errors::bad_request(add(&add(&self.id, &Value::Str(" cannot fetch margin adjustments for type ".to_string())), &type_var)));
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("subType".to_string(), subType.clone());
m.insert("mgnMode".to_string(), Value::Str("isolated".to_string()));
m
});
let mut until: Value = self.safe_integer_k(params.clone(), "until", &[]);
params = self.omit(params.clone(), Value::Str("until".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());
}
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let mut response: Value = Value::Null;
let mut now: Value = self.milliseconds();
let mut oneWeekAgo: Value = subtract(&now, &Value::Int(604800000));
let mut threeMonthsAgo: Value = subtract(&now, &Value::Int(7776000000));
if is_true(&(is_equal(&since, &Value::Null))) || is_true(&(is_greater_than(&since, &oneWeekAgo))) {
let __ws_arg_96 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_account_bills(&[__ws_arg_96]).await;
} else if is_greater_than(&since, &threeMonthsAgo) {
let __ws_arg_97 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_account_bills_archive(&[__ws_arg_97]).await;
} else {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" fetchMarginAdjustmentHistory () cannot fetch margin adjustments older than 3 months".to_string()))));
}
//
// {
// code: '0',
// data: [
// {
// bal: '67621.4325135010619812',
// balChg: '-10.0000000000000000',
// billId: '691293628710342659',
// ccy: 'USDT',
// clOrdId: '',
// execType: '',
// fee: '0',
// fillFwdPx: '',
// fillIdxPx: '',
// fillMarkPx: '',
// fillMarkVol: '',
// fillPxUsd: '',
// fillPxVol: '',
// fillTime: '1711089244850',
// from: '',
// instId: 'XRP-USDT-SWAP',
// instType: 'SWAP',
// interest: '0',
// mgnMode: 'isolated',
// notes: '',
// ordId: '',
// pnl: '0',
// posBal: '73.12',
// posBalChg: '10.00',
// px: '',
// subType: '160',
// sz: '10',
// tag: '',
// to: '',
// tradeId: '0',
// ts: '1711089244699',
// type: '6'
// }
// ],
// msg: ''
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut modifications: Value = self.parse_margin_modifications(data.clone(), &[]);
return self.filter_by_symbol_since_limit(modifications.clone(), &[symbol.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchPositionsHistory
* @description fetches historical positions
* @see https://www.okx.com/docs-v5/en/#trading-account-rest-api-get-positions-history
* @param {string} [symbols] unified market symbols
* @param {int} [since] timestamp in ms of the earliest position to fetch
* @param {int} [limit] the maximum amount of records to fetch, default=100, max=100
* @param {object} params extra parameters specific to the exchange API endpoint
* @param {string} [params.marginMode] "cross" or "isolated"
*
* EXCHANGE SPECIFIC PARAMETERS
* @param {string} [params.instType] margin, swap, futures or option
* @param {string} [params.type] the type of latest close position 1: close position partially, 2:close all, 3:liquidation, 4:partial liquidation; 5:adl, is it is the latest type if there are several types for the same position
* @param {string} [params.posId] position id, there is attribute expiration, the posid will be expired if it is more than 30 days after the last full close position, then position will use new posid
* @param {string} [params.before] timestamp in ms of the earliest position to fetch based on the last update time of the position
* @param {string} [params.after] timestamp in ms of the latest position to fetch based on the last update time of the position
* @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 marginMode: Value = self.safe_string_k(params.clone(), "marginMode", &[]);
let mut instType: Value = self.safe_string_upper(params.clone(), Value::Str("instType".to_string()), &[]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("until".to_string()), Value::Str("marginMode".to_string()), Value::Str("instType".to_string())]), &[]);
if is_equal(&limit, &Value::Null) {
limit = Value::Int(100);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), limit.clone());
m
});
if !is_equal(&symbols, &Value::Null) {
let mut symbolsLength: Value = get_array_length(&symbols);
if is_equal(&symbolsLength, &Value::Int(1)) {
let mut market: Value = self.market(get_value(&symbols, &Value::Int(0)));
add_element_to_object(&mut request, &Value::Str("instId".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("mgnMode".to_string()), marginMode.clone());
}
if !is_equal(&instType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("instType".to_string()), instType.clone());
}
let __ws_arg_98 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_account_positions_history(&[__ws_arg_98]).await;
//
// {
// code: '0',
// data: [
// {
// cTime: '1708735940395',
// ccy: 'USDT',
// closeAvgPx: '0.6330444444444444',
// closeTotalPos: '27',
// direction: 'long',
// fee: '-1.69566',
// fundingFee: '-11.870404179341788',
// instId: 'XRP-USDT-SWAP',
// instType: 'SWAP',
// lever: '3.0',
// liqPenalty: '0',
// mgnMode: 'cross',
// openAvgPx: '0.623',
// openMaxPos: '15',
// pnl: '27.11999999999988',
// pnlRatio: '0.0241732402722634',
// posId: '681423155054862336',
// realizedPnl: '13.553935820658092',
// triggerPx: '',
// type: '2',
// uTime: '1711088748170',
// uly: 'XRP-USDT'
// },
// ...
// ],
// msg: ''
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut positions: Value = self.parse_positions(data.clone(), &[symbols.clone(), params.clone()]);
return self.filter_by_since_limit(positions.clone(), &[since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name okx#fetchLongShortRatioHistory
* @description fetches the long short ratio history for a unified market symbol
* @see https://www.okx.com/docs-v5/en/#trading-statistics-rest-api-get-contract-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
* @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
* @param {int} [params.until] timestamp in ms of the latest ratio to fetch
* @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;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchLongShortRatioHistory() requires a symbol argument".to_string()))));
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("instId".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut until: Value = self.safe_string2(params.clone(), Value::Str("until".to_string()), Value::Str("end".to_string()), &[]);
params = self.omit(params.clone(), Value::Str("until".to_string()), &[]);
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("end".to_string()), until.clone());
}
if !is_equal(&timeframe, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("period".to_string()), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("begin".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), limit.clone());
}
let __ws_arg_99 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_rubik_stat_contracts_long_short_account_ratio_contract(&[__ws_arg_99]).await;
//
// {
// "code": "0",
// "data": [
// ["1729323600000", "0.9398602814619824"],
// ["1729323300000", "0.9398602814619824"],
// ["1729323000000", "0.9398602814619824"],
// ],
// "msg": ""
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_1015: bool = true;
while { if !__for_first_1015 { i = add(&i, &Value::Int(1)); } __for_first_1015 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut entry: Value = get_value(&data, &i);
let mut entry: Value = get_value(&data, &i);
append_to_array(&mut result, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timestamp".to_string(), self.safe_string(entry.clone(), Value::Int(0), &[]));
m.insert("longShortRatio".to_string(), self.safe_string(entry.clone(), Value::Int(1), &[]));
m
}));
}
}
return self.parse_long_short_ratio_history(result.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);
let mut timestamp: Value = self.safe_integer_k(info.clone(), "timestamp", &[]);
let mut symbol: Value = Value::Null;
if !is_equal(&market, &Value::Null) {
symbol = get_value(&market, &Value::Str("symbol".to_string()));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), info.clone());
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("timeframe".to_string(), Value::Null);
m.insert("longShortRatio".to_string(), self.safe_number_k(info.clone(), "longShortRatio", &[]));
m
});
Value::Null
}
}