Connect Schwab
AlertKeeper reads your Schwab accounts through Schwab's own API, with an app key of your own: once a day it brings in your positions and balances, the transactions since the last read, and the greeks of your open options. It never trades. Your broker files keep working as before -- a row both carry is counted once, matched by what it means: Schwab's API lists each fill of an order where the file shows the order, dates an expiry the day it was posted, and moves cash to and from its bank sweep, which the files never show. The app key must be yours alone: Schwab keeps one sign-in per app key and login, so another program signing in with the same key ends AlertKeeper's sign-in (and the other way round).
Steps
- If another program on this computer already signs in to Schwab with the app key you mean to use, don't sign in twice -- AlertKeeper's sign-in would end that program's. Set that program to use AlertKeeper's sign-in instead (Sharing the sign-in with your own programs, below), and only then Connect here.
- On developer.schwab.com, sign up for a developer account with your Schwab login. Schwab looks at new developer accounts before they can make apps; that can take a few days.
- Make one app, just for AlertKeeper (the product Accounts and Trading Production). For its callback, copy the address Settings → Broker shows -- this computer (127.0.0.1), port 8080, /callback -- exactly; choose another port there first if 8080 is taken on your computer. Schwab reviews new apps: wait until it says Ready For Use.
- Your app's page there shows its App key and Secret. In AlertKeeper: Settings → Broker, type both and the callback port, and press Connect. Both go into your Keychain (Mac) or Credential Manager (Windows), never into a file.
- Schwab's sign-in opens in your browser: sign in, allow access, and choose the accounts AlertKeeper may read.
- The browser then warns that 127.0.0.1's connection isn't private: that's AlertKeeper on your own computer, catching Schwab's answer. Choose to go on (Advanced → Proceed). If the browser won't, copy the whole address from its address bar into Or paste the address on Settings → Broker.
- Press Read now on Settings → Broker for the first read (two years of transactions, a minute or two); after that it happens by itself once a day, and the button says when: Read at 2:17 PM.
What you should see
- Settings → Broker: Connected · sign in again by a day 7 days ahead (and how long that is), and a table of your Schwab accounts -- each with the AlertKeeper account it fills, when it was last read, its cash and its value. An account AlertKeeper already had (the same last digits) is filled; a new one appears as "Schwab ...123" -- rename it on Settings → Accounts. An account you don't want (an empty one, say): Read it? says Reading; change makes it Not read -- the daily read leaves it alone and never makes it again.
- A position moved whole from one of your accounts to another ends in the first with no gain or loss and goes on in the second.
- A close of a position opened before the oldest history Schwab gives (two years back) is a grey note on Trades -- its gain isn't known, so it's in no total. Nothing to do.
- Two days before the 7-day sign-in ends, Positions and AlertKeeper's dot say "Sign in to Schwab again by Tue 10/21 2:16 PM": Connect again on Settings → Broker, and it clears.
- Positions: your Schwab positions and trades, as with your files, and Δ · Θ (delta and theta) beside each open option.
- Health's Broker card: when each account was last read, and the daily refresh. Schwab's sign-in lasts 7 days; then it wants you to sign in again: Connect again.
If it doesn't work
- Health's Broker card is red, "Schwab refused the token's refresh" with Schwab's reason: the sign-in ended early (often another program signed in with the same app key). Connect again; if another program uses the key, give AlertKeeper an app of its own.
- "Port 8080 is in use": another program is listening there right now. Try again in a minute, or paste the address.
- "Schwab said no": the key or secret was typed wrong, or the app isn't Ready For Use yet, or its callback isn't exactly the one Settings → Broker shows.
- A row under Review in Schwab's own words: a kind of transaction AlertKeeper doesn't read yet. It's kept as Schwab gave it, never guessed; your broker file for those days fills the gap.
- An account's line on Settings → Broker says what went wrong when a read didn't finish; the next day's read tries again from where the last whole one ended.
- To stop: Disconnect wipes the key, the secret and the tokens.
Sharing the sign-in with your own programs
Most people never need this. It's for someone who also runs a program of their own that reads Schwab with the same app key: rather than signing in itself -- which would end AlertKeeper's sign-in -- that program can use AlertKeeper's.
The sign-in's state, always: AlertKeeper keeps a small file other programs on this computer may read, broker/schwab-status.json in AlertKeeper's data folder (~/Library/Application Support/AlertKeeper on a Mac, %LOCALAPPDATA%\AlertKeeper on Windows): when the current access token runs out (expires_at), when it was last refreshed (last_refresh_at) and, if Schwab refused a refresh, its code, words and time (refusal) -- times in seconds since 1970. No token is ever in it.
The token itself, only when you say: on Settings → Broker, Share the sign-in with other programs on this Mac (off until you turn it on). AlertKeeper then writes broker/schwab-share.json, which only you can read, with the address to ask and the key. Your program sends a GET to that address with the header Authorization: Bearer and the key, and gets back access_token and expires_at (seconds since 1970); AlertKeeper keeps the token fresh, so it answers at once. A wrong key gets 401 -- read the file again, AlertKeeper may have started since; with sharing off, or no sign-in, 503. Never the refresh token, the app key or the secret; only from this computer; a new key each time AlertKeeper starts; nothing at all while the switch is off. The Broker page says it's on, and when the sign-in was last given.
Good to know
- What is stored where: the app key, the secret and the tokens only in your Keychain (Mac) or Credential Manager (Windows) -- never in a file, a backup or a log. AlertKeeper's data folder keeps only the names of those entries, the callback port, the dates, and for each Schwab account its last digits and Schwab's own name for it -- never the full account number.
- AlertKeeper never trades: it doesn't use Schwab's order functions at all.