@migueddev/schwab-client
v1.1.0
Published
Unofficial Schwab API for trading and market data (TypeScript/Node.js)
Maintainers
Readme
📦 @migueddev/schwab-client
An unofficial client in Node.js + TypeScript to interact with the Charles Schwab API.
Supports OAuth2 authentication, token auto-refresh, authorization scraping, and access to Trader and Market Data APIs.
✨ Features
- 🔑 OAuth2 Authentication (Authorization Code + Refresh Token)
- ♻️ Automatic token refresh
- 📂 Token persistence in JSON file
- 🛠 Modular: Clear separation between
TraderAPI,MarketDataAPI - 🖥 TOTP (2FA) support
- 🤖 Scraping with Puppeteer to get the
authorization_code
📦 Installation
npm install @migueddev/schwab-client🚀 Usage
Client initialization
import { SchwabClient } from '@migueddev/schwab-client';
(async () => {
const client = await SchwabClient.init({
loginId: 'your-login-id',
password: 'your-password',
totpSecret: 'your-2fa-secret',
appKey: 'your-app-key',
appSecret: 'your-app-secret',
callbackUrl: 'https://your-callback-url.com',
tokensFilePath: './tokens.json', // optional
timeoutMs: 5000, // optional
enableLogging: true, // optional
autoRefreshTokens: true, // optional
});
// List all linked accounts
const accounts = await client.trader.getLinkedAccounts();
console.log(accounts);
// Get details for a specific account
const accountDetails = await client.trader.getAccountDetails(
accounts[0].accountHash,
{ fields: 'positions' },
);
console.log(accountDetails);
})();⚙️ API
The client presents the following main modules:
trader
getLinkedAccounts()- Get list of linked account numbers (encrypted)getAccountDetails(accountHash, params)- Get balances and optionally positions for a specific accountgetAllAccountsDetails(params)- Get balances and optionally positions for all linked accountsgetAccountOrders(accountHash, params)- Get orders for a specific accountplaceOrder(accountHash, orderRequest)- Place a new order for a specific accountgetOrderDetails(accountHash, orderId)- Get details of a specific order for a specific accountcancelOrder(accountHash, orderId)- Cancel a specific order for a specific accountreplaceOrder(accountHash, orderId, orderRequest)- Replace a specific order for a specific accountgetAllOrders(params)- Get all orders across all accountspreviewOrder(accountHash, previewOrder)- Preview an order before placing it
👪 Contributing
Contributions to @migueddev/schwab-client are always welcome! If you want to contribute:
- Follow Conventional Commits: All commit messages should follow the Conventional Commits standard.
- Fork the repository and create a branch for your feature or bugfix.
- Write clear code and tests: Make sure your code is well-structured, readable, and includes tests where applicable.
- Submit a Pull Request (PR): Provide a detailed description of the changes and link any related issues.
- Review Process: Your PR will be reviewed and feedback may be provided before merging.
We appreciate your contributions to make @migueddev/schwab-client better!
📜 Licencia
This project is under license MIT.
⚠️ Disclaimer
This is an unofficial Schwab API client. Use at your own risk. Please adhere to Charles Schwab's Terms and Conditions.
