schwab-node
schwab-node is a Node.js/TypeScript SDK that simplifies access to Charles Schwab's developer APIs.
Overview
This package was designed to reduce the amount of brokerage-specific plumbing required before market-data applications become useful. Rather than exposing raw API mechanics directly, it organizes functionality around practical domains such as market data, account access, derivatives, and live stream consumption.
This SDK provides:
- OAuth login and token refresh
- authenticated request construction
- response validation
- real-time streaming setup
- a set of higher-level helpers for common options workflow
System Outline
This system is organized around three primary services:
1. Authentication
- Primary authentication
- Automatic re-authentication
2. API Requests
- Account/orders
- Historical data
- Securities snapshot
- Bespoke derivative search
3. Streaming
- Simplified connection to Schwab's stream
- All outbound traffic is run through ZeroMQ, allowing language-agnostic connections to the data stream
Key Technical Decisions
Centralized Authentication
- With multiple, disparate modules potentially needing authentication, the auth layer exists as a separate broker of authentication, shared among modules while retaining control of its own refresh and initiation logic.
Centralized Request Logic
- Schwab-node utilizes a centralized request pattern so ownership of request and auth resides in one place (and not spread about the package), and the API logic doesn't need to integrate any authentication.
- This centralized configuration also allows us to implement a rate-limited queue so as not to run afoul of Schwab's rate limits.
Zod-backed request and response validation
- Because input and output integrity is critical for financial data, Zod provides a runtime trust boundary for both.
Websocket → ZeroMQ
- The Schwab stream's surface is designed so the user never interacts with the WebSocket directly. The SDK provides simplified (but not simple) interactions with the stream.
- With ZeroMQ, we can have a single upstream connection and many local consumers.
- ZeroMQ is language agnostic—you can consume the stream with interfaces written in a number of languages.
Current public surface
Account
- getAccounts
- getAccountNumbers
- getUserPreference
Market Data
- getQuote
- getPriceHistory
- getMovers
- getMarketHours
Derivatives
- getOptionChain
- getOptionExpirations
- getAtmOptionData
- greekFilter
Streaming
- SchwabStreamer
- order book / chart / screener / account activity streams
- ZeroMQ publisher/subscriber helpers