// 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;
// Dynamic `this[method](...)` re-entries are emitted as
// `self.call_dynamic_checked(...)` (blanket-impl'd on every Core) so an
// unresolvable name raises NotSupported instead of yielding a silent Null.
use crate::exchange::CallDynamicChecked;
pub struct BullishCore {
pub exchange: crate::exchange::Exchange,
}
impl BullishCore {
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 = BullishCore::describe(self);
self.initialize_properties(described);
// compatibility for sandbox/testnet options in userConfig
let user_config = self.userConfig.clone();
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self, &[user_config]);
}
/// 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 BullishCore {
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_ticker(self, ticker, &[market])
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_trade(self, trade, &[market])
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_order(self, order, &[market])
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_market(self, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_ohlcv(self, ohlcv, &[market])
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_balance(self, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_position(self, position, &[market])
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_deposit_address(self, depositAddress, &[currency])
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_transfer(self, transfer, &[currency])
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_currency(self, currency)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_open_interest(self, interest, &[market])
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_account(self, account)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_transaction(self, transaction, &[currency])
}
fn parse_borrow_rate(&self, info: crate::Value, currency: crate::Value) -> crate::Value {
// Forward to the inherent method on BullishCore.
BullishCore::parse_borrow_rate(self, info, &[currency])
}
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 BullishCore.
BullishCore::sign(self, path, &[api, method, params, headers, body])
}
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 BullishCore.
BullishCore::handle_errors(self, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for BullishCore {
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[..]).await,
"cancel_order" => self.cancel_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).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[4.min(args.len())..]).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[4.min(args.len())..]).await,
"fetch_accounts" => self.fetch_accounts(&args[..]).await,
"fetch_balance" => self.fetch_balance(&args[..]).await,
"fetch_borrow_rate_history" => self.fetch_borrow_rate_history(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_canceled_and_closed_orders" => self.fetch_canceled_and_closed_orders(&args[..]).await,
"fetch_canceled_orders" => self.fetch_canceled_orders(&args[..]).await,
"fetch_closed_orders" => self.fetch_closed_orders(&args[..]).await,
"fetch_currencies" => self.fetch_currencies(&args[..]).await,
"fetch_deposit_address" => self.fetch_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_deposits_withdrawals" => self.fetch_deposits_withdrawals(&args[..]).await,
"fetch_funding_rate_history" => self.fetch_funding_rate_history(&args[..]).await,
"fetch_markets" => self.fetch_markets(&args[..]).await,
"fetch_my_trades" => self.fetch_my_trades(&args[..]).await,
"fetch_ohlcv" => self.fetch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_interest" => self.fetch_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_open_orders" => self.fetch_open_orders(&args[..]).await,
"fetch_order" => self.fetch_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_book" => self.fetch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_order_trades" => self.fetch_order_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_orders" => self.fetch_orders(&args[..]).await,
"fetch_positions" => self.fetch_positions(&args[..]).await,
"fetch_ticker" => self.fetch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_time" => self.fetch_time(&args[..]).await,
"fetch_trades" => self.fetch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"fetch_transfers" => self.fetch_transfers(&args[..]).await,
"get_closest_limit" => self.get_closest_limit(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"get_timestamp" => self.get_timestamp(),
"handle_errors" => self.handle_errors(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), args.get(4).cloned().unwrap_or(crate::Value::Null), args.get(5).cloned().unwrap_or(crate::Value::Null), args.get(6).cloned().unwrap_or(crate::Value::Null), args.get(7).cloned().unwrap_or(crate::Value::Null), args.get(8).cloned().unwrap_or(crate::Value::Null)),
"handle_pagination_params" => self.handle_pagination_params(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"handle_since_and_until" => self.handle_since_and_until(&args[..]),
"handle_token" => self.handle_token(&args[..]).await,
"load_account" => self.load_account(&args[..]).await,
"parse_account" => self.parse_account(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance" => self.parse_balance(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_balance_for_single_currency" => self.parse_balance_for_single_currency(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_borrow_rate" => self.parse_borrow_rate(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_currency" => self.parse_currency(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"parse_deposit_address" => self.parse_deposit_address(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"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[1.min(args.len())..]),
"parse_open_interest" => self.parse_open_interest(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_order" => self.parse_order(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_position" => self.parse_position(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_ticker" => self.parse_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_trade" => self.parse_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transaction" => self.parse_transaction(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"parse_transfer" => self.parse_transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"safe_deterministic_call" => self.safe_deterministic_call(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]).await,
"sign" => self.sign(args.get(0).cloned().unwrap_or(crate::Value::Null), &args[1.min(args.len())..]),
"sign_in" => self.sign_in(&args[..]).await,
"transfer" => self.transfer(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args[4.min(args.len())..]).await,
"withdraw" => self.withdraw(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), &args[3.min(args.len())..]).await,
// Fall through to the base-only methods (cancelOrderWithClientOrderId, …).
_ => self.call_dynamic_base(method, args).await,
}
})
}
}
impl std::ops::Deref for BullishCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { &self.exchange }
}
impl std::ops::DerefMut for BullishCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { &mut self.exchange }
}
impl BullishCore {
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("bullish".into()));
m.insert("name".to_string(), Value::Str("Bullish".into()));
m.insert("countries".to_string(), Value::from(vec![Value::Str("DE".into())]));
m.insert("version".to_string(), Value::Str("v3".into()));
m.insert("rateLimit".to_string(), Value::Int(20));
m.insert("pro".to_string(), Value::Bool(true));
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CORS".to_string(), Value::Null);
m.insert("spot".to_string(), Value::Bool(true));
m.insert("margin".to_string(), Value::Bool(false));
m.insert("swap".to_string(), Value::Bool(true));
m.insert("future".to_string(), Value::Bool(true));
m.insert("option".to_string(), Value::Bool(true));
m.insert("addMargin".to_string(), Value::Bool(false));
m.insert("borrowMargin".to_string(), Value::Bool(false));
m.insert("cancelAllOrders".to_string(), Value::Bool(true));
m.insert("cancelOrder".to_string(), Value::Bool(true));
m.insert("cancelOrders".to_string(), Value::Bool(false));
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("createMarketOrder".to_string(), Value::Bool(true));
m.insert("createMarketSellOrder".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Bool(true));
m.insert("createPostOnlyOrder".to_string(), Value::Bool(true));
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("fetchAccounts".to_string(), Value::Bool(true));
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("fetchBorrowRateHistories".to_string(), Value::Bool(false));
m.insert("fetchBorrowRateHistory".to_string(), Value::Bool(true));
m.insert("fetchCanceledAndClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCanceledOrders".to_string(), Value::Bool(true));
m.insert("fetchClosedOrder".to_string(), Value::Bool(false));
m.insert("fetchClosedOrders".to_string(), Value::Bool(true));
m.insert("fetchCrossBorrowRate".to_string(), Value::Bool(false));
m.insert("fetchCrossBorrowRates".to_string(), Value::Bool(false));
m.insert("fetchCurrencies".to_string(), Value::Bool(true));
m.insert("fetchDeposit".to_string(), Value::Bool(false));
m.insert("fetchDepositAddress".to_string(), Value::Bool(true));
m.insert("fetchDepositAddresses".to_string(), Value::Bool(false));
m.insert("fetchDepositAddressesByNetwork".to_string(), Value::Bool(false));
m.insert("fetchDeposits".to_string(), Value::Bool(false));
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("fetchFundingRate".to_string(), Value::Bool(false));
m.insert("fetchFundingRateHistory".to_string(), Value::Bool(true));
m.insert("fetchFundingRates".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("fetchL3OrderBook".to_string(), Value::Bool(false));
m.insert("fetchLedger".to_string(), Value::Bool(false));
m.insert("fetchLeverage".to_string(), Value::Bool(false));
m.insert("fetchLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarketLeverageTiers".to_string(), Value::Bool(false));
m.insert("fetchMarkets".to_string(), Value::Bool(true));
m.insert("fetchMarkOHLCV".to_string(), Value::Bool(false));
m.insert("fetchMyTrades".to_string(), Value::Bool(true));
m.insert("fetchOHLCV".to_string(), Value::Bool(true));
m.insert("fetchOpenInterest".to_string(), Value::Bool(true));
m.insert("fetchOpenInterestHistory".to_string(), Value::Bool(false));
m.insert("fetchOpenInterests".to_string(), Value::Bool(false));
m.insert("fetchOpenOrder".to_string(), Value::Bool(false));
m.insert("fetchOpenOrders".to_string(), Value::Bool(true));
m.insert("fetchOrder".to_string(), Value::Bool(true));
m.insert("fetchOrderBook".to_string(), Value::Bool(true));
m.insert("fetchOrderBooks".to_string(), Value::Bool(false));
m.insert("fetchOrders".to_string(), Value::Bool(true));
m.insert("fetchOrderTrades".to_string(), Value::Bool(true));
m.insert("fetchPosition".to_string(), Value::Bool(false));
m.insert("fetchPositionHistory".to_string(), Value::Bool(false));
m.insert("fetchPositionMode".to_string(), Value::Bool(false));
m.insert("fetchPositions".to_string(), Value::Bool(true));
m.insert("fetchPositionsForSymbol".to_string(), Value::Bool(false));
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("fetchStatus".to_string(), Value::Bool(false));
m.insert("fetchTicker".to_string(), Value::Bool(true));
m.insert("fetchTickers".to_string(), Value::Bool(false));
m.insert("fetchTime".to_string(), Value::Bool(true));
m.insert("fetchTrades".to_string(), Value::Bool(true));
m.insert("fetchTradingFee".to_string(), Value::Bool(false));
m.insert("fetchTradingFees".to_string(), Value::Bool(false));
m.insert("fetchTradingLimits".to_string(), Value::Bool(false));
m.insert("fetchTransactionFee".to_string(), Value::Bool(false));
m.insert("fetchTransactionFees".to_string(), Value::Bool(false));
m.insert("fetchTransactions".to_string(), Value::Bool(false));
m.insert("fetchTransfers".to_string(), Value::Bool(true));
m.insert("fetchWithdrawal".to_string(), Value::Bool(false));
m.insert("fetchWithdrawals".to_string(), Value::Bool(false));
m.insert("fetchWithdrawalWhitelist".to_string(), Value::Bool(false));
m.insert("reduceMargin".to_string(), Value::Bool(false));
m.insert("repayMargin".to_string(), Value::Bool(false));
m.insert("setLeverage".to_string(), Value::Bool(false));
m.insert("setMargin".to_string(), Value::Bool(false));
m.insert("setMarginMode".to_string(), Value::Bool(false));
m.insert("setPositionMode".to_string(), Value::Bool(false));
m.insert("signIn".to_string(), Value::Bool(true));
m.insert("transfer".to_string(), Value::Bool(true));
m.insert("withdraw".to_string(), Value::Bool(true));
m.insert("ws".to_string(), Value::Bool(true));
m
}));
m.insert("timeframes".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("1m".to_string(), Value::Str("1m".into()));
m.insert("5m".to_string(), Value::Str("5m".into()));
m.insert("30m".to_string(), Value::Str("30m".into()));
m.insert("1h".to_string(), Value::Str("1h".into()));
m.insert("6h".to_string(), Value::Str("6h".into()));
m.insert("12h".to_string(), Value::Str("12h".into()));
m.insert("1d".to_string(), Value::Str("1d".into()));
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/68f0686b-84f0-4da9-a751-f7089af3a9ed".into()));
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.exchange.bullish.com/trading-api".into()));
m.insert("private".to_string(), Value::Str("https://api.exchange.bullish.com/trading-api".into()));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("https://api.simnext.bullish-test.com/trading-api".into()));
m.insert("private".to_string(), Value::Str("https://api.simnext.bullish-test.com/trading-api".into()));
m
}));
m.insert("www".to_string(), Value::Str("https://bullish.com/".into()));
m.insert("referral".to_string(), Value::Str("".into()));
m.insert("doc".to_string(), Value::from(vec![Value::Str("https://api.exchange.bullish.com/docs/api/rest/".into())]));
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("v1/nonce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/time".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/assets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/assets/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/vol-grids".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/assets/{symbol}/vol-grid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/markets".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/markets/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets/{symbol}/orderbook/hybrid".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets/{symbol}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets/{symbol}/tick".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets/{symbol}/candle".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets/{symbol}/auctions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/markets/{symbol}/auctions/noii".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/markets/{symbol}/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/markets/{symbol}/funding-rate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/markets/{symbol}/auctions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/option-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/index-prices".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/index-prices/{assetSymbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/expiry-prices/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/option-ladder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/option-ladder/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m.insert("private".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("get".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/history/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/orders/{orderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/orders/client-order-id/{clientOrderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/amm-instructions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/amm-instructions/{instructionId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/transactions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/limits/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/deposit-instructions/crypto/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/withdrawal-instructions/crypto/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/deposit-instructions/fiat/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/withdrawal-instructions/fiat/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/self-hosted/verification-attempts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v1/history/trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v1/trades/{tradeId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v1/trades/client-order-id/{clientOrderId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/accounts/asset".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/accounts/asset/{symbol}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/users/logout".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/users/hmac/login".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/accounts/trading-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/accounts/trading-accounts/{tradingAccountId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/derivatives-positions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/derivatives-settlement".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/transfer".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/history/borrow-interest".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/mmp-configuration".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/otc-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/otc-trades/{otcTradeId}".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/otc-trades/unconfirmed-trade".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/otc-trades/delegated-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/idb/delegated-accounts".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/idb/otc-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m.insert("post".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("v2/orders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/command".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(5));
m
}));
m.insert("v2/amm-instructions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/withdrawal".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/users/login".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/simulate-portfolio-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/bulk-simulate-portfolio-margin".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v1/wallets/self-hosted/initiate".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/mmp-configuration".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/otc-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/otc-command".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/idb/otc-trades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m.insert("v2/idb/otc-command".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), Value::Int(1));
m
}));
m
}));
m
}));
m
}));
m.insert("fees".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("trading".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tierBased".to_string(), Value::Bool(false));
m.insert("percentage".to_string(), Value::Bool(true));
m.insert("taker".to_string(), self.parse_number(Value::Str("0.001".into()), &[]));
m.insert("maker".to_string(), self.parse_number(Value::Str("0.001".into()), &[]));
m
}));
m
}));
m.insert("precisionMode".to_string(), Value::Int(crate::runtime::TICK_SIZE));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("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.insert("BTC".to_string(), Value::Str("BTC".into()));
m.insert("EOS".to_string(), Value::Str("EOS".into()));
m.insert("ERC20".to_string(), Value::Str("ETH".into()));
m
}));
m.insert("defaultNetwork".to_string(), Value::Str("ERC20".into()));
m.insert("defaultNetworks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("USDC".to_string(), Value::Str("ERC20".into()));
m
}));
m.insert("tradingAccountId".to_string(), Value::Null);
m
}));
m.insert("features".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("default".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("sandbox".to_string(), Value::Bool(true));
m.insert("createOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("triggerPrice".to_string(), Value::Bool(true));
m.insert("triggerPriceType".to_string(), Value::Null);
m.insert("triggerDirection".to_string(), Value::Bool(false));
m.insert("stopLossPrice".to_string(), Value::Bool(false));
m.insert("takeProfitPrice".to_string(), Value::Bool(false));
m.insert("attachedStopLossTakeProfit".to_string(), Value::Null);
m.insert("timeInForce".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("IOC".to_string(), Value::Bool(true));
m.insert("FOK".to_string(), Value::Bool(true));
m.insert("PO".to_string(), Value::Bool(true));
m.insert("GTD".to_string(), Value::Bool(false));
m
}));
m.insert("hedged".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("leverage".to_string(), Value::Bool(false));
m.insert("marketBuyByCost".to_string(), Value::Bool(false));
m.insert("marketBuyRequiresPrice".to_string(), Value::Bool(false));
m.insert("selfTradePrevention".to_string(), Value::Bool(false));
m.insert("iceberg".to_string(), Value::Bool(false));
m
}));
m.insert("createOrders".to_string(), Value::Null);
m.insert("fetchMyTrades".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m.insert("untilDays".to_string(), Value::Int(90));
m
}));
m.insert("fetchOrder".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("untilDays".to_string(), Value::Int(90));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchOpenOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("untilDays".to_string(), Value::Int(90));
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("fetchCanceledAndClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(90));
m.insert("untilDays".to_string(), Value::Int(90));
m.insert("trigger".to_string(), Value::Bool(false));
m.insert("trailing".to_string(), Value::Bool(false));
m.insert("symbolRequired".to_string(), Value::Bool(false));
m
}));
m.insert("fetchClosedOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(1));
m.insert("daysBackCanceled".to_string(), Value::Int(1));
m.insert("untilDays".to_string(), Value::Int(1));
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("fetchCanceledOrders".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("marginMode".to_string(), Value::Bool(false));
m.insert("limit".to_string(), Value::Int(100));
m.insert("daysBack".to_string(), Value::Int(1));
m.insert("untilDays".to_string(), Value::Int(1));
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("fetchOHLCV".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("limit".to_string(), Value::Int(1000));
m
}));
m
}));
m.insert("spot".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
m
}));
m.insert("swap".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("linear".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("extends".to_string(), Value::Str("default".into()));
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("default".into()));
m
}));
m.insert("inverse".to_string(), Value::Null);
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("1".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("5".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("6".to_string(), Value::Str("DuplicateOrderId".into()).clone());
m.insert("13".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("15".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("18".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("1002".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2001".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2002".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2003".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2004".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2005".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("2006".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2007".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2008".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2009".to_string(), Value::Str("BadSymbol".into()).clone());
m.insert("2010".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("2011".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("2012".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2013".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("2015".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2016".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2017".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2018".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("2020".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("2021".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("2029".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("2035".to_string(), Value::Str("InvalidNonce".into()).clone());
m.insert("3001".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("3002".to_string(), Value::Str("OrderNotFound".into()).clone());
m.insert("3003".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("3004".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("3005".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("3006".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("3007".to_string(), Value::Str("DuplicateOrderId".into()).clone());
m.insert("3031".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("3032".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("3033".to_string(), Value::Str("PermissionDenied".into()).clone());
m.insert("3034".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("3035".to_string(), Value::Str("RateLimitExceeded".into()).clone());
m.insert("3047".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("3048".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("3049".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("3051".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("3052".to_string(), Value::Str("InsufficientFunds".into()).clone());
m.insert("3063".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("3064".to_string(), Value::Str("OrderNotFillable".into()).clone());
m.insert("3065".to_string(), Value::Str("MarketClosed".into()).clone());
m.insert("3066".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("3067".to_string(), Value::Str("MarketClosed".into()).clone());
m.insert("6007".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("6011".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("6012".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("6013".to_string(), Value::Str("InvalidOrder".into()).clone());
m.insert("8301".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("8305".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("8306".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("8307".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("8310".to_string(), Value::Str("InvalidAddress".into()).clone());
m.insert("8311".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("8313".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("8315".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("8316".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("8317".to_string(), Value::Str("OperationRejected".into()).clone());
m.insert("8318".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("8319".to_string(), Value::Str("NotSupported".into()).clone());
m.insert("8320".to_string(), Value::Str("InvalidAddress".into()).clone());
m.insert("8322".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("8327".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("8329".to_string(), Value::Str("ExchangeError".into()).clone());
m.insert("8331".to_string(), Value::Str("InvalidAddress".into()).clone());
m.insert("8332".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("8333".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("8334".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("8335".to_string(), Value::Str("InvalidAddress".into()).clone());
m.insert("8336".to_string(), Value::Str("InvalidAddress".into()).clone());
m.insert("8399".to_string(), Value::Str("ExchangeError".into()).clone());
m
}));
m.insert("broad".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("HttpInvalidParameterException".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("UNAUTHORIZED_COMMAND".to_string(), Value::Str("AuthenticationError".into()).clone());
m.insert("QUERY_FILTER_ERROR".to_string(), Value::Str("BadRequest".into()).clone());
m.insert("INVALID_SYMBOL".to_string(), Value::Str("BadSymbol".into()).clone());
m
}));
m
}));
m
})]);
Value::Null
}
/*
* @method
* @name bullish#fetchTime
* @description fetches the current integer timestamp in milliseconds from the exchange server
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--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_v1_time(&[params]).await;
return self.safe_integer_k(response, "timestamp", &[]);
Value::Null
}
/*
* @method
* @name bullish#fetchCurrencies
* @description fetches all available currencies on an exchange
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/assets
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an associative dictionary of currencies
*/
pub async fn fetch_currencies(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.public_get_v1_assets(&[params]).await;
return self.parse_currencies(response);
Value::Null
}
pub fn parse_currency(&self, mut rawCurrency: Value) -> Value {
let mut id: Value = self.safe_string_k(rawCurrency.clone(), "symbol", &[]);
let mut code: Value = self.safe_currency_code(id.clone(), &[]);
let mut name: Value = self.safe_string_k(rawCurrency.clone(), "name", &[]);
let mut precision: Value = self.safe_string_k(rawCurrency.clone(), "precision", &[]);
return self.safe_currency_structure(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("code".to_string(), code);
m.insert("name".to_string(), name);
m.insert("active".to_string(), Value::Null);
m.insert("deposit".to_string(), Value::Null);
m.insert("withdraw".to_string(), Value::Null);
m.insert("fee".to_string(), self.safe_number_k(rawCurrency.clone(), "minFee", &[]));
m.insert("precision".to_string(), self.parse_number(self.parse_precision(&[precision]), &[]));
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m.insert("withdraw".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), Value::Null);
m.insert("max".to_string(), Value::Null);
m
}));
m
}));
m.insert("networks".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m.insert("type".to_string(), Value::Str("crypto".into()));
m.insert("info".to_string(), rawCurrency);
m
}));
Value::Null
}
/*
* @method
* @name bullish#fetchMarkets
* @description retrieves data on all markets for ace
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/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 matches!(self.safe_bool_k(self.options.clone(), "adjustForTimeDifference", &[Value::Bool(false)]), Value::Bool(true)) {
self.load_time_difference(&[]).await;
}
let mut response: Value = self.public_get_v1_markets(&[params]).await;
return self.parse_markets(response);
Value::Null
}
pub fn parse_market(&self, mut market: Value) -> Value {
//
// {
// "marketId": "20069",
// "symbol": "BTC-USDC-20250516",
// "quoteAssetId": "5",
// "baseAssetId": "1",
// "quoteSymbol": "USDC",
// "baseSymbol": "BTC",
// "quotePrecision": "4",
// "basePrecision": "8",
// "pricePrecision": "4",
// "quantityPrecision": "8",
// "costPrecision": "4",
// "minQuantityLimit": "0.00050000",
// "maxQuantityLimit": "200.00000000",
// "maxPriceLimit": null,
// "minPriceLimit": null,
// "maxCostLimit": null,
// "minCostLimit": null,
// "timeZone": "Etc/UTC",
// "tickSize": "0.1000",
// "liquidityTickSize": "100.0000",
// "liquidityPrecision": "4",
// "makerFee": "0",
// "takerFee": "2",
// "roundingCorrectionFactor": "0.00000100",
// "makerMinLiquidityAddition": "1000000",
// "orderTypes":
// [
// "LMT",
// "MKT",
// "STOP_LIMIT",
// "POST_ONLY"
// ],
// "spotTradingEnabled": true,
// "marginTradingEnabled": true,
// "marketEnabled": true,
// "createOrderEnabled": true,
// "cancelOrderEnabled": true,
// "liquidityInvestEnabled": true,
// "liquidityWithdrawEnabled": true,
// "feeTiers":
// [
// {
// "feeTierId": "1",
// "staticSpreadFee": "0.00000000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "10",
// "staticSpreadFee": "0.00100000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "11",
// "staticSpreadFee": "0.00150000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "12",
// "staticSpreadFee": "0.00150000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "13",
// "staticSpreadFee": "0.00300000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "14",
// "staticSpreadFee": "0.00300000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "15",
// "staticSpreadFee": "0.00500000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "16",
// "staticSpreadFee": "0.00500000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "17",
// "staticSpreadFee": "0.01000000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "18",
// "staticSpreadFee": "0.01000000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "19",
// "staticSpreadFee": "0.01500000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "2",
// "staticSpreadFee": "0.00000000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "20",
// "staticSpreadFee": "0.01500000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "21",
// "staticSpreadFee": "0.02000000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "22",
// "staticSpreadFee": "0.02000000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "3",
// "staticSpreadFee": "0.00010000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "4",
// "staticSpreadFee": "0.00010000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "5",
// "staticSpreadFee": "0.00020000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "6",
// "staticSpreadFee": "0.00020000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "7",
// "staticSpreadFee": "0.00060000",
// "isDislocationEnabled": false
// },
// {
// "feeTierId": "8",
// "staticSpreadFee": "0.00060000",
// "isDislocationEnabled": true
// },
// {
// "feeTierId": "9",
// "staticSpreadFee": "0.00100000",
// "isDislocationEnabled": false
// }
// ],
// "marketType": "DATED_FUTURE",
// "contractMultiplier": "1",
// "settlementAssetSymbol": "USDC",
// "underlyingQuoteSymbol": "USDC",
// "underlyingBaseSymbol": "BTC",
// "openInterestLimitUSD": "100000000.0000",
// "concentrationRiskPercentage": "100.00",
// "concentrationRiskThresholdUSD": "30000000.0000",
// "expiryDatetime": "2025-05-16T08:00:00.000Z",
// "priceBuffer": "0.1",
// "feeGroupId": "4"
// }
//
// option
// {
// "marketId": "20997",
// "symbol": "BTC-USDC-20260130-160000-P",
// "quoteAssetId": "5",
// "baseAssetId": "1",
// "quoteSymbol": "USDC",
// "baseSymbol": "BTC",
// "quotePrecision": "4",
// "basePrecision": "8",
// "pricePrecision": "4",
// "quantityPrecision": "8",
// "costPrecision": "4",
// "minQuantityLimit": "0.00050000",
// "maxQuantityLimit": "200.00000000",
// "maxPriceLimit": null,
// "minPriceLimit": null,
// "maxCostLimit": null,
// "minCostLimit": null,
// "timeZone": "Etc/UTC",
// "tickSize": "10.0000",
// "makerFee": "0",
// "takerFee": "2",
// "roundingCorrectionFactor": "0.00000100",
// "makerMinLiquidityAddition": "-1",
// "orderTypes": [ "LMT", "MKT", "STOP_LIMIT", "POST_ONLY" ],
// "spotTradingEnabled": true,
// "marginTradingEnabled": true,
// "marketEnabled": true,
// "createOrderEnabled": true,
// "cancelOrderEnabled": true,
// "amendOrderEnabled": true,
// "marketType": "OPTION",
// "contractMultiplier": "1",
// "settlementAssetSymbol": "USDC",
// "underlyingQuoteSymbol": "USDC",
// "underlyingBaseSymbol": "BTC",
// "openInterestLimitUSD": "100000000.0000",
// "concentrationRiskPercentage": "100.00",
// "concentrationRiskThresholdUSD": "30000000.0000",
// "expiryDatetime": "2026-01-30T08:00:00.000Z",
// "priceBuffer": "0",
// "feeGroupId": "10",
// "optionStrikePrice": "160000.0000",
// "optionType": "PUT",
// "premiumCapRatio": "0.1000"
// }
//
let mut id: Value = self.safe_string_k(market.clone(), "symbol", &[]);
let mut baseId: Value = self.safe_string_k(market.clone(), "baseSymbol", &[]);
let mut quoteId: Value = self.safe_string_k(market.clone(), "quoteSymbol", &[]);
let mut base: Value = self.safe_currency_code(baseId.clone(), &[]);
let mut quote: Value = self.safe_currency_code(quoteId.clone(), &[]);
if (base == Value::Null) || (quote == Value::Null) {
return Value::Null;
}
let mut symbol: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", base, Value::Str("/".into())).into()), quote).into());
let mut basePrecision: Value = self.safe_string_k(market.clone(), "basePrecision", &[]);
let mut quotePrecision: Value = self.safe_string_k(market.clone(), "quotePrecision", &[]);
let mut amountPrecision: Value = self.safe_string_k(market.clone(), "quantityPrecision", &[]);
let mut pricePrecision: Value = self.safe_string_k(market.clone(), "pricePrecision", &[]);
let mut costPrecision: Value = self.safe_string_k(market.clone(), "costPrecision", &[]);
let mut minQuantityLimit: Value = self.safe_string_k(market.clone(), "minQuantityLimit", &[]);
let mut maxQuantityLimit: Value = self.safe_string_k(market.clone(), "maxQuantityLimit", &[]);
let mut minPriceLimit: Value = self.safe_string_k(market.clone(), "minPriceLimit", &[]);
let mut maxPriceLimit: Value = self.safe_string_k(market.clone(), "maxPriceLimit", &[]);
let mut minCostLimit: Value = self.safe_string_k(market.clone(), "minCostLimit", &[]);
let mut maxCostLimit: Value = self.safe_string_k(market.clone(), "maxCostLimit", &[]);
let mut settleId: Value = self.safe_string_k(market.clone(), "settlementAssetSymbol", &[]);
let mut settle: Value = self.safe_currency_code(settleId.clone(), &[]);
let mut type_var: Value = self.parse_market_type(&[self.safe_string_k(market.clone(), "marketType", &[]), Value::Str("spot".into())]).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
let mut spot: Value = Value::Bool(false);
let mut swap: Value = Value::Bool(false);
let mut future: Value = Value::Bool(false);
let mut option: Value = Value::Bool(false);
let mut contract: Value = Value::Bool(true);
let mut linear: Value = Value::Null;
let mut inverse: Value = Value::Null;
let mut expiryDatetime: Value = Value::Null;
let mut contractSize: Value = Value::Null;
let mut optionType: Value = Value::Null;
let mut strike: Value = Value::Null;
let mut margin: Value = Value::Bool(false);
if (type_var.as_str() == Some("spot")) {
spot = Value::Bool(true);
contract = Value::Bool(false);
margin = self.safe_bool_k(market.clone(), "marginTradingEnabled", &[]);
} else {
contractSize = self.safe_number_k(market.clone(), "contractMultiplier", &[]);
symbol = Value::Str(format!("{}{}", symbol, Value::Str(format!("{}{}", Value::Str(":".into()), settle).into())).into());
linear = Value::Bool(settle.as_str() == quote.as_str());
inverse = Value::Bool(!(linear.as_bool() == Some(true)));
if (type_var.as_str() == Some("swap")) {
swap = Value::Bool(true);
} else {
expiryDatetime = self.safe_string_k(market.clone(), "expiryDatetime", &[]);
let mut idParts: Value = Value::Array(id.as_str().map(|__s| __s.split("-").map(|__p| Value::Str(__p.to_string().into())).collect()).unwrap_or_default());
let mut datePart: Value = self.safe_string(idParts.clone(), Value::Int(2), &[]);
let mut dateYmd: Value = datePart.as_str().map(|__s| { let __c: Vec<char> = __s.chars().collect(); let __l = __c.len() as i64; let __i = __l.min(2); let __j = __l; if __i <= __j { __c[__i as usize..__j as usize].iter().collect::<String>() } else { String::new() } }).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
symbol = Value::Str(format!("{}{}", symbol, Value::Str(format!("{}{}", Value::Str("-".into()), dateYmd).into())).into());
if (type_var.as_str() == Some("future")) {
future = Value::Bool(true);
} else if (type_var.as_str() == Some("option")) {
option = Value::Bool(true);
optionType = self.safe_string_lower_k(market.clone(), "optionType", &[]);
strike = self.parse_to_numeric(self.safe_string_k(market.clone(), "optionStrikePrice", &[]));
symbol = Value::Str(format!("{}{}", symbol, Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str("-".into()), self.number_to_string(strike.clone())).into()), Value::Str("-".into())).into()), self.safe_string(idParts, Value::Int(4), &[])).into())).into());
}
}
}
return self.safe_market_structure(&[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("symbol".to_string(), symbol);
m.insert("base".to_string(), base);
m.insert("baseId".to_string(), baseId);
m.insert("quote".to_string(), quote);
m.insert("quoteId".to_string(), quoteId);
m.insert("settle".to_string(), settle);
m.insert("settleId".to_string(), settleId);
m.insert("type".to_string(), type_var);
m.insert("spot".to_string(), spot);
m.insert("margin".to_string(), margin);
m.insert("swap".to_string(), swap);
m.insert("future".to_string(), future);
m.insert("option".to_string(), option);
m.insert("contract".to_string(), contract);
m.insert("linear".to_string(), linear);
m.insert("inverse".to_string(), inverse);
m.insert("taker".to_string(), self.fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("taker")).cloned().unwrap_or(Value::Null));
m.insert("maker".to_string(), self.fees.as_map().and_then(|__m| __m.get("trading")).cloned().unwrap_or(Value::Null).as_map().and_then(|__m| __m.get("maker")).cloned().unwrap_or(Value::Null));
m.insert("contractSize".to_string(), contractSize);
m.insert("expiry".to_string(), self.parse8601(expiryDatetime.clone()));
m.insert("expiryDatetime".to_string(), expiryDatetime);
m.insert("strike".to_string(), strike);
m.insert("optionType".to_string(), optionType);
m.insert("limits".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minQuantityLimit, &[]));
m.insert("max".to_string(), self.parse_number(maxQuantityLimit, &[]));
m
}));
m.insert("price".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minPriceLimit, &[]));
m.insert("max".to_string(), self.parse_number(maxPriceLimit, &[]));
m
}));
m.insert("cost".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("min".to_string(), self.parse_number(minCostLimit, &[]));
m.insert("max".to_string(), self.parse_number(maxCostLimit, &[]));
m
}));
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
}));
m.insert("precision".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("amount".to_string(), self.parse_number(self.parse_precision(&[amountPrecision]), &[]));
m.insert("price".to_string(), self.parse_number(self.parse_precision(&[pricePrecision]), &[]));
m.insert("cost".to_string(), self.parse_number(self.parse_precision(&[costPrecision]), &[]));
m.insert("base".to_string(), self.parse_number(self.parse_precision(&[basePrecision]), &[]));
m.insert("quote".to_string(), self.parse_number(self.parse_precision(&[quotePrecision]), &[]));
m
}));
m.insert("active".to_string(), self.safe_bool_k(market.clone(), "marketEnabled", &[]));
m.insert("created".to_string(), Value::Null);
m.insert("info".to_string(), market);
m
})]);
Value::Null
}
pub fn parse_market_type(&self, optional_args: &[Value]) -> Option<String> {
let mut type_var = get_arg(optional_args, 0, Value::Null);
let mut defaultType = get_arg(optional_args, 1, Value::Null);
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("SPOT".to_string(), Value::Str("spot".into()));
m.insert("PERPETUAL".to_string(), Value::Str("swap".into()));
m.insert("DATED_FUTURE".to_string(), Value::Str("future".into()));
m.insert("OPTION".to_string(), Value::Str("option".into()));
m
});
return self.safe_string(types, type_var, &[defaultType]).as_str().map(str::to_owned);
}
/*
* @method
* @name bullish#fetchOrderBook
* @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/orderbook/hybrid
* @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 (not used by bullish)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn fetch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_0 = self.extend(request, &[params]);
let mut response: Value = self.public_get_v1_markets_symbol_orderbook_hybrid(&[__ws_arg_0]).await;
//
// {
// "bids": [
// {
// "price": "1.00000000",
// "priceLevelQuantity": "1.00000000"
// }
// ],
// "asks": [
// {
// "price": "1.00000000",
// "priceLevelQuantity": "1.00000000"
// }
// ],
// "datetime": "2021-05-20T01:01:01.000Z",
// "timestamp": "1621490985000",
// "sequenceNumber": 999
// }
//
let mut timestamp: Value = self.safe_integer_k(response.clone(), "timestamp", &[]);
return self.parse_order_book(response, symbol, &[timestamp, Value::Str("bids".into()), Value::Str("asks".into()), Value::Str("price".into()), Value::Str("priceLevelQuantity".into())]);
Value::Null
}
/*
* @method
* @name bullish#fetchTrades
* @description get the list of most recent trades for a particular symbol
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/trades
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/markets/-symbol-/trades
* @param {string} symbol unified symbol of the market to fetch trades for
* @param {int} [since] timestamp in ms of the earliest trade to fetch
* @param {int} [limit] the maximum amount of trades to fetch (max 100)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest trade to fetch
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=public-trades}
*/
pub async fn fetch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(100);
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
let mut paramsPagination: Value = self.handle_pagination_params(Value::Str("fetchTrades".into()), &[since.clone(), paramsPaginate.clone()]);
return self.fetch_paginated_call_dynamic(Value::Str("fetchTrades".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPagination, maxLimit]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let mut paramsSinceAndUntil: Value = self.handle_since_and_until(&[since.clone(), paramsPaginate]);
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("_pageSize".into(), self.get_closest_limit(limit.clone())); }
}
let __ws_arg_1 = self.extend(request, &[paramsSinceAndUntil]);
let mut response: Value = self.public_get_v1_history_markets_symbol_trades(&[__ws_arg_1]).await;
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name bullish#fetchMyTrades
* @description fetch all trades made by the user
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/trades
* @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] the latest time in ms to fetch trades for
* @param {string} [params.orderId] the order id to fetch trades for
* @param {string} [params.clientOrderId] the client order id to fetch trades for
* @param {string} [params.tradingAccountId] the trading account id to fetch trades for
* @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol.clone());
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut clientOrderId: Option<String> = self.safe_string_k(params.clone(), "clientOrderId", &[]).as_str().map(str::to_owned);
let mut response: Value = Value::Null;
if (clientOrderId.is_some()) {
let __ws_arg_2 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v1_trades_client_order_id_client_order_id(&[__ws_arg_2]).await;
} else {
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchMyTrades".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
let mut paramsPagination: Value = self.handle_pagination_params(Value::Str("fetchMyTrades".into()), &[since.clone(), paramsPaginate.clone()]);
return self.fetch_paginated_call_dynamic(Value::Str("fetchMyTrades".into()), &[symbol, since.clone(), limit.clone(), paramsPagination, Value::Int(100)]).await;
}
let mut paramsSinceAndUntil: Value = self.handle_since_and_until(&[since.clone(), paramsPaginate]);
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("_pageSize".into(), self.get_closest_limit(limit.clone())); }
}
//
// [
// {
// "baseFee": "0.00000000",
// "createdAtDatetime": "2025-05-18T15:57:28.132Z",
// "createdAtTimestamp": "1747583848132",
// "handle": null,
// "isTaker": true,
// "orderId": "844242293909618689",
// "price": "103942.7048",
// "publishedAtTimestamp": "1747769786131",
// "quantity": "1.00000000",
// "quoteAmount": "103942.7048",
// "quoteFee": "0.0000",
// "side": "BUY",
// "symbol": "BTCUSDC",
// "tradeId": "100178000000288892"
// }, ...
// ]
//
let __ws_arg_3 = self.extend(request, &[paramsSinceAndUntil]);
response = self.private_get_v1_history_trades(&[__ws_arg_3]).await;
}
return self.parse_trades(response, &[market, since, limit]);
Value::Null
}
/*
* @method
* @name bullish#fetchOrderTrades
* @description fetch all the trades made from a single order
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/trades
* @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] the client order id to fetch trades for
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn fetch_order_trades(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut clientOrderId: Option<String> = self.safe_string_k(params.clone(), "clientOrderId", &[]).as_str().map(str::to_owned);
let mut paramsExtended: Value = params.clone();
if (clientOrderId.is_none()) {
paramsExtended = self.extend(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id);
m
}), &[params]);
}
return self.fetch_my_trades(&[symbol, since, limit, paramsExtended]).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
// [
// {
// "tradeId": "100178000000367159",
// "symbol": "BTCUSDC",
// "price": "103891.8977",
// "quantity": "0.00029411",
// "quoteAmount": "30.5556",
// "side": "BUY",
// "isTaker": true,
// "createdAtTimestamp": "1747768055826",
// "createdAtDatetime": "2025-05-20T19:07:35.826Z"
// }, ...
// ]
//
// [
// {
// "tradeId": "100020000000000060",
// "symbol": "BTCUSDC",
// "price": "1.00000000",
// "quantity": "1.00000000",
// "side": "BUY",
// "isTaker": true,
// "createdAtDatetime": "2021-05-20T01:01:01.000Z",
// "createdAtTimestamp": "1621490985000"
// }
// ]
//
// fetchMyTrades
// [
// {
// "baseFee": "0.00000000",
// "createdAtDatetime": "2025-05-18T15:57:28.132Z",
// "createdAtTimestamp": "1747583848132",
// "handle": null,
// "isTaker": true,
// "orderId": "844242293909618689",
// "price": "103942.7048",
// "publishedAtTimestamp": "1747769786131",
// "quantity": "1.00000000",
// "quoteAmount": "103942.7048",
// "quoteFee": "0.0000",
// "side": "BUY",
// "symbol": "BTCUSDC",
// "tradeId": "100178000000288892"
// }, ...
// ]
//
let mut marketId: Value = self.safe_string_k(trade.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut symbol: Value = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "createdAtTimestamp", &[]);
let mut price: Value = self.safe_string_k(trade.clone(), "price", &[]);
let mut amount: Value = self.safe_string_k(trade.clone(), "quantity", &[]);
let mut side: Value = self.safe_string_lower_k(trade.clone(), "side", &[]);
let mut isTaker: Value = self.safe_bool_k(trade.clone(), "isTaker", &[]);
let mut currency: Value = marketResolved.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null);
let mut code: Value = self.safe_currency_code(currency, &[]);
let mut feeCost: Value = self.safe_number_k(trade.clone(), "quoteFee", &[]);
let mut fee: Value = Value::Null;
if (feeCost != Value::Null) {
fee = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), code);
m.insert("cost".to_string(), feeCost);
m
});
}
let mut takerOrMaker: Value = Value::Null;
if (isTaker.as_bool() == Some(true)) {
takerOrMaker = Value::Str("taker".into());
} else {
takerOrMaker = Value::Str("maker".into());
}
let mut orderId: Value = self.safe_string_k(trade.clone(), "orderId", &[]);
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));
m.insert("symbol".to_string(), symbol);
m.insert("id".to_string(), self.safe_string_k(trade, "tradeId", &[]));
m.insert("order".to_string(), orderId);
m.insert("type".to_string(), Value::Null);
m.insert("takerOrMaker".to_string(), takerOrMaker);
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("amount".to_string(), amount);
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m
}), &[marketResolved]);
Value::Null
}
/*
* @method
* @name bullish#fetchTicker
* @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/tick
* @param {string} symbol unified symbol of the market to fetch the ticker for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_ticker(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_4 = self.extend(request, &[params]);
let mut response: Value = self.public_get_v1_markets_symbol_tick(&[__ws_arg_4]).await;
return self.parse_ticker(response, &[market]);
Value::Null
}
pub fn parse_ticker(&self, mut ticker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// {
// "createdAtDatetime": "2021-05-20T01:01:01.000Z",
// "createdAtTimestamp": "1621490985000",
// "high": "1.00000000",
// "low": "1.00000000",
// "bestBid": "1.00000000",
// "bidVolume": "1.00000000",
// "bestAsk": "1.00000000",
// "askVolume": "1.00000000",
// "vwap": "1.00000000",
// "open": "1.00000000",
// "close": "1.00000000",
// "last": "1.00000000",
// "change": "1.00000000",
// "percentage": "1.00000000",
// "average": "1.00000000",
// "baseVolume": "1.00000000",
// "quoteVolume": "1.00000000",
// "bancorPrice": "1.00000000",
// "markPrice": "19999.00",
// "fundingRate": "0.01",
// "openInterest": "100000.32452",
// "lastTradeDatetime": "2021-05-20T01:01:01.000Z",
// "lastTradeTimestamp": "1621490985000",
// "lastTradeQuantity": "1.00000000",
// "ammData": [
// {
// "feeTierId": "1",
// "bidSpreadFee": "0.00040000",
// "askSpreadFee": "0.00040000",
// "baseReservesQuantity": "245.56257825",
// "quoteReservesQuantity": "3424383.3629",
// "currentPrice": "16856.0000"
// }
// ]
// }
//
let mut marketId: Value = self.safe_string_k(ticker.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[marketId, market]);
let mut timestamp: Value = self.safe_integer_k(ticker.clone(), "createdAtTimestamp", &[]);
return self.safe_ticker(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("high".to_string(), self.safe_string_k(ticker.clone(), "high", &[]));
m.insert("low".to_string(), self.safe_string_k(ticker.clone(), "low", &[]));
m.insert("bid".to_string(), self.safe_string2(ticker.clone(), Value::Str("bid".into()), Value::Str("bestBid".into()), &[]));
m.insert("bidVolume".to_string(), self.safe_string_k(ticker.clone(), "bidVolume", &[]));
m.insert("ask".to_string(), self.safe_string2(ticker.clone(), Value::Str("ask".into()), Value::Str("bestAsk".into()), &[]));
m.insert("askVolume".to_string(), self.safe_string_k(ticker.clone(), "askVolume", &[]));
m.insert("vwap".to_string(), self.safe_string_k(ticker.clone(), "vwap", &[]));
m.insert("open".to_string(), self.safe_string_k(ticker.clone(), "open", &[]));
m.insert("close".to_string(), self.safe_string_k(ticker.clone(), "close", &[]));
m.insert("last".to_string(), self.safe_string_k(ticker.clone(), "last", &[]));
m.insert("previousClose".to_string(), Value::Null);
m.insert("change".to_string(), self.safe_string_k(ticker.clone(), "change", &[]));
m.insert("percentage".to_string(), self.safe_string_k(ticker.clone(), "percentage", &[]));
m.insert("average".to_string(), self.safe_string_k(ticker.clone(), "average", &[]));
m.insert("baseVolume".to_string(), self.safe_string_k(ticker.clone(), "baseVolume", &[]));
m.insert("quoteVolume".to_string(), self.safe_string_k(ticker.clone(), "quoteVolume", &[]));
m.insert("markPrice".to_string(), self.safe_string_k(ticker.clone(), "markPrice", &[]));
m.insert("info".to_string(), ticker);
m
}), &[marketResolved]);
Value::Null
}
pub async fn safe_deterministic_call(&mut self, mut method: 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 timeframe = get_arg(optional_args, 3, Value::Null);
let mut params = get_arg(optional_args, 4, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut maxRetriesparamsMaxRetriesVariable = self.handle_option_integer_and_params(params, method.clone(), Value::Str("maxRetries".into()), &[Value::Int(3)]);
let mut maxRetries: Value = maxRetriesparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsMaxRetries: Value = maxRetriesparamsMaxRetriesVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (method.as_str() != Some("fetchOHLCV")) && (method.as_str() != Some("fetchFundingRateHistory")) && (method.as_str() != Some("fetchTrades")) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" safeDeterministicCall() does not support the ".into())).into()), method).into()), Value::Str(" method".into()))));
}
let mut errors: Value = Value::Int(0);
let mut paramsOmitted: Value = self.omit(paramsMaxRetries, Value::Str("until".into()), &[]);
while errors.as_f64().unwrap_or(f64::NAN) <= maxRetries.as_f64().unwrap_or(f64::NAN) {
let _try_result = futures::FutureExt::catch_unwind(std::panic::AssertUnwindSafe(async {
if (method.as_str() == Some("fetchOHLCV")) {
return self.fetch_ohlcv(symbol.clone(), &[timeframe.clone(), since.clone(), limit.clone(), paramsOmitted.clone()]).await;
} else if (method.as_str() == Some("fetchFundingRateHistory")) {
return self.fetch_funding_rate_history(&[symbol.clone(), since.clone(), limit.clone(), paramsOmitted.clone()]).await;
} else {
return self.fetch_trades(symbol.clone(), &[since.clone(), limit.clone(), paramsOmitted.clone()]).await;
}
#[allow(unreachable_code)] { Value::Null }})).await;
match _try_result { Ok(__try_ok) => { if !matches!(__try_ok, Value::Null) { return __try_ok; } return Value::Null; } Err(_try_err) => { let e: Value = panic_to_value(_try_err);
if matches!(&e, Value::Str(__s) if __s.contains("[RateLimitExceeded]")) {
panic!("{}", e);
}
errors = (match (&(errors), &(Value::Int(1))) { (Value::Int(x), Value::Int(y)) => Value::Int(x + y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 + *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x + *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x + y), _ => Value::Null });
if errors.as_f64().unwrap_or(f64::NAN) > maxRetries.as_f64().unwrap_or(f64::NAN) {
panic!("{}", e);
}
} }
}
return Value::from(vec![]);
Value::Null
}
/*
* @method
* @name bullish#fetchOHLCV
* @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/candle
* @param {string} symbol unified symbol of the market to fetch OHLCV data for
* @param {string} timeframe the length of time each candle represents
* @param {int} [since] timestamp in ms of the earliest candle to fetch
* @param {int} [limit] the maximum amount of candles to fetch (max 100)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest entry
* @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn fetch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".into()));
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 (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut maxLimit: Value = Value::Int(100);
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchOHLCV".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
return self.fetch_paginated_call_deterministic(Value::Str("fetchOHLCV".into()), &[symbol, since.clone(), limit.clone(), timeframe.clone(), paramsPaginate.clone(), maxLimit.clone()]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("timeBucket".to_string(), self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]));
m.insert("_pageSize".to_string(), maxLimit.clone());
m
});
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("createdAtDatetime[lte]".into()), request, paramsPaginate, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut untilParam: Value = self.safe_integer_k(requestUntil.clone(), "createdAtDatetime[lte]", &[]);
let mut until: Value = Value::Null;
if (untilParam != Value::Null) {
until = untilParam.clone();
}
let mut duration: Value = self.parse_timeframe(timeframe.clone());
let mut maxDelta: Value = (match (&((match (&(duration), &(maxLimit)) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
let mut startTime: Value = since.clone();
// both of since and until are required
if (since == Value::Null) && (untilParam == Value::Null) {
let mut now: Value = self.milliseconds();
until = now.clone();
startTime = (match (&(now), &(maxDelta)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
} else if (since == Value::Null) && (untilParam != Value::Null) {
startTime = (match (&(untilParam), &(maxDelta)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
} else if (untilParam == Value::Null) {
until = self.sum(&[startTime.clone(), maxDelta]);
}
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("createdAtDatetime[gte]".into(), self.iso8601(startTime)); }
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("createdAtDatetime[lte]".into(), self.iso8601(until)); }
let __ws_arg_5 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.public_get_v1_markets_symbol_candle(&[__ws_arg_5]).await;
//
// [
// {
// "open": "100846.7490",
// "high": "100972.4001",
// "low": "100840.8129",
// "close": "100972.2602",
// "volume": "30.56064890",
// "createdAtTimestamp": "1746720540000",
// "createdAtDatetime": "2025-05-08T16:09:00.000Z",
// "publishedAtTimestamp": "1746720636007"
// }, ...
// ]
//
let mut ohlcvs: Value = self.to_array(response);
return self.parse_ohlc_vs(ohlcvs, &[market, timeframe, since, limit]);
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::from(vec![self.safe_integer_k(ohlcv.clone(), "createdAtTimestamp", &[]), self.safe_number_k(ohlcv.clone(), "open", &[]), self.safe_number_k(ohlcv.clone(), "high", &[]), self.safe_number_k(ohlcv.clone(), "low", &[]), self.safe_number_k(ohlcv.clone(), "close", &[]), self.safe_number_k(ohlcv, "volume", &[])]);
Value::Null
}
/*
* @method
* @name bullish#fetchFundingRateHistory
* @description fetches historical funding rate prices
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/markets/-symbol-/funding-rate
* @param {string} symbol unified symbol of the market to fetch the funding rate history for
* @param {int} [since] not sent to exchange api, exchange api always returns the most recent data, only used to filter exchange response
* @param {int} [limit] the maximum amount of funding rate structures to fetch
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/?id=funding-rate-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 (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() requires a symbol argument".into()))));
}
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut maxLimit: Value = Value::Int(100);
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchFundingRateHistory".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
let mut paramsPagination: Value = self.handle_pagination_params(Value::Str("fetchFundingRateHistory".into()), &[since.clone(), paramsPaginate.clone()]);
return self.fetch_paginated_call_dynamic(Value::Str("fetchFundingRateHistory".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPagination, maxLimit]).await;
}
let mut market: Value = self.market(symbol.clone());
if (market.as_map().and_then(|__m| __m.get("swap")).cloned().unwrap_or(Value::Null).as_bool() != Some(true)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchFundingRateHistory() supports swap markets only".into()))));
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("_pageSize".into(), self.get_closest_limit(limit.clone())); }
}
let mut paramsSinceAndUntil: Value = self.handle_since_and_until(&[since.clone(), paramsPaginate, Value::Str("updatedAtDatetime[gte]".into()), Value::Str("updatedAtDatetime[lte]".into())]);
let __ws_arg_6 = self.extend(request, &[paramsSinceAndUntil]);
let mut response: Value = self.public_get_v1_history_markets_symbol_funding_rate(&[__ws_arg_6]).await;
//
// [
// {
// "fundingRate": "0.00125",
// "updatedAtDatetime": "2025-05-18T09:06:04.074Z"
// },
// {
// "fundingRate": "0.00125",
// "updatedAtDatetime": "2025-05-18T08:59:59.033Z"
// }, ...
// ]
//
let mut rates: Vec<Value> = Vec::new();
let mut result: Value = self.to_array(response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_488: bool = true;
while { if !__for_first_488 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_488 = false; i.as_f64().unwrap_or(f64::NAN) < ((result.len() as i64) as f64) } {
let mut entry: Value = result.as_array().and_then(|__arr| match &i { Value::Int(__n) => __arr.get(*__n as usize), Value::Str(__s) => __s.parse::<usize>().ok().and_then(|__n| __arr.get(__n)), _ => None }).cloned().unwrap_or(Value::Null);
let mut datetime: Value = self.safe_string_k(entry.clone(), "updatedAtDatetime", &[]);
rates.push(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), entry.clone());
m.insert("symbol".to_string(), symbol.clone());
m.insert("fundingRate".to_string(), self.safe_number_k(entry, "fundingRate", &[]));
m.insert("timestamp".to_string(), self.parse8601(datetime.clone()));
m.insert("datetime".to_string(), datetime);
m
}));
}
}
let mut sorted: Value = self.sort_by(Value::from(rates), Value::Str("timestamp".into()), &[]);
return self.filter_by_symbol_since_limit(sorted, &[self.safe_string_k(market, "symbol", &[]), since, limit]);
Value::Null
}
/*
* @method
* @name bullish#fetchOrders
* @description fetches information on multiple orders made by the user
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--orders
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--history
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve (5, 25, 50, 100, default is 25)
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} [params.until] timestamp in ms of the latest order to fetch
* @param {string} [params.tradingAccountId] the trading account id (mandatory parameter)
* @param {string} [params.orderId] the id of the order to fetch for
* @param {string} [params.clientOrderId] the client id of the order to fetch for
* @param {string} [params.status] filter by order status, 'OPEN', 'CANCELLED', 'CLOSED', 'REJECTED'
* @param {bool} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
* @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_orders(&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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut paginate: Value = self.safe_bool_k(params.clone(), "paginate", &[Value::Bool(false)]);
if paginate.as_bool() == Some(true) {
let mut paramsPagination: Value = self.handle_pagination_params(Value::Str("fetchOrders".into()), &[since.clone(), params.clone()]);
return self.fetch_paginated_call_dynamic(Value::Str("fetchOrders".into()), &[symbol.clone(), since.clone(), limit.clone(), paramsPagination, Value::Int(100)]).await;
}
let mut market: Value = Value::Null;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut paramsSinceAndUntil: Value = self.handle_since_and_until(&[since.clone(), params]);
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("_pageSize".into(), self.get_closest_limit(limit.clone())); }
}
let mut method: Value = Value::Str("privateGetV2HistoryOrders".into());
let mut paramsMethod: Value = Value::Null;
{ let __destr_tmp = self.handle_option_string_and_params(paramsSinceAndUntil, Value::Str("fetchOrders".into()), Value::Str("method".into()), &[method.clone()]); method = __destr_tmp.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null); paramsMethod = __destr_tmp.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); }
let mut response: Value = Value::from(vec![]);
if (method.as_str() == Some("privateGetV2Orders")) {
//
// [
// {
// "clientOrderId": "187",
// "orderId": "297735387747975681",
// "symbol": "BTCUSDC",
// "price": "1.00000000",
// "averageFillPrice": "1.00000000",
// "stopPrice": "1.00000000",
// "allowBorrow": false,
// "quantity": "1.00000000",
// "quantityFilled": "1.00000000",
// "quoteAmount": "1.00000000",
// "baseFee": "0.00100000",
// "quoteFee": "0.0010",
// "borrowedBaseQuantity": "1.00000000",
// "borrowedQuoteQuantity": "1.00000000",
// "isLiquidation": false,
// "side": "BUY",
// "type": "LMT",
// "timeInForce": "GTC",
// "status": "OPEN",
// "statusReason": "User cancelled",
// "statusReasonCode": "1002",
// "createdAtDatetime": "2021-05-20T01:01:01.000Z",
// "createdAtTimestamp": "1621490985000",
// }
// ]
//
let __ws_arg_7 = self.extend(request.clone(), &[paramsMethod.clone()]);
response = self.private_get_v2_orders(&[__ws_arg_7]).await;
} else if (method.as_str() == Some("privateGetV2HistoryOrders")) {
let __ws_arg_8 = self.extend(request, &[paramsMethod]);
response = self.private_get_v2_history_orders(&[__ws_arg_8]).await;
} else {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", self.id.clone(), Value::Str(" fetchOrders() method parameter must be either \"privateGetV2Orders\" or \"privateGetV2HistoryOrders\"".into()))));
}
return self.parse_orders(response, &[market, since, limit]);
Value::Null
}
pub fn handle_pagination_params(&self, mut method: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut ninetyDays: Value = (match (&((match (&((match (&((match (&(Value::Int(90)), &(Value::Int(24))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null });
let mut now: Value = self.milliseconds();
let mut allowedSince: Value = (match (&(now), &(ninetyDays)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
if (since != Value::Null) && (since.as_f64().unwrap_or(f64::NAN) < allowedSince.as_f64().unwrap_or(f64::NAN)) {
panic!("{}", crate::exchange_errors::bad_request(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), method).into()), Value::Str("() only allows fetching entries up to 90 days in the past".into()))));
}
let mut paramsOmitted: Value = self.omit(params, Value::Str("paginate".into()), &[]);
let mut paramsExtended: Value = self.extend(paramsOmitted, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("paginationDirection".to_string(), Value::Str("backward".into()));
m
})]);
let mut until: Option<i64> = self.safe_integer_k(paramsExtended.clone(), "until", &[]).as_i64();
if (until.is_none()) {
return self.extend(paramsExtended.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("until".to_string(), now);
m
})]);
}
return paramsExtended;
Value::Null
}
pub fn handle_since_and_until(&self, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut sinceKey = get_arg(optional_args, 2, Value::Str("createdAtDatetime[gte]".into()));
let mut untilKey = get_arg(optional_args, 3, Value::Str("createdAtDatetime[lte]".into()));
let mut untilParam: Value = self.safe_integer_k(params.clone(), "until", &[]);
let mut until: Value = Value::Null;
if (untilParam != Value::Null) {
until = untilParam.clone();
}
let mut sinceFromUntil: bool = (since == Value::Null) && (untilParam != Value::Null);
let mut paramsResult: Value = params.clone();
if sinceFromUntil {
paramsResult = self.omit(params, Value::Str("until".into()), &[]);
}
if (since != Value::Null) || (untilParam != Value::Null) {
let mut timeDelta: Value = (match (&((match (&((match (&((match (&(Value::Int(7)), &(Value::Int(24))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(1000))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }); // 7 days
let mut sinceResolved: Value = since.clone();
if (since == Value::Null) && (untilParam != Value::Null) {
sinceResolved = (match (&(untilParam), &(timeDelta)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
}
if (since != Value::Null) && (untilParam == Value::Null) {
let mut now: Value = self.milliseconds();
let mut latestSince: Value = (match (&(now), &(timeDelta)) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
if since.as_f64().unwrap_or(f64::NAN) > latestSince.as_f64().unwrap_or(f64::NAN) {
until = now;
} else {
until = self.sum(&[since, timeDelta]);
}
}
let mut sinceDate: Value = self.iso8601(sinceResolved);
let mut untilDate: Value = self.iso8601(until);
add_element_to_object(&mut paramsResult, &sinceKey, sinceDate);
add_element_to_object(&mut paramsResult, &untilKey, untilDate);
}
return paramsResult;
Value::Null
}
pub fn get_closest_limit(&self, mut limit: Value) -> Value {
let mut pageSize: Value = Value::Int(5);
if (limit == Value::Null) {
return pageSize;
}
if (limit.as_f64().unwrap_or(f64::NAN) > ((5i64) as f64)) && (limit.as_f64().unwrap_or(f64::NAN) < ((26i64) as f64)) {
pageSize = Value::Int(25);
} else if (limit.as_f64().unwrap_or(f64::NAN) > ((25i64) as f64)) && (limit.as_f64().unwrap_or(f64::NAN) < ((51i64) as f64)) {
pageSize = Value::Int(50);
} else if limit.as_f64().unwrap_or(f64::NAN) > ((50i64) as f64) {
pageSize = Value::Int(100);
}
return pageSize;
Value::Null
}
/*
* @method
* @name bullish#fetchOpenOrders
* @description fetch all unfilled currently open orders
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--history
* @param {string} symbol unified market symbol of the market orders were made in
* @param {int} [since] the earliest time in ms to fetch orders for
* @param {int} [limit] the maximum number of order structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.tradingAccountId the trading account id (mandatory parameter)
* @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
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("OPEN".into()));
m
});
let __ws_arg_9 = self.extend(request, &[params]);
return self.fetch_orders(&[symbol, since, limit, __ws_arg_9]).await;
Value::Null
}
/*
* @method
* @name bullish#fetchCanceledOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--orders
* @param {string} symbol unified market symbol of the canceled orders
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the max number of canceled orders to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tradingAccountId] the trading account id (mandatory parameter)
* @returns {object} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("CANCELLED".into()));
m.insert("method".to_string(), Value::Str("privateGetV2Orders".into()));
m
});
let __ws_arg_10 = self.extend(request, &[params]);
return self.fetch_orders(&[symbol, since, limit, __ws_arg_10]).await;
Value::Null
}
/*
* @method
* @name bullish#fetchClosedOrders
* @description fetches information on multiple closed orders made by the user
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--orders
* @param {string} symbol unified market symbol of the closed orders
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the max number of closed orders to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.tradingAccountId the trading account id (mandatory parameter)
* @returns {object} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("CLOSED".into()));
m.insert("method".to_string(), Value::Str("privateGetV2Orders".into()));
m
});
let __ws_arg_11 = self.extend(request, &[params]);
return self.fetch_orders(&[symbol, since, limit, __ws_arg_11]).await;
Value::Null
}
/*
* @method
* @name bullish#fetchCanceledAndClosedOrders
* @description fetches information on multiple canceled orders made by the user
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--history
* @param {string} symbol unified market symbol of the closed orders
* @param {int} [since] timestamp in ms of the earliest order
* @param {int} [limit] the max number of closed orders to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tradingAccountId] the trading account id (mandatory parameter)
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_canceled_and_closed_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("status".to_string(), Value::Str("CLOSED".into()));
m.insert("method".to_string(), Value::Str("privateGetV2HistoryOrders".into()));
m
});
let __ws_arg_12 = self.extend(request, &[params]);
return self.fetch_orders(&[symbol, since, limit, __ws_arg_12]).await;
Value::Null
}
/*
* @method
* @name bullish#fetchOrder
* @description fetches information on an order made by the user
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v2/orders/-orderId-
* @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.traidingAccountId] the trading account id (mandatory parameter)
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn fetch_order(&mut self, mut id: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("orderId".to_string(), id);
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let __ws_arg_13 = self.extend(request, &[params]);
let mut response: Value = self.private_get_v2_orders_order_id(&[__ws_arg_13]).await;
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name bullish#createOrder
* @description create a trade order
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/orders
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit' or 'STOP_LIMIT' or 'POST_ONLY'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fulfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] a custom client order id
* @param {float} [params.triggerPrice] the price at which a stop order is triggered at
* @param {string} [params.timeInForce] the time in force for the order, either 'GTC' (Good Till Cancelled) or 'IOC' (Immediate or Cancel), default is 'GTC'
* @param {bool} [params.allowBorrow] if true, the order will be allowed to borrow assets to fulfill the order (default is false)
* @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.traidingAccountId the trading account id (mandatory parameter)
* @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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("commandType".to_string(), Value::Str("V3CreateOrder".into()));
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("side".to_string(), side.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.amount_to_precision(symbol.clone(), amount));
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let mut isMarketOrder: Value = (Value::Bool((type_var.as_str() == Some("market")) || (type_var.as_str() == Some("MARKET"))));
let mut postOnlyparamsPostOnlyVariable = self.handle_post_only(isMarketOrder.clone(), Value::Bool(type_var.as_str() == Some("POST_ONLY")), &[params]);
let mut postOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPostOnly: Value = postOnlyparamsPostOnlyVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut orderType: Value = type_var;
if postOnly.as_bool() == Some(true) {
orderType = Value::Str("POST_ONLY".into());
}
let mut timeInForceparamsTimeInForceVariable = self.handle_option_string_and_params(paramsPostOnly, Value::Str("createOrder".into()), Value::Str("timeInForce".into()), &[Value::Str("GTC".into())]);
let mut timeInForce: Value = timeInForceparamsTimeInForceVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTimeInForce: Value = timeInForceparamsTimeInForceVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null); // is mandatory
add_element_to_object(&mut paramsTimeInForce, &Value::Str("timeInForce".into()), timeInForce.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null));
if !(matches!(&isMarketOrder, Value::Bool(true))) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol.clone(), price)); }
}
let mut triggerPrice: Value = self.safe_string_k(paramsTimeInForce.clone(), "triggerPrice", &[]);
if (triggerPrice != Value::Null) {
if matches!(&isMarketOrder, Value::Bool(true)) {
panic!("{}", crate::exchange_errors::not_supported(format!("{}{}", self.id.clone(), Value::Str(" createOrder() does not support market trigger orders".into()))));
}
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("stopPrice".into(), self.price_to_precision(symbol, triggerPrice.clone())); }
orderType = Value::Str("STOP_LIMIT".into());
}
let mut paramsOmitted: Value = (if (triggerPrice != Value::Null) { self.omit(paramsTimeInForce.clone(), Value::Str("triggerPrice".into()), &[]) } else { paramsTimeInForce });
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), orderType.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null)); }
let __ws_arg_14 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_post_v2_orders(&[__ws_arg_14]).await;
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name bullish#editOrder
* @description edit a trade limit order
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/command-amend
* @param {string} id order id
* @param {string} [symbol] unified symbol of the market to create an order in
* @param {string} [type] 'limit' or 'POST_ONLY'
* @param {string} [side] not used by bullish editOrder
* @param {float} [amount] how much of the currency you want to trade in units of the base currency
* @param {float} [price] the price for the order, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.traidingAccountId] the trading account id (mandatory parameter)
* @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.clientOrderId] a unique identifier for the order, automatically generated if not sent
* @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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut market: Value = self.market(symbol.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("commandType".to_string(), Value::Str("V1AmendOrder".into()));
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let mut clientOrderId: Option<String> = self.safe_string_k(params.clone(), "clientOrderId", &[]).as_str().map(str::to_owned);
if (clientOrderId.is_none()) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("orderId".into(), id); }
}
if (type_var != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), type_var.as_str().map(|__s| Value::Str(__s.to_uppercase().into())).unwrap_or(Value::Null)); }
}
let mut postOnly: Value = self.safe_bool_k(params.clone(), "postOnly", &[Value::Bool(false)]);
if postOnly.as_bool() == Some(true) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("type".into(), Value::Str("POST_ONLY".into())); }
}
if (amount != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("quantity".into(), self.amount_to_precision(symbol.clone(), amount)); }
}
if (price != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("price".into(), self.price_to_precision(symbol, price)); }
}
let mut paramsOmitted: Value = (if postOnly.as_bool() == Some(true) { self.omit(params.clone(), Value::Str("postOnly".into()), &[]) } else { params });
let __ws_arg_15 = self.extend(request, &[paramsOmitted]);
let mut response: Value = self.private_post_v2_command(&[__ws_arg_15]).await;
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name bullish#cancelOrder
* @description cancels an open order
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/command-cancellations
* @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.commandType the command type, default is 'V3CancelOrder' (mandatory parameter)
* @param {string} [params.traidingAccountId] the trading account id (mandatory parameter)
* @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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
if (symbol == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" cancelOrder() requires a symbol argument".into()))));
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("tradingAccountId".to_string(), tradingAccountId);
m.insert("commandType".to_string(), self.safe_string_k(params.clone(), "commandType", &[Value::Str("V3CancelOrder".into())]));
m.insert("orderId".to_string(), id);
m
});
let __ws_arg_16 = self.extend(request, &[params]);
let mut response: Value = self.private_post_v2_command(&[__ws_arg_16]).await;
return self.parse_order(response, &[market]);
Value::Null
}
/*
* @method
* @name bullish#cancelAllOrders
* @description cancel all open orders in a market
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v2/command-cancellations
* @param {string} [symbol] alpaca cancelAllOrders cannot setting symbol, it will cancel all open orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.traidingAccountId the trading account id (mandatory parameter)
* @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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let mut market: Value = Value::Null;
if (symbol != Value::Null) {
market = self.market(symbol);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("commandType".into(), Value::Str("V1CancelAllOrdersByMarket".into())); }
} else {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("commandType".into(), Value::Str("V1CancelAllOrders".into())); }
}
let __ws_arg_17 = self.extend(request, &[params]);
let mut response: Value = self.private_post_v2_command(&[__ws_arg_17]).await;
//
// {
// "message": "Command acknowledged - CancelAllOrders",
// "requestId": "633900538459062272"
// }
//
let mut orders: Value = Value::from(vec![response]);
return self.parse_orders(orders, &[market]);
Value::Null
}
pub fn parse_order(&self, mut order: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchOrders, fetchOrder
// {
// "clientOrderId": "187",
// "orderId": "297735387747975680",
// "symbol": "BTCUSDC",
// "price": "1.00000000",
// "averageFillPrice": "1.00000000",
// "stopPrice": "1.00000000",
// "allowBorrow": false,
// "quantity": "1.00000000",
// "quantityFilled": "1.00000000",
// "quoteAmount": "1.00000000",
// "baseFee": "0.00100000",
// "quoteFee": "0.0010",
// "borrowedBaseQuantity": "1.00000000",
// "borrowedQuoteQuantity": "1.00000000",
// "isLiquidation": false,
// "side": "BUY",
// "type": "LMT",
// "timeInForce": "GTC",
// "status": "OPEN",
// "statusReason": "User cancelled",
// "statusReasonCode": "1002",
// "createdAtDatetime": "2021-05-20T01:01:01.000Z",
// "createdAtTimestamp": "1621490985000",
// }
//
// createOrder
// {
// "message": "Command acknowledged - CreateOrder",
// "requestId": "633910976353665024",
// "orderId": "633910775316480001",
// "clientOrderId": "1234567"
// }
//
// cancelOrder
// {
// "message": "Command acknowledged - CancelOrder",
// "requestId": "633910976353665024",
// "orderId": "633910775316480001"
// }
//
// cancelAllOrders
// {
// "message": "Command acknowledged - CancelAllOrders",
// "requestId": "633900538459062272"
// }
//
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut marketResolved: Value = self.safe_market(&[(if (market == Value::Null) { marketId.clone() } else { Value::Null }), market]);
let mut symbol: Value = self.safe_symbol(marketId, &[marketResolved.clone()]);
let mut id: Value = self.safe_string_k(order.clone(), "orderId", &[]);
let mut timestamp: Value = self.safe_integer_k(order.clone(), "createdAtTimestamp", &[]);
let mut type_var: Value = self.safe_string_k(order.clone(), "type", &[]);
let mut side: Value = self.safe_string_lower_k(order.clone(), "side", &[]);
let mut price: Value = self.safe_string_k(order.clone(), "price", &[]);
let mut amount: Value = self.safe_string_k(order.clone(), "quantity", &[]);
let mut filled: Value = self.safe_string_k(order.clone(), "quantityFilled", &[]);
let mut status: Value = self.parse_order_status(self.safe_string_k(order.clone(), "status", &[])).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null);
if (status.as_str() == Some("closed")) {
let mut statusReason: Option<String> = self.safe_string_k(order.clone(), "statusReason", &[]).as_str().map(str::to_owned);
if (statusReason.as_deref() == Some("User cancelled")) {
status = Value::Str("canceled".into());
}
}
let mut timeInForce: Value = self.safe_string_k(order.clone(), "timeInForce", &[]);
let mut stopPrice: Value = self.safe_string_k(order.clone(), "stopPrice", &[]);
let mut cost: Value = self.safe_string_k(order.clone(), "quoteAmount", &[]);
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut quoteFee: Value = self.safe_number_k(order.clone(), "quoteFee", &[]);
if (quoteFee != Value::Null) {
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("cost".into(), quoteFee); }
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("currency".into(), marketResolved.as_map().and_then(|__m| __m.get("quote")).cloned().unwrap_or(Value::Null)); }
}
let mut average: Value = self.safe_string_k(order.clone(), "averageFillPrice", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("clientOrderId".to_string(), self.safe_string_k(order.clone(), "clientOrderId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastTradeTimestamp".to_string(), Value::Null);
m.insert("status".to_string(), status);
m.insert("symbol".to_string(), symbol);
m.insert("type".to_string(), self.parse_order_type(type_var.clone()).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("timeInForce".to_string(), timeInForce);
m.insert("postOnly".to_string(), Value::Bool(type_var.as_str() == Some("POST_ONLY")));
m.insert("side".to_string(), side);
m.insert("price".to_string(), price);
m.insert("triggerPrice".to_string(), stopPrice);
m.insert("amount".to_string(), amount);
m.insert("filled".to_string(), filled);
m.insert("remaining".to_string(), Value::Null);
m.insert("cost".to_string(), cost);
m.insert("trades".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("info".to_string(), order);
m.insert("average".to_string(), average);
m
}), &[marketResolved]);
Value::Null
}
pub fn parse_order_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("OPEN".to_string(), Value::Str("open".into()));
m.insert("CLOSED".to_string(), Value::Str("closed".into()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".into()));
m.insert("REJECTED".to_string(), Value::Str("rejected".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub fn parse_order_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("LMT".to_string(), Value::Str("limit".into()));
m.insert("MKT".to_string(), Value::Str("market".into()));
m.insert("POST_ONLY".to_string(), Value::Str("limit".into()));
m.insert("STOP_LIMIT".to_string(), Value::Str("limit".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name bullish#fetchDepositsWithdrawals
* @description fetch history of deposits and withdrawals
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/wallets/transactions
* @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
* @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
* @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a list of [transaction structure]{@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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("createdAtDatetime[lte]".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut until: Value = self.safe_integer_k(requestUntil.clone(), "createdAtDatetime[lte]", &[]);
if (until != Value::Null) {
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("createdAtDatetime[lte]".into(), self.iso8601(until)); }
}
if (since != Value::Null) {
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("createdAtDatetime[gte]".into(), self.iso8601(since.clone())); }
}
let __ws_arg_18 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.private_get_v1_wallets_transactions(&[__ws_arg_18]).await;
//
// {
// "data": [
// {
// "custodyTransactionId": "0x791fc85f16a84cbd5250d5517ecad497f564d2e5cc54d31466fe70b952fd58da",
// "direction": "DEPOSIT",
// "quantity": "150",
// "symbol": "USDC",
// "fee": "0",
// "memo": "0x34625d5f0b6575503a0669994dea24271bfbd443",
// "createdAtDateTime": "2025-11-04T14:31:17.000Z",
// "updatedAtDateTime": "2025-11-04T14:44:17.500Z",
// "status": "COMPLETE",
// "statusReason": "OK",
// "network": "ETH",
// "transactionDetails": {
// "address": "0x34625d5f0b6575503a0669994dea24271bfbd443",
// "blockchainTxId": "0x791fc85f16a84cbd5250d5517ecad497f564d2e5cc54d31466fe70b952fd58da",
// "swiftUetr": null,
// "sources": [
// {
// "address": "0x2653435d52a5f49551ebb757f25b2c8bb954859b"
// }
// ]
// }
// }
// ],
// "links": {
// "previous": null,
// "next": null
// },
// "totalCount": 1
// }
//
let mut data: Value = self.safe_list_k(response, "data", &[Value::from(vec![])]);
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
}
return self.parse_transactions(data, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name bullish#withdraw
* @description make a withdrawal
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v1/wallets/withdrawal
* @param {string} code unified currency code
* @param {float} amount the amount to withdraw
* @param {string} address the address to withdraw to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.tag] memo / destination tag, required for currencies in options['withdrawTagRequiredCurrencies']
* @param {string} params.timestamp the timestamp of the withdrawal request (mandatory)
* @param {string} params.nonce the nonce of the withdrawal request (mandatory)
* @param {string} params.network network for withdraw (mandatory)
* @returns {object} a [transaction structure]{@link https://docs.ccxt.com/?id=transaction-structure}
*/
pub async fn withdraw(&mut self, mut code: Value, mut amount: Value, mut address: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
// todo check this method properly
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("command".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("commandType".to_string(), Value::Str("V1Withdraw".into()));
m.insert("destinationId".to_string(), address);
m.insert("symbol".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.currency_to_precision(code.clone(), amount, &[]));
m
}));
m
});
let mut networkCodeparamsNetworkCodeVariable = self.handle_network_code_and_params(params);
let mut networkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsNetworkCode: Value = networkCodeparamsNetworkCodeVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if (networkCode != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("network".into(), self.network_code_to_id(networkCode, &[code])); }
} else {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" withdraw() requires a network parameter".into()))));
}
let __ws_arg_19 = self.extend(request, &[paramsNetworkCode]);
let mut response: Value = self.private_post_v1_wallets_withdrawal(&[__ws_arg_19]).await;
return self.parse_transaction(response, &[currency]);
Value::Null
}
pub fn parse_transaction(&self, mut transaction: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "custodyTransactionId": "0x791fc85f16a84cbd5250d5517ecad497f564d2e5cc54d31466fe70b952fd58da",
// "direction": "DEPOSIT",
// "quantity": "150",
// "symbol": "USDC",
// "fee": "0",
// "memo": "0x34625d5f0b6575503a0669994dea24271bfbd443",
// "createdAtDateTime": "2025-11-04T14:31:17.000Z",
// "updatedAtDateTime": "2025-11-04T14:44:17.500Z",
// "status": "COMPLETE",
// "statusReason": "OK",
// "network": "ETH",
// "transactionDetails": {
// "address": "0x34625d5f0b6575503a0669994dea24271bfbd443",
// "blockchainTxId": "0x791fc85f16a84cbd5250d5517ecad497f564d2e5cc54d31466fe70b952fd58da",
// "swiftUetr": null,
// "sources": [
// {
// "address": "0x2653435d52a5f49551ebb757f25b2c8bb954859b"
// }
// ]
// }
// }
//
let mut id: Value = self.safe_string_k(transaction.clone(), "custodyTransactionId", &[]);
let mut type_var: Value = self.safe_string_k(transaction.clone(), "direction", &[]);
let mut timestamp: Value = self.parse8601(self.safe_string_k(transaction.clone(), "createdAtDateTime", &[]));
let mut updated: Value = self.parse8601(self.safe_string_k(transaction.clone(), "updatedAtDateTime", &[]));
let mut network: Value = self.safe_string_k(transaction.clone(), "network", &[]);
let mut transactionDetails: Value = self.safe_dict_k(transaction.clone(), "transactionDetails", &[]);
let mut txid: Value = self.safe_string_k(transactionDetails.clone(), "blockchainTxId", &[]);
let mut address: Value = self.safe_string_k(transactionDetails.clone(), "address", &[]);
let mut amount: Value = self.safe_number_k(transaction.clone(), "quantity", &[]);
let mut currencyId: Value = self.safe_string_k(transaction.clone(), "symbol", &[]);
let mut code: Value = self.safe_currency_code(currencyId, &[currency]);
let mut status: Value = self.safe_string_k(transaction.clone(), "status", &[]);
let mut sources: Value = self.safe_list_k(transactionDetails, "sources", &[Value::from(vec![])]);
let mut source: Value = self.safe_dict(sources, Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut sourceAddress: Value = self.safe_string_k(source, "address", &[]);
let mut fee: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), Value::Null);
m.insert("cost".to_string(), Value::Null);
m.insert("rate".to_string(), Value::Null);
m
});
let mut feeCost: Value = self.safe_number_k(transaction.clone(), "fee", &[]);
if (feeCost != Value::Null) {
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("cost".into(), feeCost); }
if let Value::Dict(__d) = &mut fee { std::sync::Arc::make_mut(__d).insert("currency".into(), code.clone()); }
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), id);
m.insert("txid".to_string(), txid);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("network".to_string(), self.network_id_to_code(&[network, code.clone()]));
m.insert("addressFrom".to_string(), sourceAddress);
m.insert("address".to_string(), address.clone());
m.insert("addressTo".to_string(), address);
m.insert("amount".to_string(), amount);
m.insert("type".to_string(), self.parse_transaction_type(type_var).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("currency".to_string(), code);
m.insert("status".to_string(), self.parse_transaction_status(status).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("updated".to_string(), updated);
m.insert("tagFrom".to_string(), Value::Null);
m.insert("tag".to_string(), Value::Null);
m.insert("tagTo".to_string(), Value::Null);
m.insert("comment".to_string(), Value::Null);
m.insert("internal".to_string(), Value::Null);
m.insert("fee".to_string(), fee);
m.insert("info".to_string(), transaction);
m
});
Value::Null
}
pub fn parse_transaction_type(&self, mut type_var: Value) -> Option<String> {
let mut types: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("DEPOSIT".to_string(), Value::Str("deposit".into()));
m.insert("WITHDRAW".to_string(), Value::Str("withdrawal".into()));
m
});
return self.safe_string(types, type_var.clone(), &[type_var.clone()]).as_str().map(str::to_owned);
}
pub fn parse_transaction_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("COMPLETE".to_string(), Value::Str("ok".into()));
m.insert("FAILED".to_string(), Value::Str("failed".into()));
m.insert("PENDING".to_string(), Value::Str("pending".into()));
m.insert("CANCELLED".to_string(), Value::Str("canceled".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
pub async fn load_account(&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 tradingAccountIdOptionparamsTradingAccountIdVariable = self.handle_option_string_and_params(params, Value::Str("loadAccount".into()), Value::Str("tradingAccountId".into()), &[]);
let mut tradingAccountIdOption: Value = tradingAccountIdOptionparamsTradingAccountIdVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsTradingAccountId: Value = tradingAccountIdOptionparamsTradingAccountIdVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut tradingAccountId: Value = tradingAccountIdOption;
if (tradingAccountId == Value::Null) {
let mut response: Value = self.private_get_v1_accounts_trading_accounts(&[paramsTradingAccountId]).await;
let mut accounts: Value = self.to_array(response);
{
let mut i: Value = Value::Int(0);
let mut __for_first_489: bool = true;
while { if !__for_first_489 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_489 = false; i.as_f64().unwrap_or(f64::NAN) < ((accounts.len() as i64) as f64) } {
let mut account: Value = self.safe_dict(accounts.clone(), i.clone(), &[]);
let mut name: Option<String> = self.safe_string_k(account.clone(), "tradingAccountName", &[]).as_str().map(str::to_owned);
if (name.as_deref() == Some("Primary Account")) {
tradingAccountId = self.safe_string_k(account, "tradingAccountId", &[]);
break;
}
}
}
}
if (tradingAccountId == Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(format!("{}{}", self.id.clone(), Value::Str(" loadAccount() requires a tradingAccountId parameter in options[\"tradingAccountId\"] or params[\"tradingAccountId\"], fetchAccounts() was not able to find the Primary account".into()))));
}
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("tradingAccountId".into(), tradingAccountId); }
return self.safe_string_k(self.options.clone(), "tradingAccountId", &[]);
Value::Null
}
/*
* @method
* @name bullish#fetchAccounts
* @description fetch all the accounts associated with a profile
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#tag--trading-accounts
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/?id=account-structure} indexed by the account type
*/
pub async fn fetch_accounts(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut response: Value = self.private_get_v1_accounts_trading_accounts(&[params.clone()]).await;
return self.parse_accounts(response, &[params]);
Value::Null
}
pub fn parse_account(&self, mut account: Value) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(account.clone(), "tradingAccountId", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("code".to_string(), Value::Null);
m.insert("info".to_string(), account);
m
});
Value::Null
}
/*
* @method
* @name bullish#fetchDepositAddress
* @description fetch the deposit address for a currency associated with this account
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/wallets/deposit-instructions/crypto/-symbol-
* @param {string} code unified currency code
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.network] network for deposit address
* @returns {object} an [address structure]{@link https://docs.ccxt.com/?id=address-structure}
*/
pub async fn fetch_deposit_address(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_20 = self.extend(request, &[params.clone()]);
let mut response: Value = self.private_get_v1_wallets_deposit_instructions_crypto_symbol(&[__ws_arg_20]).await;
//
// [
// {
// "network": "ETH",
// "address": "0xc2fc755082d052bb334763b144851a0031999f33",
// "symbol": "ETH"
// }
// ]
//
let mut safeResponse: Value = self.to_array(response);
let mut length: f64 = ((safeResponse.len() as i64) as f64);
let mut data: Value = self.safe_dict(safeResponse.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networkAndParams: Value = self.handle_network_code_and_params(params);
let mut networkParam: Value = networkAndParams.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut networkDefinedByUser: bool = networkParam != Value::Null;
let mut network: Value = networkParam;
if (length > ((1i64) as f64)) || (networkDefinedByUser) {
// some currencies have multiple networks
if (network == Value::Null) {
// use default network if not specified and multiple are available
network = self.safe_string(self.safe_dict_k(self.options.clone(), "defaultNetworks", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]), code.clone(), &[self.safe_string_k(self.options.clone(), "defaultNetwork", &[])]);
}
if (network != Value::Null) {
{
let mut i: Value = Value::Int(0);
let mut __for_first_490: bool = true;
while { if !__for_first_490 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_490 = false; i.as_f64().unwrap_or(f64::NAN) < ((safeResponse.len() as i64) as f64) } {
let mut entry: Value = self.safe_dict(safeResponse.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut networkId: Value = self.safe_string_k(entry.clone(), "network", &[]);
let mut networkCode: Value = self.network_id_to_code(&[networkId, code.clone()]);
if (network.as_str() == networkCode.as_str()) {
data = entry;
break;
}
}
}
if networkDefinedByUser {
data = Value::Map({
let mut m = indexmap::IndexMap::new();
m
}); // return an empty structure if the user-defined network was not found
}
}
}
return self.parse_deposit_address(data, &[currency]);
Value::Null
}
pub fn parse_deposit_address(&self, mut depositAddress: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
let mut id: Value = self.safe_string_k(depositAddress.clone(), "symbol", &[]);
let mut network: Value = self.safe_string_k(depositAddress.clone(), "network", &[]);
let mut code: Value = self.safe_currency_code(id, &[currency]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), depositAddress.clone());
m.insert("currency".to_string(), code.clone());
m.insert("network".to_string(), self.network_id_to_code(&[network, code]));
m.insert("address".to_string(), self.safe_string_k(depositAddress, "address", &[]));
m.insert("tag".to_string(), Value::Null);
m
});
Value::Null
}
/*
* @method
* @name bullish#fetchBalance
* @description query for balance and get the amount of funds available for trading or funds locked in orders
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/accounts/asset
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/accounts/asset/-symbol-
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.tradingAccountId the trading account id (mandatory parameter)
* @param {string} [params.code] unified currency code, default is undefined
* @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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let mut response: Value = Value::Null;
let mut code: Value = self.safe_string_k(params.clone(), "code", &[]);
if (code != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("symbol".into(), self.currency(code.clone()).as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
let __ws_arg_21 = self.extend(request.clone(), &[params.clone()]);
response = self.private_get_v1_accounts_asset_symbol(&[__ws_arg_21]).await;
return self.parse_balance_for_single_currency(response.clone(), code);
} else {
let __ws_arg_22 = self.extend(request, &[params]);
response = self.private_get_v1_accounts_asset(&[__ws_arg_22]).await;
return self.parse_balance(response);
}
Value::Null
}
pub fn parse_balance_for_single_currency(&self, mut response: Value, mut code: Value) -> Value {
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
});
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("free".into(), self.safe_string_k(response.clone(), "availableQuantity", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(response, "lockedQuantity", &[])); }
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
return self.safe_balance(result);
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 i: Value = Value::Int(0);
let mut __for_first_491: bool = true;
while { if !__for_first_491 { if let Value::Int(n) = &mut i { *n += 1; } } __for_first_491 = false; i.as_f64().unwrap_or(f64::NAN) < get_array_length(&response).as_f64().unwrap_or(f64::NAN) } {
let mut balance: Value = self.safe_dict(response.clone(), i.clone(), &[]);
let mut symbol: Value = self.safe_string_k(balance.clone(), "assetSymbol", &[]);
let mut code: Value = self.safe_currency_code(symbol, &[]);
let mut account: Value = self.account();
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("total".into(), self.safe_string_k(balance.clone(), "availableQuantity", &[])); }
if let Value::Dict(__d) = &mut account { std::sync::Arc::make_mut(__d).insert("used".into(), self.safe_string_k(balance, "lockedQuantity", &[])); }
if (code != Value::Null) {
if let Value::Dict(__d) = &mut result { std::sync::Arc::make_mut(__d).insert(crate::runtime::stringify_param(&code), account); }
}
}
}
return self.safe_balance(result);
Value::Null
}
/*
* @method
* @name bullish#fetchPositions
* @description fetch all open positions
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/derivatives-positions
* @param {string[]|undefined} symbols list of unified market symbols
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} params.tradingAccountId the trading account id
* @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
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let __ws_arg_23 = self.extend(request, &[params]);
let mut response: Value = self.private_get_v1_derivatives_positions(&[__ws_arg_23]).await;
//
// [
// {
// "tradingAccountId": "111000000000001",
// "symbol": "BTC-USDC-PERP",
// "side": "BUY",
// "quantity": "1.00000000",
// "notional": "1.0000",
// "entryNotional": "1.0000",
// "mtmPnl": "1.0000",
// "reportedMtmPnl": "1.0000",
// "reportedFundingPnl": "1.0000",
// "realizedPnl": "1.0000",
// "settlementAssetSymbol": "USDC",
// "createdAtDatetime": "2021-05-20T01:01:01.000Z",
// "createdAtTimestamp": "1621490985000",
// "updatedAtDatetime": "2021-05-20T01:01:01.000Z",
// "updatedAtTimestamp": "1621490985000"
// }
// ]
//
let mut results: Value = self.parse_positions(response, &[symbols.clone()]);
return self.filter_by_array_positions(results, Value::Str("symbol".into()), &[symbols]);
Value::Null
}
pub fn parse_position(&self, mut position: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// [
// {
// "tradingAccountId": "111000000000001",
// "symbol": "BTC-USDC-PERP",
// "side": "BUY",
// "quantity": "1.00000000",
// "notional": "1.0000",
// "entryNotional": "1.0000",
// "mtmPnl": "1.0000",
// "reportedMtmPnl": "1.0000",
// "reportedFundingPnl": "1.0000",
// "realizedPnl": "1.0000",
// "settlementAssetSymbol": "USDC",
// "createdAtDatetime": "2021-05-20T01:01:01.000Z",
// "createdAtTimestamp": "1621490985000",
// "updatedAtDatetime": "2021-05-20T01:01:01.000Z",
// "updatedAtTimestamp": "1621490985000"
// }
// ]
//
let mut marketResolved: Value = self.safe_market(&[self.safe_string_k(position.clone(), "symbol", &[]), market]);
let mut symbol: Value = marketResolved.as_map().and_then(|__m| __m.get("symbol")).cloned().unwrap_or(Value::Null);
let mut timestamp: Value = self.safe_integer_k(position.clone(), "createdAtTimestamp", &[]);
let mut side: Value = self.safe_string_k(position.clone(), "side", &[]);
return self.safe_position(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), position.clone());
m.insert("id".to_string(), Value::Null);
m.insert("symbol".to_string(), symbol);
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("lastUpdateTimestamp".to_string(), self.safe_integer_k(position.clone(), "updatedAtTimestamp", &[]));
m.insert("hedged".to_string(), Value::Null);
m.insert("side".to_string(), self.parse_position_side(side).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("contracts".to_string(), self.safe_number_k(position.clone(), "quantity", &[]));
m.insert("contractSize".to_string(), Value::Null);
m.insert("entryPrice".to_string(), Value::Null);
m.insert("markPrice".to_string(), Value::Null);
m.insert("lastPrice".to_string(), Value::Null);
m.insert("notional".to_string(), self.safe_number_k(position, "notional", &[]));
m.insert("leverage".to_string(), Value::Null);
m.insert("collateral".to_string(), Value::Null);
m.insert("initialMargin".to_string(), Value::Null);
m.insert("initialMarginPercentage".to_string(), Value::Null);
m.insert("maintenanceMargin".to_string(), Value::Null);
m.insert("maintenanceMarginPercentage".to_string(), Value::Null);
m.insert("unrealizedPnl".to_string(), Value::Null);
m.insert("liquidationPrice".to_string(), Value::Null);
m.insert("marginMode".to_string(), Value::Null);
m.insert("marginRatio".to_string(), Value::Null);
m.insert("percentage".to_string(), Value::Null);
m.insert("stopLossPrice".to_string(), Value::Null);
m.insert("takeProfitPrice".to_string(), Value::Null);
m
}));
Value::Null
}
pub fn parse_position_side(&self, mut side: Value) -> Option<String> {
let mut sides: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BUY".to_string(), Value::Str("long".into()));
m.insert("SELL".to_string(), Value::Str("short".into()));
m
});
return self.safe_string(sides, side.clone(), &[side.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name bullish#fetchTransfers
* @description fetch a history of internal transfers made on an account
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/transfer
* @param {string} code unified currency code of the currency transferred
* @param {int} [since] the earliest time in ms to fetch transfers for
* @param {int} [limit] the maximum number of transfer structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} params.until the latest time in ms to fetch transfers for (default time now)
* @param {string} params.tradingAccountId the trading account id
* @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn fetch_transfers(&mut self, optional_args: &[Value]) -> Value {
let mut code = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut maxLimit: Value = Value::Int(100);
let mut paginateparamsPaginateVariable = self.handle_option_bool_and_params(params, Value::Str("fetchTransfers".into()), Value::Str("paginate".into()), &[Value::Bool(false)]);
let mut paginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsPaginate: Value = paginateparamsPaginateVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
if paginate.as_bool() == Some(true) {
let mut paramsPagination: Value = self.handle_pagination_params(Value::Str("fetchTransfers".into()), &[since.clone(), paramsPaginate.clone()]);
return self.fetch_paginated_call_dynamic(Value::Str("fetchTransfers".into()), &[code.clone(), since.clone(), limit.clone(), paramsPagination, maxLimit]).await;
}
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let mut currency: Value = Value::Null;
if (code != Value::Null) {
currency = self.currency(code);
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("assetSymbol".into(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null)); }
}
let mut until: Option<i64> = self.safe_integer_k(paramsPaginate.clone(), "until", &[]).as_i64();
// since and until are mandatory for this endpoint, set until to now if both are undefined
let mut untilMissing: bool = (since == Value::Null) && (until.is_none());
let mut paramsUntil: Value = paramsPaginate.clone();
if untilMissing {
let __ws_arg_24 = self.milliseconds();
paramsUntil = self.extend(paramsPaginate, &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("until".to_string(), __ws_arg_24);
m
})]);
}
let mut paramsSinceAndUntil: Value = self.handle_since_and_until(&[since.clone(), paramsUntil]);
if (limit != Value::Null) {
if let Value::Dict(__d) = &mut request { std::sync::Arc::make_mut(__d).insert("_pageSize".into(), self.get_closest_limit(limit.clone())); }
}
let __ws_arg_25 = self.extend(request, &[paramsSinceAndUntil]);
let mut response: Value = self.private_get_v1_history_transfer(&[__ws_arg_25]).await;
return self.parse_transfers(response, &[currency, since, limit]);
Value::Null
}
/*
* @method
* @name bullish#transfer
* @description transfer currency internally between wallets on the same account
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#post-/v1/command-commandType-V1TransferAsset
* @param {string} code unified currency codeåå
* @param {float} amount amount to transfer
* @param {string} fromAccount account ID to transfer from
* @param {string} toAccount account ID to transfer to
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} a [transfer structure]{@link https://docs.ccxt.com/?id=transfer-structure}
*/
pub async fn transfer(&mut self, mut code: Value, mut amount: Value, mut fromAccount: Value, mut toAccount: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
// todo check this method properly
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("commandType".to_string(), Value::Str("V2TransferAsset".into()));
m.insert("assetSymbol".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("quantity".to_string(), self.currency_to_precision(code.clone(), amount.clone(), &[]));
m.insert("fromTradingAccountId".to_string(), fromAccount.clone());
m.insert("toTradingAccountId".to_string(), toAccount.clone());
m
});
let __ws_arg_26 = self.extend(request, &[params]);
let mut response: Value = self.private_post_v2_command(&[__ws_arg_26]).await;
//
// {
// "message": "Command acknowledged - TransferAsset",
// "requestId": "633909659774222336"
// }
//
let mut transferOptions: Value = self.safe_dict_k(self.options.clone(), "transfer", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut fillResponseFromRequest: Value = self.safe_bool_k(transferOptions, "fillResponseFromRequest", &[Value::Bool(true)]);
let mut transfer: Value = self.parse_transfer(response, &[currency]);
if fillResponseFromRequest.as_bool() == Some(true) {
if let Value::Dict(__d) = &mut transfer { std::sync::Arc::make_mut(__d).insert("fromAccount".into(), fromAccount); }
if let Value::Dict(__d) = &mut transfer { std::sync::Arc::make_mut(__d).insert("toAccount".into(), toAccount); }
if let Value::Dict(__d) = &mut transfer { std::sync::Arc::make_mut(__d).insert("amount".into(), amount); }
if let Value::Dict(__d) = &mut transfer { std::sync::Arc::make_mut(__d).insert("currency".into(), code); }
}
return transfer;
Value::Null
}
pub fn parse_transfer(&self, mut transfer: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// fetchTransfers
// {
// "requestId": "1",
// "toTradingAccountId": "111000000000001",
// "fromTradingAccountId": "121000000000001",
// "assetSymbol": "BTC",
// "quantity": "1.00000000",
// "status": "CLOSED",
// "statusReasonCode": "6002",
// "statusReason": "Executed",
// "createdAtTimestamp": "1621490985000",
// "createdAtDatetime": "2021-05-20T01:01:01.000Z"
// }
//
// transfer
// {
// "message": "Command acknowledged - TransferAsset",
// "requestId": "633909659774222336"
// }
//
let mut timestamp: Value = self.safe_integer_k(transfer.clone(), "createdAtTimestamp", &[]);
let mut currencyId: Value = self.safe_string_k(transfer.clone(), "assetSymbol", &[]);
let mut status: Value = self.safe_string_k(transfer.clone(), "status", &[]);
if (status == Value::Null) {
status = self.safe_string_k(transfer.clone(), "message", &[]);
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), self.safe_string_k(transfer.clone(), "requestId", &[]));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("amount".to_string(), self.safe_number_k(transfer.clone(), "quantity", &[]));
m.insert("fromAccount".to_string(), self.safe_string_k(transfer.clone(), "fromTradingAccountId", &[]));
m.insert("toAccount".to_string(), self.safe_string_k(transfer.clone(), "toTradingAccountId", &[]));
m.insert("status".to_string(), self.parse_transfer_status(status).map(|__s| Value::Str(__s.into())).unwrap_or(Value::Null));
m.insert("info".to_string(), transfer);
m
});
Value::Null
}
pub fn parse_transfer_status(&self, mut status: Value) -> Option<String> {
let mut statuses: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("CLOSED".to_string(), Value::Str("ok".into()));
m.insert("OPEN".to_string(), Value::Str("pending".into()));
m.insert("REJECTED".to_string(), Value::Str("failed".into()));
m.insert("Command acknowledged - TransferAsset".to_string(), Value::Str("ok".into()));
m
});
return self.safe_string(statuses, status.clone(), &[status.clone()]).as_str().map(str::to_owned);
}
/*
* @method
* @name bullish#fetchBorrowRateHistory
* @description retrieves a history of a currencies borrow interest rate at specific time slots
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/history/borrow-interest
* @param {string} code unified currency code
* @param {int} [since] timestamp for the earliest borrow rate
* @param {int} [limit] the maximum number of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure} to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int} params.until the latest time in ms to fetch entries for
* @param {string} params.tradingAccountId the trading account id
* @returns {object[]} an array of [borrow rate structures]{@link https://docs.ccxt.com/?id=borrow-rate-structure}
*/
pub async fn fetch_borrow_rate_history(&mut self, mut code: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
promise_all(&Value::from(vec![self.load_markets(&[]).await, self.handle_token(&[]).await])).await;
let mut tradingAccountId: Value = self.load_account(&[params.clone()]).await;
let mut currency: Value = self.currency(code.clone());
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("assetSymbol".to_string(), currency.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m.insert("tradingAccountId".to_string(), tradingAccountId);
m
});
let mut now: Value = self.milliseconds();
let mut startTimestamp: Value = since.clone();
let mut requestUntilparamsUntilVariable = self.handle_until_option(Value::Str("createdAtDatetime[lte]".into()), request, params, &[]);
let mut requestUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(0)).cloned().unwrap_or(Value::Null);
let mut paramsUntil: Value = requestUntilparamsUntilVariable.as_array().and_then(|__arr| __arr.get(1)).cloned().unwrap_or(Value::Null);
let mut until: Value = self.safe_integer_k(requestUntil.clone(), "createdAtDatetime[lte]", &[]);
// current endpoint requires both since and until parameters
if (since == Value::Null) {
startTimestamp = (match (&(now), &((match (&((match (&((match (&((match (&(Value::Int(1000)), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(24))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(90))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null }))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null }); // Only the last 90 days of data is available for querying
}
if (until == Value::Null) {
until = now;
}
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("createdAtDatetime[gte]".into(), self.iso8601(startTimestamp)); }
if let Value::Dict(__d) = &mut requestUntil { std::sync::Arc::make_mut(__d).insert("createdAtDatetime[lte]".into(), self.iso8601(until)); }
let __ws_arg_27 = self.extend(requestUntil, &[paramsUntil]);
let mut response: Value = self.private_get_v1_history_borrow_interest(&[__ws_arg_27]).await;
return self.parse_borrow_rate_history(response, code, since, limit);
Value::Null
}
pub fn parse_borrow_rate(&self, mut info: Value, optional_args: &[Value]) -> Value {
let mut currency = get_arg(optional_args, 0, Value::Null);
//
// {
// "assetId": "1",
// "assetSymbol": "BTC",
// "borrowedQuantity": "1.00000000",
// "totalBorrowedQuantity": "1.00000000",
// "createdAtDatetime": "2020-08-21T08:00:00.000Z",
// "createdAtTimestamp": "1621490985000"
// }
//
let mut timestamp: Value = self.safe_integer_k(info.clone(), "createdAtTimestamp", &[]);
let mut currencyId: Value = self.safe_string_k(info.clone(), "assetSymbol", &[]);
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("currency".to_string(), self.safe_currency_code(currencyId, &[currency]));
m.insert("rate".to_string(), self.safe_number_k(info.clone(), "borrowedQuantity", &[]));
m.insert("period".to_string(), Value::Int(86400000));
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp));
m.insert("info".to_string(), info);
m
});
Value::Null
}
pub fn get_timestamp(&self) -> Value {
return (match (&(self.milliseconds()), &(self.safe_integer_k(self.options.clone(), "timeDifference", &[Value::Int(0)]))) { (Value::Int(x), Value::Int(y)) => Value::Int(x - y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 - *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x - *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x - y), _ => Value::Null });
Value::Null
}
/*
* @method
* @name bullish#fetchOpenInterest
* @description fetches the open interest of a specific market
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#get-/v1/markets/-symbol-/tick
* @param {string} symbol unified symbol of the market to fetch the open interest for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object} an [open interest structure]{@link https://docs.ccxt.com/?id=ticker-structure}
*/
pub async fn fetch_open_interest(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if (self.markets.clone() == Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol);
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("symbol".to_string(), market.as_map().and_then(|__m| __m.get("id")).cloned().unwrap_or(Value::Null));
m
});
let __ws_arg_28 = self.extend(request, &[params]);
let mut response: Value = self.public_get_v1_markets_symbol_tick(&[__ws_arg_28]).await;
return self.parse_open_interest(response, &[market]);
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);
//
// {
// "createdAtDatetime": "2021-05-20T01:01:01.000Z",
// "createdAtTimestamp": "1621490985000",
// "high": "1.00000000",
// "low": "1.00000000",
// "bestBid": "1.00000000",
// "bidVolume": "1.00000000",
// "bestAsk": "1.00000000",
// "askVolume": "1.00000000",
// "vwap": "1.00000000",
// "open": "1.00000000",
// "close": "1.00000000",
// "last": "1.00000000",
// "change": "1.00000000",
// "percentage": "1.00000000",
// "average": "1.00000000",
// "baseVolume": "1.00000000",
// "quoteVolume": "1.00000000",
// "bancorPrice": "1.00000000",
// "markPrice": "19999.00",
// "fundingRate": "0.01",
// "openInterest": "100000.32452",
// "lastTradeDatetime": "2021-05-20T01:01:01.000Z",
// "lastTradeTimestamp": "1621490985000",
// "lastTradeQuantity": "1.00000000",
// "ammData": [
// {
// "feeTierId": "1",
// "bidSpreadFee": "0.00040000",
// "askSpreadFee": "0.00040000",
// "baseReservesQuantity": "245.56257825",
// "quoteReservesQuantity": "3424383.3629",
// "currentPrice": "16856.0000"
// }
// ]
// }
//
let mut openInterest: Value = self.safe_string_k(interest.clone(), "openInterest", &[]);
return self.safe_open_interest(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), interest.clone());
m.insert("symbol".to_string(), self.safe_string_k(market.clone(), "symbol", &[]));
m.insert("openInterestAmount".to_string(), openInterest.clone());
m.insert("openInterestValue".to_string(), Value::Null);
m.insert("timestamp".to_string(), self.safe_string_k(interest.clone(), "createdAtTimestamp", &[]));
m.insert("datetime".to_string(), self.safe_string_k(interest, "createdAtDatetime", &[]));
m.insert("baseVolume".to_string(), openInterest);
m.insert("quoteVolume".to_string(), Value::Null);
m
}), &[market]);
Value::Null
}
pub fn sign(&self, mut path: Value, optional_args: &[Value]) -> Value {
let mut api = get_arg(optional_args, 0, Value::from(vec![Value::Str("public".into())]));
let mut method = get_arg(optional_args, 1, Value::Str("GET".into()));
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let __api_empty = Vec::new();
let api = api.as_array().unwrap_or(&__api_empty);
let mut apiName: Value = api.get(0).cloned().unwrap_or(Value::Null);
let mut requestHeaders: Value = Value::Null;
let mut requestBody: Value = Value::Null;
let mut request: Value = self.omit(params.clone(), self.extract_params(path.clone()), &[]);
let mut endpoint: Value = Value::Str(format!("{}{}", Value::Str("/".into()), self.implode_params(path.clone(), params.clone())).into());
let mut apiUrl: Value = self.safe_string(self.urls.as_map().and_then(|__m| __m.get("api")).cloned().unwrap_or(Value::Null), apiName.clone(), &[]);
if (apiUrl == Value::Null) {
panic!("{}", crate::exchange_errors::exchange_error(format!("{}{}", self.id.clone(), Value::Str(" sign() has no API URL for this endpoint".into()))));
}
let mut url: Value = Value::Str(format!("{}{}", apiUrl, endpoint).into());
if (apiName.as_str() == Some("private")) {
self.check_required_credentials(&[]);
let mut nonce: Value = Value::Str(format!("{}", self.microseconds()).into());
let mut timestamp: Value = Value::Str(format!("{}", self.get_timestamp()).into());
if (method.as_str() == Some("GET")) {
let mut payload: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", timestamp, nonce).into()), method).into()), Value::Str("/trading-api/".into())).into()), path).into());
let mut signature: Value = self.hmac(self.encode(payload.clone()), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[Value::Str("hex".into())]);
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BX-TIMESTAMP".to_string(), timestamp.clone());
m.insert("BX-NONCE".to_string(), nonce.clone());
m.insert("BX-SIGNATURE".to_string(), signature.clone());
m
});
} else if (method.as_str() == Some("POST")) {
requestBody = json_stringify(¶ms);
let mut payload: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", Value::Str(format!("{}{}", timestamp, nonce).into()), method).into()), Value::Str("/trading-api/".into())).into()), path).into()), requestBody).into());
let mut digest: Value = self.hash(self.encode(payload), Value::Str("sha256".into()), &[Value::Str("hex".into())]);
let mut signature: Value = self.hmac(self.encode(digest), self.encode(self.secret.clone()), Value::Str("sha256".into()), &[Value::Str("hex".into())]);
requestHeaders = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("BX-TIMESTAMP".to_string(), timestamp);
m.insert("BX-NONCE".to_string(), nonce);
m.insert("BX-SIGNATURE".to_string(), signature);
m.insert("Content-Type".to_string(), Value::Str("application/json".into()));
m
});
if let Value::Dict(__d) = &mut requestHeaders { std::sync::Arc::make_mut(__d).insert("Content-Type".into(), Value::Str("application/json".into())); }
let mut rateLimitToken: Value = self.safe_string_k(request.clone(), "rateLimitToken", &[]);
if (rateLimitToken != Value::Null) {
if let Value::Dict(__d) = &mut requestHeaders { std::sync::Arc::make_mut(__d).insert("BX-RATE-LIMIT-TOKEN".into(), rateLimitToken); }
}
}
if (path.as_str() == Some("v1/users/hmac/login")) {
requestHeaders = (if (requestHeaders == Value::Null) { Value::Map({
let mut m = indexmap::IndexMap::new();
m
}) } else { requestHeaders.clone() });
if let Value::Dict(__d) = &mut requestHeaders { std::sync::Arc::make_mut(__d).insert("BX-PUBLIC-KEY".into(), self.apiKey.clone()); }
} else {
let mut token: Value = self.token.clone();
if (token == Value::Null) {
panic!("{}", crate::exchange_errors::authentication_error(format!("{}{}", self.id.clone(), Value::Str(" requires a token, please call signIn() first".into()))));
}
requestHeaders = (if (requestHeaders == Value::Null) { Value::Map({
let mut m = indexmap::IndexMap::new();
m
}) } else { requestHeaders.clone() });
if let Value::Dict(__d) = &mut requestHeaders { std::sync::Arc::make_mut(__d).insert("Authorization".into(), Value::Str(format!("{}{}", Value::Str("Bearer ".into()), token).into())); }
}
}
if (method.as_str() == Some("GET")) {
let mut query: Value = self.urlencode(request, &[]);
if ((query.len() as i64) as f64) > ((0i64) as f64) {
url = Value::Str(format!("{}{}", url, Value::Str(format!("{}{}", Value::Str("?".into()), query).into())).into());
}
}
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("url".to_string(), url);
m.insert("method".to_string(), method);
m.insert("body".to_string(), requestBody);
m.insert("headers".to_string(), requestHeaders);
m
});
Value::Null
}
/*
* @method
* @name bullish#signIn
* @description sign in, must be called prior to using other authenticated methods
* @see https://api.exchange.bullish.com/docs/api/rest/trading-api/v2/#overview--add-authenticated-request-header
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns response from exchange
*/
pub async fn sign_in(&mut self, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut response: Value = self.private_get_v1_users_hmac_login(&[params]).await;
//
// {
// "authorizer": "113363EFA2CA00007368524E02000000",
// "ownerAuthorizer": "113363EFA2CA00007368524E02000000",
// "token": "eyJhbGciOiJFUzI1NiJ9.eyJpc3MiOiJiMXgtYXV0aC1zZXJ2aWNlIiwic3ViIjoiNDY0OTc4MzAiLCJleHAiOjE3NDczMzgzNDMsIlNUQUdFIjoiQVVUSEVOVElDQVRFRF9XSVRIX0JMT0NLQ0hBSU4ifQ.5FSyrihzc1wsJqAY8pVX36Y4ZXg3HopLJypPEbHg5bBK8FbL_oLxkj6zM_iOYL2a1x6-ICG0pQjr8hF_k8Yg-w"
// }
//
let mut token: Value = self.safe_string_k(response.clone(), "token", &[]);
let mut authorizer: Value = self.safe_string_k(response, "authorizer", &[]);
if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("authorizer".into(), authorizer); }
self.token = token.clone();
{ let __be_tmp = self.sum(&[self.milliseconds(), (match (&((match (&((match (&(Value::Int(1000)), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(60))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })), &(Value::Int(24))) { (Value::Int(x), Value::Int(y)) => Value::Int(x * y), (Value::Int(x), Value::Float(y)) => Value::Float(*x as f64 * *y), (Value::Float(x), Value::Int(y)) => Value::Float(*x * *y as f64), (Value::Float(x), Value::Float(y)) => Value::Float(x * y), _ => Value::Null })]); if let Value::Dict(__d) = &mut self.options { std::sync::Arc::make_mut(__d).insert("tokenExpires".into(), __be_tmp); } }; // token expires in 24 hours
return token;
Value::Null
}
pub async fn handle_token(&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 now: Value = self.milliseconds();
let mut token: Value = self.token.clone();
let mut tokenExpires: Value = self.safe_integer_k(self.options.clone(), "tokenExpires", &[]);
if (token == Value::Null) || (tokenExpires == Value::Null) || (now.as_f64().unwrap_or(f64::NAN) > tokenExpires.as_f64().unwrap_or(f64::NAN)) {
return self.sign_in(&[]).await;
} else {
return self.token.clone();
}
Value::Null
}
pub fn handle_errors(&self, mut httpCode: Value, mut reason: Value, mut url: Value, mut method: Value, mut headers: Value, mut body: Value, mut response: Value, mut requestHeaders: Value, mut requestBody: Value) -> Value {
if (response == Value::Null) {
return Value::Null;
}
//
// {
// "type": "HttpInvalidParameterException",
// "message": "HTTP_INVALID_PARAMETER: '100m' is not a valid time bucket"
// }
//
// {
// "message": "Order size outside valid range",
// "raw": null,
// "errorCode": 6023,
// "errorCodeName": "ORDER_SIZE_OUTSIDE_VALID_RANGE"
// }
//
let mut code: Value = self.safe_string_k(response.clone(), "errorCode", &[]);
let mut type_var: Value = self.safe_string_k(response.clone(), "type", &[]);
if ((code != Value::Null) && (code.as_str() != Some("0")) && (code.as_str() != Some("1001"))) || ((type_var != Value::Null) && (type_var.as_str() == Some("HttpInvalidParameterException"))) {
let mut message: Value = Value::Str("".into());
let mut errorCodeName: Value = self.safe_string_k(response, "errorCodeName", &[]);
if (errorCodeName != Value::Null) {
message = errorCodeName;
} else {
message = type_var;
}
let mut feedback: Value = Value::Str(format!("{}{}", Value::Str(format!("{}{}", self.id.clone(), Value::Str(" ".into())).into()), body).into());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), message.clone(), feedback.clone());
self.throw_broadly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("broad")).cloned().unwrap_or(Value::Null), message, feedback.clone());
self.throw_exactly_matched_exception(self.exceptions.as_map().and_then(|__m| __m.get("exact")).cloned().unwrap_or(Value::Null), code, feedback.clone());
panic!("{}", crate::exchange_errors::exchange_error(feedback));
}
return Value::Null;
Value::Null
}
}