transaction hystory

This commit is contained in:
zastian-dev
2026-02-10 16:45:42 +00:00
parent a19906560a
commit 5bb6f2d686
2 changed files with 183 additions and 11 deletions

View File

@@ -96,6 +96,12 @@ pub struct Order {
pub qty: String,
pub side: String,
pub status: String,
#[serde(default)]
pub filled_avg_price: Option<String>,
#[serde(default)]
pub filled_at: Option<String>,
#[serde(default)]
pub created_at: Option<String>,
}
impl AlpacaClient {
@@ -415,6 +421,35 @@ impl AlpacaClient {
response.json().await.context("Failed to parse order")
}
/// Get closed/filled orders (transaction history).
pub async fn get_orders(&self, limit: u32) -> Result<Vec<Order>> {
self.enforce_rate_limit().await;
let url = format!(
"{}/orders?status=closed&limit={}&direction=desc",
TRADING_BASE_URL, limit
);
let response = self
.http_client
.get(&url)
.headers(self.auth_headers())
.send()
.await
.context("Failed to get orders")?;
if !response.status().is_success() {
let status = response.status();
let text = response.text().await.unwrap_or_default();
anyhow::bail!("API error {}: {}", status, text);
}
response
.json()
.await
.context("Failed to parse orders response")
}
/// Check if market is open.
pub async fn is_market_open(&self) -> Result<bool> {
let clock = self.get_clock().await?;