Crate apca

source ·
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§

  • A module comprising the functionality backing interactions with the trading API.
  • A module for retrieving market data.

Structs§

  • An error as reported by API endpoints.
  • An object encapsulating the information used for working with the Alpaca API.
  • A Client is the entity used by clients of this module for interacting with the Alpaca API.

Enums§

  • The error type as used by this crate.
  • An error encountered while issuing a request.

Traits§

  • A trait representing “something” that users can subscribe to to receive updates through a stream.