Expand description
A crate for interacting with the Alpaca
API. In many ways it mirrors the
structure of the upstream API, which is composed of functionality
for trading (represented here by the api
module) as well as
market data retrieval (provided as part of the data
module).
Most operations require a Client
object, instantiation of which
in turn happens via a ApiInfo
instance, which captures relevant
configuration data such as credentials and URLs to use. A common
workflow is to just set the APCA_API_KEY_ID
(to the Alpaca key ID)
and APCA_API_SECRET_KEY
(to the Alpaca secret key) environment
variables and use default values for everything else.
use apca::ApiInfo;
use apca::Client;
// Assumes credentials to be present in the `APCA_API_KEY_ID` and
// `APCA_API_SECRET_KEY` environment variables.
let api_info = ApiInfo::from_env().unwrap();
let client = Client::new(api_info);
With a Client
instance available, we can now start issuing
requests to the upstream Trading API.
use apca::api::v2::account;
// Inquire general information about the account, such as available
// cash and buying power.
let account = client.issue::<account::Get>(&()).await.unwrap();
let currency = account.currency;
println!("cash:\t{} {currency}", account.cash);
println!("buying power:\t{} {currency}", account.buying_power);
Modules§
- api
- A module comprising the functionality backing interactions with the trading API.
- data
- A module for retrieving market data.
Structs§
- ApiError
- An error as reported by API endpoints.
- ApiInfo
- An object encapsulating the information used for working with the Alpaca API.
- Client
- A
Client
is the entity used by clients of this module for interacting with the Alpaca API.
Enums§
- Error
- The error type as used by this crate.
- Request
Error - An error encountered while issuing a request.
Traits§
- Subscribable
- A trait representing “something” that users can subscribe to to receive updates through a stream.