You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.8 KiB
109 lines
2.8 KiB
use crate::api::{
|
|
types::{
|
|
paginated_response::PaginatedResponse,
|
|
transaction::{LatestTransaction, TransactionCompany, TransactionsAggregated},
|
|
},
|
|
FastInsidersApi,
|
|
};
|
|
|
|
impl FastInsidersApi {
|
|
pub async fn get_transactions(
|
|
&self,
|
|
company_slug: Option<String>,
|
|
page: i64,
|
|
size: i64,
|
|
) -> Result<PaginatedResponse<TransactionCompany>, ()> {
|
|
let route = &format!(
|
|
"{}/transaction?{}&page={}&size={}",
|
|
self.url,
|
|
company_slug.map_or("".to_string(), |c| format!("company_slug={}", c)),
|
|
page,
|
|
size,
|
|
);
|
|
|
|
#[cfg(client)]
|
|
let res = reqwasm::http::Request::get(route)
|
|
.send()
|
|
.await
|
|
.map_err(|_| ())?
|
|
.json::<PaginatedResponse<TransactionCompany>>()
|
|
.await
|
|
.map_err(|_| ())?;
|
|
|
|
#[cfg(engine)]
|
|
let res = reqwest::get(route)
|
|
.await
|
|
.map_err(|_| ())?
|
|
.json::<PaginatedResponse<TransactionCompany>>()
|
|
.await
|
|
.map_err(|_| ())?;
|
|
|
|
Ok(res)
|
|
}
|
|
|
|
pub async fn get_aggregated_transactions(
|
|
&self,
|
|
hours: Option<String>,
|
|
page: i64,
|
|
size: i64,
|
|
) -> Result<PaginatedResponse<TransactionsAggregated>, ()> {
|
|
let route = &format!(
|
|
"{}/transaction/aggregated?{}&page={}&size={}",
|
|
self.url,
|
|
hours.map_or("".to_string(), |c| format!("hours={}", c)),
|
|
page,
|
|
size,
|
|
);
|
|
|
|
#[cfg(client)]
|
|
let res = reqwasm::http::Request::get(route)
|
|
.send()
|
|
.await
|
|
.map_err(|_| ())?
|
|
.json::<PaginatedResponse<TransactionsAggregated>>()
|
|
.await
|
|
.map_err(|_| ())?;
|
|
|
|
#[cfg(engine)]
|
|
let res = reqwest::get(route)
|
|
.await
|
|
.map_err(|_| ())?
|
|
.json::<PaginatedResponse<TransactionsAggregated>>()
|
|
.await
|
|
.map_err(|_| ())?;
|
|
|
|
Ok(res)
|
|
}
|
|
|
|
pub async fn get_latest_transactions(
|
|
&self,
|
|
_: Option<String>,
|
|
page: i64,
|
|
size: i64,
|
|
) -> Result<PaginatedResponse<LatestTransaction>, ()> {
|
|
let route = &format!(
|
|
"{}/transaction/latest?page={}&size={}",
|
|
self.url, page, size,
|
|
);
|
|
|
|
#[cfg(client)]
|
|
let res = reqwasm::http::Request::get(route)
|
|
.send()
|
|
.await
|
|
.map_err(|_| ())?
|
|
.json::<PaginatedResponse<LatestTransaction>>()
|
|
.await
|
|
.map_err(|_| ())?;
|
|
|
|
#[cfg(engine)]
|
|
let res = reqwest::get(route)
|
|
.await
|
|
.map_err(|_| ())?
|
|
.json::<PaginatedResponse<LatestTransaction>>()
|
|
.await
|
|
.map_err(|_| ())?;
|
|
|
|
Ok(res)
|
|
}
|
|
}
|