use crate::core::types::AccountType;
#[derive(Debug, Clone)]
pub struct ParadexUrls {
pub rest: &'static str,
pub ws: &'static str,
}
impl ParadexUrls {
pub const MAINNET: Self = Self {
rest: "https://api.prod.paradex.trade/v1",
ws: "wss://ws.api.prod.paradex.trade/v1",
};
pub const TESTNET: Self = Self {
rest: "https://api.testnet.paradex.trade/v1",
ws: "wss://ws.api.testnet.paradex.trade/v1",
};
pub fn rest_url(&self) -> &str {
self.rest
}
pub fn ws_url(&self) -> &str {
self.ws
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum ParadexEndpoint {
Auth,
SystemConfig,
SystemState,
SystemTime,
Markets,
MarketsSummary,
Orderbook,
OrderbookInteractive,
BboInteractive,
Trades,
Klines,
Account,
AccountInfo,
AccountHistory,
Balances,
Positions,
Subaccounts,
CreateOrder,
CreateOrderBatch,
GetOrder,
GetOrderByClientId,
OpenOrders,
OrdersHistory,
CancelOrder,
CancelOrderBatch,
CancelAllOrders,
ModifyOrder,
CreateAlgoOrder,
CancelAlgoOrder,
Fills,
FundingPayments,
Transactions,
Transfers,
Liquidations,
Tradebusts,
}
impl ParadexEndpoint {
pub fn path(&self) -> &'static str {
match self {
Self::Auth => "/auth",
Self::SystemConfig => "/system/config",
Self::SystemState => "/system/state",
Self::SystemTime => "/system/time",
Self::Markets => "/markets",
Self::MarketsSummary => "/markets/summary",
Self::Orderbook => "/orderbook/{market}",
Self::OrderbookInteractive => "/orderbook/{market}/interactive",
Self::BboInteractive => "/bbo/{market}/interactive",
Self::Trades => "/trades",
Self::Klines => "/klines",
Self::Account => "/account",
Self::AccountInfo => "/account/info",
Self::AccountHistory => "/account/history",
Self::Balances => "/balances",
Self::Positions => "/positions",
Self::Subaccounts => "/subaccounts",
Self::CreateOrder => "/orders",
Self::CreateOrderBatch => "/orders/batch",
Self::GetOrder => "/orders/{order_id}",
Self::GetOrderByClientId => "/orders/by-client-id/{client_id}",
Self::OpenOrders => "/orders",
Self::OrdersHistory => "/orders/history",
Self::CancelOrder => "/orders/{order_id}",
Self::CancelOrderBatch => "/orders/batch",
Self::CancelAllOrders => "/orders",
Self::ModifyOrder => "/orders/{order_id}",
Self::CreateAlgoOrder => "/algo/orders",
Self::CancelAlgoOrder => "/algo/orders/{algo_id}",
Self::Fills => "/fills",
Self::FundingPayments => "/funding/payments",
Self::Transactions => "/transactions",
Self::Transfers => "/transfers",
Self::Liquidations => "/liquidations",
Self::Tradebusts => "/tradebusts",
}
}
pub fn requires_auth(&self) -> bool {
match self {
Self::SystemConfig
| Self::SystemState
| Self::SystemTime
| Self::Markets
| Self::MarketsSummary
| Self::Orderbook
| Self::OrderbookInteractive
| Self::BboInteractive
| Self::Trades
| Self::Klines => false,
_ => true,
}
}
pub fn method(&self) -> &'static str {
match self {
Self::Auth
| Self::CreateOrder
| Self::CreateOrderBatch
| Self::CreateAlgoOrder => "POST",
Self::CancelOrder
| Self::CancelOrderBatch
| Self::CancelAllOrders
| Self::CancelAlgoOrder => "DELETE",
Self::ModifyOrder => "PUT",
_ => "GET",
}
}
}
pub fn format_symbol(base: &str, quote: &str, _account_type: AccountType) -> String {
format!("{}-{}-PERP", base.to_uppercase(), quote.to_uppercase())
}
pub fn map_kline_resolution(interval: &str) -> &'static str {
match interval {
"1m" => "1",
"5m" => "5",
"15m" => "15",
"30m" => "30",
"1h" => "60",
"4h" => "240",
"1d" => "D",
"1w" => "W",
_ => "60", }
}