Not sure if you’re still looking for a solution to this, but I can share what I’ve been doing to get a cash balance snapshot. It uses the working code examples from the API tutorials, so the tvPost and getAvailableAccounts functions are imported from the services.js and storage.js helper files, respectively. You will also need to authorize your access token, etc.
let cash = await tvPost('/cashBalance/getcashbalancesnapshot', {
accountId: getAvailableAccounts()[0].id
});
Note that this endpoint pulls from the REST API, so I would only do this once at the start of your session (it’s nice to have it immediately). In order to keep it up-to-date though, you should connect to the WebSocket and subscribe to the user/syncrequest endpoint. There is an excellent example of how this works here.
Every time you make a trade, it will update your cashBalance entity before and after you enter the position, so you should be able to use that to update your balance. If you are in the middle of a trade and want to keep a running tally, you will need to query your positions and current prices (by subscribing to the market data URL) and calculate the running P&L. This is Alexander’s solution, if you’re interested in checking it out.