use crate::model::Empty;
use crate::futures::model::{ExchangeInformation, ServerTime, Symbol};
use crate::client::Client;
use crate::errors::{Result, Error}; use crate::api::API;
use crate::api::Futures;
#[derive(Clone)]
pub struct FuturesGeneral {
pub client: Client,
}
impl FuturesGeneral {
pub async fn ping(&self) -> Result<String> {
self.client
.get::<Empty>(API::Futures(Futures::Ping), None)
.await?; Ok("pong".into())
}
pub async fn get_server_time(&self) -> Result<ServerTime> {
self.client.get(API::Futures(Futures::Time), None).await }
pub async fn exchange_info(&self) -> Result<ExchangeInformation> {
self.client
.get(API::Futures(Futures::ExchangeInfo), None)
.await }
pub async fn get_symbol_info<S>(&self, symbol: S) -> Result<Symbol>
where
S: Into<String>,
{
let upper_symbol = symbol.into().to_uppercase();
match self.exchange_info().await {
Ok(info) => {
for item in info.symbols {
if item.symbol == upper_symbol {
return Ok(item);
}
}
Err(Error::Custom("Symbol not found".to_string())) }
Err(e) => Err(e),
}
}
}