WebSocket client for the Thinkorswim wsjson websocket API
npm install tos-wsjson-clientThis 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:
``
NODE_ENV=development
DEBUG=*
DEBUG_DEPTH=5either the following
TOS_ACCESS_TOKEN=
TOS_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 the .env.development file.
TOS_USERNAME=
TOS_PASSWORD=
``
node --env-file=.env dist/example/testApp.js
``
node --env-file=.env dist/example/wsProxyServer.js
``
node dist/example/wsProxyClient.js
> authenticateWithAccessToken {"accessToken":"
> quotes ["ABNB", "UBER"]
> accountPositions "1234567890"
There seems to be currently two ways to authenticate:
1. From scratch with username and password:
1.1 Send a message with the login/schwab service including the authCode obtained from the browser oauth flow at trade.thinkorswim.com;
1.2 This will return a token and refreshToken which should be saved for future use;
1.3. The authCode is single use and cannot be used again once exchanged for a token.
2. From a previously obtained token
2.1 Send a message with the login service including the token returned from the login/schwab response message (step 1 above)
2.2 This will return the same token, weirdly, and a refreshToken, which should be saved for future use
2.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 š
``
yarn add tos-wsjson-client
`typescript
import { WsJsonClient } from "toa-wsjson-client";
const client = new WsJsonClient();
await client.authenticateWithAccessToken(accessToken, refreshToken);
const chartRequest = {
symbol: "UBER",
timeAggregation: "DAY",
range: "YEAR2",
includeExtendedHours: true,
};
for await (const { body: 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