use crate::error::Result;
use crate::http::HttpClient;
use crate::request::{ActivityQueryParams, TradeQueryParams};
use crate::types::{Activity, ClosedPosition, Position, PositionValue, Trade};
pub struct DataClient {
http_client: HttpClient,
}
impl DataClient {
pub fn new(host: impl Into<String>) -> Self {
Self {
http_client: HttpClient::new(host),
}
}
pub async fn get_positions(&self, user: &str) -> Result<Vec<Position>> {
let path = format!("/positions?user={}", user);
self.http_client.get(&path, None).await
}
pub async fn get_positions_value(&self, user: &str) -> Result<Vec<PositionValue>> {
let path = format!("/value?user={}", user);
self.http_client.get(&path, None).await
}
pub async fn get_trades(
&self,
user: &str,
params: Option<TradeQueryParams>,
) -> Result<Vec<Trade>> {
let mut path = format!("/trades?user={}", user);
if let Some(params) = params {
path.push_str(¶ms.to_query_string());
}
println!("{}", path);
self.http_client.get(&path, None).await
}
pub async fn get_activity(
&self,
user: &str,
params: Option<ActivityQueryParams>,
) -> Result<Vec<Activity>> {
let mut path = format!("/activity?user={}", user);
if let Some(params) = params {
path.push_str(¶ms.to_query_string());
}
self.http_client.get(&path, None).await
}
pub async fn get_closed_positions(&self, user: &str) -> Result<Vec<ClosedPosition>> {
let path = format!("/closed-positions?user={}", user);
self.http_client.get(&path, None).await
}
}