use crate::core::types::{AccountType, Symbol};
pub struct MexcUrls;
impl MexcUrls {
pub fn base_url() -> &'static str {
"https://api.mexc.com"
}
pub fn futures_base_url() -> &'static str {
"https://contract.mexc.com"
}
pub fn ws_url() -> &'static str {
"wss://wbs-api.mexc.com/ws"
}
pub fn futures_ws_url() -> &'static str {
"wss://contract.mexc.com/edge"
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum MexcEndpoint {
Ping, ServerTime, ExchangeInfo, Orderbook, RecentTrades, Klines, Ticker24hr, TickerPrice, BookTicker, AvgPrice,
Account, MyTrades, TradeFee,
PlaceOrder, TestOrder, CancelOrder, CancelAllOrders, QueryOrder, OpenOrders, AllOrders,
BatchOrders,
BatchOrdersCancel,
Transfer, TransferHistory,
DepositAddress, Withdraw, DepositHistory, WithdrawHistory,
SubAccountCreate, SubAccountList, SubAccountTransfer, SubAccountAssets,
FuturesPing, FuturesTicker, FuturesOrderbook, FuturesKlines, FuturesRecentTrades, FuturesContractInfo,
FuturesMarkPrice,
FuturesFundingRate,
FuturesOpenInterest,
}
impl MexcEndpoint {
pub fn path(&self) -> &'static str {
match self {
Self::Ping => "/api/v3/ping",
Self::ServerTime => "/api/v3/time",
Self::ExchangeInfo => "/api/v3/exchangeInfo",
Self::Orderbook => "/api/v3/depth",
Self::RecentTrades => "/api/v3/trades",
Self::Klines => "/api/v3/klines",
Self::Ticker24hr => "/api/v3/ticker/24hr",
Self::TickerPrice => "/api/v3/ticker/price",
Self::BookTicker => "/api/v3/ticker/bookTicker",
Self::AvgPrice => "/api/v3/avgPrice",
Self::Account => "/api/v3/account",
Self::MyTrades => "/api/v3/myTrades",
Self::TradeFee => "/api/v3/tradeFee",
Self::PlaceOrder => "/api/v3/order",
Self::TestOrder => "/api/v3/order/test",
Self::CancelOrder => "/api/v3/order",
Self::CancelAllOrders => "/api/v3/openOrders",
Self::QueryOrder => "/api/v3/order",
Self::OpenOrders => "/api/v3/openOrders",
Self::AllOrders => "/api/v3/allOrders",
Self::BatchOrders => "/api/v3/batchOrders",
Self::BatchOrdersCancel => "/api/v3/batchOrders",
Self::Transfer => "/api/v3/capital/transfer",
Self::TransferHistory => "/api/v3/capital/transfer",
Self::DepositAddress => "/api/v3/capital/deposit/address",
Self::Withdraw => "/api/v3/capital/withdraw",
Self::DepositHistory => "/api/v3/capital/deposit/hisrec",
Self::WithdrawHistory => "/api/v3/capital/withdraw/history",
Self::SubAccountCreate => "/api/v3/sub-account/virtualSubAccount",
Self::SubAccountList => "/api/v3/sub-account/list",
Self::SubAccountTransfer => "/api/v3/capital/sub-account/universalTransfer",
Self::SubAccountAssets => "/api/v3/sub-account/assets",
Self::FuturesPing => "/api/v1/contract/ping",
Self::FuturesTicker => "/api/v1/contract/ticker",
Self::FuturesOrderbook => "/api/v1/contract/depth", Self::FuturesKlines => "/api/v1/contract/kline", Self::FuturesRecentTrades => "/api/v1/contract/deals", Self::FuturesContractInfo => "/api/v1/contract/detail",
Self::FuturesMarkPrice => "/api/v1/contract/index_price", Self::FuturesFundingRate => "/api/v1/contract/funding_rate", Self::FuturesOpenInterest => "/api/v1/contract/open_interest", }
}
pub fn method(&self) -> &'static str {
match self {
Self::PlaceOrder
| Self::TestOrder
| Self::BatchOrders
| Self::Transfer
| Self::Withdraw
| Self::SubAccountCreate
| Self::SubAccountTransfer => "POST",
Self::CancelOrder
| Self::CancelAllOrders
| Self::BatchOrdersCancel => "DELETE",
_ => "GET",
}
}
pub fn is_private(&self) -> bool {
match self {
Self::Ping
| Self::ServerTime
| Self::ExchangeInfo
| Self::Orderbook
| Self::RecentTrades
| Self::Klines
| Self::Ticker24hr
| Self::TickerPrice
| Self::BookTicker
| Self::AvgPrice
| Self::FuturesPing
| Self::FuturesTicker
| Self::FuturesOrderbook
| Self::FuturesKlines
| Self::FuturesRecentTrades
| Self::FuturesContractInfo
| Self::FuturesMarkPrice
| Self::FuturesFundingRate
| Self::FuturesOpenInterest => false,
_ => true,
}
}
pub fn is_futures(&self) -> bool {
matches!(
self,
Self::FuturesPing
| Self::FuturesTicker
| Self::FuturesOrderbook
| Self::FuturesKlines
| Self::FuturesRecentTrades
| Self::FuturesContractInfo
| Self::FuturesMarkPrice
| Self::FuturesFundingRate
| Self::FuturesOpenInterest
)
}
pub fn is_capital(&self) -> bool {
matches!(
self,
Self::Transfer
| Self::TransferHistory
| Self::DepositAddress
| Self::Withdraw
| Self::DepositHistory
| Self::WithdrawHistory
| Self::SubAccountCreate
| Self::SubAccountList
| Self::SubAccountTransfer
| Self::SubAccountAssets
)
}
}
pub fn format_symbol(symbol: &Symbol, account_type: AccountType) -> String {
match account_type {
AccountType::Spot | AccountType::Margin => {
format!("{}{}", symbol.base.to_uppercase(), symbol.quote.to_uppercase())
},
AccountType::FuturesCross | AccountType::FuturesIsolated => {
format!("{}_{}", symbol.base.to_uppercase(), symbol.quote.to_uppercase())
},
_ => {
format!("{}{}", symbol.base.to_uppercase(), symbol.quote.to_uppercase())
},
}
}
pub struct MexcWsChannels;
impl MexcWsChannels {
pub fn mini_ticker(symbol: &str) -> String {
format!("spot@public.miniTicker.v3.api.pb@{}@UTC+0", symbol)
}
pub fn aggre_deals(symbol: &str) -> String {
format!("spot@public.aggre.deals.v3.api.pb@100ms@{}", symbol)
}
pub fn aggre_depth(symbol: &str) -> String {
format!("spot@public.aggre.depth.v3.api.pb@100ms@{}", symbol)
}
pub fn limit_depth(symbol: &str, levels: u32) -> String {
format!("spot@public.limit.depth.v3.api.pb@{}@{}", symbol, levels)
}
pub fn kline(symbol: &str, interval: &str) -> String {
format!("spot@public.kline.v3.api.pb@{}@{}", symbol, interval)
}
pub fn book_ticker(symbol: &str) -> String {
format!("spot@public.bookTicker.v3.api.pb@{}", symbol)
}
pub fn futures_funding_rate(_symbol: &str) -> &'static str {
"push.funding.rate"
}
}
pub fn map_kline_interval(interval: &str) -> &'static str {
match interval {
"1m" => "1m",
"5m" => "5m",
"15m" => "15m",
"30m" => "30m",
"1h" => "60m",
"4h" => "4h",
"8h" => "8h",
"1d" => "1d",
"1w" => "1w",
"1M" => "1M",
_ => "1h", }
}