alpaca-http
HTTP REST API client for the Alpaca trading platform.
Overview
alpaca-http provides a high-level, asynchronous Rust client for Alpaca's REST API. It covers trading, market data, broker API, and account management endpoints, allowing you to build automated trading systems with ease.
Features
- Asynchronous API: Built on top of
reqwestandtokiofor high-performance, non-blocking I/O. - Comprehensive Endpoint Support:
- Trading: Place, list, and cancel orders (market, limit, stop, bracket, OCO, OTO).
- Account: Get account details, activities, portfolio history, and configurations.
- Market Data: Fetch bars, quotes, and trades for stocks, crypto, and options.
- Assets: List and query asset information.
- Broker API: Account management, funding, journals, and compliance.
- Options: Options contracts and market data.
- Corporate Actions: Dividends, splits, and other corporate events.
- Calendar & Clock: Market hours and trading calendar.
- Local Currency Trading: Exchange rates and FX support.
- IRA Accounts: Contributions, distributions, and beneficiaries.
- Type-Safe Requests: Structured request and response models for all endpoints.
- Automated Authentication: Handles API key headers and environment-based configuration.
- Rate Limiting: Built-in rate limit handling with retry support.
Installation
Add to your Cargo.toml:
[]
= "0.20.0"
Usage
use AlpacaHttpClient;
use AlpacaCredentials;
async
API Reference
Main Types
AlpacaHttpClient- The primary entry point for making REST API calls.CreateOrderRequest- Builder for order creation requests.ReplaceOrderRequest- Builder for order modification requests.
Main Modules
client- Core HTTP client implementation.endpoints- Request and response models for all supported endpoints.
Endpoint Categories
Trading API
get_account()- Get account informationcreate_order(),get_order(),list_orders(),cancel_order()- Order managementreplace_order()- Modify existing ordersget_position(),list_positions(),close_position()- Position managementlist_activities()- Account activitiesget_portfolio_history()- Historical portfolio data
Market Data API
get_bars(),get_multi_bars()- Stock bars (OHLCV)get_quotes(),get_trades()- Quotes and tradesget_crypto_bars()- Cryptocurrency dataget_option_bars()- Options market dataget_latest_quote(),get_latest_trade()- Real-time data
Assets & Options
list_assets(),get_asset()- Asset informationlist_option_contracts(),get_option_contract()- Options contracts
Broker API
create_broker_account(),get_broker_account()- Account managementcreate_ach_relationship(),list_ach_relationships()- ACH fundingcreate_transfer(),list_transfers()- Wire/ACH transferscreate_journal(),list_journals()- Journal entrieslist_documents(),get_document()- Account documents
Calendar & Clock
get_calendar()- Trading calendarget_clock()- Market clock status
Corporate Actions
list_corporate_actions()- Dividends, splits, etc.
Local Currency Trading
get_exchange_rates()- All exchange ratesget_exchange_rate()- Specific currency pair rate
IRA Accounts
list_ira_contributions(),create_ira_contribution()- IRA contributionslist_ira_distributions()- IRA distributionslist_ira_beneficiaries()- IRA beneficiaries
Examples
Run examples with cargo run -p alpaca-http --example <name>:
| Example | Description |
|---|---|
http_get_account |
Get account information |
http_create_market_order |
Place a market order |
http_create_limit_order |
Place a limit order with GTC |
http_list_orders |
List and filter orders |
http_cancel_order |
Cancel an open order |
http_get_positions |
List all positions |
http_close_position |
Close a position |
market_data |
Fetch real-time and historical market data |
options_trading |
Options trading examples |
trading_bracket_order |
Advanced bracket orders |
# Get account info
# Place a market order (Paper trading)
Note: Examples require ALPACA_API_KEY and ALPACA_API_SECRET environment variables.
Changelog
v0.20.0 (latest)
- Added IRA Account endpoints (contributions, distributions, beneficiaries)
- Added Local Currency Trading endpoints (exchange rates)
- Added Calendar & Clock endpoints
- Added Corporate Actions endpoints
- Added Options Trading endpoints
- Added Broker API endpoints (accounts, funding, journals)
- Added OAuth 2.0 support
- Improved async ergonomics
- Added support for latest market data v2 endpoints
License
MIT