// 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;
use crate::pro::*;
pub struct PacificaCore {
pub parent: crate::exchanges::pacifica::PacificaCore,
}
impl PacificaCore {
pub fn new(config: Option<crate::Value>) -> Self {
let mut s = Self { parent: crate::exchanges::pacifica::PacificaCore::new(config) };
s.init();
s
}
pub fn init(&mut self) {
let described = PacificaCore::describe(self);
self.initialize_properties(described);
<Self as crate::exchange_generated::ExchangeBase>::after_construct(self);
}
/// Compatibility no-op. The old pointer-based dispatch needed a post-move
/// `bind()`; static trait dispatch (review #1) needs no binding, so this
/// just exists so callers that still call it keep compiling.
#[inline]
pub fn bind(&mut self) {}
}
impl crate::exchange::DerivedExchange for PacificaCore {
fn nonce(&self, ) -> crate::Value {
crate::exchange::DerivedExchange::nonce(&self.parent)
}
fn parse_ticker(&self, ticker: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_ticker(&self.parent, ticker, market)
}
fn parse_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_trade(&self.parent, trade, market)
}
fn parse_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_order(&self.parent, order, market)
}
fn parse_market(&self, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_market(&self.parent, market)
}
fn parse_ohlcv(&self, ohlcv: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_ohlcv(&self.parent, ohlcv, market)
}
fn parse_order_book(&self, ob: crate::Value, symbol: crate::Value, ts: crate::Value, bk: crate::Value, ak: crate::Value, pk: crate::Value, ak2: crate::Value, ck: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_order_book(&self.parent, ob, symbol, ts, bk, ak, pk, ak2, ck)
}
fn parse_balance(&self, response: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_balance(&self.parent, response)
}
fn parse_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_position(&self.parent, position, market)
}
fn parse_funding_rate(&self, rate: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_funding_rate(&self.parent, rate, market)
}
fn parse_deposit(&self, tx: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_deposit(&self.parent, tx, currency)
}
fn parse_deposit_address(&self, depositAddress: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_deposit_address(&self.parent, depositAddress, currency)
}
fn parse_last_price(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_last_price(&self.parent, entry, market)
}
fn parse_withdrawal(&self, tx: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_withdrawal(&self.parent, tx, currency)
}
fn parse_ledger_entry(&self, entry: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_ledger_entry(&self.parent, entry, currency)
}
fn parse_transfer(&self, transfer: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_transfer(&self.parent, transfer, currency)
}
fn parse_currency(&self, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_currency(&self.parent, currency)
}
fn parse_bid_ask(&self, bidask: crate::Value, price_key: crate::Value, amount_key: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_bid_ask(&self.parent, bidask, price_key, amount_key, market)
}
fn parse_open_interest(&self, interest: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_open_interest(&self.parent, interest, market)
}
fn parse_liquidation(&self, liquidation: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_liquidation(&self.parent, liquidation, market)
}
fn parse_funding_rate_history(&self, entry: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_funding_rate_history(&self.parent, entry, market)
}
fn parse_margin_modification(&self, data: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_margin_modification(&self.parent, data, market)
}
fn parse_account(&self, account: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_account(&self.parent, account)
}
fn parse_my_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_my_trade(&self.parent, trade, market)
}
fn parse_transaction(&self, transaction: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_transaction(&self.parent, transaction, currency)
}
fn parse_borrow_interest(&self, info: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_borrow_interest(&self.parent, info, market)
}
fn parse_adl_rank(&self, info: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_adl_rank(&self.parent, info, market)
}
fn parse_income(&self, info: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_income(&self.parent, info, market)
}
fn parse_greeks(&self, greeks: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_greeks(&self.parent, greeks, market)
}
fn parse_margin_mode(&self, margin_mode: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_margin_mode(&self.parent, margin_mode, market)
}
fn parse_conversion(&self, conversion: crate::Value, from_currency: crate::Value, to_currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_conversion(&self.parent, conversion, from_currency, to_currency)
}
fn parse_borrow_rate(&self, info: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_borrow_rate(&self.parent, info, currency)
}
fn parse_leverage(&self, leverage: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_leverage(&self.parent, leverage, market)
}
fn parse_market_leverage_tiers(&self, info: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_market_leverage_tiers(&self.parent, info, market)
}
fn parse_deposit_withdraw_fee(&self, fee: crate::Value, currency: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_deposit_withdraw_fee(&self.parent, fee, currency)
}
fn parse_prediction_trade(&self, trade: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_prediction_trade(&self.parent, trade, market)
}
fn parse_prediction_order(&self, order: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_prediction_order(&self.parent, order, market)
}
fn parse_prediction_position(&self, position: crate::Value, market: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::parse_prediction_position(&self.parent, position, market)
}
fn create_expired_option_market(&self, symbol: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::create_expired_option_market(&self.parent, symbol)
}
fn sign(&self, path: crate::Value, api: crate::Value, method: crate::Value, params: crate::Value, headers: crate::Value, body: crate::Value) -> crate::Value {
crate::exchange::DerivedExchange::sign(&self.parent, 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 {
crate::exchange::DerivedExchange::handle_errors(&self.parent, code, reason, url, method, headers, body, response, request_headers, request_body)
}
}
impl crate::exchange_generated::ExchangeBase for PacificaCore {
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_ws" => self.cancel_all_orders_ws(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_order_ws" => self.cancel_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"cancel_orders_ws" => self.cancel_orders_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"create_order_ws" => self.create_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"edit_order_ws" => self.edit_order_ws(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null), args.get(2).cloned().unwrap_or(crate::Value::Null), args.get(3).cloned().unwrap_or(crate::Value::Null), &args.get(4..).unwrap_or(&[]).to_vec()[..]).await,
"handle_error_message" => self.handle_error_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_pong" => self.handle_pong(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_ws_tickers" => self.handle_ws_tickers(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ws_ticker" => self.parse_ws_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"request_id" => self.request_id(),
"un_watch_my_trades" => self.un_watch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_ohlcv" => self.un_watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_order_book" => self.un_watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_orders" => self.un_watch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_tickers" => self.un_watch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"un_watch_trades" => self.un_watch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_my_trades" => self.watch_my_trades(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_ohlcv" => self.watch_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_order_book" => self.watch_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_orders" => self.watch_orders(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_ticker" => self.watch_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"watch_tickers" => self.watch_tickers(&args.get(0..).unwrap_or(&[]).to_vec()[..]).await,
"watch_trades" => self.watch_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]).await,
"wrap_as_post_action" => self.wrap_as_post_action(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
// Go-style inheritance: an un-overridden method dispatches to the parent core.
_ => crate::exchange_generated::ExchangeBase::call_dynamic(&mut self.parent, method, args).await,
}
})
}
}
impl PacificaCore {
/// Synchronous WS handler dispatch — routes a handler-name string (from the
/// venue's handle_message dispatch table) to the real handler method.
#[allow(dead_code, unreachable_patterns, clippy::all)]
pub fn dispatch_ws_handler(&mut self, __name: &crate::Value, args: &[crate::Value]) -> crate::Value {
let __n = match __name { crate::Value::Str(s) => s.as_str(), _ => return crate::Value::Null };
match __n {
"cancel_all_orders_ws" => { crate::exchange_stubs::enqueue_spawn("cancel_all_orders_ws", args.to_vec()); crate::Value::Null },
"cancel_order_ws" => { crate::exchange_stubs::enqueue_spawn("cancel_order_ws", args.to_vec()); crate::Value::Null },
"cancel_orders_ws" => { crate::exchange_stubs::enqueue_spawn("cancel_orders_ws", args.to_vec()); crate::Value::Null },
"create_order_ws" => { crate::exchange_stubs::enqueue_spawn("create_order_ws", args.to_vec()); crate::Value::Null },
"edit_order_ws" => { crate::exchange_stubs::enqueue_spawn("edit_order_ws", args.to_vec()); crate::Value::Null },
"handle_error_message" => self.handle_error_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_message" => { self.handle_message(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_my_trades" => { self.handle_my_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_my_trades_unsubscription" => { self.handle_my_trades_unsubscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_ohlcv" => { self.handle_ohlcv(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_ohlcv_unsubscription" => { self.handle_ohlcv_unsubscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order" => { self.handle_order(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order_book" => { self.handle_order_book(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order_book_unsubscription" => { self.handle_order_book_unsubscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_order_unsubscription" => { self.handle_order_unsubscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_pong" => self.handle_pong(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"handle_subscription_response" => { self.handle_subscription_response(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_tickers_unsubscription" => { self.handle_tickers_unsubscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_trades" => { self.handle_trades(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_trades_unsubscription" => { self.handle_trades_unsubscription(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_ws_post" => { self.handle_ws_post(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)); crate::Value::Null },
"handle_ws_tickers" => self.handle_ws_tickers(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
"parse_ws_ticker" => self.parse_ws_ticker(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"parse_ws_trade" => self.parse_ws_trade(args.get(0).cloned().unwrap_or(crate::Value::Null), &args.get(1..).unwrap_or(&[]).to_vec()[..]),
"ping" => self.ping(args.get(0).cloned().unwrap_or(crate::Value::Null)),
"request_id" => self.request_id(),
"setup_api_key_headers" => { self.setup_api_key_headers(&args.get(0..).unwrap_or(&[]).to_vec()[..]); crate::Value::Null },
"un_watch_my_trades" => { crate::exchange_stubs::enqueue_spawn("un_watch_my_trades", args.to_vec()); crate::Value::Null },
"un_watch_ohlcv" => { crate::exchange_stubs::enqueue_spawn("un_watch_ohlcv", args.to_vec()); crate::Value::Null },
"un_watch_order_book" => { crate::exchange_stubs::enqueue_spawn("un_watch_order_book", args.to_vec()); crate::Value::Null },
"un_watch_orders" => { crate::exchange_stubs::enqueue_spawn("un_watch_orders", args.to_vec()); crate::Value::Null },
"un_watch_tickers" => { crate::exchange_stubs::enqueue_spawn("un_watch_tickers", args.to_vec()); crate::Value::Null },
"un_watch_trades" => { crate::exchange_stubs::enqueue_spawn("un_watch_trades", args.to_vec()); crate::Value::Null },
"watch_my_trades" => { crate::exchange_stubs::enqueue_spawn("watch_my_trades", args.to_vec()); crate::Value::Null },
"watch_ohlcv" => { crate::exchange_stubs::enqueue_spawn("watch_ohlcv", args.to_vec()); crate::Value::Null },
"watch_order_book" => { crate::exchange_stubs::enqueue_spawn("watch_order_book", args.to_vec()); crate::Value::Null },
"watch_orders" => { crate::exchange_stubs::enqueue_spawn("watch_orders", args.to_vec()); crate::Value::Null },
"watch_ticker" => { crate::exchange_stubs::enqueue_spawn("watch_ticker", args.to_vec()); crate::Value::Null },
"watch_tickers" => { crate::exchange_stubs::enqueue_spawn("watch_tickers", args.to_vec()); crate::Value::Null },
"watch_trades" => { crate::exchange_stubs::enqueue_spawn("watch_trades", args.to_vec()); crate::Value::Null },
"wrap_as_post_action" => self.wrap_as_post_action(args.get(0).cloned().unwrap_or(crate::Value::Null), args.get(1).cloned().unwrap_or(crate::Value::Null)),
_ => crate::Value::Null,
}
}
}
impl std::ops::Deref for PacificaCore {
type Target = crate::exchange::Exchange;
fn deref(&self) -> &crate::exchange::Exchange { std::ops::Deref::deref(&self.parent) }
}
impl std::ops::DerefMut for PacificaCore {
fn deref_mut(&mut self) -> &mut crate::exchange::Exchange { std::ops::DerefMut::deref_mut(&mut self.parent) }
}
impl PacificaCore {
pub fn describe(&self) -> Value {
return self.deep_extend(self.parent.describe(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("has".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Bool(true));
m.insert("cancelOrderWs".to_string(), Value::Bool(true));
m.insert("cancelOrdersWs".to_string(), Value::Bool(true));
m.insert("cancelAllOrdersWs".to_string(), Value::Bool(true));
m.insert("createOrderWs".to_string(), Value::Bool(true));
m.insert("createOrdersWs".to_string(), Value::Bool(false));
m.insert("editOrderWs".to_string(), Value::Bool(true));
m.insert("watchBalance".to_string(), Value::Bool(false));
m.insert("watchMyTrades".to_string(), Value::Bool(true));
m.insert("watchOHLCV".to_string(), Value::Bool(true));
m.insert("watchOrderBook".to_string(), Value::Bool(true));
m.insert("watchOrders".to_string(), Value::Bool(true));
m.insert("watchTicker".to_string(), Value::Bool(true));
m.insert("watchTickers".to_string(), Value::Bool(true));
m.insert("watchTrades".to_string(), Value::Bool(true));
m.insert("watchTradesForSymbols".to_string(), Value::Bool(false));
m.insert("watchPosition".to_string(), Value::Bool(false));
m.insert("unWatchOrderBook".to_string(), Value::Bool(true));
m.insert("unWatchTickers".to_string(), Value::Bool(true));
m.insert("unWatchTrades".to_string(), Value::Bool(true));
m.insert("unWatchOHLCV".to_string(), Value::Bool(true));
m.insert("unWatchMyTrades".to_string(), Value::Bool(true));
m.insert("unWatchOrders".to_string(), Value::Bool(true));
m
}));
m.insert("urls".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("api".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("wss://ws.pacifica.fi/ws".to_string()));
m
}));
m
}));
m.insert("test".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("public".to_string(), Value::Str("wss://test-ws.pacifica.fi/ws".to_string()));
m
}));
m
}));
m
}));
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("options".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("headers".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m
}));
m.insert("streaming".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ping".to_string(), Value::Str("ping".to_string()).clone());
m.insert("keepAlive".to_string(), Value::Int(20000));
m
}));
m.insert("exceptions".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("ws".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("exact".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
}));
m
}));
m
})]);
Value::Null
}
pub fn setup_api_key_headers(&self, optional_args: &[Value]) {
let mut key = get_arg(optional_args, 0, Value::Null);
let mut headers: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
if !is_equal(&key, &Value::Null) {
add_element_to_object(&mut headers, &Value::Str("PF-API-KEY".to_string()), key.clone());
} else {
if !is_equal(&self.handle_option(Value::Str("setupApiKeyHeaders".to_string()), Value::Str("apiKey".to_string()), &[]), &Value::Null) {
add_element_to_object(&mut headers, &Value::Str("PF-API-KEY".to_string()), get_value(&self.options, &Value::Str("apiKey".to_string())));
}
}
add_element_to_object(get_value_mut(get_value_mut(unsafe { crate::runtime::coerce_value_to_mut(&self.options) }, &Value::Str("ws".to_string())), &Value::Str("options".to_string())), &Value::Str("headers".to_string()), headers.clone());
}
/*
* @method
* @name pacifica#createOrderWs
* @description create a trade order
* @see https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/create-market-order
* @see https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/create-limit-order
* @param {string} symbol unified symbol of the market to create an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {float} [params.triggerPrice] The price a trigger order is triggered at
* @param {float|undefined} [params.stopLossPrice] the price that a stop loss order is triggered at (optional provide stopLossCloid)
* @param {float|undefined} [params.takeProfitPrice] the price that a take profit order is triggered at (optional provide takeProfitCloid)
* @param {string|undefined} [params.timeInForce] "GTC", "IOC", or "PO" or "ALO" or "PO_TOB" (or "TOB" - PO by top of book)
* @param {bool|undefined} [params.reduceOnly] Ensures that the executed order does not flip the opened position.
* @param {string|undefined} [params.clientOrderId] client order id, (optional uuid v4 e.g.: f47ac10b-58cc-4372-a567-0e02b2c3d479)
* @param {int|undefined} [params.expiryWindow] time to live in milliseconds
* @param {string|undefined} [params.agentAddress] only if agent wallet in use.
* @param {string|undefined} [params.originAddress] only if agent in use. Agent's owner address ( default = credentials walletAddress )
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn create_order_ws(&mut self, mut symbol: Value, mut type_var: Value, mut side: Value, mut amount: Value, optional_args: &[Value]) -> Value {
let mut price = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut requestoperationTypeVariable = self.parent.create_order_request(symbol.clone(), type_var.clone(), side.clone(), amount.clone(), &[price.clone(), params.clone()]);
let mut request: Value = get_value(&requestoperationTypeVariable, &Value::Int(0));
let mut operationType: Value = get_value(&requestoperationTypeVariable, &Value::Int(1));
params = self.omit(params.clone(), Value::List(vec![Value::Str("reduceOnly".to_string()), Value::Str("clientOrderId".to_string()), Value::Str("stopLimitPrice".to_string()), Value::Str("timeInForce".to_string()), Value::Str("triggerPrice".to_string()), Value::Str("stopLossCloid".to_string()), Value::Str("stopLossPrice".to_string()), Value::Str("stopLossLimitPrice".to_string()), Value::Str("takeProfitCloid".to_string()), Value::Str("takeProfitPrice".to_string()), Value::Str("takeProfitLimitPrice".to_string()), Value::Str("expiryWindow".to_string()), Value::Str("agentAddress".to_string()), Value::Str("originAddress".to_string())]), &[]);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut wsRequest: Value = self.wrap_as_post_action(operationType.clone(), request.clone());
let mut requestId: Value = self.safe_string_k(wsRequest.clone(), "id", &[]);
if is_equal(&operationType, &Value::Str("create_stop_order".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrderWs() do not support stop order type of order. Check provided arguments correctly!".to_string()))));
} else if is_equal(&operationType, &Value::Str("set_position_tpsl".to_string())) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" createOrderWs() do not support set position tpsl type of order. Check provided arguments correctly!".to_string()))));
}
let mut response: Value = self.watch(url.clone(), requestId.clone(), &[wsRequest.clone(), requestId.clone()]).await;
//
// market order
// {
// "code": 200,
// "data": {
// "I": "79f948fd-7556-4066-a128-083f3ea49322",
// "i": 645953,
// "s": "BTC"
// },
// "id": "660065de-8f32-46ad-ba1e-83c93d3e3966",
// "t": 1749223025962,
// "type": "create_market_order"
// }
//
// limit order
// {
// "code": 200,
// "data": {
// "I": "79f948fd-7556-4066-a128-083f3ea49322",
// "i": 645953,
// "s": "BTC"
// },
// "id": "660065de-8f32-46ad-ba1e-83c93d3e3966",
// "t": 1749223025962,
// "type": "create_order"
// }
//
let mut code: Value = self.safe_integer_k(response.clone(), "code", &[]);
let mut success: bool = false;
if is_equal(&code, &Value::Int(200)) {
success = true;
}
let mut status: Value = Value::Null;
if !is_true(&success) {
status = Value::Str("rejected".to_string());
} else {
status = Value::Str("open".to_string());
}
let mut order: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderId: Value = self.safe_string_k(order.clone(), "i", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "I", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("status".to_string(), status.clone());
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m
}), &[]);
Value::Null
}
/*
* @method
* @name pacifica#editOrderWs
* @description edit a trade order
* @see https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/edit-order
* @param {string} id edit order id
* @param {string} symbol unified symbol of the market to edit an order in
* @param {string} type 'market' or 'limit'
* @param {string} side 'buy' or 'sell'
* @param {float} amount how much of currency you want to trade in units of base currency
* @param {float} price the price at which the order is to be fulfilled, in units of the quote currency
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string} [params.clientOrderId] client order id, (optional uuid v4 e.g.: f47ac10b-58cc-4372-a567-0e02b2c3d479)
* @param {int|undefined} [params.expiryWindow] time to live in milliseconds
* @param {string|undefined} [params.agentAddress] only if agent wallet in use
* @param {string|undefined} [params.originAddress] only if agent in use. Agent's owner address ( default = credentials walletAddress )
* @returns {object} an [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn edit_order_ws(&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
}));
let mut batchOperationType: Value = Value::Str("edit_order".to_string());
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut request: Value = self.parent.edit_order_request(id.clone(), symbol.clone(), type_var.clone(), side.clone(), amount.clone(), price.clone(), market.clone(), &[params.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("originAddress".to_string()), Value::Str("agentAddress".to_string()), Value::Str("expiryWindow".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut wsRequest: Value = self.wrap_as_post_action(batchOperationType.clone(), request.clone());
let mut requestId: Value = self.safe_string_k(wsRequest.clone(), "id", &[]);
let mut response: Value = self.watch(url.clone(), requestId.clone(), &[wsRequest.clone(), requestId.clone()]).await;
// {
// "code": 200,
// "data": {
// "I": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
// "i": 645954,
// "s": "BTC"
// },
// "id": "660065de-8f32-46ad-ba1e-83c93d3e3966",
// "t": 1749223026150,
// "type": "edit_order"
// }
let mut code: Value = self.safe_integer_k(response.clone(), "code", &[]);
let mut success: bool = false;
if is_equal(&code, &Value::Int(200)) {
success = true;
}
let mut status: Value = Value::Null;
if !is_true(&success) {
status = Value::Str("rejected".to_string());
} else {
status = Value::Str("open".to_string());
}
let mut order: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderId: Value = self.safe_string_k(order.clone(), "i", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "I", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("status".to_string(), status.clone());
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m
}), &[]);
Value::Null
}
/*
* @method
* @name pacifica#cancelOrdersWs
* @description cancel multiple orders
* @see https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/batch-order
* @see https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/cancel-order
* @param {string[]} ids order ids
* @param {string} [symbol] unified market symbol
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string|string[]} [params.clientOrderId] client order ids, (optional uuid v4 e.g.: f47ac10b-58cc-4372-a567-0e02b2c3d479)
* @param {int|undefined} [params.expiryWindow] time to live in milliseconds
* @param {string|undefined} [params.agentAddress] only if agent wallet in use
* @param {string|undefined} [params.originAddress] only if agent in use. Agent's owner address ( default = credentials walletAddress )
* @returns {object} an list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_orders_ws(&mut self, mut ids: Value, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
let mut batchOperationType: Value = Value::Str("batch_orders".to_string());
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str("cancelOrders() requires a \"symbol\" argument!".to_string()))));
}
let mut request: Value = self.parent.cancel_orders_request(ids.clone(), &[symbol.clone(), params.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("originAddress".to_string()), Value::Str("agentAddress".to_string()), Value::Str("expiryWindow".to_string()), Value::Str("clientOrderIds".to_string())]), &[]);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut wsRequest: Value = self.wrap_as_post_action(batchOperationType.clone(), request.clone());
let mut requestId: Value = self.safe_string_k(wsRequest.clone(), "id", &[]);
let mut response: Value = self.watch(url.clone(), requestId.clone(), &[wsRequest.clone(), requestId.clone()]).await;
//
// {
// "code": 200,
// "data": {
// "results": [
// {
// "success": true,
// "order_id": 645953,
// "client_order_id": "57a5efb1-bb96-49a5-8bfd-f25d5f22bc7e",
// "symbol": "BTC"
// },
// {
// "success": true,
// "order_id": 645954,
// "symbol": "ETH"
// }
// ]
// },
// "id": "660065de-8f32-46ad-ba1e-83c93d3e3966",
// "t": 1749223025962,
// "type": "batch_orders"
// }
//
let mut data: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut results: Value = self.safe_list_k(data.clone(), "results", &[Value::List(vec![])]);
let mut ordersToReturn: Value = Value::List(vec![]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_569: bool = true;
while { if !__for_first_569 { i = add(&i, &Value::Int(1)); } __for_first_569 = false; is_less_than(&i, &get_array_length(&results)) } {
let mut order: Value = get_value(&results, &i);
let mut order: Value = get_value(&results, &i);
let mut error: Value = self.safe_string_k(order.clone(), "error", &[]);
let mut success: Value = self.safe_bool_k(order.clone(), "success", &[Value::Bool(false)]);
let mut marketId: Value = self.safe_string_k(order.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut orderId: Value = self.safe_string_k(order.clone(), "i", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "I", &[]);
let mut status: Value = Value::Null;
if is_true(&(!is_equal(&error, &Value::Null))) || is_true(&(!is_equal(&success, &Value::Bool(true)))) {
status = Value::Str("closed".to_string());
} else {
status = Value::Str("canceled".to_string());
}
append_to_array(&mut ordersToReturn, self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("status".to_string(), status.clone());
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), get_value(&market, &Value::Str("symbol".to_string())));
m
}), &[]));
}
}
return ordersToReturn;
Value::Null
}
/*
* @method
* @name pacifica#cancelOrderWs
* @description cancels an open order
* @see https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/cancel-order
* @param {string} id order id
* @param {string} symbol unified symbol of the market the order was made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {bool|undefined} [params.stop] necessary if this is to cancel a stop order.
* @param {string|undefined} [params.clientOrderId] client order id, (optional uuid v4 e.g.: f47ac10b-58cc-4372-a567-0e02b2c3d479)
* @param {int|undefined} [params.expiryWindow] time to live in milliseconds
* @param {string|undefined} [params.agentAddress] only if agent wallet in use
* @param {string|undefined} [params.originAddress] only if agent in use. Agent's owner address ( default = credentials walletAddress )
* @returns {object} An [order structure]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_order_ws(&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
}));
let mut operationType: Value = Value::Str("cancel_order".to_string());
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str(" cancelOrderWs() requires a symbol argument".to_string()))));
}
let mut request: Value = self.parent.cancel_order_request(id.clone(), &[symbol.clone(), params.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("originAddress".to_string()), Value::Str("agentAddress".to_string()), Value::Str("expiryWindow".to_string()), Value::Str("trigger".to_string()), Value::Str("stop".to_string()), Value::Str("clientOrderId".to_string())]), &[]);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut wsRequest: Value = self.wrap_as_post_action(operationType.clone(), request.clone());
let mut requestId: Value = self.safe_string_k(wsRequest.clone(), "id", &[]);
let mut response: Value = self.watch(url.clone(), requestId.clone(), &[wsRequest.clone(), requestId.clone()]).await;
//
// {
// "code": 200,
// "data": {
// "I": "79f948fd-7556-4066-a128-083f3ea49322",
// "i": null,
// "s": "BTC"
// },
// "id": "1bb2b72f-f545-4938-8a38-c5cda8823675",
// "t": 1749223343610,
// "type": "cancel_order"
// }
//
let mut code: Value = self.safe_integer_k(response.clone(), "code", &[]);
let mut success: bool = false;
if is_equal(&code, &Value::Int(200)) {
success = true;
}
let mut status: Value = Value::Null;
if !is_true(&success) {
status = Value::Str("rejected".to_string());
} else {
status = Value::Str("open".to_string());
}
let mut order: Value = self.safe_dict_k(response.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut orderId: Value = self.safe_string_k(order.clone(), "i", &[]);
let mut clientOrderId: Value = self.safe_string_k(order.clone(), "I", &[]);
return self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), orderId.clone());
m.insert("clientOrderId".to_string(), clientOrderId.clone());
m.insert("status".to_string(), status.clone());
m.insert("info".to_string(), response.clone());
m.insert("symbol".to_string(), symbol.clone());
m
}), &[]);
Value::Null
}
/*
* @method
* @name pacifica#cancelAllOrdersWs
* @description cancel all open orders in a market
* @see https://docs.pacifica.fi/api-documentation/api/websocket/trading-operations/cancel-all-orders
* @param {string} symbol (optional) unified market symbol of the market to cancel orders in.
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {boolean|undefined} [params.excludeReduceOnly] whether to exclude reduce-only orders
* @param {int|undefined} [params.expiryWindow] time to live in milliseconds
* @param {string|undefined} [params.agentAddress] only if agent wallet in use
* @param {string|undefined} [params.originAddress] only if agent in use. Agent's owner address ( default = credentials walletAddress )
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn cancel_all_orders_ws(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut operationType: Value = Value::Str("cancel_all_orders".to_string());
let mut request: Value = self.parent.cancel_all_orders_request(symbol.clone(), &[params.clone()]);
params = self.omit(params.clone(), Value::List(vec![Value::Str("excludeReduceOnly".to_string()), Value::Str("agentAddress".to_string()), Value::Str("originAddress".to_string()), Value::Str("expiryWindow".to_string())]), &[]);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut wsRequest: Value = self.wrap_as_post_action(operationType.clone(), request.clone());
let mut requestId: Value = self.safe_string_k(wsRequest.clone(), "id", &[]);
let mut response: Value = self.watch(url.clone(), requestId.clone(), &[wsRequest.clone(), requestId.clone()]).await;
return Value::List(vec![self.safe_order(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), response.clone());
m
}), &[])]);
Value::Null
}
/*
* @method
* @name pacifica#watchOrderBook
* @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/orderbook
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {int} [limit] the maximum amount of order book entries to return
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int|undefined} [params.aggLevel] aggregation level for price grouping. Defaults to 1. Can be 1, 10, 100, 1000, 10000
* @returns {object} an [order book structure]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn watch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut limit = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.setup_api_key_headers(&[]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut aggLevel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOrderBook".to_string()), Value::Str("aggLevel".to_string()), &[Value::Int(1)]); aggLevel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("subscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("book".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("agg_level".to_string(), aggLevel.clone());
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
let mut orderbook: Value = self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
return orderbook.limit();
Value::Null
}
/*
* @method
* @name pacifica#unWatchOrderBook
* @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/orderbook
* @param {string} symbol unified symbol of the market to fetch the order book for
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {int|undefined} [params.aggLevel] aggregation level for price grouping. Defaults to 1. Can be 1, 10, 100, 1000, 10000
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure}
*/
pub async fn un_watch_order_book(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
let mut aggLevel: Value = Value::Null;
{ let __destr_tmp = self.handle_option_and_params(params.clone(), Value::Str("watchOrderBook".to_string()), Value::Str("aggLevel".to_string()), &[Value::Int(1)]); aggLevel = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut subMessageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("book".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("agg_level".to_string(), aggLevel.clone());
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
Value::Null
}
pub fn handle_order_book(&mut self, mut client: Value, mut message: Value) {
//
// {
// "channel": "book",
// "data": {
// "l": [
// [
// {
// "a": "37.86",
// "n": 4,
// "p": "157.47"
// },
// // ... other aggegated bid levels
// ],
// [
// {
// "a": "12.7",
// "n": 2,
// "p": "157.49"
// },
// {
// "a": "44.45",
// "n": 3,
// "p": "157.5"
// },
// // ... other aggregated ask levels
// ]
// ],
// "s": "SOL",
// "t": 1749051881187,
// "li": 1559885104 // sequence id - last order id
// }
// }
//
let mut entry: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(entry.clone(), "s", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut levels: Value = self.safe_list_k(entry.clone(), "l", &[Value::List(vec![])]);
let mut result: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("bids".to_string(), self.safe_list(levels.clone(), Value::Int(0), &[Value::List(vec![])]));
m.insert("asks".to_string(), self.safe_list(levels.clone(), Value::Int(1), &[Value::List(vec![])]));
m
});
let mut timestamp: Value = self.safe_integer_k(entry.clone(), "t", &[]);
let mut snapshot: Value = self.parse_order_book(result.clone(), symbol.clone(), &[timestamp.clone(), Value::Str("bids".to_string()), Value::Str("asks".to_string()), Value::Str("p".to_string()), Value::Str("a".to_string())]);
let mut nonce: Value = self.safe_integer_k(entry.clone(), "li", &[]);
if is_true(&(!is_equal(&nonce, &Value::Null))) && is_true(&(!is_equal(&nonce, &Value::Int(0)))) {
add_element_to_object(&mut snapshot, &Value::Str("nonce".to_string()), nonce.clone());
}
if !is_true(&(Value::Bool(in_op(&self.orderbooks, &symbol)))) {
let mut ob: Value = self.order_book(&[snapshot.clone()]);
add_element_to_object(&mut self.orderbooks, &symbol, ob.clone());
}
let mut orderbook: Value = get_value(&self.orderbooks, &symbol);
orderbook.reset(snapshot.clone());
let mut messageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
client.resolve(&[orderbook.clone(), messageHash.clone()]);
}
/*
* @method
* @name pacifica#watchTicker
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/prices
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
* @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 watch_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
}));
let mut tickers: Value = self.watch_tickers(&[Value::List(vec![symbol.clone()]), params.clone()]).await;
return get_value(&tickers, &symbol);
Value::Null
}
/*
* @method
* @name pacifica#watchTickers
* @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/prices
* @param {string[]} symbols 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 watch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
self.setup_api_key_headers(&[]);
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true)]);
let mut messageHash: Value = Value::Str("tickers".to_string());
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("subscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("prices".to_string()));
m
}));
m
});
let __ws_arg_0 = self.extend(request.clone(), &[params.clone()]);
let mut tickers: Value = self.watch(url.clone(), messageHash.clone(), &[__ws_arg_0, messageHash.clone()]).await;
if is_true(&self.newUpdates) {
return self.filter_by_array_tickers(tickers.clone(), Value::Str("symbol".to_string()), &[symbols.clone()]);
}
return self.tickers.clone();
Value::Null
}
/*
* @method
* @name pacifica#unWatchTickers
* @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/prices
* @param {string[]} symbols 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 un_watch_tickers(&mut self, optional_args: &[Value]) -> Value {
let mut symbols = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
symbols = self.market_symbols(&[symbols.clone(), Value::Null, Value::Bool(true)]);
let mut subMessageHash: Value = Value::Str("tickers".to_string());
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("prices".to_string()));
m
}));
m
});
let __ws_arg_1 = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[__ws_arg_1, messageHash.clone()]).await;
Value::Null
}
/*
* @method
* @name pacifica#watchMyTrades
* @description watches information on multiple trades made by the user
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/account-trades
* @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|undefined} [params.account] will default to options' walletAddress if not provided
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn watch_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
}));
let mut userAddress: Value = Value::Null;
{ let __destr_tmp = self.parent.handle_origin_and_single_address(Value::Str("watchMyTrades".to_string()), params.clone()); userAddress = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut messageHash: Value = Value::Str("myTrades".to_string());
if !is_equal(&symbol, &Value::Null) {
symbol = self.symbol(symbol.clone());
messageHash = add(&messageHash, &add(&Value::Str(":".to_string()), &symbol));
}
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("subscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("account_trades".to_string()));
m.insert("account".to_string(), userAddress.clone());
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
let mut trades: Value = self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
if is_true(&self.newUpdates) {
limit = trades.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_symbol_since_limit(trades.clone(), &[symbol.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
/*
* @method
* @name pacifica#unWatchMyTrades
* @description unWatches information on multiple trades made by the user
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/account-trades
* @param {string} symbol unified market symbol of the market orders were made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string|undefined} [params.account] will default to options' walletAddress if not provided
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn un_watch_my_trades(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if !is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" unWatchMyTrades does not support a symbol argument, unWatch from all markets only".to_string()))));
}
let mut userAddress: Value = Value::Null;
{ let __destr_tmp = self.parent.handle_origin_and_single_address(Value::Str("unWatchMyTrades".to_string()), params.clone()); userAddress = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut messageHash: Value = Value::Str("unsubscribe:myTrades".to_string());
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("account_trades".to_string()));
m.insert("account".to_string(), userAddress.clone());
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
Value::Null
}
pub fn handle_ws_tickers(&mut self, mut client: Value, mut message: Value) -> Value {
//
// {
// "channel": "prices",
// "data": [
// {
// "funding": "0.0000125",
// "mark": "105473",
// "mid": "105476",
// "next_funding": "0.0000125",
// "open_interest": "0.00524",
// "oracle": "105473",
// "symbol": "BTC",
// "timestamp": 1749051612681,
// "volume_24h": "63265.87522",
// "yesterday_price": "955476"
// }
// // ... other symbol prices
// ],
// }
//
let mut parsedTickers: Value = Value::List(vec![]);
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
{
let mut i: Value = Value::Int(0);
let mut __for_first_570: bool = true;
while { if !__for_first_570 { i = add(&i, &Value::Int(1)); } __for_first_570 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut info: Value = get_value(&data, &i);
let mut info: Value = get_value(&data, &i);
let mut marketId: Value = self.safe_string_k(info.clone(), "symbol", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut ticker: Value = self.parse_ws_ticker(info.clone(), &[market.clone()]);
add_element_to_object(&mut self.tickers, &symbol, ticker.clone());
append_to_array(&mut parsedTickers, ticker.clone());
}
}
let mut tickers: Value = self.index_by(parsedTickers.clone(), Value::Str("symbol".to_string()));
client.resolve(&[tickers.clone(), Value::Str("tickers".to_string())]);
return Value::Bool(true);
Value::Null
}
pub fn parse_ws_ticker(&self, mut rawTicker: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
return self.parse_ticker(rawTicker.clone(), &[market.clone()]);
Value::Null
}
pub fn handle_my_trades(&mut self, mut client: Value, mut message: Value) {
//
// {
// "channel": "account_trades",
// "data": [
// {
// "h": 80063441, // history id
// "i": 1559912767, // oid
// "I": null, // cloid
// "u": "BrZp5bidJ3WUvceSq7X78bhjTfZXeezzGvGEV4hAYKTa", // account address
// "s": "BTC", // symbol
// "p": "89477", // price
// "o": "89505", // entry price
// "a": "0.00036", // amount
// "te": "fulfill_taker",
// "ts": "close_long",
// "tc": "normal", // trade type
// "f": "0.012885", // fee
// "n": "-0.022965", // pnl
// "t": 1765018588190,
// "li": 1559912767
// }
// ]
// }
//
if is_equal(&self.myTrades, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
self.myTrades = ArrayCacheBySymbolById::new(limit.clone());
}
let mut trades: Value = self.myTrades.clone();
let mut symbols: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut dataLength: Value = get_array_length(&data);
if is_equal(&dataLength, &Value::Int(0)) {
return;
}
{
let mut i: Value = Value::Int(0);
let mut __for_first_571: bool = true;
while { if !__for_first_571 { i = add(&i, &Value::Int(1)); } __for_first_571 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rawTrade: Value = get_value(&data, &i);
let mut rawTrade: Value = get_value(&data, &i);
let mut parsed: Value = self.parse_ws_trade(rawTrade.clone(), &[]);
let mut symbol: Value = get_value(&parsed, &Value::Str("symbol".to_string()));
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut symbols, &symbol, Value::Bool(true));
}
trades.append(parsed.clone());
}
}
let mut keys: Value = object_keys(&symbols);
{
let mut i: Value = Value::Int(0);
let mut __for_first_572: bool = true;
while { if !__for_first_572 { i = add(&i, &Value::Int(1)); } __for_first_572 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut currentMessageHash: Value = add(&Value::Str("myTrades:".to_string()), &get_value(&keys, &i));
client.resolve(&[trades.clone(), currentMessageHash.clone()]);
}
}
// non-symbol specific
let mut messageHash: Value = Value::Str("myTrades".to_string());
client.resolve(&[trades.clone(), messageHash.clone()]);
}
/*
* @method
* @name pacifica#watchTrades
* @description watches information on multiple trades made in a market
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/trades
* @param {string} symbol unified market symbol of the market trades were made in
* @param {int} [since] the earliest time in ms to fetch trades for
* @param {int} [limit] the maximum number of trade structures to retrieve
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn watch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut since = get_arg(optional_args, 0, Value::Null);
let mut limit = get_arg(optional_args, 1, Value::Null);
let mut params = get_arg(optional_args, 2, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut messageHash: Value = add(&Value::Str("trade:".to_string()), &symbol);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("subscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("trades".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
let mut trades: Value = self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
if is_true(&self.newUpdates) {
limit = trades.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_since_limit(trades.clone(), &[since.clone(), limit.clone(), Value::Str("timestamp".to_string()), Value::Bool(true)]);
Value::Null
}
/*
* @method
* @name pacifica#unWatchTrades
* @description unWatches information on multiple trades made in a market
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/trades
* @param {string} symbol unified market symbol of the market trades were made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/?id=trade-structure}
*/
pub async fn un_watch_trades(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut params = get_arg(optional_args, 0, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut subMessageHash: Value = add(&Value::Str("trade:".to_string()), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("trades".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
Value::Null
}
pub fn handle_trades(&mut self, mut client: Value, mut message: Value) {
//
// {
// "channel": "trades",
// "data": [
// {
// "h": 80062522,
// "s": "BTC",
// "a": "0.00001",
// "p": "89471",
// "d": "close_short",
// "tc": "normal",
// "t": 1765018379085,
// "li": 1559885104
// }
// ]
// }
//
let mut entry: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
let mut first: Value = self.safe_dict(entry.clone(), Value::Int(0), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(first.clone(), "s", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
if !is_true(&(Value::Bool(in_op(&self.trades, &symbol)))) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "tradesLimit", &[Value::Int(1000)]);
let mut stored = ArrayCache::new(limit.clone());
add_element_to_object(&mut self.trades, &symbol, stored.clone());
}
let mut trades: Value = get_value(&self.trades, &symbol);
{
let mut i: Value = Value::Int(0);
let mut __for_first_573: bool = true;
while { if !__for_first_573 { i = add(&i, &Value::Int(1)); } __for_first_573 = false; is_less_than(&i, &get_array_length(&entry)) } {
let mut data: Value = self.safe_dict(entry.clone(), i.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut trade: Value = self.parse_ws_trade(data.clone(), &[]);
trades.append(trade.clone());
}
}
let mut messageHash: Value = add(&Value::Str("trade:".to_string()), &symbol);
client.resolve(&[trades.clone(), messageHash.clone()]);
}
pub fn parse_ws_trade(&self, mut trade: Value, optional_args: &[Value]) -> Value {
let mut market = get_arg(optional_args, 0, Value::Null);
//
// fetchMyTrades
//
// {
// "h": 80063441, // history id
// "i": 1559912767, // oid
// "I": null, // cloid
// "u": "BrZp5bidJ3WUvceSq7X78bhjTfZXeezzGvGEV4hAYKTa", // account address
// "s": "BTC", // symbol
// "p": "89477", // price
// "o": "89505", // entry price
// "a": "0.00036", // amount
// "te": "fulfill_taker",
// "ts": "close_long",
// "tc": "normal", // trade type
// "f": "0.012885", // fee
// "n": "-0.022965", // pnl
// "t": 1765018588190,
// "li": 1559912767
// }
//
// fetchTrades
//
// {
// "h": 80062522,
// "s": "BTC",
// "a": "0.00001",
// "p": "89471",
// "d": "close_short",
// "tc": "normal",
// "t": 1765018379085,
// "li": 1559885104
// }
//
let mut timestamp: Value = self.safe_integer_k(trade.clone(), "t", &[]);
let mut price: Value = self.safe_string_k(trade.clone(), "p", &[]);
let mut amount: Value = self.safe_string_k(trade.clone(), "a", &[]);
let mut marketId: Value = self.safe_string_k(trade.clone(), "s", &[]);
market = self.safe_market(&[marketId.clone(), market.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut id: Value = self.safe_string_k(trade.clone(), "h", &[]);
let mut fee: Value = self.safe_string_k(trade.clone(), "f", &[]);
let mut side: Value = self.safe_string2(trade.clone(), Value::Str("ts".to_string()), Value::Str("d".to_string()), &[]);
if is_equal(&side, &Value::Str("open_long".to_string())) {
side = Value::Str("buy".to_string());
} else if is_equal(&side, &Value::Str("close_long".to_string())) {
side = Value::Str("sell".to_string());
} else if is_equal(&side, &Value::Str("open_short".to_string())) {
side = Value::Str("sell".to_string());
} else if is_equal(&side, &Value::Str("close_short".to_string())) {
side = Value::Str("buy".to_string());
}
let mut eventType: Value = self.safe_string_k(trade.clone(), "te", &[]);
let mut takerOrMaker: Value = Value::Null;
if !is_equal(&eventType, &Value::Null) {
takerOrMaker = ternary(is_true(&(is_equal(&eventType, &Value::Str("fulfill_maker".to_string())))), Value::Str("maker".to_string()), Value::Str("taker".to_string()));
}
let mut orderId: Value = self.safe_string_k(trade.clone(), "i", &[]);
// public trades have no orderId
if is_equal(&orderId, &Value::Null) {
takerOrMaker = Value::Null;
}
return self.safe_trade(Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("info".to_string(), trade.clone());
m.insert("timestamp".to_string(), timestamp.clone());
m.insert("datetime".to_string(), self.iso8601(timestamp.clone()));
m.insert("symbol".to_string(), symbol.clone());
m.insert("id".to_string(), id.clone());
m.insert("order".to_string(), self.safe_string_k(trade.clone(), "i", &[]));
m.insert("type".to_string(), Value::Null);
m.insert("side".to_string(), side.clone());
m.insert("takerOrMaker".to_string(), takerOrMaker.clone());
m.insert("price".to_string(), price.clone());
m.insert("amount".to_string(), amount.clone());
m.insert("cost".to_string(), Value::Null);
m.insert("fee".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("cost".to_string(), fee.clone());
m.insert("currency".to_string(), Value::Str("USDC".to_string()));
m
}));
m
}), &[market.clone()]);
Value::Null
}
/*
* @method
* @name pacifica#watchOHLCV
* @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/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
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn watch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut parsedTf: Value = self.safe_string(self.timeframes.clone(), timeframe.clone(), &[timeframe.clone()]);
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("subscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("candle".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), parsedTf.clone());
m
}));
m
});
let mut messageHash: Value = add(&add(&add(&Value::Str("candles:".to_string()), &parsedTf), &Value::Str(":".to_string())), &symbol);
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
let mut ohlcv: Value = self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
if is_true(&self.newUpdates) {
limit = ohlcv.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_since_limit(ohlcv.clone(), &[since.clone(), limit.clone(), Value::Int(0), Value::Bool(true)]);
Value::Null
}
/*
* @method
* @name pacifica#unWatchOHLCV
* @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/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 {object} [params] extra parameters specific to the exchange API endpoint
* @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
*/
pub async fn un_watch_ohlcv(&mut self, mut symbol: Value, optional_args: &[Value]) -> Value {
let mut timeframe = get_arg(optional_args, 0, Value::Str("1m".to_string()));
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut market: Value = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("candle".to_string()));
m.insert("symbol".to_string(), get_value(&market, &Value::Str("id".to_string())));
m.insert("interval".to_string(), timeframe.clone());
m
}));
m
});
let mut subMessageHash: Value = add(&add(&add(&Value::Str("candles:".to_string()), &timeframe), &Value::Str(":".to_string())), &symbol);
let mut messagehash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messagehash.clone(), &[message.clone(), messagehash.clone()]).await;
Value::Null
}
pub fn handle_ohlcv(&mut self, mut client: Value, mut message: Value) {
//
// {
// "channel": "candle",
// "data": {
// "t": 1749052260000,
// "T": 1749052320000,
// "s": "SOL",
// "i": "1m",
// "o": "157.3",
// "c": "157.32",
// "h": "157.32",
// "l": "157.3",
// "v": "1.22",
// "n": 8
// }
// }
//
let mut data: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut marketId: Value = self.safe_string_k(data.clone(), "s", &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut timeframe: Value = self.safe_string_k(data.clone(), "i", &[]);
if is_equal(&timeframe, &Value::Null) {
return;
}
if !is_true(&(Value::Bool(in_op(&self.ohlcvs, &symbol)))) {
add_element_to_object(&mut self.ohlcvs, &symbol, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
}
let mut symbolOhlcvs: Value = self.safe_value(self.ohlcvs.clone(), symbol.clone(), &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut ohlcv: Value = self.safe_value(symbolOhlcvs.clone(), timeframe.clone(), &[]);
if is_equal(&ohlcv, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "OHLCVLimit", &[Value::Int(1000)]);
ohlcv = ArrayCacheByTimestamp::new(limit.clone());
add_element_to_object(&mut symbolOhlcvs, &timeframe, ohlcv.clone());
}
let mut parsed: Value = self.parse_ohlcv(data.clone(), &[]);
ohlcv.append(parsed.clone());
let mut messageHash: Value = add(&add(&add(&Value::Str("candles:".to_string()), &timeframe), &Value::Str(":".to_string())), &symbol);
client.resolve(&[ohlcv.clone(), messageHash.clone()]);
}
/*
* @method
* @name pacifica#watchOrders
* @description watches information on multiple orders made by the user
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/account-order-updates
* @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|undefined} [params.account] will default to options' walletAddress if not provided
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn watch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut since = get_arg(optional_args, 1, Value::Null);
let mut limit = get_arg(optional_args, 2, Value::Null);
let mut params = get_arg(optional_args, 3, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
let mut userAddress: Value = Value::Null;
{ let __destr_tmp = self.parent.handle_origin_and_single_address(Value::Str("watchOrders".to_string()), params.clone()); userAddress = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut market: Value = Value::Null;
let mut messageHash: Value = Value::Str("order".to_string());
if !is_equal(&symbol, &Value::Null) {
market = self.market(symbol.clone());
symbol = get_value(&market, &Value::Str("symbol".to_string()));
messageHash = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
}
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("subscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("account_order_updates".to_string()));
m.insert("account".to_string(), userAddress.clone());
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
let mut orders: Value = self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
if is_true(&self.newUpdates) {
limit = orders.get_limit(symbol.clone(), limit.clone());
}
return self.filter_by_symbol_since_limit(orders.clone(), &[symbol.clone(), since.clone(), limit.clone(), Value::Bool(true)]);
Value::Null
}
/*
* @method
* @name pacifica#unWatchOrders
* @description unWatches information on multiple orders made by the user
* @see https://docs.pacifica.fi/api-documentation/api/websocket/subscriptions/account-order-updates
* @param {string} symbol unified market symbol of the market orders were made in
* @param {object} [params] extra parameters specific to the exchange API endpoint
* @param {string|undefined} [params.account] will default to options' walletAddress if not provided
* @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/?id=order-structure}
*/
pub async fn un_watch_orders(&mut self, optional_args: &[Value]) -> Value {
let mut symbol = get_arg(optional_args, 0, Value::Null);
let mut params = get_arg(optional_args, 1, Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
if is_equal(&self.markets, &Value::Null) {
self.load_markets(&[]).await;
}
if !is_equal(&symbol, &Value::Null) {
panic!("{}", crate::exchange_errors::not_supported(add(&self.id, &Value::Str(" unWatchOrders() does not support a symbol argument, unWatch from all markets only".to_string()))));
}
let mut messageHash: Value = Value::Str("unsubscribe:order".to_string());
let mut isTestnet: Value = self.isSandboxModeEnabled.clone();
let mut urlKey: Value = ternary(is_true(&(isTestnet)), Value::Str("test".to_string()), Value::Str("api".to_string()));
let mut url: Value = get_value(&get_value(&get_value(&self.urls, &urlKey), &Value::Str("ws".to_string())), &Value::Str("public".to_string()));
let mut userAddress: Value = Value::Null;
{ let __destr_tmp = self.parent.handle_origin_and_single_address(Value::Str("unWatchOrders".to_string()), params.clone()); userAddress = get_value(&__destr_tmp, &Value::Int(0)); params = get_value(&__destr_tmp, &Value::Int(1)); }
let mut request: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("unsubscribe".to_string()));
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("source".to_string(), Value::Str("account_order_updates".to_string()));
m.insert("account".to_string(), userAddress.clone());
m
}));
m
});
let mut message: Value = self.extend(request.clone(), &[params.clone()]);
return self.watch(url.clone(), messageHash.clone(), &[message.clone(), messageHash.clone()]).await;
Value::Null
}
pub fn handle_order(&mut self, mut client: Value, mut message: Value) {
// not snapshot, only updates
// {
// "channel": "account_order_updates",
// "data": [
// {
// "i": 1559665358,
// "I": null,
// "u": "BrZp5bidJ3WUvceSq7X78bhjTfZXeezzGvGEV4hAYKTa",
// "s": "BTC",
// "d": "bid",
// "p": "89501",
// "ip": "89501",
// "lp": "89501",
// "a": "0.00012",
// "f": "0.00012",
// "oe": "fulfill_limit",
// "os": "filled",
// "ot": "limit",
// "sp": null,
// "si": null,
// "r": false,
// "ct": 1765017049008,
// "ut": 1765017219639,
// "li": 1559696133
// }
// ]
// }
let mut data: Value = self.safe_list_k(message.clone(), "data", &[Value::List(vec![])]);
if is_equal(&self.orders, &Value::Null) {
let mut limit: Value = self.safe_integer_k(self.options.clone(), "ordersLimit", &[Value::Int(1000)]);
self.orders = ArrayCacheBySymbolById::new(limit.clone());
}
let mut dataLength: Value = get_array_length(&data);
if is_equal(&dataLength, &Value::Int(0)) {
return;
}
let mut stored: Value = self.orders.clone();
let mut messageHash: Value = Value::Str("order".to_string());
let mut marketSymbols: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m
});
{
let mut i: Value = Value::Int(0);
let mut __for_first_574: bool = true;
while { if !__for_first_574 { i = add(&i, &Value::Int(1)); } __for_first_574 = false; is_less_than(&i, &get_array_length(&data)) } {
let mut rawOrder: Value = get_value(&data, &i);
let mut rawOrder: Value = get_value(&data, &i);
let mut order: Value = self.parse_order(rawOrder.clone(), &[]);
stored.append(order.clone());
let mut symbol: Value = self.safe_string_k(order.clone(), "symbol", &[]);
if !is_equal(&symbol, &Value::Null) {
add_element_to_object(&mut marketSymbols, &symbol, Value::Bool(true));
}
}
}
let mut keys: Value = object_keys(&marketSymbols);
{
let mut i: Value = Value::Int(0);
let mut __for_first_575: bool = true;
while { if !__for_first_575 { i = add(&i, &Value::Int(1)); } __for_first_575 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut symbol: Value = get_value(&keys, &i);
let mut symbol: Value = get_value(&keys, &i);
let mut innerMessageHash: Value = add(&add(&messageHash, &Value::Str(":".to_string())), &symbol);
client.resolve(&[stored.clone(), innerMessageHash.clone()]);
}
}
client.resolve(&[stored.clone(), messageHash.clone()]);
}
pub fn handle_error_message(&self, mut client: Value, mut message: Value) -> Value {
//
// 'rl' key is present only when a rate-limited API key is used
// {"id":"64107e37-a999-4b90-a3cf-b4322ae110d9","type":"cancel_order","code":420,"err":"Failed to cancel order","t":1769474703073,"rl":{"r":1245,"q":1250,"t":56}}
//
let mut error: Value = self.safe_string_k(message.clone(), "err", &[Value::Str("".to_string())]);
let mut postType: Value = self.safe_string_k(message.clone(), "type", &[Value::Str("".to_string())]);
let mut data: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut id: Value = self.safe_string_k(message.clone(), "id", &[]);
if is_equal(&id, &Value::Null) {
id = self.safe_string_k(data.clone(), "id", &[]);
}
let _try_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
self.handle_errors(Value::Int(0), error.clone(), Value::Str("".to_string()), postType.clone(), get_value(&get_value(&get_value(&self.options, &Value::Str("ws".to_string())), &Value::Str("options".to_string())), &Value::Str("headers".to_string())), self.json(data.clone()), message.clone(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
#[allow(unreachable_code)] { Value::Null }}));
if let Err(_try_err) = _try_result { let e: Value = panic_to_value(_try_err);
client.reject(&[e.clone(), id.clone()]);
return Value::Bool(true);
}
return Value::Bool(false);
Value::Null
}
pub fn handle_order_book_unsubscription(&mut self, mut client: Value, mut subscription: Value) {
let mut marketId: Value = self.safe_string2(subscription.clone(), Value::Str("symbol".to_string()), Value::Str("s".to_string()), &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut subMessageHash: Value = add(&Value::Str("orderbook:".to_string()), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
if is_true(&Value::Bool(in_op(&self.orderbooks, &symbol))) {
remove(&mut self.orderbooks, &symbol);
}
}
pub fn handle_trades_unsubscription(&mut self, mut client: Value, mut subscription: Value) {
let mut marketId: Value = self.safe_string2(subscription.clone(), Value::Str("symbol".to_string()), Value::Str("s".to_string()), &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut subMessageHash: Value = add(&Value::Str("trade:".to_string()), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
if is_true(&Value::Bool(in_op(&self.trades, &symbol))) {
remove(&mut self.trades, &symbol);
}
}
pub fn handle_tickers_unsubscription(&mut self, mut client: Value, mut subscription: Value) {
let mut subMessageHash: Value = Value::Str("tickers".to_string());
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
let mut symbols: Value = object_keys(&self.tickers);
{
let mut i: Value = Value::Int(0);
let mut __for_first_576: bool = true;
while { if !__for_first_576 { i = add(&i, &Value::Int(1)); } __for_first_576 = false; is_less_than(&i, &get_array_length(&symbols)) } {
remove(&mut self.tickers, &get_value(&symbols, &i));
}
}
}
pub fn handle_ohlcv_unsubscription(&mut self, mut client: Value, mut subscription: Value) {
let mut marketId: Value = self.safe_string2(subscription.clone(), Value::Str("symbol".to_string()), Value::Str("s".to_string()), &[]);
let mut market: Value = self.safe_market(&[marketId.clone()]);
let mut symbol: Value = get_value(&market, &Value::Str("symbol".to_string()));
let mut interval: Value = self.safe_string_k(subscription.clone(), "interval", &[]);
let mut timeframe: Value = self.find_timeframe(interval.clone(), &[]);
if is_equal(&timeframe, &Value::Null) {
return;
}
let mut subMessageHash: Value = add(&add(&add(&Value::Str("candles:".to_string()), &timeframe), &Value::Str(":".to_string())), &symbol);
let mut messageHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subMessageHash);
self.clean_unsubscription(client.clone(), subMessageHash.clone(), messageHash.clone(), &[]);
if is_true(&(!is_equal(&symbol, &Value::Null))) && is_true(&(Value::Bool(in_op(&self.ohlcvs, &symbol)))) {
if is_true(&(!is_equal(&timeframe, &Value::Null))) && is_true(&(Value::Bool(in_op(&get_value(&self.ohlcvs, &symbol), &timeframe)))) {
remove(&mut get_value(&self.ohlcvs, &symbol), &timeframe);
}
}
}
pub fn handle_order_unsubscription(&mut self, mut client: Value, mut subscription: Value) {
let mut subHash: Value = Value::Str("order".to_string());
let mut unSubHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subHash);
self.clean_unsubscription(client.clone(), subHash.clone(), unSubHash.clone(), &[Value::Bool(true)]);
let mut topicStructure: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("topic".to_string(), Value::Str("orders".to_string()));
m
});
self.clean_cache(topicStructure.clone());
}
pub fn handle_my_trades_unsubscription(&mut self, mut client: Value, mut subscription: Value) {
let mut subHash: Value = Value::Str("myTrades".to_string());
let mut unSubHash: Value = add(&Value::Str("unsubscribe:".to_string()), &subHash);
self.clean_unsubscription(client.clone(), subHash.clone(), unSubHash.clone(), &[Value::Bool(true)]);
let mut topicStructure: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("topic".to_string(), Value::Str("myTrades".to_string()));
m
});
self.clean_cache(topicStructure.clone());
}
pub fn handle_subscription_response(&mut self, mut client: Value, mut message: Value) {
// {
// "channel": "subscribe",
// "data": {
// "source": "book",
// "symbol": "SOL",
// "agg_level": 1
// }
// }
//
// {
// "channel": "unsubscribe",
// "data": {
// "source": "book",
// "symbol": "SOL",
// "agg_level": 1
// }
// }
//
let mut data: Value = self.safe_dict_k(message.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut method: Value = self.safe_string_k(message.clone(), "channel", &[]);
if is_equal(&method, &Value::Str("unsubscribe".to_string())) {
let mut subscription: Value = self.safe_dict_k(data.clone(), "data", &[Value::Map({
let mut m = indexmap::IndexMap::new();
m
})]);
let mut type_var: Value = self.safe_string_k(subscription.clone(), "source", &[]);
if is_equal(&type_var, &Value::Str("book".to_string())) {
self.handle_order_book_unsubscription(client.clone(), subscription.clone());
} else if is_equal(&type_var, &Value::Str("trades".to_string())) {
self.handle_trades_unsubscription(client.clone(), subscription.clone());
} else if is_equal(&type_var, &Value::Str("prices".to_string())) {
self.handle_tickers_unsubscription(client.clone(), subscription.clone());
} else if is_equal(&type_var, &Value::Str("candle".to_string())) {
self.handle_ohlcv_unsubscription(client.clone(), subscription.clone());
} else if is_equal(&type_var, &Value::Str("account_order_updates".to_string())) {
self.handle_order_unsubscription(client.clone(), subscription.clone());
} else if is_equal(&type_var, &Value::Str("account_trades".to_string())) {
self.handle_my_trades_unsubscription(client.clone(), subscription.clone());
}
}
}
pub fn handle_message(&mut self, mut client: Value, mut message: Value) {
//
// {
// "channel":"subscribe",
// "data":{
// "method":"unsubscribe",
// "subscription":{
// "type":"l2Book",
// "coin":"BTC",
// "nSigFigs":5,
// "mantissa":null
// }
// }
// }
//
if is_equal(&self.handle_error_message(client.clone(), message.clone()), &Value::Bool(true)) {
return;
}
let mut postType: Value = self.safe_string_k(message.clone(), "type", &[]);
let mut topic: Value = self.safe_string_k(message.clone(), "channel", &[Value::Str("".to_string())]);
let mut methods: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("pong".to_string(), Value::Str("handle_pong".to_string()).clone());
m.insert("trades".to_string(), Value::Str("handle_trades".to_string()).clone());
m.insert("book".to_string(), Value::Str("handle_order_book".to_string()).clone());
m.insert("candle".to_string(), Value::Str("handle_ohlcv".to_string()).clone());
m.insert("account_order_updates".to_string(), Value::Str("handle_order".to_string()).clone());
m.insert("account_trades".to_string(), Value::Str("handle_my_trades".to_string()).clone());
m.insert("prices".to_string(), Value::Str("handle_ws_tickers".to_string()).clone());
m.insert("subscribe".to_string(), Value::Str("handle_subscription_response".to_string()).clone());
m.insert("unsubscribe".to_string(), Value::Str("handle_subscription_response".to_string()).clone());
m
});
let mut exacMethod: Value = self.safe_value(methods.clone(), topic.clone(), &[]);
if !is_equal(&exacMethod, &Value::Null) {
self.dispatch_ws_handler(&exacMethod, &[client.clone(), message.clone()]);
return;
}
if !is_equal(&postType, &Value::Null) {
self.handle_ws_post(client.clone(), message.clone());
return;
}
let mut keys: Value = object_keys(&methods);
{
let mut i: Value = Value::Int(0);
let mut __for_first_577: bool = true;
while { if !__for_first_577 { i = add(&i, &Value::Int(1)); } __for_first_577 = false; is_less_than(&i, &get_array_length(&keys)) } {
let mut key: Value = get_value(&keys, &i);
let mut key: Value = get_value(&keys, &i);
if is_greater_than_or_equal(&get_index_of(&topic, &get_value(&keys, &i)), &Value::Int(0)) {
let mut method: Value = get_value(&methods, &key);
let mut method: Value = get_value(&methods, &key);
self.dispatch_ws_handler(&method, &[client.clone(), message.clone()]);
return;
}
}
}
}
pub fn ping(&self, mut client: Value) -> Value {
return Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("method".to_string(), Value::Str("ping".to_string()));
m
});
Value::Null
}
pub fn handle_pong(&self, mut client: Value, mut message: Value) -> Value {
//
// {
// "channel": "pong"
// }
//
let __ws_arg_2 = self.milliseconds();
crate::set_value(&mut client, &Value::Str("lastPong".to_string()), self.safe_integer_k(message.clone(), "pong", &[__ws_arg_2]));
return message;
Value::Null
}
pub fn request_id(&self) -> Value {
return self.uuid(&[]);
Value::Null
}
pub fn wrap_as_post_action(&self, mut operationType: Value, mut request: Value) -> Value {
if is_equal(&operationType, &Value::Null) {
panic!("{}", crate::exchange_errors::arguments_required(add(&self.id, &Value::Str("postAction() requires a \"operationType\" argument!".to_string()))));
}
let mut requestId: Value = self.request_id();
let mut payload: Value = Value::Map({
let mut m = indexmap::IndexMap::new();
m.insert("id".to_string(), requestId.clone());
m.insert("params".to_string(), Value::Map({
let mut m = indexmap::IndexMap::new();
m
}));
m
});
add_element_to_object(get_value_mut(&mut payload, &Value::Str("params".to_string())), &operationType, request.clone());
return payload;
Value::Null
}
pub fn handle_ws_post(&self, mut client: Value, mut message: Value) {
//
// market order
// {
// "code": 200,
// "data": {
// "I": "79f948fd-7556-4066-a128-083f3ea49322",
// "i": 645953,
// "s": "BTC"
// },
// "id": "660065de-8f32-46ad-ba1e-83c93d3e3966",
// "t": 1749223025962,
// "type": "create_market_order"
// }
//
// limit order
// {
// "code": 200,
// "data": {
// "I": "79f948fd-7556-4066-a128-083f3ea49322",
// "i": 645953,
// "s": "BTC"
// },
// "id": "660065de-8f32-46ad-ba1e-83c93d3e3966",
// "t": 1749223025962,
// "type": "create_order"
// }
//
let mut id: Value = self.safe_string_k(message.clone(), "id", &[]);
client.resolve(&[message.clone(), id.clone()]);
}
}