// 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 BtseCore {
pub exchange: crate::exchange::Exchange,
}
impl BtseCore {
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 = BtseCore::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 BtseCore {
fn nonce(&self, ) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::nonce(self, )
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_ticker(self, ticker, &[market.clone()])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_trade(self, trade, &[market.clone()])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_order(self, order, &[market.clone()])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_ohlcv(self, ohlcv, &[market.clone()])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::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 BtseCore.
BtseCore::parse_funding_rate(self, rate, &[market.clone()])
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_ledger_entry(self, entry, &[currency.clone()])
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_open_interest(self, interest, &[market.clone()])
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_funding_rate_history(self, entry, &[market.clone()])
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_transaction(self, transaction, &[currency.clone()])
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::parse_margin_mode(self, margin_mode, &[market.clone()])
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
// Forward to the inherent method on BtseCore.
BtseCore::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 BtseCore.
BtseCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BtseCore {
fn call_dynamic<'a>(&'a mut self, method: &'a str, args: Vec<crate::Value>)
-> std::pin::Pin<Box<dyn std::future::Future<Output = crate::Value> + Send + 'a>>
{
Box::pin(async move {
match method {
"cancel_all_orders" => self.cancel_all_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_all_orders_after" => self.cancel_all_orders_after(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"clean_path" => self.clean_path(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"close_position" => self.close_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_contract_order" => self.create_contract_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_order" => self.create_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"create_spot_order" => self.create_spot_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"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,
"encode_trigger_price_type" => self.encode_trigger_price_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"fetch_balance" => self.fetch_balance(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits" => self.fetch_deposits(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate" => self.fetch_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_funding_rates" => self.fetch_funding_rates(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_ledger" => self.fetch_ledger(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage" => self.fetch_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_leverage_tiers" => self.fetch_leverage_tiers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_margin_mode" => self.fetch_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_market_leverage_tiers" => self.fetch_market_leverage_tiers(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_markets" => self.fetch_markets(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_my_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_interests" => self.fetch_open_interests(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_order" => self.fetch_open_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_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_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_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_tickers" => self.fetch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_time" => self.fetch_time(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fee" => self.fetch_trading_fee(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_trading_fees" => self.fetch_trading_fees(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"fetch_withdrawals" => self.fetch_withdrawals(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"futures_request_id" => self.futures_request_id(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"nonce" => self.nonce(),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_funding_rate" => self.parse_funding_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_funding_rate_history" => self.parse_funding_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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_direction" => self.parse_ledger_entry_direction(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ledger_entry_type" => self.parse_ledger_entry_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_margin_mode" => self.parse_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_margin_mode_type" => self.parse_margin_mode_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_market" => self.parse_market(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ohlcv" => self.parse_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_order_status" => self.parse_order_status(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_order_type" => self.parse_order_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_position_side" => self.parse_position_side(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_time_in_force" => self.parse_time_in_force(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_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_transaction_type" => self.parse_transaction_type(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"request_wallet_history_rows" => self.request_wallet_history_rows(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), &args.get(2..).unwrap_or(&[]).to_vec()[..]).await,
"set_leverage" => self.set_leverage(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_margin_mode" => self.set_margin_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"set_position_mode" => self.set_position_mode(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BtseCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BtseCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BtseCore {
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("btse".to_string()));
m.insert("name".to_string(), Value::Str("BTSE".to_string()));
m.insert("countries".to_string(), Value::List(vec![Value::Str("VG".to_string())]));
m.insert("rateLimit".to_string(), divide(&Value::Int(1000), &Value::Int(75)));
m.insert("version".to_string(), Value::Str("v3".to_string()));
m.insert("certified".to_string(), Value::Bool(false));
m.insert("pro".to_string(), Value::Bool(false));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(false));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowCrossMargin".to_string(), Value::Bool(false));
m.insert("borrowIsolatedMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersAfter".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
m.insert("cancelOrdersWithClientOrderId".to_string(), Value::Bool(false));
m.insert("cancelOrderWithClientOrderId".to_string(), Value::Bool(true));
m.insert("closeAllPositions".to_string(), Value::Bool(false));
m.insert("closePosition".to_string(), Value::Bool(true));
m.insert("createDepositAddress".to_string(), Value::Bool(false));
m.insert("createLimitBuyOrder".to_string(), Value::Bool(true));
m.insert("createLimitOrder".to_string(), Value::Bool(true));
m.insert("createLimitSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrder".to_string(), Value::Bool(true));
m.insert("createMarketBuyOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createMarketOrderWithCost".to_string(), Value::Bool(false));
m.insert("createMarketSellOrder".to_string(), Value::Bool(true));
m.insert("createMarketSellOrderWithCost".to_string(), Value::Bool(false));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createOrders".to_string(), Value::Bool(false));
m.insert("createOrderWithTakeProfitAndStopLoss".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
m.insert("createReduceOnlyOrder".to_string(), Value::Bool(true));
m.insert("createStopLimitOrder".to_string(), Value::Bool(false));
m.insert("createStopLossOrder".to_string(), Value::Bool(false));
m.insert("createStopMarketOrder".to_string(), Value::Bool(true));
m.insert("createStopOrder".to_string(), Value::Bool(true));
m.insert("createTakeProfitOrder".to_string(), Value::Bool(true));
m.insert("createTrailingAmountOrder".to_string(), Value::Bool(true));
m.insert("createTrailingPercentOrder".to_string(), Value::Bool(false));
m.insert("createTriggerOrder".to_string(), Value::Bool(true));
m.insert("deposit".to_string(), Value::Bool(false));
m.insert("editOrder".to_string(), Value::Bool(true));
m.insert("editOrders".to_string(), Value::Bool(false));
m.insert("editOrderWithClientOrderId".to_string(), Value::Bool(true));
m.insert("fetchAccounts".to_string(), Value::Bool(false));
m.insert("fetchBalance".to_string(), Value::Bool(true));
m.insert("fetchBidsAsks".to_string(), Value::Bool(false));
m.insert("fetchBorrowInterest".to_string(), Value::Bool(false));
m.insert("fetchBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(false));
m.insert("fetchBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchBorrowRatesPerSymbol".to_string(), Value::Bool(false));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(false));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(false));
m.insert("fetchConvertCurrencies".to_string(), Value::Bool(false));
m.insert("fetchConvertQuote".to_string(), Value::Bool(false));
m.insert("fetchConvertTrade".to_string(), Value::Bool(false));
m.insert("fetchConvertTradeHistory".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(false));
m.insert("fetchDeposit".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(false));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(true));
m.insert("fetchDepositsWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchDepositWithdrawFee".to_string(), Value::Bool(false));
m.insert("fetchDepositWithdrawFees".to_string(), Value::Bool(false));
m.insert("fetchFundingHistory".to_string(), Value::Bool(false));
m.insert("fetchFundingInterval".to_string(), Value::Bool(false));
m.insert("fetchFundingIntervals".to_string(), Value::Bool(false));
m.insert("fetchFundingRate".to_string(), Value::Bool(true));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".to_string(), Value::Bool(true));
m.insert("fetchGreeks".to_string(), Value::Bool(false));
m.insert("fetchIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchIsolatedBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchIsolatedPositions".to_string(), Value::Bool(false));
m.insert("fetchL2OrderBook".to_string(), Value::Bool(false));
m.insert("fetchL3OrderBook".to_string(), Value::Bool(false));
m.insert("fetchLastPrices".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(true));
m.insert("fetchLedgerEntry".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(true));
m.insert("fetchLeverages".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchLiquidations".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatio".to_string(), Value::Bool(false));
m.insert("fetchLongShortRatioHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginAdjustmentHistory".to_string(), Value::Bool(false));
m.insert("fetchMarginMode".to_string(), Value::Bool(true));
m.insert("fetchMarginModes".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(true));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMarkPrices".to_string(), Value::Bool(false));
m.insert("fetchMyLiquidations".to_string(), Value::Bool(false));
m.insert("fetchMySettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(true));
m.insert("fetchOpenOrder".to_string(), Value::Bool(true));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOption".to_string(), Value::Bool(false));
m.insert("fetchOptionChain".to_string(), Value::Bool(false));
m.insert("fetchOrder".to_string(), Value::Bool(false));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(false));
m.insert("fetchOrdersByStatus".to_string(), Value::Bool(false));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchOrderWithClientOrderId".to_string(), Value::Bool(false));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(true));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(true));
m.insert("fetchPositionsHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionsRisk".to_string(), Value::Bool(false));
m.insert("fetchPremiumIndexOHLCV".to_string(), Value::Bool(false));
m.insert("fetchSettlementHistory".to_string(), Value::Bool(false));
m.insert("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(true));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(true));
m.insert("fetchTradingFees".to_string(), Value::Bool(true));
m.insert("fetchTradingLimits".to_string(), Value::Bool(false));
m.insert("fetchTransactionFee".to_string(), Value::Bool(false));
m.insert("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfer".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(false));
m.insert("fetchUnderlyingAssets".to_string(), Value::Bool(false));
m.insert("fetchVolatilityHistory".to_string(), Value::Bool(false));
m.insert("fetchWithdrawAddresses".to_string(), Value::Bool(false));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(true));
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayCrossMargin".to_string(), Value::Bool(false));
m.insert("repayIsolatedMargin".to_string(), Value::Bool(false));
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("setLeverage".to_string(), Value::Bool(true));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(true));
m.insert("setPositionMode".to_string(), Value::Bool(true));
m.insert("signIn".to_string(), Value::Bool(false));
m.insert("transfer".to_string(), Value::Bool(false));
m.insert("watchMyLiquidationsForSymbols".to_string(), Value::Bool(false));
m.insert("withdraw".to_string(), Value::Bool(false));
m.insert("ws".to_string(), Value::Bool(false));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("logo".to_string(), Value::Str("https://github.com/user-attachments/assets/879ce771-6db1-4d8f-868a-77c9621635dc".to_string()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.btse.com".to_string()));
m.insert("private".to_string(), Value::Str("https://api.btse.com".to_string()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://testapi.btse.io".to_string()));
m.insert("private".to_string(), Value::Str("https://testapi.btse.io".to_string()));
m
}));
m.insert("www".to_string(), Value::Str("https://www.btse.com".to_string()));
m.insert("doc".to_string(), Value::Str("https://support.btse.com/en/support/solutions/articles/43000044751-btse-api".to_string()));
m.insert("referral".to_string(), Value::Str("https://www.btse.com/referral/o2tjIXx5".to_string()));
m.insert("fees".to_string(), Value::Str("https://support.btse.com/en/support/solutions/articles/43000064283".to_string()));
m
}));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/market_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/ohlcv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/price".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/orderbook".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/orderbook/L2".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/time".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/market_summary".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/ohlcv".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/price".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/orderbook".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/orderbook/L2".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/funding_history".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/market/risk_limit".to_string(), Value::Int(5));
m.insert("spot/api/v3.2/availableCurrencyNetworks".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/exchangeRate".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/crypto/networks".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/assets/exchangeRate".to_string(), Value::Int(15));
m.insert("public-api/market/v1/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/exchangeInfo".to_string(), Value::Int(3));
m.insert("public-api/market/v1/orderbook".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/klines".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/ticker/24hr".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/ticker/price".to_string(), Value::Int(3));
m.insert("public-api/market/v1/ticker/indices".to_string(), Value::Int(3));
m.insert("public-api/market/v1/ticker/l1".to_string(), Value::Int(3));
m.insert("public-api/market/v1/recentFundingHistory".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/market/v1/riskLimits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(3));
m
}));
m.insert("public-api/wallet/v1/crypto/list".to_string(), Value::Int(15));
m.insert("public-api/otc/v1/markets".to_string(), Value::Int(1));
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("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/user/open_orders".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/user/trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/user/fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v3.3/invest/products".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/orders".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/history".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/user/open_orders".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/user/trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/leverage".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/margin_setting".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/wallet".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/wallet_history".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/unifiedWallet/margin".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/user/margin".to_string(), Value::Int(5));
m.insert("otc/api/v1/getMarket".to_string(), Value::Int(1));
m.insert("spot/api/v3.2/user/wallet".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("spot/api/v3.2/user/wallet_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("spot/api/v3.3/user/wallet/address".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/availableCurrencies".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/subaccount/wallet/history".to_string(), Value::Int(15));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v4/trade/order".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("spot/api/v4/trade/trade_history".to_string(), Value::Int(5));
m.insert("spot/api/v4/trade/fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v3/trade/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/trade_history".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v3/trade/margin_setting".to_string(), Value::Int(5));
m.insert("public-api/wallet/v1/assets".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(15));
m
}));
m.insert("public-api/wallet/v1/user/walletHistory".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/crypto/address".to_string(), Value::Int(15));
m.insert("public-api/otc/v1/quotes".to_string(), Value::Int(1));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/order/peg".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/order/cancelAllAfter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v3.3/invest/deposit".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/renew".to_string(), Value::Int(5));
m.insert("spot/api/v3.3/invest/redeem".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order/peg".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order/cancelAllAfter".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v2.3/order/close_position".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/leverage".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/settle_in".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/order/bind/tpsl".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("futures/api/v2.3/user/wallet/transfer".to_string(), Value::Int(5));
m.insert("futures/api/v2.3/subaccount/wallet/transfer".to_string(), Value::Int(5));
m.insert("otc/api/v1/quote".to_string(), Value::Int(1));
m.insert("otc/api/v1/accept/{quoteId}".to_string(), Value::Int(1));
m.insert("otc/api/v1/reject/{quoteId}".to_string(), Value::Int(1));
m.insert("otc/api/v1/queryOrder/{quoteId}".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/user/wallet/address".to_string(), Value::Int(15));
m.insert("spot/api/v3.3/user/wallet/withdraw".to_string(), Value::Int(15));
m.insert("spot/api/v3.2/user/wallet/convert".to_string(), Value::Int(15));
m.insert("spot/api/v3.3/user/wallet/transfer".to_string(), Value::Int(15));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v4/trade/orders/cancel_all_after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v4/trade/orders/algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders/cancel_all_after".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders/algo".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/settle_in".to_string(), Value::Int(5));
m.insert("futures/api/v3/trade/risk_limit".to_string(), Value::Int(5));
m.insert("futures/api/v3/trade/positions/tpsl".to_string(), Value::Int(1));
m.insert("futures/api/v3/trade/position_mode".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("public-api/wallet/v1/user/crypto/address".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/crypto/withdraw".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/assets/sendTo".to_string(), Value::Int(15));
m.insert("public-api/wallet/v1/user/assets/convert".to_string(), Value::Int(15));
m.insert("public-api/otc/v1/quotes".to_string(), Value::Int(1));
m.insert("public-api/otc/v1/quotes/accept".to_string(), Value::Int(1));
m
}));
m.insert("put".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("delete".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("spot/api/v3.3/order".to_string(), Value::Int(1));
m.insert("futures/api/v2.3/order".to_string(), Value::Int(1));
m.insert("spot/api/v3.3/user/wallet/address".to_string(), Value::Int(15));
m.insert("spot/api/v4/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("spot/api/v4/trade/orders/all".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("futures/api/v3/trade/positions".to_string(), Value::Int(1));
m.insert("public-api/wallet/v1/user/crypto/address".to_string(), Value::Int(15));
m
}));
m
}));
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("contract".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("mark".to_string(), Value::Bool(true));
m.insert("last".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(false));
m
}));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Bool(true));
m.insert("mark".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(false));
m
}));
m.insert("price".to_string(), Value::Bool(false));
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(true));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("daysBack".to_string(), Value::Null);
m.insert("limit".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOpenOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(300));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("mark".to_string(), Value::Bool(false));
m.insert("last".to_string(), Value::Bool(true));
m.insert("index".to_string(), Value::Bool(true));
m
}));
m.insert("stopLossPrice".to_string(), Value::Bool(true));
m.insert("takeProfitPrice".to_string(), Value::Bool(true));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(true));
m.insert("iceberg".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("daysBack".to_string(), Value::Null);
m.insert("limit".to_string(), Value::Null);
m.insert("untilDays".to_string(), Value::Int(7));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrder".to_string(), Value::Null);
m.insert("fetchOpenOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Null);
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Null);
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Null);
m.insert("fetchClosedOrders".to_string(), Value::Null);
m.insert("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(300));
m
}));
m
}));
m.insert("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("contract".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m.insert("future".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("contract".to_string()));
m
}));
m.insert("inverse".to_string(), Value::Null);
m
}));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1".to_string()));
m.insert("5m".to_string(), Value::Str("5".to_string()));
m.insert("15m".to_string(), Value::Str("15".to_string()));
m.insert("30m".to_string(), Value::Str("30".to_string()));
m.insert("1h".to_string(), Value::Str("60".to_string()));
m.insert("4h".to_string(), Value::Str("240".to_string()));
m.insert("6h".to_string(), Value::Str("360".to_string()));
m.insert("1d".to_string(), Value::Str("1440".to_string()));
m.insert("1w".to_string(), Value::Str("10080".to_string()));
m.insert("1M".to_string(), Value::Str("43200".to_string()));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m
}));
m.insert("contract".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(true));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.0002".to_string()), &[]));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.00055".to_string()), &[]));
m
}));
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("-2".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("-7".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("-7006".to_string(), Value::Str("BadSymbol".to_string()).clone());
m.insert("-11".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("1".to_string(), Value::Str("ExchangeNotAvailable".to_string()).clone());
m.insert("8".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("11".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("12".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("13".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("15".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("16".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("17".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("28".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("41".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("64".to_string(), Value::Str("ExchangeError".to_string()).clone());
m.insert("101".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("133".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("134".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("135".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("300".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("301".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("302".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("303".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("304".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("305".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("1004".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("4003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("4005".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("4051".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("10002".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("10010004".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("11000001".to_string(), Value::Str("BadRequest".to_string()).clone());
m.insert("51523".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("33001001".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("33001003".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("33199101".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("33199120".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Order not found".to_string(), Value::Str("OrderNotFound".to_string()).clone());
m.insert("Insufficient wallet balance".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("Insufficient balance".to_string(), Value::Str("InsufficientFunds".to_string()).clone());
m.insert("Authentication Failed".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("Authenticate failed".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("Signature verification failed".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("api parameter is mandatory".to_string(), Value::Str("AuthenticationError".to_string()).clone());
m.insert("Invalid nonce".to_string(), Value::Str("InvalidNonce".to_string()).clone());
m.insert("Invalid order size".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("Invalid order price".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("Maximum open orders exceeded".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("Rate limit exceeded".to_string(), Value::Str("RateLimitExceeded".to_string()).clone());
m.insert("auto-deleveraging".to_string(), Value::Str("InvalidOrder".to_string()).clone());
m.insert("BADREQUEST".to_string(), Value::Str("BadRequest".to_string()).clone());
m
}));
m
}));
m.insert("commonCurrencies".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("timeDifference".to_string(), Value::Int(0));
m.insert("adjustForTimeDifference".to_string(), Value::Bool(false));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("GTC".to_string()));
m.insert("IOC".to_string(), Value::Str("IOC".to_string()));
m.insert("FOK".to_string(), Value::Str("FOK".to_string()));
m.insert("HALFSEC".to_string(), Value::Str("HALFSEC".to_string()));
m.insert("HALFMIN".to_string(), Value::Str("HALFMIN".to_string()));
m.insert("FIVEMIN".to_string(), Value::Str("FIVEMIN".to_string()));
m.insert("HOUR".to_string(), Value::Str("HOUR".to_string()));
m.insert("TWELVEHOUR".to_string(), Value::Str("TWELVEHOUR".to_string()));
m.insert("DAY".to_string(), Value::Str("DAY".to_string()));
m.insert("WEEK".to_string(), Value::Str("WEEK".to_string()));
m.insert("MONTH".to_string(), Value::Str("MONTH".to_string()));
m
}));
m.insert("accountsByType".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("accountsById".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name btse#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://btsecom.github.io/docs/spotV3_3/en/#query-server-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_spot_api_v33_time(&[params.clone()]).await;
return self.safe_timestamp(response.clone(), Value::Str("epoch".to_string()), &[]);
Value::Null
}
/*
* @method
* @name btse#fetchMarkets
* @description retrieves data on all markets for btse
* @see https://docs.btse.com/markets/rest/get-markets/
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} an array of objects representing market data
*/
pub async fn fetch_markets(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&get_value(&self.options, &Value::Str("adjustForTimeDifference".to_string())), &Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut response: Value = self.public_get_public_api_market_v1_markets(&[params.clone()]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut markets: Value = self.safe_list_k(data.clone(), "symbols", &[Value::List(vec![])]);
return self.parse_markets(markets.clone());
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
//
// spot
// {
// "symbol": "BTC-USDT",
// "type": "Spot",
// "category": "CRYPTO",
// "tradeCurrency": "BTC",
// "baseCurrency": "BTC",
// "quoteCurrency": "USDT",
// "displayName": "Bitcoin",
// "active": true,
// "minOrderPrice": "0.1",
// "minPriceIncrement": "0.1",
// "pricePrecision": 1,
// "minOrderSize": "0.00001",
// "maxOrderSize": "100",
// "minSizeIncrement": "0.00001",
// "sizePrecision": 5
// }
//
// swap
// {
// "symbol": "BTC-PERP-USDT",
// "type": "FuturesPerpetual",
// "category": "CRYPTO",
// "tradeCurrency": "BTC-PERP",
// "baseCurrency": "BTC",
// "quoteCurrency": "USDT",
// "displayName": "Bitcoin",
// "active": true,
// "minOrderPrice": "0.1",
// "minPriceIncrement": "0.1",
// "pricePrecision": 1,
// "minOrderSize": "1",
// "maxOrderSize": "7500000",
// "minSizeIncrement": "1",
// "sizePrecision": 0,
// "contractSize": "0.00001",
// "availableSettlement": [ "USD", "USDT" ]
// }
//
// future
// {
// "symbol": "BTC-260925-USDT",
// "type": "FuturesTimeBased",
// "category": "CRYPTO",
// "tradeCurrency": "BTC-260925",
// "baseCurrency": "BTC",
// "quoteCurrency": "USDT",
// "displayName": "Bitcoin",
// "active": true,
// "minOrderPrice": "0.1",
// "minPriceIncrement": "0.1",
// "pricePrecision": 1,
// "minOrderSize": "1",
// "maxOrderSize": "100000",
// "minSizeIncrement": "1",
// "sizePrecision": 0,
// "contractSize": "0.00001",
// "availableSettlement": [ "USD", "USDT" ],
// "contractStartTime": 1774569600000,
// "contractEndTime": 1790323230000,
// "matchingStartTime": 1774569615000,
// "becomeInactiveTime": 1790323200000
// }
//
let mut marketType: Value = self.safe_string_k(market.clone(), "type", &[]);
let mut isSpot: Value = Value::Bool(is_equal(&marketType, &Value::Str("Spot".to_string())));
let mut isFuture: Value = Value::Bool(is_equal(&marketType, &Value::Str("FuturesTimeBased".to_string())));
let mut isSwap: Value = Value::Bool(is_equal(&marketType, &Value::Str("FuturesPerpetual".to_string())));
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseCurrency", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteCurrency", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
let mut symbol: Value = add(&add(&base, &Value::Str("/".to_string())), "e);
let mut maxAmountString: Value = self.safe_string_k(market.clone(), "maxOrderSize", &[]);
let mut minAmountString: Value = self.safe_string_k(market.clone(), "minOrderSize", &[]);
let mut minPriceString: Value = self.safe_string_k(market.clone(), "minOrderPrice", &[]);
let mut pricePrecision: Value = self.safe_string_k(market.clone(), "minPriceIncrement", &[]);
let mut amountPrecision: Value = self.safe_string_k(market.clone(), "minSizeIncrement", &[]);
let mut active: Value = self.safe_bool_k(market.clone(), "active", &[]);
let mut type_var: Value = Value::Str("spot".to_string());
let mut expiry: Value = Value::Null;
let mut contractSize: Value = Value::Null;
if !is_true(&isSpot) {
symbol = add(&symbol, &add(&Value::Str(":".to_string()), "e));
contractSize = self.safe_string_k(market.clone(), "contractSize", &[]);
if is_true(&isFuture) {
expiry = self.safe_integer_k(market.clone(), "contractEndTime", &[]);
symbol = add(&symbol, &add(&Value::Str("-".to_string()), &self.yymmdd(expiry.clone(), &[])));
type_var = Value::Str("future".to_string());
} else {
type_var = Value::Str("swap".to_string());
}
}
let mut fees: Value = self.safe_value_k(self.fees.clone(), "contract", &[]);
if is_true(&isSpot) {
fees = self.safe_value_k(self.fees.clone(), "spot", &[]);
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("base".to_string(), base.clone());
m.insert("quote".to_string(), quote.clone());
m.insert("settle".to_string(), ternary(is_true(&isSpot), Value::Null, quote.clone()));
m.insert("baseId".to_string(), baseId.clone());
m.insert("quoteId".to_string(), quoteId.clone());
m.insert("settleId".to_string(), ternary(is_true(&isSpot), Value::Null, quoteId.clone()));
m.insert("type".to_string(), type_var.clone());
m.insert("spot".to_string(), isSpot.clone());
m.insert("margin".to_string(), ternary(is_true(&isSpot), Value::Bool(false), Value::Null));
m.insert("swap".to_string(), isSwap.clone());
m.insert("future".to_string(), isFuture.clone());
m.insert("option".to_string(), Value::Bool(false));
m.insert("active".to_string(), active.clone());
m.insert("contract".to_string(), Value::Bool(is_true(&isSwap) || is_true(&isFuture)));
m.insert("linear".to_string(), ternary(is_true(&isSpot), Value::Null, Value::Bool(true)));
m.insert("inverse".to_string(), ternary(is_true(&isSpot), Value::Null, Value::Bool(false)));
m.insert("taker".to_string(), get_value(&fees, &Value::Str("taker".to_string())));
m.insert("maker".to_string(), get_value(&fees, &Value::Str("maker".to_string())));
m.insert("contractSize".to_string(), self.parse_number(contractSize.clone(), &[]));
m.insert("expiry".to_string(), expiry.clone());
m.insert("expiryDatetime".to_string(), self.iso8601(expiry.clone()));
m.insert("strike".to_string(), Value::Null);
m.insert("optionType".to_string(), Value::Null);
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(amountPrecision.clone(), &[]));
m.insert("price".to_string(), self.parse_number(pricePrecision.clone(), &[]));
m
}));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("leverage".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minAmountString.clone(), &[]));
m.insert("max".to_string(), self.parse_number(maxAmountString.clone(), &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minPriceString.clone(), &[]));
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market.clone());
m
})]);
Value::Null
}
/*
* @method
* @name btse#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://docs.btse.com/markets/rest/get-klines/
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch (default and max 300)
* @param {object} [params] extra parameters specific to the bitteam api endpoint
* @param {int} [params.until] timestamp in ms of the latest candle to fetch
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut maxLimit: Value = Value::Int(300);
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(), maxLimit.clone()]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut interval: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("resolution".to_string(), interval.clone());
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &maxLimit));
} else {
// the endpoint returns only 10 candles when the limit is omitted
add_element_to_object(&mut request, &Value::Str("limit".to_string()), maxLimit.clone());
}
if !is_equal(&since, &Value::Null) {
// the endpoint accepts timestamps in seconds
add_element_to_object(&mut request, &Value::Str("start".to_string()), self.parse_to_int(divide(&since, &Value::Int(1000))));
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchOHLCV".to_string()), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
if !is_equal(&since, &Value::Null) {
// check if the requested time range is too large for one request
// if so, just omit until for correct paginated calls for not to get an error from the exchange
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut maxDelta: Value = multiply(&multiply(&duration, &maxLimit), &Value::Int(1000)); // parseTimeframe returns seconds, the difference below is in milliseconds
let mut difference: Value = subtract(&until, &since);
if is_less_than(&difference, &maxDelta) {
add_element_to_object(&mut request, &Value::Str("end".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
} else {
add_element_to_object(&mut request, &Value::Str("end".to_string()), self.parse_to_int(divide(&until, &Value::Int(1000))));
}
}
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_klines(&[__ws_arg_0]).await;
//
// {
// "data": [
// [
// "1786600800",
// "1895.78",
// "1898.52",
// "1892.05",
// "1898.3",
// "560622.306372"
// ]
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786604274378
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut result: Value = self.parse_ohlc_vs(data.clone(), &[market.clone(), timeframe.clone(), since.clone(), limit.clone()]);
return result;
Value::Null
}
pub fn parse_ohlcv(&self, mut ohlcv: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return Value::List(vec![self.safe_timestamp(ohlcv.clone(), Value::Int(0), &[]), self.safe_number(ohlcv.clone(), Value::Int(1), &[]), self.safe_number(ohlcv.clone(), Value::Int(2), &[]), self.safe_number(ohlcv.clone(), Value::Int(3), &[]), self.safe_number(ohlcv.clone(), Value::Int(4), &[]), self.safe_number(ohlcv.clone(), Value::Int(5), &[])]);
Value::Null
}
/*
* @method
* @name btse#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.btse.com/markets/rest/get-orderbook/
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} A dictionary of [order book structures]{@link https://github.com/ccxt/ccxt/wiki/Manual#order-book-structure} indexed by market symbols
*/
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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("depth".to_string()), crate::runtime::Math::min(&limit, &Value::Int(50))); // the endpoint supports a maximum depth of 50
}
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_orderbook(&[__ws_arg_1]).await;
//
// {
// "data": {
// "timestamp": 1786605670799,
// "bids": [
// [ "1896.11", "0.015" ]
// ],
// "asks": [
// [ "1896.74", "0.945" ]
// ]
// },
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786605670833
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut timestamp: Value = self.safe_integer_k(data.clone(), "timestamp", &[]);
return self.parse_order_book(data.clone(), get_value(&market, &Value::Str("symbol".to_string())), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string())]);
Value::Null
}
/*
* @method
* @name btse#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://docs.btse.com/markets/rest/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, used to select the requested period and then applied client-side
* @param {int} [limit] the maximum amount of entries to fetch, applied client-side
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.period] the funding rate history period, one of '7D', '2W' or '1M', selected from since by default
* @param {int} [params.until] timestamp in ms of the latest funding rate to fetch, applied client-side
* @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()))));
}
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(" fetchFundingRateHistory() supports contract markets only".to_string()))));
}
let mut period: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("period".to_string()), &[]); period = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&period, &Value::Null) {
period = Value::Str("7D".to_string());
if !is_equal(&since, &Value::Null) {
let mut age: Value = subtract(&self.milliseconds(), &since);
let mut day: Value = Value::Int(86400000);
if is_greater_than(&age, &multiply(&Value::Int(14), &day)) {
period = Value::Str("1M".to_string());
} else if is_greater_than(&age, &multiply(&Value::Int(7), &day)) {
period = Value::Str("2W".to_string());
}
}
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("period".to_string(), period.clone());
m
});
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchFundingRateHistory".to_string()), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_recent_funding_history(&[__ws_arg_2]).await;
//
// {
// "data": [
// {
// "timestamp": 1786003200911,
// "rate": "0.0000152"
// }
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786607775380
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rates: Value = self.parse_funding_rate_histories(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
if is_equal(&until, &Value::Null) {
return rates;
}
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_455: bool = true;
while { if !__for_first_455 { i = add(&i, &Value::Int(1)); } __for_first_455 = false; is_less_than(&i, &get_array_length(&rates)) } {
let mut rate: Value = get_value(&rates, &i);
let mut rate: Value = get_value(&rates, &i);
let mut timestamp: Value = self.safe_integer_k(rate.clone(), "timestamp", &[]);
if is_true(&(is_equal(×tamp, &Value::Null))) || is_true(&(is_less_than_or_equal(×tamp, &until))) {
append_to_array(&mut result, rate.clone());
}
}
}
return result;
Value::Null
}
pub fn parse_funding_rate_history(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "timestamp": 1786003200911,
// "rate": "0.0000152"
// }
//
let mut timestamp: Value = self.safe_integer_k(contract.clone(), "timestamp", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), self.safe_symbol(Value::Null, &[market.clone()]));
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "rate", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m
});
Value::Null
}
/*
* @method
* @name btse#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://docs.btse.com/wallet/rest/get-user-assets/
* @see https://btsecom.github.io/docs/futuresV2_3/en/#query-wallet-balance
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] wallet type, spot or swap, default is spot
* @param {string} [params.wallet] futures wallet name, CROSS@ by default, or ISOLATED@ followed by the market id with -USDT appended
* @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
}));
self.load_markets(&[]).await;
let mut type_var: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchBalance".to_string()), &[Value::Null, params.clone(), type_var.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&type_var, &Value::Str("spot".to_string())) {
let mut walletResponse: Value = self.private_get_public_api_wallet_v1_user_assets(&[params.clone()]).await;
//
// {
// "data": [
// {
// "asset": "BTC",
// "type": "CRYPTO",
// "totalAmount": "100.0",
// "availableAmount": "100.0",
// "availableActions": [ "CONVERT", "TRANSFER", "WITHDRAW", "DEPOSIT", "SEND_TO" ],
// "cryptoNetwork": { "depositNetworks": [ "BITCOIN" ], "withdrawalNetworks": [ "BITCOIN" ] }
// }
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1624989977940
// }
//
response = self.safe_list_k(walletResponse.clone(), "data", &[Value::List(vec![])]);
} else {
let mut wallet: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchBalance".to_string()), Value::Str("wallet".to_string()), &[Value::Str("CROSS@".to_string())]); wallet = 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("wallet".to_string(), wallet.clone());
m
});
let __ws_arg_3 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_futures_api_v23_user_wallet(&[__ws_arg_3]).await;
}
return self.parse_balance(response.clone());
Value::Null
}
pub fn parse_balance(&self, mut response: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut totals: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut frees: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut useds: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_458: bool = true;
while { if !__for_first_458 { i = add(&i, &Value::Int(1)); } __for_first_458 = false; is_less_than(&i, &get_array_length(&response)) } {
let mut row: Value = get_value(&response, &i);
let mut row: Value = get_value(&response, &i);
let mut assets: Value = self.safe_list_k(row.clone(), "assets", &[]);
if !is_equal(&assets, &Value::Null) {
// futures wallet row: per-currency totals in assets, locked amounts in assetsInUse
// several wallet rows can report the same currency, so amounts are aggregated
let mut inUse: Value = self.safe_list_k(row.clone(), "assetsInUse", &[Value::List(vec![])]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_456: bool = true;
while { if !__for_first_456 { j = add(&j, &Value::Int(1)); } __for_first_456 = false; is_less_than(&j, &get_array_length(&inUse)) } {
let mut usedRow: Value = get_value(&inUse, &j);
let mut usedRow: Value = get_value(&inUse, &j);
let mut usedCode: Value = self.safe_currency_code(self.safe_string_k(usedRow.clone(), "currency", &[]), &[]);
if is_equal(&usedCode, &Value::Null) {
continue;
}
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(useds.clone(), usedCode.clone(), &[Value::Str("0".to_string())]), &self.safe_string_k(usedRow.clone(), "balance", &[])); add_element_to_object(&mut useds, &usedCode, __be_tmp); };
}
}
{
let mut j: Value = Value::Int(0);
let mut __for_first_457: bool = true;
while { if !__for_first_457 { j = add(&j, &Value::Int(1)); } __for_first_457 = false; is_less_than(&j, &get_array_length(&assets)) } {
let mut assetRow: Value = get_value(&assets, &j);
let mut assetRow: Value = get_value(&assets, &j);
let mut code: Value = self.safe_currency_code(self.safe_string_k(assetRow.clone(), "currency", &[]), &[]);
if is_equal(&code, &Value::Null) {
continue;
}
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(totals.clone(), code.clone(), &[Value::Str("0".to_string())]), &self.safe_string_k(assetRow.clone(), "balance", &[])); add_element_to_object(&mut totals, &code, __be_tmp); };
{ let __be_tmp = self.safe_string(useds.clone(), code.clone(), &[Value::Str("0".to_string())]); add_element_to_object(&mut useds, &code, __be_tmp); };
}
}
} else {
// unified wallet row: {"asset": "BTC", "totalAmount": "100.0", "availableAmount": "100.0"}
// legacy spot wallet row: {"available": 520.52, "currency": "USD", "total": 5566.5566}
let mut code: Value = self.safe_currency_code(self.safe_string2(row.clone(), Value::Str("asset".to_string()), Value::Str("currency".to_string()), &[]), &[]);
if is_equal(&code, &Value::Null) {
continue;
}
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(totals.clone(), code.clone(), &[Value::Str("0".to_string())]), &self.safe_string2(row.clone(), Value::Str("totalAmount".to_string()), Value::Str("total".to_string()), &[])); add_element_to_object(&mut totals, &code, __be_tmp); };
{ let __be_tmp = crate::precise::Precise::stringAdd(&self.safe_string(frees.clone(), code.clone(), &[Value::Str("0".to_string())]), &self.safe_string2(row.clone(), Value::Str("availableAmount".to_string()), Value::Str("available".to_string()), &[])); add_element_to_object(&mut frees, &code, __be_tmp); };
}
}
}
let mut codes: Value = object_keys(&totals);
{
let mut i: Value = Value::Int(0);
let mut __for_first_459: bool = true;
while { if !__for_first_459 { i = add(&i, &Value::Int(1)); } __for_first_459 = false; is_less_than(&i, &get_array_length(&codes)) } {
let mut code: Value = get_value(&codes, &i);
let mut code: Value = get_value(&codes, &i);
let mut account: Value = self.account();
add_element_to_object(&mut account, &Value::Str("total".to_string()), self.safe_string(totals.clone(), code.clone(), &[]));
add_element_to_object(&mut account, &Value::Str("free".to_string()), self.safe_string(frees.clone(), code.clone(), &[]));
add_element_to_object(&mut account, &Value::Str("used".to_string()), self.safe_string(useds.clone(), code.clone(), &[]));
add_element_to_object(&mut result, &code, account.clone());
}
}
return self.safe_balance(result.clone());
Value::Null
}
/*
* @method
* @name btse#fetchLeverageTiers
* @see https://docs.btse.com/markets/rest/get-market-risk-limits/
* @description retrieve information on the maximum leverage, for different trade sizes
* @param {string[]|undefined} symbols a list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}, indexed by market symbols
*/
pub async fn fetch_leverage_tiers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbols, &Value::Null) {
let mut length: Value = get_array_length(&symbols);
if is_equal(&length, &Value::Int(1)) {
let mut requestedSymbol: Value = self.safe_string(symbols.clone(), Value::Int(0), &[]);
let mut market: Value = self.market(requestedSymbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
}
let __ws_arg_4 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_risk_limits(&[__ws_arg_4]).await;
//
// {
// "data": [
// {
// "symbol": "BTC-PERP-USDT",
// "riskLimits": [
// { "level": 1, "value": 3000000 },
// { "level": 2, "value": 6000000 }
// ]
// }
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786609503920
// }
//
// a single-symbol request returns the entry directly in data
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[]);
if is_equal(&data, &Value::Null) {
let mut single: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
data = Value::List(vec![single.clone()]);
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_461: bool = true;
while { if !__for_first_461 { i = add(&i, &Value::Int(1)); } __for_first_461 = 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 marketId: Value = self.safe_string_k(entry.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
if is_equal(&symbols, &Value::Null) || is_true(&self.in_array(symbol.clone(), symbols.clone())) {
let mut levels: Value = self.safe_list_k(entry.clone(), "riskLimits", &[Value::List(vec![])]);
let mut tiers: Value = Value::List(vec![]);
{
let mut j: Value = Value::Int(0);
let mut __for_first_460: bool = true;
while { if !__for_first_460 { j = add(&j, &Value::Int(1)); } __for_first_460 = false; is_less_than(&j, &get_array_length(&levels)) } {
let mut level: Value = get_value(&levels, &j);
let mut level: Value = get_value(&levels, &j);
// the endpoint only reports the notional ladder, the
// per-tier leverage and margin rates are not available
append_to_array(&mut tiers, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tier".to_string(), self.safe_integer_k(level.clone(), "level", &[]));
m.insert("symbol".to_string(), symbol.clone());
m.insert("currency".to_string(), get_value(&market, &Value::Str("settle".to_string())));
m.insert("minNotional".to_string(), Value::Null);
m.insert("maxNotional".to_string(), self.safe_number_k(level.clone(), "value", &[]));
m.insert("maintenanceMarginRate".to_string(), Value::Null);
m.insert("maxLeverage".to_string(), Value::Null);
m.insert("info".to_string(), level.clone());
m
}));
}
}
add_element_to_object(&mut result, &symbol, tiers.clone()); // rows arrive ordered by level ascending, avoid sortBy which compares numeric keys lexicographically in some transpiled runtimes
}
}
}
// the exchange only provides the cap of each risk tier, so the floor
// is derived from the previous tier: 0 for the first tier, and the
// previous tier's maxNotional for every subsequent tier
let mut symbolKeys: Value = object_keys(&result);
{
let mut i: Value = Value::Int(0);
let mut __for_first_463: bool = true;
while { if !__for_first_463 { i = add(&i, &Value::Int(1)); } __for_first_463 = false; is_less_than(&i, &get_array_length(&symbolKeys)) } {
let mut symbolKey: Value = get_value(&symbolKeys, &i);
let mut symbolKey: Value = get_value(&symbolKeys, &i);
let mut tiersList: Value = get_value(&result, &symbolKey);
let mut tiersList: Value = get_value(&result, &symbolKey);
{
let mut j: Value = Value::Int(0);
let mut __for_first_462: bool = true;
while { if !__for_first_462 { j = add(&j, &Value::Int(1)); } __for_first_462 = false; is_less_than(&j, &get_array_length(&tiersList)) } {
if is_equal(&j, &Value::Int(0)) {
add_element_to_object(get_value_mut(&mut tiersList, &j), &Value::Str("minNotional".to_string()), Value::Int(0));
} else {
{ let __be_tmp = get_value(&get_value(&tiersList, &subtract(&j, &Value::Int(1))), &Value::Str("maxNotional".to_string())); add_element_to_object(get_value_mut(&mut tiersList, &j), &Value::Str("minNotional".to_string()), __be_tmp); };
}
}
}
// php copies arrays by value, so the mutated list must be written back explicitly
add_element_to_object(&mut result, &symbolKey, tiersList.clone());
}
}
return result;
Value::Null
}
/*
* @method
* @name btse#fetchMarketLeverageTiers
* @description retrieve information on the maximum leverage, for different trade sizes for a single market
* @see https://docs.btse.com/markets/rest/get-market-risk-limits/
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage tiers structure]{@link https://docs.ccxt.com/?id=leverage-tiers-structure}
*/
pub async fn fetch_market_leverage_tiers(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
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(" fetchMarketLeverageTiers() supports contract markets only".to_string()))));
}
let mut result: Value = self.fetch_leverage_tiers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return get_value(&result, &symbol);
Value::Null
}
/*
* @method
* @name btse#fetchTickers
* @see https://docs.btse.com/markets/rest/get-24-hr-ticker/
* @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
* @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true), Value::Bool(true)]);
// the unified endpoint serves all market types in one call, the legacy type param is accepted and ignored
params = self.omit(params.clone(), Value::Str("type".to_string()), &[]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[params.clone()]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
return self.parse_tickers(data.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://docs.btse.com/markets/rest/get-24-hr-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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_5 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[__ws_arg_5]).await;
//
// {
// "data": [
// {
// "symbol": "BTC-PERP-USDT",
// "lastPrice": "63790.1",
// "openPrice": "63808.3",
// "highPrice": "64446.7",
// "lowPrice": "63289.7",
// "amount": "789198764",
// "volume": "502595131.844331",
// "openTime": 1786514400,
// "closeTime": 1786602644,
// "priceChange": "-18.2",
// "priceChangePercent": "0",
// "prevClosePrice": "63842.4",
// "bidPrice": "63790",
// "bidQty": "222000",
// "askPrice": "63790.2",
// "askQty": "255355",
// "openInterest": "29489680",
// "fundingRate": "0.0001",
// "nextFundingTime": 1786608000000,
// "fundingIntervalMinutes": 480
// }
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786602644221
// }
//
// a single-symbol query returns data as one object, a multi-symbol or bare query returns an array
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
if is_equal(&data, &Value::Null) {
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
data = self.safe_dict(rows.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_ticker(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// spot rows carry the fields up to askQty, contract rows additionally carry
// openInterest, fundingRate, nextFundingTime and fundingIntervalMinutes
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut last: Value = self.safe_string_k(ticker.clone(), "lastPrice", &[]);
let mut baseVolume: Value = self.safe_string_k(ticker.clone(), "amount", &[]);
if is_true(&(!is_equal(&baseVolume, &Value::Null))) && is_true(&(!is_equal(&market, &Value::Null))) && is_true(&(is_equal(&get_value(&market, &Value::Str("contract".to_string())), &Value::Bool(true)))) {
// for contract markets the amount field is denominated in contracts, verified live -
// scaling by contractSize converts it into base currency units
let mut contractSizeString: Value = self.number_to_string(get_value(&market, &Value::Str("contractSize".to_string())));
if !is_equal(&contractSizeString, &Value::Null) {
baseVolume = crate::precise::Precise::stringMul(&baseVolume, &contractSizeString);
}
}
let mut timestamp: Value = self.safe_timestamp(ticker.clone(), Value::Str("closeTime".to_string()), &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.safe_symbol(marketId.clone(), &[market.clone()]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "highPrice", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "lowPrice", &[]));
m.insert("bid".to_string(), self.safe_string_k(ticker.clone(), "bidPrice", &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bidQty", &[]));
m.insert("ask".to_string(), self.safe_string_k(ticker.clone(), "askPrice", &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "askQty", &[]));
m.insert("vwap".to_string(), Value::Null);
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "openPrice", &[]));
m.insert("close".to_string(), last.clone());
m.insert("last".to_string(), last.clone());
m.insert("previousClose".to_string(), self.safe_string_k(ticker.clone(), "prevClosePrice", &[]));
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "priceChange", &[]));
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(), self.safe_string_k(ticker.clone(), "volume", &[]));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("info".to_string(), ticker.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchOpenInterest
* @description Retrieves the open interest of a derivative trading pair
* @see https://docs.btse.com/markets/rest/get-24-hr-ticker/
* @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=interest-history-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
}));
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::bad_request(add(&add(&self.id, &Value::Str(" fetchOpenInterest() symbol does not support market ".to_string())), &symbol)));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_6 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[__ws_arg_6]).await;
let mut interest: Value = self.safe_dict_k(response.clone(), "data", &[]);
if is_equal(&interest, &Value::Null) {
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
interest = self.safe_dict(rows.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_open_interest(interest.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchOpenInterests
* @description Retrieves the open interest for a list of symbols
* @see https://docs.btse.com/markets/rest/get-24-hr-ticker/
* @param {string[]} [symbols] a list of unified CCXT market symbols
* @param {object} [params] exchange specific parameters
* @returns {object[]} a list 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
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[params.clone()]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rows: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_464: bool = true;
while { if !__for_first_464 { i = add(&i, &Value::Int(1)); } __for_first_464 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut row: Value = get_value(&data, &i);
let mut row: Value = get_value(&data, &i);
// spot rows do not carry an open interest
if !is_equal(&self.safe_string_k(row.clone(), "openInterest", &[]), &Value::Null) {
append_to_array(&mut rows, row.clone());
}
}
}
return self.parse_open_interests(rows.clone(), &[symbols.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);
//
// ticker/24hr contract rows, see parseFundingRate for the full shape
//
let mut marketId: Value = self.safe_string_k(interest.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_timestamp(interest.clone(), Value::Str("closeTime".to_string()), &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("openInterestAmount".to_string(), self.safe_number_k(interest.clone(), "openInterest", &[]));
m.insert("openInterestValue".to_string(), self.safe_number_k(interest.clone(), "openInterestUSD", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("info".to_string(), interest.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchFundingRate
* @description fetch the current funding rate
* @see https://docs.btse.com/markets/rest/get-24-hr-ticker/
* @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
}));
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::bad_request(add(&self.id, &Value::Str(" fetchFundingRate() symbol does not support spot markets".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let __ws_arg_7 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[__ws_arg_7]).await;
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[]);
if is_equal(&data, &Value::Null) {
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
data = self.safe_dict(rows.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_funding_rate(data.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchFundingRates
* @description fetch the funding rate for multiple markets
* @see https://docs.btse.com/markets/rest/get-24-hr-ticker/
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rates structures]{@link https://docs.ccxt.com/?id=funding-rates-structure}, indexe by market symbols
*/
pub async fn fetch_funding_rates(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_ticker24hr(&[params.clone()]).await;
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut rows: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_465: bool = true;
while { if !__for_first_465 { i = add(&i, &Value::Int(1)); } __for_first_465 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut row: Value = get_value(&data, &i);
let mut row: Value = get_value(&data, &i);
// spot rows do not carry a funding rate
if !is_equal(&self.safe_string_k(row.clone(), "fundingRate", &[]), &Value::Null) {
append_to_array(&mut rows, row.clone());
}
}
}
return self.parse_funding_rates(rows.clone(), &[symbols.clone()]);
Value::Null
}
pub fn parse_funding_rate(&self, mut contract: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// ticker/24hr contract rows
// {
// "symbol": "ETH-PERP-USDT",
// "lastPrice": "1896.17",
// "openPrice": "1887.07",
// "highPrice": "1924",
// "lowPrice": "1872.44",
// "amount": "1937140691",
// "volume": "366459222.269293",
// "openTime": 1786518000,
// "closeTime": 1786607054,
// "priceChange": "9.1",
// "priceChangePercent": "0.005",
// "prevClosePrice": "1897.71",
// "bidPrice": "1896",
// "bidQty": "105",
// "askPrice": "1896.01",
// "askQty": "11354",
// "openInterest": "19344237",
// "fundingRate": "0.00006016",
// "nextFundingTime": 1786608000000,
// "fundingIntervalMinutes": 480
// }
//
let mut marketId: Value = self.safe_string_k(contract.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_timestamp(contract.clone(), Value::Str("closeTime".to_string()), &[]);
// dated futures carry a zero nextFundingTime as funding only applies to
// perpetuals, observed live, the zero means no next funding and is omitted
let mut nextFundingTimestamp: Value = self.safe_integer_omit_zero(contract.clone(), Value::Str("nextFundingTime".to_string()), &[]);
let mut fundingIntervalMinutes: Value = self.safe_integer_k(contract.clone(), "fundingIntervalMinutes", &[]);
let mut interval: Value = Value::Null;
// a wire value of zero minutes reaches this, and zero hours is not an
// interval: a caller annualising a rate divides by it. anything under an
// hour rounds to the same string, and the vocabulary has no minutes
if is_true(&(!is_equal(&fundingIntervalMinutes, &Value::Null))) && is_true(&(is_greater_than_or_equal(&fundingIntervalMinutes, &Value::Int(60)))) {
let mut hours: Value = self.parse_to_int(divide(&fundingIntervalMinutes, &Value::Int(60)));
interval = add(&to_string_val(&hours), &Value::Str("h".to_string()));
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), contract.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("markPrice".to_string(), Value::Null);
m.insert("indexPrice".to_string(), Value::Null);
m.insert("interestRate".to_string(), Value::Null);
m.insert("estimatedSettlePrice".to_string(), Value::Null);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("fundingRate".to_string(), self.safe_number_k(contract.clone(), "fundingRate", &[]));
m.insert("fundingTimestamp".to_string(), Value::Null);
m.insert("fundingDatetime".to_string(), Value::Null);
m.insert("nextFundingRate".to_string(), Value::Null);
m.insert("nextFundingTimestamp".to_string(), nextFundingTimestamp.clone());
m.insert("nextFundingDatetime".to_string(), self.iso8601(nextFundingTimestamp.clone()));
m.insert("previousFundingRate".to_string(), Value::Null);
m.insert("previousFundingTimestamp".to_string(), Value::Null);
m.insert("previousFundingDatetime".to_string(), Value::Null);
m.insert("interval".to_string(), interval.clone());
m
});
Value::Null
}
/*
* @method
* @name btse#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://docs.btse.com/markets/rest/get-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, applied client-side to the most recent trades window
* @param {int} [limit] the maximum amount of trades to fetch (max 500)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest entry to fetch, applied client-side to the most recent trades window
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("limit".to_string()), crate::runtime::Math::min(&limit, &Value::Int(500))); // the endpoint supports a maximum of 500 trades
}
// the unified trades endpoint has no server-side time filtering, since and until are applied client-side below
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchTrades".to_string()), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let __ws_arg_8 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.public_get_public_api_market_v1_trades(&[__ws_arg_8]).await;
//
// {
// "data": [
// {
// "id": 91151062,
// "timestamp": 1786605669577,
// "price": "1896.3291755587",
// "size": "0.06",
// "quoteSize": "113.7797505335",
// "side": "BUY"
// }
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786605671650
// }
//
let mut data: Value = self.safe_list_k(response.clone(), "data", &[Value::List(vec![])]);
let mut trades: Value = self.parse_trades(data.clone(), &[market.clone(), since.clone(), limit.clone()]);
if is_equal(&until, &Value::Null) {
return trades;
}
let mut result: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_466: bool = true;
while { if !__for_first_466 { i = add(&i, &Value::Int(1)); } __for_first_466 = false; is_less_than(&i, &get_array_length(&trades)) } {
let mut trade: Value = get_value(&trades, &i);
let mut trade: Value = get_value(&trades, &i);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
if is_true(&(is_equal(×tamp, &Value::Null))) || is_true(&(is_less_than_or_equal(×tamp, &until))) {
append_to_array(&mut result, trade.clone());
}
}
}
return result;
Value::Null
}
/*
* @method
* @name btse#fetchMyTrades
* @description fetch all trades made by the user
* @see https://docs.btse.com/spot/rest/get-trade-history/
* @see https://docs.btse.com/futures/rest/get-trade-history/
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trades structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms for the ending date filter, default is undefined
* @param {string} [params.type] 'spot' or 'swap' or 'future', default is 'spot'
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut paginate: Value = self.safe_bool_k(params.clone(), "paginate", &[Value::Bool(false)]);
if is_equal(&paginate, &Value::Bool(true)) {
params = self.omit(params.clone(), Value::Str("paginate".to_string()), &[]);
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".to_string()), &[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
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("count".to_string()), limit.clone());
}
{ let __destr_tmp = self.handle_until_option(Value::Str("endTime".to_string()), request.clone(), params.clone(), &[]); request = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchMyTrades".to_string()), &[market.clone(), params.clone(), marketType.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchMyTrades() requires a symbol argument for spot markets".to_string()))));
}
//
// {
// "data": [
// {
// "serialId": 375599088,
// "tradeId": "de1a79b8-f408-4e05-b8b7-7ed3c4e86542",
// "orderId": "6c72d906-cb8f-469c-8ab0-b97bc8dff9c2",
// "clOrderId": null,
// "symbol": "BTC-USD",
// "base": "BTC",
// "quote": "USD",
// "orderSide": "BUY",
// "orderType": 77,
// "triggerType": 0,
// "triggerPrice": 0,
// "price": 64235.97008,
// "size": 1.9,
// "filledSize": 0.00002,
// "feeCurrency": "BTC",
// "feeAmount": 1e-8,
// "timestamp": 1784890959551
// }
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786610160164
// }
//
let __ws_arg_9 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_spot_api_v4_trade_trade_history(&[__ws_arg_9]).await;
} else {
// the futures endpoint does not support a count parameter, the limit is applied client-side
request = self.omit(request.clone(), Value::Str("count".to_string()), &[]);
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.futures_request_id(market.clone()));
}
//
// {
// "data": [
// {
// "tradeId": "1ad38104-6248-4a45-bc56-5fa9bf7f3868",
// "orderId": "8ad94105-8cce-4e01-86b8-2d0fb403db66",
// "clOrderId": "",
// "positionId": "BTC-PERP-USDT",
// "orderSide": "BUY",
// "type": 77,
// "orderDetailType": null,
// "price": 0,
// "size": 1,
// "avgFilledPrice": 60010,
// "filledSize": 1,
// "triggerPrice": 0,
// "contractSize": 0.00001,
// "base": "BTC",
// "quote": "USDT",
// "symbol": "BTC-PERP",
// "wallet": "BTC-PERP Isolated Wallet",
// "feeCurrency": "USDT",
// "feeAmount": 0.00012002,
// "realizedPnl": 0,
// "total": -0.00012002,
// "serialId": 375598162,
// "timestamp": 1784882344446
// }
// ],
// "code": 1,
// "msg": "Success",
// "success": true,
// "time": 1786610160164
// }
//
let __ws_arg_10 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_futures_api_v3_trade_trade_history(&[__ws_arg_10]).await;
}
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[]);
if is_equal(&rows, &Value::Null) {
rows = response.clone();
}
return self.parse_trades(rows.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://btsecom.github.io/docs/spotV3_3/en/#query-user-trades-fills
* @see https://btsecom.github.io/docs/futuresV2_3/en/#query-trades-fills-2
* @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
* @param {string} [params.clientOrderId] client order id, could be used instead of the order id
* @param {string} [params.type] 'spot' or 'swap' or 'future', default is 'spot'
* @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
}));
self.load_markets(&[]).await;
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if is_equal(&clientOrderId, &Value::Null) {
if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOrderTrades() requires an id argument or a clientOrderId parameter".to_string()))));
} else {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderID".to_string(), id.clone());
m
})]);
}
} else {
params = self.extend(params.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("clOrderID".to_string(), clientOrderId.clone());
m
})]);
}
return self.fetch_my_trades(&[symbol.clone(), since.clone(), limit.clone(), params.clone()]).await;
Value::Null
}
pub fn parse_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchTrades
// {
// "id": 91151062,
// "timestamp": 1786605669577,
// "price": "1896.3291755587",
// "size": "0.06",
// "quoteSize": "113.7797505335",
// "side": "BUY"
// }
//
// fetchMyTrades spot
// {
// "tradeId": "4b4bd301-6f20-4e39-a682-ce4f9b8400a0",
// "orderId": "2fa9678b-9945-47ce-9ffe-256dc7b4dd8c",
// "clOrderID": "test spot market buy",
// "username": "romancuhari",
// "side": "BUY",
// "orderType": 77,
// "triggerType": 0,
// "price": 1952.05859608,
// "size": 0.19520586,
// "filledPrice": 1952.05859608,
// "filledSize": 0.0001,
// "triggerPrice": 0,
// "base": "ETH",
// "quote": "USDT",
// "symbol": "ETH-USDT",
// "feeCurrency": "ETH",
// "feeAmount": 0.0000002,
// "wallet": "SPOT@",
// "realizedPnl": 0,
// "total": 0,
// "serialId": 49071052,
// "timestamp": 1770814978685,
// "avgFilledPrice": 1952.05859608
// }
//
// fetchMyTrades swap
// {
// "tradeId": "b708489a-19d1-4be2-a6c2-f499f76aa176",
// "orderId": "5c6a26db-8cfb-45c7-b25d-56927bc36795",
// "username": "romancuhari",
// "side": "BUY",
// "orderType": 77,
// "triggerType": null,
// "price": 0,
// "size": 1,
// "filledPrice": 1956.59,
// "filledSize": 1,
// "triggerPrice": 0,
// "base": "ETH",
// "quote": "USDT",
// "symbol": "ETH-PERP",
// "feeCurrency": "USDT",
// "feeAmount": 0.00010761,
// "wallet": "CROSS@",
// "realizedPnl": 0,
// "total": -0.00010761,
// "serialId": 50953296,
// "timestamp": 1770821231984,
// "orderDetailType": null,
// "contractSize": 0.0001,
// "clOrderID": "",
// "positionId": "ETH-PERP-USDT",
// "avgFilledPrice": 1956.59
// }
//
// the unified futures rows echo the short symbol form but carry the full
// market id in positionId, which resolves against the markets snapshot
let mut marketId: Value = self.safe_string2(trade.clone(), Value::Str("positionId".to_string()), Value::Str("symbol".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "timestamp", &[]);
let mut fee: Value = Value::Null;
let mut feeCost: Value = self.safe_number_k(trade.clone(), "feeAmount", &[]);
if !is_equal(&feeCost, &Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), feeCost.clone());
m.insert("currency".to_string(), self.safe_currency_code(self.safe_string_k(trade.clone(), "feeCurrency", &[]), &[]));
m
});
}
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(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("id".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("tradeId".to_string()), Value::Str("serialId".to_string()), Value::Str("id".to_string())]), &[]));
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "orderId", &[]));
m.insert("type".to_string(), self.parse_order_type(self.safe_string2(trade.clone(), Value::Str("orderType".to_string()), Value::Str("type".to_string()), &[])));
m.insert("side".to_string(), self.safe_string_lower2(trade.clone(), Value::Str("side".to_string()), Value::Str("orderSide".to_string()), &[]));
m.insert("takerOrMaker".to_string(), Value::Null);
m.insert("price".to_string(), self.safe_string_n(trade.clone(), Value::List(vec![Value::Str("filledPrice".to_string()), Value::Str("avgFilledPrice".to_string()), Value::Str("price".to_string())]), &[]));
m.insert("amount".to_string(), self.safe_string2(trade.clone(), Value::Str("filledSize".to_string()), Value::Str("size".to_string()), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee.clone());
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#createOrder
* @description create a trade order
* @see https://btsecom.github.io/docs/spotV3_3/en/#create-new-order
* @see https://btsecom.github.io/docs/futuresV2_3/en/#create-new-order
* @see https://btsecom.github.io/docs/futuresV2_3/en/#create-new-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 fullfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the order
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately (default is false)
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', 'PO', 'HALFMIN', 'FIVEMIN', 'HOUR', 'TWELVEHOUR', 'DAY', 'WEEK' or 'MONTH'
* @param {float} [params.triggerPrice] the price that a trigger order is triggered at (same as takeProfitPrice)
* @param {float} [params.stopLossPrice] the price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] the price that a take profit order is triggered at
* @param {string} [params.triggerPriceType] 'INDEX_PRICE' or 'LAST_PRICE', default is 'LAST_PRICE'
* @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
* @param {float} [params.deviation] *PEG orders only* How much should the order price deviate from index price. Value is in percentage and can range from -10 to 10
* @param {float} [params.stealth] *PEG orders only* How many percent of the order is to be displayed on the orderbook
* @param {float} [params.stopPrice] *NB - It is NOT stopLossPrice or triggerPrice!!! OCO orders only* Mandatory when creating an OCO order. Indicates the stop price
* @param {bool} [params.hedged] *contract markets only* true for hedged mode, false for one way mode, default is false
* @param {string} [params.marginMode] *contract markets only* 'cross' or 'isolated' (default is 'cross') - the exchange does not have cross/isolated margin modes but instead has 'ONE_WAY', 'HEDGE' and 'ISOLATED' position modes, so this param will be converted to the appropriate position mode
* @param {string} [params.positionMode] *contract markets only* 'ONE_WAY (default) or 'HEDGE or 'ISOLATED' (if not provided, it will be derived from marginMode and hedged params)
* @param {object} [params.takeProfit] *contract markets only* *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] *contract markets only* take profit trigger price
* @param {string} [params.takeProfit.priceType] *contract markets only* 'markPrice' or 'lastPrice', default is 'markPrice'
* @param {object} [params.stopLoss] *contract markets only* *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] *contract markets only* stop loss trigger price
* @param {string} [params.stopLoss.priceType] *contract markets only* 'markPrice' or 'lastPrice', default is 'markPrice'
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
return self.create_spot_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
} else {
return self.create_contract_order(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]).await;
}
Value::Null
}
/*
* @method
* @name btse#createSpotOrder
* @description create a trade order on spot market
* @see https://docs.btse.com/spot/rest/place-order
* @see https://docs.btse.com/spot/rest/place-algo-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market', 'limit', 'OCO', 'PEG', 'TWAP' or 'TRAILING'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the order
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately, default is false
* @param {string} [params.timeInForce] 'GTC', 'IOC' or 'FOK'
* @param {float} [params.cost] *market buy and trailing buy orders only* the quote quantity that can be used as an alternative for the amount
* @param {float} [params.triggerPrice] the price that a trigger order is triggered at, same as takeProfitPrice
* @param {float} [params.stopLossPrice] the price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] the price that a take profit order is triggered at
* @param {string} [params.triggerPriceType] 'last', 'mark' or 'index', default is 'last'
* @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
* @param {float} [params.trailingPercent] the percent to trail away from the current market price
* @param {float} [params.deviation] *PEG orders only* how much should the order price deviate from the pegged price, in percent from -10 to 10
* @param {float} [params.stealth] *PEG orders only* how many percent of the order is to be displayed on the orderbook, from 1 to 100
* @param {float} [params.stopPrice] *NB - It is NOT stopLossPrice or triggerPrice!!! OCO orders only* the limit price of the stop loss leg
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_spot_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
type_var = to_upper(&type_var);
let mut upperSide: Value = to_upper(&side);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("orderSide".to_string(), upperSide.clone());
m
});
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrderId".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
}
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("MARKET".to_string())));
let mut isLimitOrder: bool = is_equal(&type_var, &Value::Str("LIMIT".to_string()));
let mut postOnly: Value = Value::Bool(false);
// exchange-specific postOnly is the same as the unified one
{ let __destr_tmp = self.handle_post_only(isMarketOrder.clone(), postOnly.clone(), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }; // this will remove PO from params.timeInForce if present
if is_true(&postOnly) {
add_element_to_object(&mut request, &Value::Str("postOnly".to_string()), Value::Bool(true));
}
let mut timeInForce: Value = self.handle_time_in_force(&[params.clone()]);
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), timeInForce.clone());
}
let mut triggerPrice: Value = self.safe_string_k(params.clone(), "triggerPrice", &[]);
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut stopLossPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut isTriggerOrder: bool = is_true(&(!is_equal(&triggerPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null)));
let mut isStopLossOrder: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isConditionalOrder: bool = is_true(&(is_true(&isTriggerOrder) || is_true(&isStopLossOrder))) && is_true(&(is_true(&isMarketOrder) || is_true(&isLimitOrder)));
let mut isAlgoOrder: bool = is_true(&isConditionalOrder) || is_true(&(!is_true(&isMarketOrder) && !is_true(&isLimitOrder)));
if is_true(&isLimitOrder) || is_true(&(is_equal(&type_var, &Value::Str("PEG".to_string())))) || is_true(&(is_equal(&type_var, &Value::Str("OCO".to_string())))) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&self.id, &Value::Str(" createOrder() requires a price argument for ".to_string())), &type_var), &Value::Str(" orders".to_string()))));
}
}
// market and trailing buys are denominated in the quote currency while
// every other combination is denominated in the base currency, the
// sizing rules are strict on both sides, verified live
let mut needsQuoteSize: bool = is_true(&(is_true(&isMarketOrder) || is_true(&(is_equal(&type_var, &Value::Str("TRAILING".to_string())))))) && is_true(&(is_equal(&upperSide, &Value::Str("BUY".to_string()))));
if is_true(&needsQuoteSize) {
let mut quoteAmount: Value = Value::Null;
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 cost: Value = self.safe_string_k(params.clone(), "cost", &[]);
params = self.omit(params.clone(), Value::Str("cost".to_string()), &[]);
if !is_equal(&cost, &Value::Null) {
quoteAmount = self.cost_to_precision(symbol.clone(), cost.clone());
} else if is_true(&createMarketBuyOrderRequiresPrice) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&self.id, &Value::Str(" createOrder() requires the price argument for market buy orders to calculate the total cost to spend, alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument".to_string()))));
} else {
let mut amountString: Value = self.number_to_string(amount.clone());
let mut priceString: Value = self.number_to_string(price.clone());
quoteAmount = self.cost_to_precision(symbol.clone(), crate::precise::Precise::stringMul(&amountString, &priceString));
}
} else {
quoteAmount = self.cost_to_precision(symbol.clone(), self.number_to_string(amount.clone()));
}
add_element_to_object(&mut request, &Value::Str("quoteOrderSize".to_string()), quoteAmount.clone());
} else {
add_element_to_object(&mut request, &Value::Str("orderSize".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
let mut response: Value = Value::Null;
if !is_true(&isAlgoOrder) {
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), type_var.clone());
if is_true(&isLimitOrder) {
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
//
// [
// {
// "orderId": "4eca2eb4-e6ad-4355-ae12-5ce757b105b3",
// "clOrderId": "",
// "status": 2,
// "market": "BTC-USD",
// "type": 76,
// "orderSide": "BUY",
// "orderPrice": 61024.1,
// "postOnly": false,
// "timestamp": 1784891308063,
// "orderDetailType": null,
// "message": null,
// "userQuoteCurrency": "USD",
// "orderCurrency": "base",
// "originalOrderBaseSize": 0.00001,
// "originalOrderQuoteSize": null,
// "currentOrderBaseSize": 0.00001,
// "currentOrderQuoteSize": null,
// "remainingOrderBaseSize": 0.00001,
// "remainingOrderQuoteSize": null,
// "filledBaseSize": 0,
// "totalFilledBaseSize": 0,
// "avgFilledPrice": 0,
// "time_in_force": "GTC"
// }
// ]
//
let __ws_arg_11 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_spot_api_v4_trade_orders(&[__ws_arg_11]).await;
} else {
if is_true(&isConditionalOrder) {
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), Value::Str("CONDITIONAL".to_string()));
let mut triggerOrderType: Value = Value::Null;
let mut triggerPriceToSend: Value = Value::Null;
if is_true(&isStopLossOrder) {
triggerOrderType = Value::Str("STOP_LOSS".to_string());
triggerPriceToSend = stopLossPrice.clone();
} else {
triggerOrderType = Value::Str("TAKE_PROFIT".to_string());
triggerPriceToSend = triggerPrice.clone();
if is_equal(&triggerPriceToSend, &Value::Null) {
triggerPriceToSend = takeProfitPrice.clone();
}
}
if is_true(&isLimitOrder) {
triggerOrderType = add(&triggerOrderType, &Value::Str("_LIMIT".to_string()));
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
add_element_to_object(&mut request, &Value::Str("triggerOrderType".to_string()), triggerOrderType.clone());
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPriceToSend.clone()));
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("last".to_string())]);
add_element_to_object(&mut request, &Value::Str("triggerPriceType".to_string()), self.encode_trigger_price_type(triggerPriceType.clone()));
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("triggerPriceType".to_string())]), &[]);
} else {
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), type_var.clone());
if is_equal(&type_var, &Value::Str("OCO".to_string())) {
// the price argument is the limit price of the take profit leg,
// the stopPrice param is the limit price of the stop loss leg
// and the triggerPrice param is where the stop loss leg fires
add_element_to_object(&mut request, &Value::Str("takeProfitOrderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
let mut stopPrice: Value = self.safe_string_k(params.clone(), "stopPrice", &[]);
if !is_equal(&stopPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopLossOrderPrice".to_string()), self.price_to_precision(symbol.clone(), stopPrice.clone()));
}
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopLossTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
}
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("last".to_string())]);
add_element_to_object(&mut request, &Value::Str("stopLossTriggerPriceType".to_string()), self.encode_trigger_price_type(triggerPriceType.clone()));
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("triggerPriceType".to_string())]), &[]);
} else if is_equal(&type_var, &Value::Str("PEG".to_string())) {
// the required stealth and optional deviation params pass through
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
} else if is_equal(&type_var, &Value::Str("TRAILING".to_string())) {
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut trailingPercent: Value = self.safe_string_k(params.clone(), "trailingPercent", &[]);
if !is_equal(&trailingAmount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("trailValue".to_string()), self.price_to_precision(symbol.clone(), trailingAmount.clone()));
add_element_to_object(&mut request, &Value::Str("trailValueType".to_string()), Value::Str("DISTANCE".to_string()));
} else if !is_equal(&trailingPercent, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("trailValue".to_string()), trailingPercent.clone());
add_element_to_object(&mut request, &Value::Str("trailValueType".to_string()), Value::Str("PERCENTAGE".to_string()));
}
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("last".to_string())]);
add_element_to_object(&mut request, &Value::Str("triggerPriceType".to_string()), self.encode_trigger_price_type(triggerPriceType.clone()));
params = self.omit(params.clone(), Value::List(vec![Value::Str("trailingAmount".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("triggerPriceType".to_string())]), &[]);
}
}
let __ws_arg_12 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_spot_api_v4_trade_orders_algo(&[__ws_arg_12]).await;
}
let mut order: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#createContractOrder
* @description create a trade order on contract market
* @see https://docs.btse.com/futures/rest/place-order
* @see https://docs.btse.com/futures/rest/place-algo-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market', 'limit', 'OCO', 'PEG', 'TWAP' or 'TRAILING'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of you want to trade in units of the base currency
* @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the order
* @param {bool} [params.postOnly] if true, the order will only be posted to the order book and not executed immediately, default is false
* @param {bool} [params.reduceOnly] if true, the order will only reduce a current position, not increase it, default is false
* @param {string} [params.timeInForce] 'GTC', 'IOC', 'FOK', 'PO', 'HALFSEC', 'HALFMIN', 'FIVEMIN', 'HOUR', 'TWELVEHOUR', 'DAY', 'WEEK' or 'MONTH'
* @param {bool} [params.hedged] true for hedged mode, false for one way mode, default is false
* @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross' - the exchange does not have cross/isolated margin modes but instead has 'ONE_WAY', 'HEDGE' and 'ISOLATED' position modes, so this param will be converted to the appropriate position mode
* @param {string} [params.positionMode] 'ONE_WAY', 'HEDGE' or 'ISOLATED' - if not provided, it will be derived from the marginMode and hedged params
* @param {float} [params.triggerPrice] the price that a trigger order is triggered at, same as takeProfitPrice
* @param {float} [params.stopLossPrice] the price that a stop loss order is triggered at
* @param {float} [params.takeProfitPrice] the price that a take profit order is triggered at
* @param {string} [params.triggerPriceType] 'last', 'mark' or 'index', default is 'mark'
* @param {float} [params.trailingAmount] the quote amount to trail away from the current market price
* @param {float} [params.trailingPercent] the percent to trail away from the current market price
* @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
* @param {float} [params.takeProfit.triggerPrice] take profit trigger price
* @param {string} [params.takeProfit.priceType] 'last', 'mark' or 'index', default is 'mark'
* @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
* @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
* @param {string} [params.stopLoss.priceType] 'last', 'mark' or 'index', default is 'mark'
* @param {float} [params.deviation] *PEG orders only* the offset applied to the pegged reference price
* @param {float} [params.stealth] *PEG orders only* the portion of the order size displayed on the book
* @param {float} [params.stopPrice] *NB - It is NOT the stopLossPrice!!! OCO orders only* the limit price of the stop loss leg
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_contract_order(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
type_var = to_upper(&type_var);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m.insert("orderSide".to_string(), to_upper(&side));
m.insert("orderSize".to_string(), self.amount_to_precision(symbol.clone(), amount.clone()));
m
});
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrderId".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
}
// handle positionMode
let mut positionMode: Value = self.safe_string_k(params.clone(), "positionMode", &[]);
// if positionMode is provided, we will get it from params and send it as is
if is_equal(&positionMode, &Value::Null) {
let mut hedged: Value = Value::Bool(false);
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("hedged".to_string()), &[hedged.clone()]); hedged = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut marginMode: Value = Value::Str("cross".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("createOrder".to_string()), Value::Str("marginMode".to_string()), &[marginMode.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marginMode, &Value::Str("isolated".to_string())) {
if is_true(&hedged) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" createOrder() cannot use isolated margin with hedged positions".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("positionMode".to_string()), Value::Str("ISOLATED".to_string()));
} else if is_true(&hedged) {
add_element_to_object(&mut request, &Value::Str("positionMode".to_string()), Value::Str("HEDGE".to_string()));
}
}
let mut isMarketOrder: Value = Value::Bool(is_equal(&type_var, &Value::Str("MARKET".to_string())));
let mut isLimitOrder: bool = is_equal(&type_var, &Value::Str("LIMIT".to_string()));
let mut postOnly: Value = Value::Bool(false);
// exchange-specific postOnly is the same as the unified one
{ let __destr_tmp = self.handle_post_only(isMarketOrder.clone(), postOnly.clone(), &[params.clone()]); postOnly = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }; // this will remove PO from params.timeInForce if present
if is_true(&postOnly) {
add_element_to_object(&mut request, &Value::Str("postOnly".to_string()), Value::Bool(true));
}
let mut timeInForce: Value = self.handle_time_in_force(&[params.clone()]);
if !is_equal(&timeInForce, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("timeInForce".to_string()), timeInForce.clone());
}
let mut triggerPrice: Value = self.safe_string_k(params.clone(), "triggerPrice", &[]);
let mut takeProfitPrice: Value = self.safe_string_k(params.clone(), "takeProfitPrice", &[]);
let mut stopLossPrice: Value = self.safe_string_k(params.clone(), "stopLossPrice", &[]);
let mut isTriggerOrder: bool = is_true(&(!is_equal(&triggerPrice, &Value::Null))) || is_true(&(!is_equal(&takeProfitPrice, &Value::Null)));
let mut isStopLossOrder: bool = !is_equal(&stopLossPrice, &Value::Null);
let mut isConditionalOrder: bool = is_true(&(is_true(&isTriggerOrder) || is_true(&isStopLossOrder))) && is_true(&(is_true(&isMarketOrder) || is_true(&isLimitOrder)));
let mut isAlgoOrder: bool = is_true(&isConditionalOrder) || is_true(&(!is_true(&isMarketOrder) && !is_true(&isLimitOrder)));
if is_true(&isLimitOrder) || is_true(&(is_equal(&type_var, &Value::Str("OCO".to_string())))) {
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::invalid_order(add(&add(&add(&self.id, &Value::Str(" createOrder() requires a price argument for ".to_string())), &type_var), &Value::Str(" orders".to_string()))));
}
}
// here we handling with attached take profit and stop loss orders
let mut takeProfit: Value = self.safe_dict_k(params.clone(), "takeProfit", &[]);
let mut stopLoss: Value = self.safe_dict_k(params.clone(), "stopLoss", &[]);
if is_true(&(!is_equal(&takeProfit, &Value::Null))) || is_true(&(!is_equal(&stopLoss, &Value::Null))) {
let mut takeProfitTriggerPrice: Value = self.safe_string_k(takeProfit.clone(), "triggerPrice", &[]);
let mut stopLossTriggerPrice: Value = self.safe_string_k(stopLoss.clone(), "triggerPrice", &[]);
if !is_equal(&takeProfitTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("takeProfitTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), takeProfitTriggerPrice.clone()));
let mut takeProfitTriggerPriceType: Value = self.safe_string_k(takeProfit.clone(), "priceType", &[]);
if !is_equal(&takeProfitTriggerPriceType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("takeProfitTriggerType".to_string()), self.encode_trigger_price_type(takeProfitTriggerPriceType.clone()));
}
}
if !is_equal(&stopLossTriggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopLossTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), stopLossTriggerPrice.clone()));
let mut stopLossTriggerPriceType: Value = self.safe_string_k(stopLoss.clone(), "priceType", &[]);
if !is_equal(&stopLossTriggerPriceType, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopLossTriggerType".to_string()), self.encode_trigger_price_type(stopLossTriggerPriceType.clone()));
}
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("takeProfit".to_string()), Value::Str("stopLoss".to_string())]), &[]);
}
let mut response: Value = Value::Null;
if !is_true(&isAlgoOrder) {
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), type_var.clone());
if is_true(&isLimitOrder) {
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
//
// {
// "status": 2,
// "type": 0,
// "symbol": "BTC-PERP",
// "postOnly": false,
// "orderSide": "BUY",
// "orderId": "0251ea47-88b5-48c0-aeb3-b38774fd1f90",
// "clOrderID": "",
// "timestamp": 1784882344361,
// "price": 57009.5,
// "avgFilledPrice": 0,
// "message": null,
// "originalOrderSize": 1,
// "currentOrderSize": 1,
// "filledSize": 0,
// "totalFilledSize": 0,
// "remainingSize": 1,
// "positionMode": "ONE_WAY",
// "positionDirection": null,
// "positionId": "BTC-PERP-USDT",
// "timeInForce": "GTC"
// }
//
let __ws_arg_13 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_futures_api_v3_trade_orders(&[__ws_arg_13]).await;
} else {
if is_true(&isConditionalOrder) {
// the futures conditional variant has no trigger direction field,
// it takes a plain trigger price with an optional limit price
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), Value::Str("CONDITIONAL".to_string()));
let mut triggerPriceToSend: Value = triggerPrice.clone();
if is_equal(&triggerPriceToSend, &Value::Null) {
triggerPriceToSend = takeProfitPrice.clone();
}
if is_equal(&triggerPriceToSend, &Value::Null) {
triggerPriceToSend = stopLossPrice.clone();
}
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPriceToSend.clone()));
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
add_element_to_object(&mut request, &Value::Str("triggerType".to_string()), self.encode_trigger_price_type(triggerPriceType.clone()));
if is_true(&isLimitOrder) {
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
params = self.omit(params.clone(), Value::List(vec![Value::Str("triggerPrice".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("triggerPriceType".to_string())]), &[]);
} else {
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), type_var.clone());
if is_equal(&type_var, &Value::Str("OCO".to_string())) {
// the price argument is the limit price of the take profit leg,
// the stopPrice param is the limit price of the stop loss leg
// and the triggerPrice param is where the stop loss leg fires
add_element_to_object(&mut request, &Value::Str("takeProfitOrderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
let mut stopPrice: Value = self.safe_string_k(params.clone(), "stopPrice", &[]);
if !is_equal(&stopPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopLossOrderPrice".to_string()), self.price_to_precision(symbol.clone(), stopPrice.clone()));
}
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("stopLossTriggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
}
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
add_element_to_object(&mut request, &Value::Str("stopLossTriggerType".to_string()), self.encode_trigger_price_type(triggerPriceType.clone()));
params = self.omit(params.clone(), Value::List(vec![Value::Str("stopPrice".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("triggerPriceType".to_string())]), &[]);
} else if is_equal(&type_var, &Value::Str("PEG".to_string())) {
// the required deviation and stealth params pass through, the
// optional price argument becomes a worst-price bound
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
} else if is_equal(&type_var, &Value::Str("TRAILING".to_string())) {
let mut trailingAmount: Value = self.safe_string_k(params.clone(), "trailingAmount", &[]);
let mut trailingPercent: Value = self.safe_string_k(params.clone(), "trailingPercent", &[]);
if !is_equal(&trailingAmount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("trailValue".to_string()), self.price_to_precision(symbol.clone(), trailingAmount.clone()));
add_element_to_object(&mut request, &Value::Str("trailValueType".to_string()), Value::Str("DISTANCE".to_string()));
} else if !is_equal(&trailingPercent, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("trailValue".to_string()), trailingPercent.clone());
add_element_to_object(&mut request, &Value::Str("trailValueType".to_string()), Value::Str("PERCENTAGE".to_string()));
}
let mut triggerPriceType: Value = self.safe_string_k(params.clone(), "triggerPriceType", &[Value::Str("mark".to_string())]);
add_element_to_object(&mut request, &Value::Str("trailTriggerPriceType".to_string()), self.encode_trigger_price_type(triggerPriceType.clone()));
params = self.omit(params.clone(), Value::List(vec![Value::Str("trailingAmount".to_string()), Value::Str("trailingPercent".to_string()), Value::Str("triggerPriceType".to_string())]), &[]);
}
}
let __ws_arg_14 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_futures_api_v3_trade_orders_algo(&[__ws_arg_14]).await;
}
// the normal futures endpoint responds with a single order dict, keep a
// one element array guard in case a gateway wraps it
let mut order: Value = response.clone();
if is_true(&Value::Bool(is_array(&response))) {
order = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
pub fn encode_trigger_price_type(&self, mut priceType: Value) -> Value {
let mut priceTypes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("last".to_string(), Value::Str("LAST_PRICE".to_string()));
m.insert("mark".to_string(), Value::Str("MARK_PRICE".to_string()));
m.insert("index".to_string(), Value::Str("INDEX_PRICE".to_string()));
m.insert("lastPrice".to_string(), Value::Str("LAST_PRICE".to_string()));
m.insert("markPrice".to_string(), Value::Str("MARK_PRICE".to_string()));
m.insert("indexPrice".to_string(), Value::Str("INDEX_PRICE".to_string()));
m
});
return self.safe_string(priceTypes.clone(), priceType.clone(), &[priceType.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchOpenOrder
* @description fetches information on an open order made by the user
* @see https://docs.btse.com/spot/rest/get-order
* @see https://docs.btse.com/futures/rest/get-orders
* @param {string} id the order id
* @param {string} [symbol] unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the order
* @param {string} [params.type] 'spot', 'swap' or 'future', default is 'spot'
* @param {bool} [params.includeCancelled] *contract markets only* if true, cancelled orders are included in the lookup
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_open_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrderId".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
} else if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchOpenOrder() requires an id argument or a clientOrderId parameter".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOrder".to_string()), &[market.clone(), params.clone(), marketType.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
let __ws_arg_15 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_spot_api_v4_trade_order(&[__ws_arg_15]).await;
} else {
// the futures endpoint doubles as the single order lookup when an
// order id is sent and responds with a bare array
let __ws_arg_16 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_futures_api_v3_trade_orders(&[__ws_arg_16]).await;
}
// accept a bare order dict, a data envelope and a one element array
let mut order: Value = self.safe_value_k(response.clone(), "data", &[response.clone()]);
if is_true(&Value::Bool(is_array(&order))) {
order = self.safe_dict(order.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
}
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#editOrder
* @description edit a trade order
* @see https://docs.btse.com/spot/rest/amend-order
* @see https://docs.btse.com/futures/rest/amend-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' (not used by btse)
* @param {string} side 'buy' or 'sell' (not used by btse)
* @param {float} [amount] how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the order, required if id is not provided
* @param {float} [params.triggerPrice] the price that a trigger order is triggered at
* @param {bool} [params.totalAmountMode] if true, the amount is treated as the new total order quantity including the already filled portion, default is false
* @param {bool} [params.slide] *contract markets only* if true and only the price is amended, the price slides to the best available price
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order(&mut self, mut id: Value, mut symbol: Value, mut type_var: Value, mut side: Value, optional_args: &[Value]) -> Value {
let mut amount = get_arg(optional_args, 0, Value::Null);
let mut price = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrderId".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
} else if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires an id argument or a clientOrderId parameter".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut triggerPrice: Value = self.safe_string_k(params.clone(), "triggerPrice", &[]);
if !is_equal(&triggerPrice, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("triggerPrice".to_string()), self.price_to_precision(symbol.clone(), triggerPrice.clone()));
params = self.omit(params.clone(), Value::Str("triggerPrice".to_string()), &[]);
}
if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderSize".to_string()), self.amount_to_precision(symbol.clone(), amount.clone()));
}
if !is_equal(&price, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
}
let mut isSlide: Value = self.safe_bool_k(params.clone(), "slide", &[Value::Bool(false)]);
if is_true(&(is_equal(&amount, &Value::Null))) && is_true(&(is_equal(&price, &Value::Null))) && is_true(&(is_equal(&triggerPrice, &Value::Null))) && is_true(&(!is_equal(&isSlide, &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" editOrder() requires an amount argument, a price argument or a triggerPrice parameter".to_string()))));
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_17 = self.extend(request.clone(), &[params.clone()]);
response = self.private_put_spot_api_v4_trade_orders(&[__ws_arg_17]).await;
} else {
// the futures amend requires an explicit amendType discriminator
// which can change the price and size together or a single field
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.futures_request_id(market.clone()));
if !is_equal(&triggerPrice, &Value::Null) {
if is_true(&(!is_equal(&amount, &Value::Null))) || is_true(&(!is_equal(&price, &Value::Null))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" editOrder() can not amend the trigger price together with the price or the amount on contract markets".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("amendType".to_string()), Value::Str("TRIGGER_PRICE".to_string()));
} else if is_true(&(!is_equal(&amount, &Value::Null))) && is_true(&(!is_equal(&price, &Value::Null))) {
add_element_to_object(&mut request, &Value::Str("amendType".to_string()), Value::Str("ALL".to_string()));
} else if !is_equal(&amount, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("amendType".to_string()), Value::Str("SIZE".to_string()));
} else {
add_element_to_object(&mut request, &Value::Str("amendType".to_string()), Value::Str("PRICE".to_string()));
}
let __ws_arg_18 = self.extend(request.clone(), &[params.clone()]);
response = self.private_put_futures_api_v3_trade_orders(&[__ws_arg_18]).await;
}
let mut order: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#cancelOrder
* @see https://docs.btse.com/spot/rest/cancel-order
* @see https://docs.btse.com/futures/rest/cancel-order
* @description cancels an open order
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a unique id for the order, required if id is not provided
* @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()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut clientOrderId: Value = self.safe_string_k(params.clone(), "clientOrderId", &[]);
if !is_equal(&clientOrderId, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("clOrderId".to_string()), clientOrderId.clone());
params = self.omit(params.clone(), Value::Str("clientOrderId".to_string()), &[]);
} else if is_equal(&id, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrder() requires an id argument or a clientOrderId parameter".to_string()))));
} else {
add_element_to_object(&mut request, &Value::Str("orderId".to_string()), id.clone());
}
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
let __ws_arg_19 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_spot_api_v4_trade_orders(&[__ws_arg_19]).await;
} else {
//
// [
// {
// "orderId": "0251ea47-88b5-48c0-aeb3-b38774fd1f90",
// "clOrderId": "",
// "symbol": "BTC-PERP",
// "orderSide": "BUY",
// "type": 76,
// "orderPrice": 56439.4,
// "orderSize": 1,
// "filledSize": 0,
// "status": 6,
// "timestamp": 1784882344500
// }
// ]
//
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.futures_request_id(market.clone()));
let __ws_arg_20 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_futures_api_v3_trade_orders(&[__ws_arg_20]).await;
}
let mut order: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#cancelAllOrders
* @description cancel all open orders in a market
* @see https://docs.btse.com/spot/rest/cancel-all-orders
* @see https://btsecom.github.io/docs/futuresV2_3/en/#cancel-order
* @param {string} [symbol] unified market symbol of the market to cancel orders in, on spot markets omit it to cancel every open order across all pairs
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot', 'swap' or 'future', default is 'spot', used when the symbol is omitted
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrders".to_string()), &[market.clone(), params.clone(), marketType.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
});
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
// the literal ALL value cancels every open order across all pairs
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), ternary(is_true(&(!is_equal(&market, &Value::Null))), get_value(&market, &Value::Str("id".to_string())), Value::Str("ALL".to_string())));
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_spot_api_v4_trade_orders_all(&[__ws_arg_21]).await;
} else {
if is_equal(&market, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelAllOrders() requires a symbol argument for contract markets".to_string()))));
}
// the unified futures api has no cancel all endpoint, the legacy
// endpoint cancels every order for the symbol when no order id is
// sent, and it identifies contracts by the short symbol form
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.futures_request_id(market.clone()));
let __ws_arg_22 = self.extend(request.clone(), &[params.clone()]);
response = self.private_delete_futures_api_v23_order(&[__ws_arg_22]).await;
}
return self.parse_orders(response.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#cancelAllOrdersAfter
* @description dead man's switch, cancel all orders after the given timeout
* @see https://docs.btse.com/spot/rest/cancel-all-after
* @see https://docs.btse.com/futures/rest/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
* @param {string} [params.type] 'spot', 'swap' or 'future', default is 'spot'
* @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
}));
self.load_markets(&[]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut response: Value = Value::Null;
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("cancelAllOrdersAfter".to_string()), &[Value::Null, params.clone(), marketType.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
add_element_to_object(&mut request, &Value::Str("timeout".to_string()), timeout.clone());
let __ws_arg_23 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_spot_api_v4_trade_orders_cancel_all_after(&[__ws_arg_23]).await;
} else {
// the futures param is named timeoutMs and is required, zero disarms
add_element_to_object(&mut request, &Value::Str("timeoutMs".to_string()), timeout.clone());
let __ws_arg_24 = self.extend(request.clone(), &[params.clone()]);
response = self.private_post_futures_api_v3_trade_orders_cancel_all_after(&[__ws_arg_24]).await;
}
return response;
Value::Null
}
/*
* @method
* @name btse#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://docs.btse.com/spot/rest/get-orders
* @see https://docs.btse.com/futures/rest/get-orders
* @param {string} [symbol] unified market symbol
* @param {int} [since] the earliest time in ms to fetch open orders for, filtered client-side
* @param {int} [limit] the maximum number of open orders structures to retrieve, filtered client-side
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot', 'swap' or 'future', default is 'spot'
* @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
}));
self.load_markets(&[]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut market: Value = Value::Null;
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
}
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchOpenOrders".to_string()), &[market.clone(), params.clone(), marketType.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut response: Value = Value::Null;
if is_equal(&marketType, &Value::Str("spot".to_string())) {
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), get_value(&market, &Value::Str("id".to_string())));
}
let __ws_arg_25 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_spot_api_v4_trade_orders(&[__ws_arg_25]).await;
} else {
if !is_equal(&market, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("symbol".to_string()), self.futures_request_id(market.clone()));
}
let __ws_arg_26 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_futures_api_v3_trade_orders(&[__ws_arg_26]).await;
}
// the endpoints have no server side time filters, accept a bare array
// and a data envelope and filter client-side
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
return self.parse_orders(rows.clone(), &[market.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// createOrder - spot
// {
// "status": 2,
// "symbol": "ETH-USDT",
// "orderType": 76,
// "price": 1000,
// "side": "BUY",
// "orderID": "cde4fb37-2e2b-437e-a816-4b55b2e2b7c7",
// "timestamp": 1770813053751,
// "triggerPrice": 0,
// "stopPrice": null,
// "trigger": false,
// "message": "",
// "clOrderID": null,
// "stealth": 1,
// "deviation": 1,
// "postOnly": false,
// "orderDetailType": null,
// "originalOrderBaseSize": 0.0001,
// "originalOrderQuoteSize": null,
// "currentOrderBaseSize": 0.0001,
// "currentOrderQuoteSize": null,
// "remainingOrderBaseSize": 0.0001,
// "remainingOrderQuoteSize": null,
// "filledBaseSize": 0,
// "totalFilledBaseSize": 0,
// "orderCurrency": "base",
// "avgFilledPrice": 0,
// "time_in_force": "GTC"
// }
//
// createOrder - swap
// {
// "status": 4,
// "symbol": "ETH-PERP",
// "orderType": 77,
// "price": 1956.59,
// "side": "BUY",
// "orderID": "5c6a26db-8cfb-45c7-b25d-56927bc36795",
// "timestamp": 1770821231984,
// "triggerPrice": 0,
// "trigger": false,
// "deviation": 100,
// "stealth": 100,
// "message": "",
// "avgFilledPrice": 1956.59,
// "clOrderID": "",
// "originalOrderSize": 1,
// "currentOrderSize": 1,
// "filledSize": 1,
// "totalFilledSize": 1,
// "remainingSize": 0,
// "postOnly": false,
// "orderDetailType": null,
// "positionMode": "ONE_WAY",
// "positionDirection": null,
// "positionId": "ETH-PERP-USDT",
// "time_in_force": "GTC"
// }
//
let mut marketId: Value = self.safe_string2(order.clone(), Value::Str("symbol".to_string()), Value::Str("market".to_string()), &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(order.clone(), "timestamp", &[]);
// open_orders rows carry no numeric status - the state lives in
// orderState (STATUS_ACTIVE / STATUS_INACTIVE), and time_in_force
// is spelled timeInForce there (observed live), so both fall back
let mut rawStatus: Value = self.safe_string2(order.clone(), Value::Str("status".to_string()), Value::Str("orderState".to_string()), &[]);
let mut rawType: Value = self.safe_string2(order.clone(), Value::Str("orderType".to_string()), Value::Str("type".to_string()), &[]);
let mut status: Value = self.parse_order_status(rawStatus.clone());
let mut orderType: Value = self.parse_order_type(rawType.clone());
if is_true(&(is_equal(&orderType, &Value::Str("market".to_string())))) && is_true(&(is_equal(&status, &Value::Str("open".to_string())))) {
// market orders never rest on the book, the exchange reports the
// partially filled code on them when a residual quote dust amount
// cannot fill, observed live, such orders are finished
status = Value::Str("closed".to_string());
}
let mut rawTimeInForce: Value = self.safe_string2(order.clone(), Value::Str("time_in_force".to_string()), Value::Str("timeInForce".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(), self.safe_string2(order.clone(), Value::Str("orderID".to_string()), Value::Str("orderId".to_string()), &[]));
m.insert("clientOrderId".to_string(), self.safe_string2(order.clone(), Value::Str("clOrderID".to_string()), Value::Str("clOrderId".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("status".to_string(), status.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("type".to_string(), orderType.clone());
m.insert("timeInForce".to_string(), self.parse_time_in_force(rawTimeInForce.clone()));
m.insert("postOnly".to_string(), self.safe_bool_k(order.clone(), "postOnly", &[]));
m.insert("reduceOnly".to_string(), self.safe_bool_k(order.clone(), "reduceOnly", &[]));
m.insert("side".to_string(), self.safe_string_lower2(order.clone(), Value::Str("side".to_string()), Value::Str("orderSide".to_string()), &[]));
m.insert("price".to_string(), self.safe_string2(order.clone(), Value::Str("price".to_string()), Value::Str("orderPrice".to_string()), &[]));
m.insert("triggerPrice".to_string(), self.omit_zero(self.safe_string2(order.clone(), Value::Str("triggerOriginalPrice".to_string()), Value::Str("triggerPrice".to_string()), &[])));
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m.insert("amount".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("currentOrderBaseSize".to_string()), Value::Str("currentOrderSize".to_string()), Value::Str("orderSize".to_string())]), &[]));
m.insert("filled".to_string(), self.safe_string_n(order.clone(), Value::List(vec![Value::Str("totalFilledBaseSize".to_string()), Value::Str("totalFilledSize".to_string()), Value::Str("filledSize".to_string())]), &[]));
m.insert("remaining".to_string(), self.safe_string2(order.clone(), Value::Str("remainingOrderBaseSize".to_string()), Value::Str("remainingSize".to_string()), &[]));
m.insert("cost".to_string(), Value::Null);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Null);
m.insert("average".to_string(), self.omit_zero(self.safe_string2(order.clone(), Value::Str("avgFilledPrice".to_string()), Value::Str("averageFillPrice".to_string()), &[])));
m
}), &[market.clone()]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Value {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("2".to_string(), Value::Str("open".to_string()));
m.insert("3".to_string(), Value::Str("closed".to_string()));
m.insert("4".to_string(), Value::Str("closed".to_string()));
m.insert("5".to_string(), Value::Str("open".to_string()));
m.insert("6".to_string(), Value::Str("canceled".to_string()));
m.insert("7".to_string(), Value::Str("refunded".to_string()));
m.insert("8".to_string(), Value::Str("rejected".to_string()));
m.insert("9".to_string(), Value::Str("open".to_string()));
m.insert("10".to_string(), Value::Str("open".to_string()));
m.insert("15".to_string(), Value::Str("rejected".to_string()));
m.insert("16".to_string(), Value::Str("rejected".to_string()));
m.insert("17".to_string(), Value::Str("rejected".to_string()));
m.insert("123".to_string(), Value::Str("open".to_string()));
m.insert("STATUS_ACTIVE".to_string(), Value::Str("open".to_string()));
m.insert("STATUS_INACTIVE".to_string(), Value::Str("canceled".to_string()));
m.insert("ORDER_INSERTED".to_string(), Value::Str("open".to_string()));
m.insert("ORDER_PARTIALLY_TRANSACTED".to_string(), Value::Str("open".to_string()));
m.insert("ORDER_FULLY_TRANSACTED".to_string(), Value::Str("closed".to_string()));
m.insert("ORDER_CANCELLED".to_string(), Value::Str("canceled".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
pub fn parse_order_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("76".to_string(), Value::Str("limit".to_string()));
m.insert("77".to_string(), Value::Str("market".to_string()));
m.insert("80".to_string(), Value::Str("limit".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn parse_time_in_force(&self, mut timeInForce: Value) -> Value {
let mut values: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("GTC".to_string(), Value::Str("GTC".to_string()));
m.insert("IOC".to_string(), Value::Str("IOC".to_string()));
m.insert("FOK".to_string(), Value::Str("FOK".to_string()));
m.insert("HALFSEC".to_string(), Value::Str("GTD".to_string()));
m.insert("HALFMIN".to_string(), Value::Str("GTD".to_string()));
m.insert("FIVEMIN".to_string(), Value::Str("GTD".to_string()));
m.insert("HOUR".to_string(), Value::Str("GTD".to_string()));
m.insert("TWELVEHOUR".to_string(), Value::Str("GTD".to_string()));
m.insert("DAY".to_string(), Value::Str("GTD".to_string()));
m.insert("WEEK".to_string(), Value::Str("GTD".to_string()));
m.insert("MONTH".to_string(), Value::Str("GTD".to_string()));
m
});
return self.safe_string(values.clone(), timeInForce.clone(), &[timeInForce.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchTradingFees
* @description fetch the trading fees for multiple markets
* @see https://docs.btse.com/spot/rest/get-fees
* @see https://btsecom.github.io/docs/futuresV2_3/en/#query-account-fee
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.type] 'spot', 'swap' or 'future' (default is 'spot')
* @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/?id=fee-structure} indexed by market symbols
*/
pub async fn fetch_trading_fees(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut response: Value = Value::Null;
let mut marketType: Value = Value::Str("spot".to_string());
{ let __destr_tmp = self.handle_market_type_and_params(Value::Str("fetchTradingFees".to_string()), &[Value::Null, params.clone(), marketType.clone()]); marketType = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&marketType, &Value::Str("spot".to_string())) {
response = self.private_get_spot_api_v4_trade_fees(&[params.clone()]).await;
} else {
// the futures fees stay on the legacy endpoint, the unified futures
// api has no fees route
response = self.private_get_futures_api_v23_user_fees(&[params.clone()]).await;
}
//
// [
// {
// "symbol": "FUSD-USD",
// "makerFee": 0.002,
// "takerFee": 0.002
// }
// ]
//
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
let mut responseList: Value = self.array_concat(Value::List(vec![]), rows.clone());
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_467: bool = true;
while { if !__for_first_467 { i = add(&i, &Value::Int(1)); } __for_first_467 = false; is_less_than(&i, &get_array_length(&responseList)) } {
let mut feeInfo: Value = get_value(&responseList, &i);
let mut feeInfo: Value = get_value(&responseList, &i);
let mut marketId: Value = self.safe_string_k(feeInfo.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut makerFee: Value = self.safe_number_k(feeInfo.clone(), "makerFee", &[]);
let mut takerFee: Value = self.safe_number_k(feeInfo.clone(), "takerFee", &[]);
add_element_to_object(&mut result, &symbol, Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), feeInfo.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), makerFee.clone());
m.insert("taker".to_string(), takerFee.clone());
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
}));
}
}
return result;
Value::Null
}
pub async fn request_wallet_history_rows(&mut self, mut methodName: Value, mut historyTypes: Value, 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
}));
// the helper always receives a non empty history type list, the list is
// rebuilt through safeList so the transpilers treat it as an array in
// every runtime
let mut typesList: Value = self.safe_list(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("types".to_string(), historyTypes.clone());
m
}), Value::Str("types".to_string()), &[Value::List(vec![])]);
self.load_markets(&[]).await;
let mut walletType: Value = self.safe_string_k(params.clone(), "walletType", &[Value::Str("SPOT".to_string())]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("walletType".to_string(), walletType.clone());
m
});
// the endpoint applies a server side history type filter sent as a
// json encoded array in the query string, verified live
add_element_to_object(&mut request, &Value::Str("historyTypes".to_string()), self.json(typesList.clone()));
params = self.omit(params.clone(), Value::Str("walletType".to_string()), &[]);
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("asset".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
} else if is_equal(&walletType, &Value::Str("SPOT".to_string())) {
panic!("{}", crate::exchange_errors::arguments_required(add(&add(&add(&self.id, &Value::Str(" ".to_string())), &methodName), &Value::Str("() requires a code argument for the spot wallet history".to_string()))));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), methodName.clone(), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_27 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_public_api_wallet_v1_user_wallet_history(&[__ws_arg_27]).await;
//
// {
// "code": 1,
// "msg": "Success",
// "time": 1786624541092,
// "data": [
// {
// "transactionTime": 1786510157962,
// "type": "DEPOSIT",
// "walletName": "SPOT@",
// "asset": "USDT",
// "netAmount": "100",
// "amount": "100",
// "transactionRef": "2026081200000367",
// "status": "COMPLETED",
// "description": null,
// "fees": "0",
// "cryptoNetwork": "ERC20",
// "toAddress": "0x36bd7cbc486658c9777672fe742971bda65d5e6f",
// "confirmTimes": "(15/15)",
// "txId": "0xb4d88986d013f799d78e6232792c44b45dff1213a015171ddcf4adfcd283b3fd"
// }
// ],
// "success": true
// }
//
let mut rawRows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
// the requested types are also filtered client side over both the legacy
// and the unified enum vocabularies as the legacy endpoint ignored the
// filter and returned the whole mixed ledger
let mut allowed: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_468: bool = true;
while { if !__for_first_468 { i = add(&i, &Value::Int(1)); } __for_first_468 = false; is_less_than(&i, &get_array_length(&typesList)) } {
let mut historyType: Value = get_value(&typesList, &i);
let mut historyType: Value = get_value(&typesList, &i);
add_element_to_object(&mut allowed, &historyType, Value::Bool(true));
add_element_to_object(&mut allowed, &self.capitalize(to_lower(&historyType)), Value::Bool(true));
}
}
let mut rows: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_469: bool = true;
while { if !__for_first_469 { i = add(&i, &Value::Int(1)); } __for_first_469 = false; is_less_than(&i, &get_array_length(&rawRows)) } {
let mut entry: Value = get_value(&rawRows, &i);
let mut entry: Value = get_value(&rawRows, &i);
let mut type_var: Value = self.safe_string_k(entry.clone(), "type", &[Value::Str("".to_string())]);
if is_true(&Value::Bool(in_op(&allowed, &type_var))) {
append_to_array(&mut rows, entry.clone());
}
}
}
return Value::List(vec![rows.clone(), currency.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchDepositsWithdrawals
* @description fetch history of deposits and withdrawals
* @see https://docs.btse.com/wallet/rest/get-user-wallet-history
* @param {string} [code] unified currency code, required for the default spot wallet
* @param {int} [since] the earliest time in ms to fetch transactions for
* @param {int} [limit] the maximum number of transaction 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 transactions for, excluded
* @param {string} [params.walletType] wallet to query, SPOT by default, ISOLATED requires params.walletName
* @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
*/
pub async fn fetch_deposits_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
}));
let mut rowscurrencyVariable = self.request_wallet_history_rows(Value::Str("fetchDepositsWithdrawals".to_string()), Value::List(vec![Value::Str("DEPOSIT".to_string()), Value::Str("WITHDRAW".to_string())]), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
let mut rows: Value = get_value(&rowscurrencyVariable, &Value::Int(0));
let mut currency: Value = get_value(&rowscurrencyVariable, &Value::Int(1));
return self.parse_transactions(rows.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchDeposits
* @description fetch all deposits made to an account
* @see https://docs.btse.com/wallet/rest/get-user-wallet-history
* @param {string} [code] unified currency code, required for the default spot wallet
* @param {int} [since] the earliest time in ms to fetch deposits for
* @param {int} [limit] the maximum number of transaction structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch deposits for, excluded
* @param {string} [params.walletType] wallet to query, SPOT by default, ISOLATED requires params.walletName
* @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
}));
let mut rowscurrencyVariable = self.request_wallet_history_rows(Value::Str("fetchDeposits".to_string()), Value::List(vec![Value::Str("DEPOSIT".to_string())]), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
let mut rows: Value = get_value(&rowscurrencyVariable, &Value::Int(0));
let mut currency: Value = get_value(&rowscurrencyVariable, &Value::Int(1));
return self.parse_transactions(rows.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchWithdrawals
* @description fetch all withdrawals made from an account
* @see https://docs.btse.com/wallet/rest/get-user-wallet-history
* @param {string} [code] unified currency code, required for the default spot wallet
* @param {int} [since] the earliest time in ms to fetch withdrawals for
* @param {int} [limit] the maximum number of transaction structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] the latest time in ms to fetch withdrawals for, excluded
* @param {string} [params.walletType] wallet to query, SPOT by default, ISOLATED requires params.walletName
* @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
}));
let mut rowscurrencyVariable = self.request_wallet_history_rows(Value::Str("fetchWithdrawals".to_string()), Value::List(vec![Value::Str("WITHDRAW".to_string())]), &[code.clone(), since.clone(), limit.clone(), params.clone()]).await;
let mut rows: Value = get_value(&rowscurrencyVariable, &Value::Int(0));
let mut currency: Value = get_value(&rowscurrencyVariable, &Value::Int(1));
return self.parse_transactions(rows.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "username": "user",
// "orderId": "2026081200000367",
// "wallet": "SPOT@",
// "currency": "USDT",
// "type": "Deposit",
// "amount": 100,
// "fees": 0,
// "description": "",
// "timestamp": 1786510157962,
// "status": "PROCESSING",
// "txId": "",
// "toAddress": "0x0000000000000000000000000000000000000000",
// "currencyNetwork": "",
// "sourceCurrency": "USDT",
// "sourceAmount": 0,
// "targetCurrency": "",
// "targetAmount": 0,
// "rate": 0
// }
//
let mut currencyId: Value = self.safe_string2(transaction.clone(), Value::Str("currency".to_string()), Value::Str("asset".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer2(transaction.clone(), Value::Str("timestamp".to_string()), Value::Str("transactionTime".to_string()), &[]);
let mut networkId: Value = self.safe_string2(transaction.clone(), Value::Str("currencyNetwork".to_string()), Value::Str("cryptoNetwork".to_string()), &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), transaction.clone());
m.insert("id".to_string(), self.safe_string2(transaction.clone(), Value::Str("orderId".to_string()), Value::Str("transactionRef".to_string()), &[]));
m.insert("txid".to_string(), self.safe_string_k(transaction.clone(), "txId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("network".to_string(), self.network_id_to_code(&[networkId.clone(), code.clone()]));
m.insert("address".to_string(), self.safe_string_k(transaction.clone(), "toAddress", &[]));
m.insert("addressTo".to_string(), self.safe_string_k(transaction.clone(), "toAddress", &[]));
m.insert("addressFrom".to_string(), Value::Null);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_transaction_type(self.safe_string_k(transaction.clone(), "type", &[])));
m.insert("amount".to_string(), self.safe_number_k(transaction.clone(), "amount", &[]));
m.insert("currency".to_string(), code.clone());
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(transaction.clone(), "status", &[])));
m.insert("updated".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("comment".to_string(), self.safe_string_k(transaction.clone(), "description", &[]));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("cost".to_string(), self.safe_number2(transaction.clone(), Value::Str("fees".to_string()), Value::Str("fee".to_string()), &[]));
m
}));
m
});
Value::Null
}
pub fn parse_transaction_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Deposit".to_string(), Value::Str("deposit".to_string()));
m.insert("Withdraw".to_string(), Value::Str("withdrawal".to_string()));
m.insert("DEPOSIT".to_string(), Value::Str("deposit".to_string()));
m.insert("WITHDRAW".to_string(), Value::Str("withdrawal".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn parse_transaction_status(&self, mut status: Value) -> Value {
// the full enum from the wallet documentation, PROCESSING is also live-verified
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("PROCESSING".to_string(), Value::Str("pending".to_string()));
m.insert("PENDING".to_string(), Value::Str("pending".to_string()));
m.insert("COMPLETED".to_string(), Value::Str("ok".to_string()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".to_string()));
m.insert("EXPIRED".to_string(), Value::Str("canceled".to_string()));
m.insert("FAILURE".to_string(), Value::Str("failed".to_string()));
m
});
return self.safe_string(statuses.clone(), status.clone(), &[status.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchLedger
* @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
* @see https://docs.btse.com/wallet/rest/get-user-wallet-history
* @param {string} [code] unified currency code
* @param {int} [since] the earliest time in ms to fetch ledger entries for
* @param {int} [limit] the maximum number of ledger entry 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 ledger entries for, excluded
* @param {string} [params.walletType] wallet to query, SPOT by default, ISOLATED requires params.walletName
* @returns {object[]} a list of [ledger structures]{@link https://docs.ccxt.com/#/?id=ledger}
*/
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
}));
self.load_markets(&[]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut walletType: Value = self.safe_string_k(params.clone(), "walletType", &[Value::Str("SPOT".to_string())]);
add_element_to_object(&mut request, &Value::Str("walletType".to_string()), walletType.clone());
params = self.omit(params.clone(), Value::Str("walletType".to_string()), &[]);
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("asset".to_string()), get_value(¤cy, &Value::Str("id".to_string())));
} else if is_equal(&walletType, &Value::Str("SPOT".to_string())) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchLedger() requires a code argument for the spot wallet history".to_string()))));
}
if !is_equal(&since, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("startTime".to_string()), since.clone());
}
if !is_equal(&limit, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("pageSize".to_string()), limit.clone());
}
let mut until: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("fetchLedger".to_string()), Value::Str("until".to_string()), &[]); until = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&until, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("endTime".to_string()), until.clone());
}
let __ws_arg_28 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_public_api_wallet_v1_user_wallet_history(&[__ws_arg_28]).await;
//
// [
// {
// "transactionTime": 1786510157962,
// "type": "DEPOSIT",
// "walletName": "SPOT@",
// "asset": "USDT",
// "netAmount": "100",
// "amount": "100",
// "transactionRef": "2026081200000367",
// "status": "PROCESSING",
// "description": "",
// "fee": "0",
// "cryptoNetwork": "",
// "toAddress": "0x0000000000000000000000000000000000000000",
// "confirmTimes": "",
// "txId": ""
// }
// ]
//
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
return self.parse_ledger(rows.clone(), &[currency.clone(), since.clone(), limit.clone()]);
Value::Null
}
pub fn parse_ledger_entry(&self, mut item: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut currencyId: Value = self.safe_string2(item.clone(), Value::Str("currency".to_string()), Value::Str("asset".to_string()), &[]);
let mut code: Value = self.safe_currency_code(currencyId.clone(), &[currency.clone()]);
let mut timestamp: Value = self.safe_integer2(item.clone(), Value::Str("timestamp".to_string()), Value::Str("transactionTime".to_string()), &[]);
let mut type_var: Value = self.safe_string_k(item.clone(), "type", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), item.clone());
m.insert("id".to_string(), self.safe_string2(item.clone(), Value::Str("orderId".to_string()), Value::Str("transactionRef".to_string()), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("direction".to_string(), self.parse_ledger_entry_direction(type_var.clone()));
m.insert("account".to_string(), self.safe_string2(item.clone(), Value::Str("wallet".to_string()), Value::Str("walletName".to_string()), &[]));
m.insert("referenceId".to_string(), self.safe_string_k(item.clone(), "txId", &[]));
m.insert("referenceAccount".to_string(), Value::Null);
m.insert("type".to_string(), self.parse_ledger_entry_type(type_var.clone()));
m.insert("currency".to_string(), code.clone());
m.insert("amount".to_string(), self.safe_number_k(item.clone(), "amount", &[]));
m.insert("before".to_string(), Value::Null);
m.insert("after".to_string(), Value::Null);
m.insert("status".to_string(), self.parse_transaction_status(self.safe_string_k(item.clone(), "status", &[])));
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code.clone());
m.insert("cost".to_string(), self.safe_number2(item.clone(), Value::Str("fees".to_string()), Value::Str("fee".to_string()), &[]));
m
}));
m
});
Value::Null
}
pub fn parse_ledger_entry_type(&self, mut type_var: Value) -> Value {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Deposit".to_string(), Value::Str("transaction".to_string()));
m.insert("Withdraw".to_string(), Value::Str("transaction".to_string()));
m.insert("Convert fiat".to_string(), Value::Str("trade".to_string()));
m.insert("Transfer_Out".to_string(), Value::Str("transfer".to_string()));
m.insert("Transfer_In".to_string(), Value::Str("transfer".to_string()));
m.insert("ReferralEarning".to_string(), Value::Str("referral".to_string()));
m.insert("Sub Account Transfer In".to_string(), Value::Str("transfer".to_string()));
m.insert("Sub Account Transfer Out".to_string(), Value::Str("transfer".to_string()));
m.insert("express buy".to_string(), Value::Str("trade".to_string()));
m.insert("spot trading fee rebate".to_string(), Value::Str("rebate".to_string()));
m.insert("futures trading fee rebate".to_string(), Value::Str("rebate".to_string()));
m.insert("general trading fee rebate".to_string(), Value::Str("rebate".to_string()));
m.insert("DEPOSIT".to_string(), Value::Str("transaction".to_string()));
m.insert("WITHDRAW".to_string(), Value::Str("transaction".to_string()));
m.insert("CONVERT".to_string(), Value::Str("trade".to_string()));
m.insert("ASSET_CONVERSION".to_string(), Value::Str("trade".to_string()));
m.insert("SEND".to_string(), Value::Str("transfer".to_string()));
m.insert("RECEIVE".to_string(), Value::Str("transfer".to_string()));
m.insert("REFERRAL".to_string(), Value::Str("referral".to_string()));
m.insert("TRANSFER_IN".to_string(), Value::Str("transfer".to_string()));
m.insert("TRANSFER_OUT".to_string(), Value::Str("transfer".to_string()));
m.insert("SUB_ACCOUNT_TRANSFER_IN".to_string(), Value::Str("transfer".to_string()));
m.insert("SUB_ACCOUNT_TRANSFER_OUT".to_string(), Value::Str("transfer".to_string()));
m.insert("REALIZED_PNL".to_string(), Value::Str("trade".to_string()));
m.insert("FUNDING".to_string(), Value::Str("fee".to_string()));
m
});
return self.safe_string(types.clone(), type_var.clone(), &[type_var.clone()]);
Value::Null
}
pub fn parse_ledger_entry_direction(&self, mut type_var: Value) -> Value {
let mut directions: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("Deposit".to_string(), Value::Str("in".to_string()));
m.insert("Withdraw".to_string(), Value::Str("out".to_string()));
m.insert("Transfer_Out".to_string(), Value::Str("out".to_string()));
m.insert("Transfer_In".to_string(), Value::Str("in".to_string()));
m.insert("ReferralEarning".to_string(), Value::Str("in".to_string()));
m.insert("Sub Account Transfer In".to_string(), Value::Str("in".to_string()));
m.insert("Sub Account Transfer Out".to_string(), Value::Str("out".to_string()));
m.insert("spot trading fee rebate".to_string(), Value::Str("in".to_string()));
m.insert("futures trading fee rebate".to_string(), Value::Str("in".to_string()));
m.insert("general trading fee rebate".to_string(), Value::Str("in".to_string()));
m.insert("trial fund".to_string(), Value::Str("in".to_string()));
m.insert("token voucher in".to_string(), Value::Str("in".to_string()));
m.insert("token voucher out".to_string(), Value::Str("out".to_string()));
m.insert("Strategy Income".to_string(), Value::Str("in".to_string()));
m.insert("Strategy Pay".to_string(), Value::Str("out".to_string()));
m.insert("DEPOSIT".to_string(), Value::Str("in".to_string()));
m.insert("WITHDRAW".to_string(), Value::Str("out".to_string()));
m.insert("RECEIVE".to_string(), Value::Str("in".to_string()));
m.insert("SEND".to_string(), Value::Str("out".to_string()));
m.insert("REFERRAL".to_string(), Value::Str("in".to_string()));
m.insert("GET_PAID".to_string(), Value::Str("in".to_string()));
m.insert("PAID".to_string(), Value::Str("out".to_string()));
m.insert("TRANSFER_IN".to_string(), Value::Str("in".to_string()));
m.insert("TRANSFER_OUT".to_string(), Value::Str("out".to_string()));
m.insert("SUB_ACCOUNT_TRANSFER_IN".to_string(), Value::Str("in".to_string()));
m.insert("SUB_ACCOUNT_TRANSFER_OUT".to_string(), Value::Str("out".to_string()));
m.insert("INVEST".to_string(), Value::Str("out".to_string()));
m.insert("REDEEM".to_string(), Value::Str("in".to_string()));
m
});
return self.safe_string(directions.clone(), type_var.clone(), &[]);
Value::Null
}
/*
* @method
* @name btse#fetchTradingFee
* @description fetch the trading fees for a market
* @see https://docs.btse.com/spot/rest/get-fees
* @see https://btsecom.github.io/docs/futuresV2_3/en/#query-account-fee
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
});
let mut response: Value = Value::Null;
if is_equal(&get_value(&market, &Value::Str("spot".to_string())), &Value::Bool(true)) {
let __ws_arg_29 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_spot_api_v4_trade_fees(&[__ws_arg_29]).await;
} else {
// the futures fees stay on the legacy endpoint, the unified futures
// api has no fees route
let __ws_arg_30 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_futures_api_v23_user_fees(&[__ws_arg_30]).await;
}
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[response.clone()]);
let mut feeInfo: Value = self.safe_dict(rows.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut makerFee: Value = self.safe_number_k(feeInfo.clone(), "makerFee", &[]);
let mut takerFee: Value = self.safe_number_k(feeInfo.clone(), "takerFee", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), feeInfo.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("maker".to_string(), makerFee.clone());
m.insert("taker".to_string(), takerFee.clone());
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("tierBased".to_string(), Value::Bool(true));
m
});
Value::Null
}
/*
* @method
* @name btse#fetchPositions
* @description fetch all open positions
* @see https://docs.btse.com/futures/rest/get-positions/
* @param {string[]} [symbols] list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/?id=position-structure}
*/
pub async fn fetch_positions(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
symbols = self.market_symbols(&[symbols.clone()]);
let mut response: Value = self.private_get_futures_api_v3_trade_positions(&[params.clone()]).await;
//
// the response is a bare array of position rows
//
let mut rows: Value = self.safe_list_k(response.clone(), "data", &[]);
if is_equal(&rows, &Value::Null) {
rows = response.clone();
}
return self.parse_positions(rows.clone(), &[symbols.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchPositionsForSymbol
* @description fetch open positions for a single market
* @see https://docs.btse.com/futures/rest/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
* @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
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let __ws_arg_31 = self.futures_request_id(market.clone());
params = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), __ws_arg_31);
m
}), &[params.clone()]);
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);
//
// {
// "marginType": 91,
// "entryPrice": 1968.78,
// "markPrice": 1967.47829431,
// "symbol": "ETH-PERP",
// "side": "BUY",
// "orderValue": 3.93495658,
// "settleWithAsset": "USDT",
// "unrealizedProfitLoss": -0.00260341,
// "totalMaintenanceMargin": 0.0218963,
// "size": 20,
// "liquidationPrice": 0,
// "isolatedLeverage": 25,
// "adlScoreBucket": 1,
// "contractSize": 0.0001,
// "liquidationInProgress": false,
// "timestamp": 1770880518034,
// "takeProfitOrder": {
// "orderId": "18b4056a-59de-424a-843e-c2df5c9f7265",
// "side": "SELL",
// "triggerPrice": 2500,
// "triggerUseLastPrice": false
// },
// "stopLossOrder": {
// "orderId": "e7ef1035-0773-446d-9a80-2de0e1de2c13",
// "side": "SELL",
// "triggerPrice": 1000,
// "triggerUseLastPrice": false
// },
// "positionMode": "ONE_WAY",
// "positionDirection": null,
// "positionId": "ETH-PERP-USDT",
// "walletName": "CROSS@",
// "currentLeverage": 0.2,
// "minimumRequiredMargin": 0
// }
//
// rows echo the short symbol form, while positionId carries the full market
// id, optionally suffixed with the isolated wallet discriminator after a pipe
let mut marketId: Value = self.safe_string_k(position.clone(), "positionId", &[]);
if !is_equal(&marketId, &Value::Null) {
let mut parts: Value = split(&marketId, &Value::Str("|".to_string()));
marketId = self.safe_string(parts.clone(), Value::Int(0), &[]);
} else {
marketId = self.safe_string_k(position.clone(), "symbol", &[]);
}
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "timestamp", &[]);
let mut marginType: Value = self.safe_string_k(position.clone(), "marginType", &[]);
let mut side: Value = self.safe_string_lower2(position.clone(), Value::Str("positionDirection".to_string()), Value::Str("side".to_string()), &[]);
let mut positionMode: Value = self.safe_string_k(position.clone(), "positionMode", &[]);
let mut hedged: Value = Value::Bool(is_true(&(is_equal(&positionMode, &Value::Str("HEDGE".to_string())))) || is_true(&(is_equal(&positionMode, &Value::Str("ISOLATED".to_string())))));
let mut takeProfitOrder: Value = self.safe_dict_k(position.clone(), "takeProfitOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut takeProfitPrice: Value = self.safe_string_k(takeProfitOrder.clone(), "triggerPrice", &[]);
let mut stopLossOrder: Value = self.safe_dict_k(position.clone(), "stopLossOrder", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut stopLossPrice: Value = self.safe_string_k(stopLossOrder.clone(), "triggerPrice", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), self.safe_string_k(position.clone(), "positionId", &[]));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("entryPrice".to_string(), self.parse_number(self.safe_string_k(position.clone(), "entryPrice", &[]), &[]));
m.insert("markPrice".to_string(), self.parse_number(self.safe_string_k(position.clone(), "markPrice", &[]), &[]));
m.insert("lastPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), self.parse_number(takeProfitPrice.clone(), &[]));
m.insert("stopLossPrice".to_string(), self.parse_number(stopLossPrice.clone(), &[]));
m.insert("notional".to_string(), self.parse_number(self.safe_string2(position.clone(), Value::Str("notionalValue".to_string()), Value::Str("orderValue".to_string()), &[]), &[]));
m.insert("collateral".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), self.parse_number(self.safe_string_k(position.clone(), "unrealizedProfitLoss", &[]), &[]));
m.insert("realizedPnl".to_string(), Value::Null);
m.insert("side".to_string(), self.parse_position_side(side.clone()));
m.insert("contracts".to_string(), self.parse_number(self.safe_string_k(position.clone(), "size", &[]), &[]));
m.insert("contractSize".to_string(), self.parse_number(self.safe_string_k(position.clone(), "contractSize", &[]), &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("lastUpdateTimestamp".to_string(), Value::Null);
m.insert("hedged".to_string(), hedged.clone());
m.insert("maintenanceMargin".to_string(), self.parse_number(self.safe_string_k(position.clone(), "totalMaintenanceMargin", &[]), &[]));
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("leverage".to_string(), self.parse_number(self.safe_string_k(position.clone(), "currentLeverage", &[]), &[]));
m.insert("liquidationPrice".to_string(), self.parse_number(self.safe_string_k(position.clone(), "liquidationPrice", &[]), &[]));
m.insert("marginRatio".to_string(), Value::Null);
m.insert("marginMode".to_string(), self.parse_margin_mode_type(marginType.clone()));
m.insert("percentage".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn parse_margin_mode_type(&self, mut marginMode: Value) -> Value {
let mut marginModes: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("91".to_string(), Value::Str("cross".to_string()));
m.insert("92".to_string(), Value::Str("isolated".to_string()));
m.insert("CROSS".to_string(), Value::Str("cross".to_string()));
m.insert("ISOLATED".to_string(), Value::Str("isolated".to_string()));
m
});
return self.safe_string(marginModes.clone(), marginMode.clone(), &[marginMode.clone()]);
Value::Null
}
pub fn parse_position_side(&self, mut side: Value) -> Value {
let mut sides: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("buy".to_string(), Value::Str("long".to_string()));
m.insert("sell".to_string(), Value::Str("short".to_string()));
m
});
return self.safe_string(sides.clone(), side.clone(), &[side.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchPositionMode
* @description fetchs the position mode, hedged or one way, hedged for btse is set identically for all linear markets or all inverse markets
* @see https://docs.btse.com/futures/rest/get-position-mode
* @param {string} symbol unified symbol of the market to fetch entry for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an object detailing whether the market is in hedged or one-way mode
*/
pub async fn fetch_position_mode(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" fetchPositionMode() requires a symbol argument".to_string()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m
});
let __ws_arg_32 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_api_v3_trade_position_mode(&[__ws_arg_32]).await;
//
// [
// {
// "symbol": "ETH-PERP",
// "positionMode": "HEDGE"
// }
// ]
//
let mut data: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut positionMode: Value = self.safe_string_k(data.clone(), "positionMode", &[]);
let mut hedged: Value = Value::Bool(is_true(&(is_equal(&positionMode, &Value::Str("HEDGE".to_string())))) || is_true(&(is_equal(&positionMode, &Value::Str("ISOLATED".to_string())))));
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), data.clone());
m.insert("hedged".to_string(), hedged.clone());
m
});
Value::Null
}
/*
* @method
* @name btse#setPositionMode
* @description NB!!! This method also sets margin mode to cross on btse. Set hedged to true or false for a cross-margin market.
* @see https://docs.btse.com/futures/rest/change-position-mode
* @param {bool} hedged set to true to use dualSidePosition
* @param {string} symbol unified symbol of the market to set position mode for
* @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
}));
// NB!!! This method also sets margin mode to cross on btse
// btse do not have specific endpoint for marginMode
// both marginMode and positionMode are set and get with the same endpoints
// it terms of btse positionMode could be HEDGE, ONE_WAY or ISOLATED
// ISOLATED positionMode is always hedged and multi-position
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setPositionMode() requires a symbol argument".to_string()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut positionMode: Value = ternary(is_true(&hedged), Value::Str("HEDGE".to_string()), Value::Str("ONE_WAY".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m.insert("positionMode".to_string(), positionMode.clone());
m
});
let __ws_arg_33 = self.extend(request.clone(), &[params.clone()]);
return self.private_post_futures_api_v3_trade_position_mode(&[__ws_arg_33]).await;
Value::Null
}
/*
* @method
* @name btse#fetchMarginMode
* @description fetches the margin mode of a specific symbol
* @see https://docs.btse.com/futures/rest/get-leverage
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [margin mode structure]{@link https://docs.ccxt.com/?id=margin-mode-structure}
*/
pub async fn fetch_margin_mode(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m
});
let __ws_arg_34 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_api_v3_trade_leverage(&[__ws_arg_34]).await;
let mut data: Value = self.safe_dict(response.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
return self.parse_margin_mode(data.clone(), &[market.clone()]);
Value::Null
}
pub fn parse_margin_mode(&self, mut marginMode: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "symbol": "ETH-PERP",
// "leverage": 10,
// "marginMode": "ISOLATED",
// "positionDirection": "SHORT"
// }
//
let mut marketId: Value = self.safe_string_k(marginMode.clone(), "symbol", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut positionMode: Value = self.safe_string_lower(marginMode.clone(), Value::Str("marginMode".to_string()), &[]);
let mut marginModeValue: Value = Value::Str("cross".to_string());
if is_equal(&positionMode, &Value::Str("isolated".to_string())) {
marginModeValue = Value::Str("isolated".to_string());
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), marginMode.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m.insert("marginMode".to_string(), marginModeValue.clone());
m
});
Value::Null
}
/*
* @method
* @name btse#setMarginMode
* @description set margin mode to 'cross' or 'isolated'
* @see https://docs.btse.com/futures/rest/change-position-mode
* @param {string} marginMode 'cross' or 'isolated'
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool} [params.hedged] set to true to use dualSidePosition, required for setting marginMode to cross on btse
* @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
}));
// btse do not have specific endpoint for marginMode
// both marginMode and positionMode are set and get with the same endpoints
// it terms of btse positionMode could be HEDGE, ONE_WAY or ISOLATED
// ISOLATED positionMode is always hedged and multi-position
// we use params.hedged to define the positionMode when marginMode is cross
// and warn user if the params are not correct for the marginMode being set
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a symbol argument".to_string()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
marginMode = to_lower(&marginMode);
let mut positionMode: Value = Value::Str("ONE_WAY".to_string());
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 argument should be either cross or isolated".to_string()))));
}
let mut hedged: Value = self.safe_bool_k(params.clone(), "hedged", &[]);
if is_equal(&marginMode, &Value::Str("cross".to_string())) {
if !is_true(&(Value::Bool(in_op(¶ms, &Value::Str("hedged".to_string()))))) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" setMarginMode() requires a hedged parameter for cross margin mode".to_string()))));
} else if is_equal(&hedged, &Value::Bool(true)) {
positionMode = Value::Str("HEDGE".to_string());
}
} else if is_true(&(Value::Bool(in_op(¶ms, &Value::Str("hedged".to_string()))))) && is_true(&(!is_equal(&hedged, &Value::Bool(true)))) {
panic!("{}", crate::exchange_errors::bad_request(add(&self.id, &Value::Str(" setMarginMode() hedged parameter cannot be false for isolated margin mode".to_string()))));
} else {
positionMode = Value::Str("ISOLATED".to_string());
}
params = self.omit(params.clone(), Value::Str("hedged".to_string()), &[]);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m.insert("positionMode".to_string(), positionMode.clone());
m
});
let __ws_arg_35 = self.extend(request.clone(), &[params.clone()]);
return self.private_post_futures_api_v3_trade_position_mode(&[__ws_arg_35]).await;
Value::Null
}
/*
* @method
* @name btse#closePosition
* @description closes an open position for a market
* @see https://docs.btse.com/futures/rest/close-position/
* @param {string} symbol unified CCXT market symbol
* @param {string} [side] not used by btse
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.positionId] the id of the position to close, mandatory
* @param {string} [params.type] 'limit' or 'market' (default is 'market')
* @param {float} [params.price] required if params.type is 'limit'
* @param {bool} [params.postOnly] true if the order should be post only
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn close_position(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut side = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut positionId: Value = self.safe_string_k(params.clone(), "positionId", &[]);
if is_equal(&positionId, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" closePosition() requires a positionId parameter".to_string()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m
});
let mut type_var: Value = Value::Str("market".to_string());
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("closePosition".to_string()), Value::Str("type".to_string()), &[type_var.clone()]); type_var = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
type_var = to_upper(&type_var);
add_element_to_object(&mut request, &Value::Str("orderType".to_string()), type_var.clone());
if is_equal(&type_var, &Value::Str("LIMIT".to_string())) {
let mut price: Value = self.safe_string_k(params.clone(), "price", &[]);
if is_equal(&price, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" closePosition() requires a price parameter for limit orders".to_string()))));
}
add_element_to_object(&mut request, &Value::Str("orderPrice".to_string()), self.price_to_precision(symbol.clone(), price.clone()));
params = self.omit(params.clone(), Value::Str("price".to_string()), &[]);
}
let __ws_arg_36 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_delete_futures_api_v3_trade_positions(&[__ws_arg_36]).await;
let mut order: Value = self.safe_dict(response.clone(), Value::Int(0), &[]);
if is_equal(&order, &Value::Null) {
order = response.clone();
}
return self.parse_order(order.clone(), &[market.clone()]);
Value::Null
}
/*
* @method
* @name btse#fetchLeverage
* @description fetch the leverage for a market
* @see https://docs.btse.com/futures/rest/get-leverage
* @param {string} symbol unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [leverage structure]{@link https://docs.ccxt.com/?id=leverage-structure}
*/
pub async fn fetch_leverage(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m
});
let __ws_arg_37 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_get_futures_api_v3_trade_leverage(&[__ws_arg_37]).await;
//
// [
// {
// "symbol": "ETH-PERP",
// "leverage": 10,
// "marginMode": "ISOLATED",
// "positionDirection": "LONG"
// },
// {
// "symbol": "ETH-PERP",
// "leverage": 10,
// "marginMode": "ISOLATED",
// "positionDirection": "SHORT"
// }
// ]
//
let mut safeResponse: Value = Value::List(vec![]);
if is_true(&Value::Bool(is_array(&response))) {
safeResponse = response.clone();
}
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m
});
let mut longLeverage: Value = Value::Null;
let mut shortLeverage: Value = Value::Null;
let mut marginMode: Value = Value::Null;
{
let mut i: Value = Value::Int(0);
let mut __for_first_470: bool = true;
while { if !__for_first_470 { i = add(&i, &Value::Int(1)); } __for_first_470 = false; is_less_than(&i, &get_array_length(&safeResponse)) } {
let mut entrty: Value = get_value(&safeResponse, &i);
let mut entrty: Value = get_value(&safeResponse, &i);
let mut leverageValue: Value = self.safe_integer_k(entrty.clone(), "leverage", &[]);
let mut positionDirection: Value = self.safe_string_k(entrty.clone(), "positionDirection", &[]);
marginMode = self.safe_string_lower(entrty.clone(), Value::Str("marginMode".to_string()), &[]);
if is_equal(&positionDirection, &Value::Str("LONG".to_string())) {
longLeverage = leverageValue.clone();
} else if is_equal(&positionDirection, &Value::Str("SHORT".to_string())) {
shortLeverage = leverageValue.clone();
} else if is_equal(&positionDirection, &Value::Null) {
longLeverage = leverageValue.clone();
shortLeverage = leverageValue.clone();
}
}
}
add_element_to_object(&mut result, &Value::Str("marginMode".to_string()), marginMode.clone());
add_element_to_object(&mut result, &Value::Str("longLeverage".to_string()), longLeverage.clone());
add_element_to_object(&mut result, &Value::Str("shortLeverage".to_string()), shortLeverage.clone());
return result;
Value::Null
}
/*
* @method
* @name btse#setLeverage
* @description set the level of leverage for a market
* @see https://docs.btse.com/futures/rest/change-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.positionMode] ONE_WAY or HEDGE, defaults to ONE_WAY on the exchange side when omitted
* @param {string} [params.positionDirection] LONG or SHORT, identifies the side to update in hedge mode
* @param {string} [params.positionId] existing position id to update, disambiguates the target position in hedge mode
* @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()))));
}
self.load_markets(&[]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), self.futures_request_id(market.clone()));
m.insert("leverage".to_string(), leverage.clone());
m
});
// the endpoint defaults to the ISOLATED bucket when marginMode is omitted,
// verified live - a bare call on a cross account silently changes the
// isolated leverage only, so the unified marginMode param is translated here
let mut marginMode: Value = Value::Null;
{ let __destr_tmp = self.handle_margin_mode_and_params(Value::Str("setLeverage".to_string()), &[params.clone()]); marginMode = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if !is_equal(&marginMode, &Value::Null) {
add_element_to_object(&mut request, &Value::Str("marginMode".to_string()), to_upper(&marginMode));
}
let __ws_arg_38 = self.extend(request.clone(), &[params.clone()]);
let mut response: Value = self.private_post_futures_api_v3_trade_leverage(&[__ws_arg_38]).await;
return response;
Value::Null
}
pub fn handle_errors(&self, mut code: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if is_true(&(is_equal(&response, &Value::Null))) || is_true(&(is_equal(&response, &Value::Null))) {
return Value::Null;
}
//
// spot
//
// {"code":10002,"msg":"UNAUTHORIZED: Authentication Failed","time":1770477230034,"data":null,"success":false}
// {"code":51523,"msg":"BADREQUEST: Insufficient wallet balance","time":1770814875493,"data":null,"success":false}
//
// futures
//
// {"status":400,"errorCode":-2,"message":"symbol parameter is mandatory","extraData":null}
// {"status":400,"errorCode":-7,"message":"Authenticate failed","extraData":null}
//
let mut success: Value = self.safe_bool_k(response.clone(), "success", &[Value::Bool(true)]);
if !is_equal(&success, &Value::Bool(true)) {
let mut spotErrorCode: Value = self.safe_string_k(response.clone(), "code", &[]);
let mut spotMessage: Value = self.safe_string_k(response.clone(), "msg", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), spotErrorCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), spotMessage.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut errorCode: Value = self.safe_string_k(response.clone(), "errorCode", &[]);
if !is_equal(&errorCode, &Value::Null) {
let mut message: Value = self.safe_string_k(response.clone(), "message", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), errorCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
//
// futures order and leverage endpoints reply with HTTP 200 and encode failures in a numeric status field, per the API Enum section of the docs
//
// {"symbol":"ETH-PERP","timestamp":1770892916507,"status":135,"type":93,"message":"{\"msgKey\":\"trade.error.invalid.position_id\",\"params\":[\"ETH-PERP-USDT\"] ,\"default_msg\":\"User is in ISOLATE_HEDGE in market: ETH-PERP-USDT, but positionId is empty in the request.\"}"}
//
// success statuses such as 2 ORDER_INSERTED, 4 ORDER_FULLY_TRANSACTED, 5 ORDER_PARTIALLY_TRANSACTED, 6 ORDER_CANCELLED, 9 TRIGGER_INSERTED, 10 TRIGGER_ACTIVATED and 20 SUCCESS fall through without matching
//
// the legacy error envelope documented on the error codes page carries
// the numeric api status enum in the code field beside the http status
//
// {"status":400,"error":"Bad Request","code":301,"message":"Invalid order size"}
//
let mut legacyErrorText: Value = self.safe_string_k(response.clone(), "error", &[]);
let mut legacyEnumCode: Value = self.safe_string_k(response.clone(), "code", &[]);
if is_true(&(!is_equal(&legacyErrorText, &Value::Null))) && is_true(&(!is_equal(&legacyEnumCode, &Value::Null))) {
let mut legacyMessage: Value = self.safe_string_k(response.clone(), "message", &[]);
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), legacyEnumCode.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), legacyMessage.clone(), feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
let mut rows: Value = Value::List(vec![]);
if is_true(&Value::Bool(is_array(&response))) {
rows = response.clone();
} else {
rows = Value::List(vec![response.clone()]);
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_471: bool = true;
while { if !__for_first_471 { i = add(&i, &Value::Int(1)); } __for_first_471 = false; is_less_than(&i, &get_array_length(&rows)) } {
let mut row: Value = get_value(&rows, &i);
let mut row: Value = get_value(&rows, &i);
let mut status: Value = self.safe_string_k(row.clone(), "status", &[]);
if !is_equal(&status, &Value::Null) {
let mut message: Value = self.safe_string_k(row.clone(), "message", &[]);
let mut embedded: Value = self.parse_json_value(message.clone());
if !is_equal(&embedded, &Value::Null) {
message = self.safe_string_k(embedded.clone(), "default_msg", &[message.clone()]);
}
let mut feedback: Value = add(&add(&self.id, &Value::Str(" ".to_string())), &body);
self.throw_exactly_matched_exception(get_value(&self.exceptions, &Value::Str("exact".to_string())), status.clone(), feedback.clone());
self.throw_broadly_matched_exception(get_value(&self.exceptions, &Value::Str("broad".to_string())), message.clone(), feedback.clone());
}
}
}
return Value::Null;
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 baseUrl: Value = get_value(&get_value(&self.urls, &Value::Str("api".to_string())), &api);
let mut url: Value = add(&add(&baseUrl, &Value::Str("/".to_string())), &self.implode_params(path.clone(), params.clone()));
let mut query: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
// the futures v3 trading api reads DELETE params from a signed json
// body like its POST and PUT counterparts, while the spot v4 and the
// legacy apis keep DELETE params in the query string, verified live
// in both directions
let mut isBodyDelete: bool = is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))) && is_true(&(is_equal(&Value::Bool(starts_with(&path, &Value::Str("futures/api/v3/".to_string()))), &Value::Bool(true))));
let mut queryString: Value = Value::Str("".to_string());
if is_true(&(is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))))) && !is_true(&isBodyDelete) {
if is_greater_than(&get_array_length(&object_keys(&query)), &Value::Int(0)) {
queryString = self.urlencode(query.clone(), &[]);
url = add(&url, &add(&Value::Str("?".to_string()), &queryString));
}
}
if is_equal(&api, &Value::Str("private".to_string())) {
self.check_required_credentials(&[]);
let mut nonce: Value = self.nonce();
let mut bodyString: Value = self.json(query.clone());
if is_true(&(is_true(&(is_equal(&method, &Value::Str("GET".to_string())))) || is_true(&(is_equal(&method, &Value::Str("DELETE".to_string())))))) && !is_true(&isBodyDelete) {
bodyString = Value::Str("".to_string());
} else {
body = bodyString.clone();
}
// the signed urlpath is the path relative to the base url of the product, the
// spot and futures apis of every generation mount under /spot and /futures and
// sign the /api/v... remainder, while the public-api wallet, otc and markets
// endpoints mount on the bare host and sign the full path with the leading slash
let mut signPath: Value = Value::Null;
if is_equal(&Value::Bool(starts_with(&path, &Value::Str("public-api/".to_string()))), &Value::Bool(true)) {
signPath = add(&Value::Str("/".to_string()), &path);
} else {
signPath = self.clean_path(path.clone());
}
let mut payload: Value = add(&add(&signPath, &to_string_val(&nonce)), &bodyString);
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha384".to_string()), &[]);
headers = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("request-api".to_string(), self.apiKey.clone());
m.insert("request-nonce".to_string(), to_string_val(&nonce));
m.insert("request-sign".to_string(), signature.clone());
m.insert("Content-Type".to_string(), Value::Str("application/json".to_string()));
m.insert("BROKER-ID".to_string(), Value::Str("ccxt".to_string()));
m
});
}
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 futures_request_id(&self, mut market: Value) -> Value {
return self.safe_string(get_value(&market, &Value::Str("info".to_string())), Value::Str("tradeCurrency".to_string()), &[get_value(&market, &Value::Str("id".to_string()))]);
Value::Null
}
pub fn clean_path(&self, mut path: Value) -> Value {
let mut result: Value = replace_str(&path, &Value::Str("spot".to_string()), &Value::Str("".to_string()));
result = replace_str(&result, &Value::Str("futures".to_string()), &Value::Str("".to_string()));
result = replace_str(&result, &Value::Str("otc".to_string()), &Value::Str("".to_string()));
return result;
Value::Null
}
pub fn nonce(&self) -> Value {
return subtract(&self.milliseconds(), &get_value(&self.options, &Value::Str("timeDifference".to_string())));
Value::Null
}
}