@alpaca-open-api/core
v1.0.2
Published
Typed fetch clients and types for the Alpaca Markets API, generated from the official OpenAPI specifications with Orval
Maintainers
Readme
- ⚡ Fully typed request/response types straight from the specs.
- 🛰️ One namespace per API:
tradingApi,dataApi,brokerApi,authxApi. - 🔒 Every call routes through one small shared mutator that resolves host + auth per API.
Install
npm install @alpaca-open-api/coreUsage
Credentials and environment come from env vars (ALPACA_API_KEY, ALPACA_API_SECRET, ALPACA_ENV; live by default), read by the shared mutator.
import { tradingApi, dataApi, tradingModel } from '@alpaca-open-api/core';
// Each call returns { data, status, headers }; `data` is typed from the spec.
const { data: account } = await tradingApi.getAccount();
console.log(account?.cash);
const { data: quote } = await dataApi.stockLatestQuoteSingle('AAPL', { feed: 'iex' });
console.log(quote?.quote?.ap);
// Place an order (uses the live account unless ALPACA_ENV=paper):
await tradingApi.postOrder({ symbol: 'AAPL', side: 'buy', qty: '1', type: 'market', time_in_force: 'day' });
// Schema types are exported per API as `*Model` namespaces:
type Account = tradingModel.Account;Client namespaces: tradingApi, dataApi, brokerApi, authxApi; matching model (schema) types: tradingModel, dataModel, brokerModel, authxModel. makeMutator and API_ROUTING are also exported if you need to customize routing.
Configuration
| Variable | Required | Default | Purpose |
| --- | :---: | --- | --- |
| ALPACA_API_KEY | ✅ | — | API key (live and paper keys are different) |
| ALPACA_API_SECRET | ✅ | — | API secret |
| ALPACA_ENV | | live | paper or live. Selects paper/live (trading) and sandbox/production (broker, authx). |
⚠️ Defaults to
live(real money/orders). SetALPACA_ENV=paper(with your paper keys) to test safely.
Documentation
Full docs, the MCP server (@alpaca-open-api/mcp), and source:
https://github.com/yagop/alpaca-open-api
Disclaimer
Unofficial and not affiliated with, endorsed by, or sponsored by Alpaca. Provided "as is", without warranty of any kind. Nothing here is financial, investment, or trading advice. Trading involves substantial risk of loss — always test with paper trading (ALPACA_ENV=paper) first.
