| Crates.io | rpaca |
| lib.rs | rpaca |
| version | 0.7.8 |
| created_at | 2025-08-20 02:03:00.362384+00 |
| updated_at | 2025-09-11 05:13:33.20491+00 |
| description | A rust crate wrapping the Alpaca API |
| homepage | https://github.com/Saver05/rpaca |
| repository | https://github.com/Saver05/rpaca |
| max_upload_size | |
| id | 1802781 |
| size | 237,499 |
rpaca is a lightweight, idiomatic Rust client for interacting with the Alpaca trading API.
It enables easy integration with account info, orders, assets, positions, and market data with strong typing and clean
abstractions.
rpaca provides a Rust interface to the Alpaca API, allowing developers to:
The library supports both paper trading (for testing) and live trading environments.
Add rpaca to your Cargo.toml:
[dependencies]
rpaca = "0.5.0"
rpaca requires Alpaca API credentials. You can create an account at Alpaca to obtain your
API key and secret.
Create a .env file in your project root:
APCA_API_KEY_ID=your_api_key
APCA_API_SECRET_KEY=your_api_secret
Then in your code:
use rpaca::auth::{Alpaca, TradingType};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// For paper trading (recommended for testing)
let alpaca = Alpaca::from_env(TradingType::Paper)?;
// For live trading
// let alpaca = Alpaca::from_env(TradingType::Live)?;
Ok(())
}
use rpaca::auth::{Alpaca, TradingType};
fn main() {
let client = Alpaca::new(
"your_api_key".to_string(),
"your_api_secret".to_string(),
TradingType::Paper
);
}
use rpaca::auth::{Alpaca, TradingType};
use rpaca::trading::v2::get_account_info::get_account_info;
#[tokio::main]
async fn main() {
let alpaca = Alpaca::from_env(TradingType::Paper).unwrap();
match get_account_info(&alpaca).await {
Ok(account) => println!("Account: {account:?}"),
Err(e) => println!("Error: {e:?}"),
}
}
use rpaca::auth::{Alpaca, TradingType};
use rpaca::trading::v2::orders::{create_order, OrderRequest};
#[tokio::main]
async fn main() {
let alpaca = Alpaca::from_env(TradingType::Paper).unwrap();
match create_order(&alpaca, OrderRequest::builder()
.symbol("AAPL")
.qty("1")
.side("buy")
.order_type("market")
.time_in_force("day")
.build()).await {
Ok(order) => {
println!("Order created: {:?}", order);
}
Err(e) => {
println!("Error: {:?}", e);
}
}
}
use rpaca::auth::{Alpaca, TradingType};
use rpaca::market_data::v2::stock::get_bars;
use chrono::{Utc, Duration};
#[tokio::main]
async fn main() {
let alpaca = Alpaca::from_env(TradingType::Paper).unwrap();
let end = Utc::now();
let start = end - Duration::days(7);
match get_bars(&alpaca, vec!["AAPL".to_string()], "1Day", start, end, 100).await {
Ok(bars) => println!("Bars: {:?}", bars),
Err(e) => println!("Error: {:?}", e),
}
}
For detailed documentation, visit docs.rs/rpaca.
This project is currently in active development. While the core functionality is stable, breaking changes may occur in future versions as we continue to expand the API coverage.
Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.
This project is licensed under either of:
at your option.