6 releases
Uses new Rust 2024
| 0.8.1 | Nov 13, 2025 |
|---|---|
| 0.8.0 | Nov 13, 2025 |
| 0.7.8 | Sep 11, 2025 |
| 0.7.6 | Aug 20, 2025 |
#727 in Asynchronous
260KB
4K
SLoC
📦 rpaca – A Rust Client for the Alpaca Trading API
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.
🚀 Overview
rpaca provides a Rust interface to the Alpaca API, allowing developers to:
- Access and manage trading accounts
- Submit and track orders for stocks and other assets
- Monitor positions and portfolio performance
- Access market data for stocks and options
- Work with watchlists and other account features
The library supports both paper trading (for testing) and live trading environments.
✨ Features
Trading
- ✅ Authentication - Simple API key authentication with support for environment variables
- ✅ Account Management - Access account information and configurations
- ✅ Order Management - Submit and manage stock orders with various order types
- ✅ Portfolio Management - View and manage positions and overall portfolio
- ✅ Market Data - Access stock and options data
- ✅ Calendar & Clock - Fetch market calendar and clock data
- ✅ Watchlists - Create and manage watchlists
- 🚧 Crypto - Access to cryptocurrency endpoints (in development)
Market Data
- ✅ Stock - Get all stock information
- 🚧 Everything else work in progress
📋 Installation
Add rpaca to your Cargo.toml:
[dependencies]
rpaca = "0.5.0"
🔑 Authentication
rpaca requires Alpaca API credentials. You can create an account at Alpaca to obtain your
API key and secret.
Using Environment Variables
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(())
}
Direct Authentication
use rpaca::auth::{Alpaca, TradingType};
fn main() {
let client = Alpaca::new(
"your_api_key".to_string(),
"your_api_secret".to_string(),
TradingType::Paper
);
}
📝 Examples
Getting Account Information
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:?}"),
}
}
Creating an Order
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);
}
}
}
Getting Market Data
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),
}
}
📚 Documentation
For detailed documentation, visit docs.rs/rpaca.
🛠️ Development Status
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.
🤝 Contributing
Contributions are welcome! Feel free to open issues or submit pull requests on the GitHub repository.
📜 License
This project is licensed under either of:
at your option.
Dependencies
~9–28MB
~358K SLoC