This is a node and browser API client for the (undocumented) thinkorswim WebSocket API.
🚧 Work in progress 🚧
- Node 18+
yarn install
yarn build
Create a .env
file with the following:
DEBUG=*
DEBUG_DEPTH=5
# either the following
TOS_ACCESS_TOKEN=<access_token>
TOS_REFRESH_TOKEN=<refresh_token>
# or the following
# if you don't have an access token and refresh token, you can use your username and password
# this will launch a browser to authenticate and then save the access token and refresh token to .env
TOS_USERNAME=<username>
TOS_PASSWORD=<password>
node --env-file=.env dist/example/testApp.js
node --env-file=.env dist/example/wsProxyServer.js
node dist/example/wsProxyClient.js
> authenticateWithAccessToken {"accessToken":"<auth_token>","refreshToken":"<refresh_token>"}
> quotes ["ABNB", "UBER"]
> accountPositions "1234567890"
There seems to be currently two ways to authenticate:
-
From scratch with username and password:
1.1 Send a message with the
login/schwab
service including theauthCode
obtained from the browser oauth flow attrade.thinkorswim.com
;1.2 This will return a
token
andrefreshToken
which should be saved for future use;1.3. The
authCode
is single use and cannot be used again once exchanged for a token. -
From a previously obtained
token
2.1 Send a message with the
login
service including thetoken
returned from thelogin/schwab
response message (step 1 above)2.2 This will return the same
token
, weirdly, and arefreshToken
, which should be saved for future use2.3 The token is valid for 24 hours.
- ✅ Authentication via access token
- ✅ Quotes
- ✅ Price History (chart)
- ✅ Account positions
- ✅ Place & submit order
- ✅ Cancel order
- ✅ User properties
- ✅ Create alert
- ✅ Cancel alert
- ✅ Instrument search
- ✅ Option chains
- ✅ Alert lookup
- ✅ Option chain details
- ✅ Option chain quotes
- ✅ Option quotes
- ✅ Order events
- ✅ Market depth
- ✅ Get watchlist
- ❌ Instrument order events
- ❌ Alert subscription
- ❌ And many more 😀
import WsJsonClient from "tda-wsjson-client/wsJsonClient";
const client = new WsJsonClient();
await client.authenticate(accessToken);
console.log(loginResponse);
const chartRequest = {
symbol: "UBER",
timeAggregation: "DAY",
range: "YEAR2",
includeExtendedHours: true,
};
for await (const event of client.chart(chartRequest)) {
console.log(event);
}
For more sample usage check out https://github.com/huskly/tos-wsjson-client/blob/master/src/example/testApp.ts
yarn test
MIT