Skip to main content

@alpacahq/alpaca-trade-api

A TypeScript SDK for the Alpaca Trading API and Market Data API, with a single unified Alpaca client, typed errors and response metadata, opt-in resilience (retry with observability / timeout / rate limiting / secure-by-default redirects), pagination helpers, ergonomic order builders, normalized market-data accessors, and real-time WebSocket streaming. Dual ESM + CJS build; requires Node ≥ 20.

How the docs are organized

  • Getting started — install, first call, order builders, and workflow helpers.
  • Authentication — API keys, OAuth, paper/live/sandbox.
  • Resilience & configuration — retry (with onRetry/onGiveUp observability), timeouts, redirects, rate limiting, typed errors, and response headers via withResponse.
  • Market data — normalized, symbol-keyed accessors and latest-price helpers.
  • Streaming — real-time trading and market-data WebSocket streams.
  • Pagination — iterate/collect helpers and the generic pagination helper.
  • Runtime & module compatibility — the Node/Bun/Deno/edge/browser support matrix, ESM + CJS module formats, the REST-only entrypoint, and dependencies.
  • Examples — runnable end-to-end programs (a paper trading bot and a market-data backend), generated from the repository examples during every docs build.
  • API reference — a curated, example-driven reference for every REST endpoint (Trading API and Market Data API) in the sidebar, generated from the SDK's capability maps. Streaming and ergonomic helpers are documented in the guides above.

The repository README.md remains the canonical narrative; these pages are a focused companion.