Equities

Schwab Setup Guide

Time: 15 minutes | Difficulty: Advanced | Market: Equities Mode: Full automation (conditional) | API: Schwab Trader API (REST + Streaming) | Docs: developer.schwab.com

This guide wires a Schwab stock trading bot to the Schwab Trader API using the botwir3 runtime. Configure API credentials, connect to US equities, and run automated trading strategies locally.


⚠ Access requirements

Schwab requires developer application approval before API trading access is granted. This may include:

  • Registering a developer application at developer.schwab.com
  • Approval process (typically 1-3 business days)
  • OAuth2 authentication with token refresh (30-minute access tokens, 7-day refresh tokens)
  • Non-commercial use terms for individual accounts

Schwab Developer Portal — Application Registration

The user is responsible for obtaining appropriate access and complying with all platform terms.

Before you start

Verify that automated operation is permitted under Schwab's current terms of service before deploying. The Schwab Trader API replaced the legacy TD Ameritrade API. botwir3 provides tools for building structured automation. The user is responsible for compliance with the platform's terms and all applicable regulations.

Schwab Terms of Service | Last verified: May 2026

What you need

  • A Schwab brokerage account
  • A registered developer application (approved)
  • OAuth2 client ID and secret from the developer portal
  • The botwir3 runtime downloaded and unzipped
  • A strategy config file from the builder

Step 1: Create API credentials

  1. Register at developer.schwab.com
  2. Create a new application under My Apps
  3. Set the callback URL to https://127.0.0.1 (for local OAuth flow)
  4. Wait for approval (1-3 business days)
  5. Once approved, note the Client ID and Client Secret
  6. Complete the OAuth2 authorization flow to obtain access and refresh tokens

Permissions required: Trading access is granted through the Schwab Trader API — Individual product. Permissions to disable: N/A. Withdrawal is not available through the API.

🔒 Security. OAuth2 access tokens expire after 30 minutes and must be refreshed using the 7-day refresh token. The bot handles token refresh automatically. Credentials are stored in a local config file and are not transmitted to botwir3 or any third party. botwir3 never sees, stores, or has access to platform credentials.

Step 2: Configure the adapter

Create adapter.json in the bot directory:

{
  "adapter": "schwab",
  "credentials": {
    "client_id": "paste-client-id-here",
    "client_secret": "paste-client-secret-here",
    "refresh_token": "paste-refresh-token-here"
  },
  "trading_pair": "AAPL",
  "environment": "live",
  "rate_limit_ms": 500
}

Common symbols: AAPL, TSLA, SPY, QQQ, MSFT, NVDA. Schwab uses standard ticker symbols.

API keys are stored in a local config file on the machine running the bot. They are not transmitted to botwir3 or any third party. botwir3 never sees, stores, or has access to platform credentials.

Step 3: Test the connection

botwir3 test --adapter schwab

Expected output:

[botwir3] Adapter: schwab
[botwir3] Connection: OK
[botwir3] OAuth2: token valid (refreshes automatically)
[botwir3] Permissions: trading
[botwir3] Rate limit: per API documentation

Step 4: Start the bot

botwir3 start --config my-strategy.json

The runtime loads the strategy, computes the spec hash, connects to Schwab via the local OAuth2 credentials, and begins evaluating signals. The gate function compares proposed actions against the configured spec. The user is responsible for monitoring the bot and verifying execution outcomes.

Rate limits and considerations

EndpointLimitNotes
REST APIRate-limited per documentationApplies to all endpoints.
StreamingPer connectionReal-time quotes and order updates.
OAuth2 tokens30-minute access / 7-day refreshBot handles refresh automatically. Refresh tokens must be regenerated after 7 days of inactivity.

Token management. The 7-day refresh token expires if not used within 7 days. If the bot is stopped for longer than 7 days, the OAuth2 authorization flow must be completed again to obtain a new refresh token.

Pattern Day Trader rule. Accounts under $25,000 are subject to FINRA's Pattern Day Trader rule. The user is responsible for understanding and configuring strategy constraints accordingly.

Common Schwab bot configurations include long-term DCA into index funds (SPY, QQQ), momentum strategies on large-cap equities, and options strategies for accounts with options approval. All actions and decisions are recorded in the local ledger.

Troubleshooting

ErrorCauseFix
CONNECTION_REFUSEDOAuth2 token expired or invalidRe-run the OAuth2 authorization flow to obtain new tokens
TOKEN_REFRESH_FAILEDRefresh token expired (>7 days inactive)Complete the full OAuth2 authorization flow again
APP_NOT_APPROVEDDeveloper application still pendingWait for approval (1-3 business days) or check developer portal status
PERMISSION_DENIEDAccount not enabled for the requested operationVerify account permissions in the Schwab brokerage dashboard
MANDATE_INTEGRITY_VIOLATIONConfig file modified while bot is runningStop the bot, verify config, restart

Related guides


One bot. $129. No subscription. No $749/mo platform. → Build for Schwab


Build your Charles Schwab bot

Ready to build?