use crate::core::types::{AccountType, Symbol};
pub struct HtxUrls;
impl HtxUrls {
pub fn base_url(_testnet: bool) -> &'static str {
"https://api.huobi.pro"
}
pub fn futures_base_url(_testnet: bool) -> &'static str {
"https://api.hbdm.com"
}
pub fn ws_market_url(_testnet: bool) -> &'static str {
"wss://api.huobi.pro/ws"
}
pub fn ws_linear_swap_url(_testnet: bool) -> &'static str {
"wss://api.hbdm.com/linear-swap-ws"
}
pub fn ws_mbp_url(_testnet: bool) -> &'static str {
"wss://api.huobi.pro/feed"
}
pub fn ws_account_url(_testnet: bool) -> &'static str {
"wss://api.huobi.pro/ws/v2"
}
pub fn base_url_aws(_testnet: bool) -> &'static str {
"https://api-aws.huobi.pro"
}
pub fn ws_market_url_aws(_testnet: bool) -> &'static str {
"wss://api-aws.huobi.pro/ws"
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum HtxEndpoint {
ServerTime, Symbols, SymbolsV1, Ticker, Tickers, Orderbook, Klines, RecentTrades, HistoryTrades,
AccountList, Balance, AccountInfo, Ledger,
PlaceOrder, CancelOrder, CancelAllOrders, CancelOpenOrders, OrderStatus, OpenOrders, OrderHistory, MatchResults, TransactFee,
DepositAddress, WithdrawQuota, WithdrawAddress, Withdraw, WithdrawCancel, DepositHistory, WithdrawHistory,
FuturesTicker, FuturesOrderbook, FuturesKlines, FuturesTrades,
OrderMatchResults,
OpenInterest,
FundingRateHistory,
MarkPrice,
MarkPriceKline,
EliteAccountRatio,
HistoricalFundingRate,
AlgoOrders,
Transfer, TransferHistory,
SubAccountCreate, SubAccountList, SubAccountTransfer, SubAccountBalance, }
impl HtxEndpoint {
pub fn path(&self) -> &'static str {
match self {
Self::ServerTime => "/v1/common/timestamp",
Self::Symbols => "/v2/settings/common/symbols",
Self::SymbolsV1 => "/v1/common/symbols",
Self::Ticker => "/market/detail/merged",
Self::Tickers => "/market/tickers",
Self::Orderbook => "/market/depth",
Self::Klines => "/market/history/kline",
Self::RecentTrades => "/market/trade",
Self::HistoryTrades => "/market/history/trade",
Self::AccountList => "/v1/account/accounts",
Self::Balance => "/v1/account/accounts/{account-id}/balance",
Self::AccountInfo => "/v2/account/asset-valuation",
Self::Ledger => "/v2/account/ledger",
Self::PlaceOrder => "/v1/order/orders/place",
Self::CancelOrder => "/v1/order/orders/{order-id}/submitcancel",
Self::CancelAllOrders => "/v1/order/orders/batchcancel",
Self::CancelOpenOrders => "/v1/order/orders/batchCancelOpenOrders",
Self::OrderStatus => "/v1/order/orders/{order-id}",
Self::OpenOrders => "/v1/order/openOrders",
Self::OrderHistory => "/v1/order/orders",
Self::MatchResults => "/v1/order/matchresults",
Self::TransactFee => "/v2/reference/transact-fee-rate",
Self::DepositAddress => "/v2/account/deposit/address",
Self::WithdrawQuota => "/v2/account/withdraw/quota",
Self::WithdrawAddress => "/v2/account/withdraw/address",
Self::Withdraw => "/v1/dw/withdraw/api/create",
Self::WithdrawCancel => "/v1/dw/withdraw-virtual/{withdraw-id}/cancel",
Self::DepositHistory => "/v1/query/deposit-withdraw",
Self::WithdrawHistory => "/v1/query/deposit-withdraw",
Self::FuturesTicker => "/linear-swap-ex/market/detail/merged",
Self::FuturesOrderbook => "/linear-swap-ex/market/depth",
Self::FuturesKlines => "/linear-swap-ex/market/history/kline",
Self::FuturesTrades => "/linear-swap-ex/market/trade",
Self::OrderMatchResults => "/v1/order/orders/{order-id}/matchresults",
Self::OpenInterest => "/linear-swap-api/v1/swap_open_interest",
Self::FundingRateHistory => "/linear-swap-api/v3/swap-funding-rate-history",
Self::MarkPrice => "/linear-swap-api/v1/swap_index",
Self::MarkPriceKline => "/index/market/history/linear_swap_mark_price_kline",
Self::EliteAccountRatio => "/linear-swap-api/v1/swap_elite_account_ratio",
Self::HistoricalFundingRate => "/linear-swap-api/v1/swap_historical_funding_rate",
Self::AlgoOrders => "/v2/algo-orders",
Self::Transfer => "/v1/futures/transfer",
Self::TransferHistory => "/v2/account/transfer",
Self::SubAccountCreate => "/v2/sub-user/creation",
Self::SubAccountList => "/v2/sub-user/user-list",
Self::SubAccountTransfer => "/v1/subuser/transfer",
Self::SubAccountBalance => "/v1/account/accounts/{sub-uid}",
}
}
pub fn method(&self) -> &'static str {
match self {
Self::PlaceOrder
| Self::CancelOrder
| Self::CancelAllOrders
| Self::CancelOpenOrders
| Self::Withdraw
| Self::WithdrawCancel
| Self::AlgoOrders
| Self::Transfer
| Self::SubAccountCreate
| Self::SubAccountTransfer => "POST",
_ => "GET",
}
}
pub fn is_private(&self) -> bool {
match self {
Self::ServerTime
| Self::Symbols
| Self::SymbolsV1
| Self::Ticker
| Self::Tickers
| Self::Orderbook
| Self::Klines
| Self::RecentTrades
| Self::HistoryTrades
| Self::FuturesTicker
| Self::FuturesOrderbook
| Self::FuturesKlines
| Self::FuturesTrades
| Self::OpenInterest
| Self::FundingRateHistory
| Self::MarkPrice
| Self::MarkPriceKline
| Self::EliteAccountRatio
| Self::HistoricalFundingRate => false,
_ => true,
}
}
pub fn path_with_vars(&self, vars: &[(&str, &str)]) -> String {
let mut path = self.path().to_string();
for (key, value) in vars {
let placeholder = format!("{{{}}}", key);
path = path.replace(&placeholder, value);
}
path
}
}
pub fn format_symbol(symbol: &Symbol, account_type: AccountType) -> String {
match account_type {
AccountType::FuturesCross | AccountType::FuturesIsolated => {
format!("{}-{}", symbol.base.to_uppercase(), symbol.quote.to_uppercase())
}
_ => {
format!("{}{}", symbol.base.to_lowercase(), symbol.quote.to_lowercase())
}
}
}
pub fn map_kline_interval(interval: &str) -> &'static str {
match interval {
"1m" => "1min",
"5m" => "5min",
"15m" => "15min",
"30m" => "30min",
"1h" => "60min",
"4h" => "4hour",
"1d" => "1day",
"1w" => "1week",
"1M" => "1mon",
"1y" => "1year",
_ => "60min", }
}
pub fn account_type_to_string(account_type: AccountType) -> &'static str {
match account_type {
AccountType::Spot => "spot",
AccountType::Margin => "margin",
AccountType::FuturesCross | AccountType::FuturesIsolated => "futures",
_ => "spot",
}
}