Schwab API Setup Instructions¶
✅ Your Configuration is Ready!¶
Your Schwab credentials are properly configured:
- API Key: XmMkbKAQvjPC8SyxeC3u...
- App Secret: nqBhlSgTLP2eZapGeQdZ...
- Callback URL: https://127.0.0.1:5000/callback
🔐 One-Time Authentication Required¶
You need to authenticate once to create a token file. After that, it will work automatically.
Option 1: Run the Setup Script (Recommended)¶
Open a new terminal window and run:
This will: 1. Open your browser to Schwab login 2. Ask you to approve the app 3. Redirect you to a URL (will show SSL error - that's OK!) 4. Copy the ENTIRE URL from browser address bar 5. Paste it back in terminal
Option 2: Manual Python Authentication¶
If you prefer, run this in a Python terminal:
Then paste this code:
from schwab import auth
from dotenv import load_dotenv
import os
# Load credentials
load_dotenv('/Users/bertfrichot/Claude-Micro-Cap-Experiment/.env')
api_key = os.getenv('SCHWAB_CLIENT_ID')
app_secret = os.getenv('SCHWAB_CLIENT_SECRET')
callback_url = os.getenv('SCHWAB_CALLBACK_URL')
token_path = os.path.expanduser('~/.schwab_tokens.json')
# Authenticate (will open browser)
client = auth.client_from_manual_flow(
api_key=api_key,
app_secret=app_secret,
callback_url=callback_url,
token_path=token_path
)
# Test connection
accounts = client.get_account_numbers().json()
print(f"✅ Success! Found {len(accounts)} account(s)")
print(f"✅ Tokens saved to: {token_path}")
What to Expect:¶
- Browser opens - Log in to Schwab
- Approve access - Click "Allow" or "Approve"
- Redirect page - You'll see an SSL error page (this is normal!)
- Copy URL - Copy the ENTIRE URL from address bar, looks like:
- Paste back - Paste into terminal when prompted
- Done! - Token file created at
~/.schwab_tokens.json
After Authentication:¶
Once you have the token file, you can use Schwab API in any script:
from schwab import auth
import os
api_key = os.getenv('SCHWAB_CLIENT_ID')
app_secret = os.getenv('SCHWAB_CLIENT_SECRET')
token_path = os.path.expanduser('~/.schwab_tokens.json')
client = auth.client_from_token_file(token_path, api_key, app_secret)
# Now you can use the client!
accounts = client.get_account_numbers().json()
Troubleshooting:¶
SSL Certificate Error in Browser: - This is NORMAL! Just copy the URL from address bar anyway
"Callback URL mismatch":
- Make sure your Schwab app has callback URL: https://127.0.0.1:5000/callback
- Must match exactly (including port 5000)
Token expires: - Tokens expire after ~7 days of inactivity - Just run setup again to refresh
🚀 Next Steps After Setup:¶
Once authenticated, you can:
-
Test connection:
-
Fetch live portfolio data:
-
Run trading analytics with real data:
📝 Token File Location:¶
Your tokens will be saved at:
Keep this file safe! It contains your authentication credentials.
Need Help?
Run the setup script and follow the prompts. If you get stuck, let me know what error you see!