Node.js client developed for HackThe6 for the Wealthsimple API - https://developers.wealthsimple.com
Note: Development on this has been halted, as I do not have valid API credentials after HackThe6 has been completed. There are not functions for every API and they have not been fully tested. I do not work for Wealthsimple and do not know if this module will ever be completed.
This uses a functional programming style which provides a function for each individual API implemented.
TODO List:
- Complete functions for all Wealthsimple API's in v1
- Break up into multiple files (auth, users, accounts, people, etc) so that you can import less code if not all are functions required
- Write unit tests
- Complete examples
npm install --save https://github.com/anthfran/wealthsimple-node
See /examples folder for more
const credentials = {
"client_id": "XXXXXXXXX",
"client_secret": "XXXXXXXXX",
"redirect_uri": "https://localhost:3000/auth"
};
const wealthsimple = require('wealthsimple-node').appId(credentials);Note: This will return the whole tokens object, some which you may need and some which you may not. The only keys that are important to save are:
- access_token
- refresh_token
- created_at
- expires_in
You can save the entire response if you want. An example below will create a tokens object that can be used by this library.
wealthsimple.tokenExchange(authCode)
.then(response => {
return {
access_token: response.access_token,
refresh_token: response.refresh_token,
created_at: response.created_at,
expires_in: response.expires_in
}
})
.then(tokens => {
// store tokens
})
.catch(error => {
// do something with error
});// NB: Params are optional and a full list can be found on the Wealthsimple website
let params = {
account_types: "ca_tfsa"
};
wealthsimple.listAccounts(tokens, params);
})
.catch(error => {
// do something with error
});wealthsimple.tokenRefresh(tokens)
.then(response => {
// store the response, or just the minimum data as below
return {
access_token: response.access_token,
refresh_token: response.refresh_token,
created_at: response.created_at,
expires_in: response.expires_in
}
})
.then(tokens => {
// store tokens
});wealthsimple.refreshTokenIfExpired(tokens)
.then(refreshed => {
if (tokens.access_token !== refreshed.access_token) {
// store new tokens
}
let params = {}
return wealthsimple.listAccounts(tokens, params);
})
.catch(error => {
// do something with error
});- tokenExchange
- tokenRefresh
- refreshTokenIfExpired
- createUser
- listUsers
- getUser
- createPerson
- listPeople
- getPerson
- updatePerson
- createAccount
- listAccounts
- getAccount
- getAccountTypes
- getDailyValues
- listPositions
- listTransactions
- getProjection
- listBankAccounts
- createDeposit
- listDeposits
- getDeposit
Exchanges an auth code for OAuth2 tokens
codeString Auth string from Wealthsimple redirect
wealthsimple.tokenExchange(authCode).then(response=>console.log(response));Returns Promise Promise which will resolve containing OAuth2 Tokens
Refreshes OAuth2 tokens
tokensObject Tokens object from Wealthsimple
wealthsimple.tokenRefresh(refreshToken).then(response=>console.log(response));Returns Promise Promise which will resolve containing OAuth2 Tokens
If the token is not expired, return the tokens object. Otherwise refreshes the tokens
tokensObject Tokens object from Wealthsimple
Returns Promise Promise which will resolve containing OAuth2 Tokens
Create a User https://developers.wealthsimple.com/#operation/Create%20User
bodyObject
wealthsimple.createUser(body).then(response=>console.log(response));Returns Promise Promise which will resolve with newly created user
List Users https://developers.wealthsimple.com/#operation/List%20Users This API will return a list of Users scoped by the authorization credentials.
tokensObject Tokens object from WealthsimpleparamsObject? See Wealthsimple website for an example of the request parameters
wealthsimple.listUsers(token).then(response=>console.log(response));let params = { limit: 25, offset: 50, created_before: "2017-06-21"};
wealthsimple.listUsers(token, params).then(response=>console.log(response));Returns Promise Promise which will resolve with newly created user
Get User https://developers.wealthsimple.com/#operation/Get%20User
wealthsimple.getUser(token, userId).then(response=>console.log(response));Returns Promise Promise which will resolve with user info
Create Person https://developers.wealthsimple.com/#operation/Create%20Person
tokensObject Tokens object from WealthsimplebodyObject See Wealthsimple website for an example of the request body
wealthsimple.createPerson(token, body).then(response=>console.log(response));Returns Promise Promise which will resolve with the created Person
List People https://developers.wealthsimple.com/#operation/List%20People This API will return a list of People scoped by the authorization credentials.
tokensObject Tokens object from WealthsimpleparamsObject See Wealthsimple website for an example of the request parameters
wealthsimple.createPerson(token, body).then(response=>console.log(response));Returns Promise Promise which will resolve with the list of people
Get Person https://developers.wealthsimple.com/#operation/Get%20Person Get a Person entity if you know the person_id and the current credentials have access to the Person.
wealthsimple.getPerson(token, "person-12398ud").then(response=>console.log(response));Returns Promise Promise which will resolve with the Person details
Update Person https://developers.wealthsimple.com/#operation/Update%20Person You can add/remove information to the Person entity as the information becomes available using this API. To remove a previously set attribute, set the value to null. Attributes that are not mentioned in the request payload will leave the attribute unchanged in the Person entity.
tokensObject Tokens object from WealthsimplepersonIdString Example "person-12398ud"bodyObject See Wealthsimple website for an example of the body
wealthsimple.updatePerson(token, "person-12398ud", body).then(response=>console.log(response));Returns Promise Promise which will resolve with the updated Person
Create Account https://developers.wealthsimple.com/#operation/Create%20Account You can add/remove information to the Person entity as the information becomes available using this API. To remove a previously set attribute, set the value to null. Attributes that are not mentioned in the request payload will leave the attribute unchanged in the Person entity.
tokensObject Tokens object from WealthsimplepersonIdString Example "person-12398ud"bodyObject See Wealthsimple website for an example of the body
wealthsimple.createAccount(token, body).then(response=>console.log(response));Returns Promise Promise which will resolve with the created Account
List Accounts https://developers.wealthsimple.com/#operation/List%20Accounts
tokensObject Tokens object from WealthsimpleparamsObject? Optional filter params, See Wealthsimple website for an example of the request parameters
wealthsimple.listAccounts(token).then(response=>console.log(response));wealthsimple.listAccounts(token,params).then(response=>console.log(response));Returns Promise Promise which will resolve with the list of accounts
Get Account https://developers.wealthsimple.com/#operation/Get%20Account
wealthsimple.listAccounts(token).then(response=>console.log(response));wealthsimple.getAccount(token,accountId).then(response=>console.log(response));Returns Promise Promise which will resolve with the account details
Get Account Types https://developers.wealthsimple.com/#operation/Get%20Account%20Types Returns openable account types. If a client_id is provided it will scope the types to the client in question, otherwise it will default to the requestor
tokensObject Tokens object from WealthsimpleparamsObject? Optional filter params, See Wealthsimple website for an example of the request parameters
wealthsimple.getAccountTypes(token).then(response=>console.log(response));wealthsimple.getAccountTypes(token,params).then(response=>console.log(response));Returns Promise Promise which will resolve with the account details
Get Daily Values https://developers.wealthsimple.com/#operation/List%20Daily%20Values Returns historical daily values for a given account. This API will only return a maximum of 365 days worth of daily values from a given start date. By default, it will return historical values for the last 30-days. The start date must occur before the end date if provided. If the difference between the start date and the end date exceeds 365 days, an error will be thrown. The number of Daily Values can be potentially prohibitively large, the results are paginated.
tokensObject Tokens object from WealthsimpleparamsObject? Optional filter params, See Wealthsimple website for an example of the request parametersparams.accound_idObject Required account_id param
wealthsimple.getDailyValues(token,{ params.accound_id: "rrsp-r3e9c1w" }).then(response=>console.log(response));Returns Promise Promise which will resolve with the account daily values
List Positions https://developers.wealthsimple.com/#tag/Positions Returns positions for a given account. This API will also allow you to retrieve historical Positions held on a given date.
tokensObject Tokens object from WealthsimpleparamsObject? Optional filter params, See Wealthsimple website for an example of the request parametersparams.accound_idObject Required account_id param
wealthsimple.listPositions(token,{ params.accound_id: "rrsp-r3e9c1w" }).then(response=>console.log(response));Returns Promise Promise which will resolve with the account positions
List Transactions https://developers.wealthsimple.com/#operation/List%20Transactions Lists all Transactions. The number of Transactions can be potentially prohibitively large, the results are paginated. By default, the API will return the 250 latest transactions in the last 30 days.
tokensObject Tokens object from WealthsimpleparamsObject? Optional filter params, See Wealthsimple website for an example of the request parametersparams.accound_idObject Required account_id param
wealthsimple.listTransactions(token,{ params.accound_id: "rrsp-r3e9c1w" }).then(response=>console.log(response));Returns Promise Promise which will resolve with the account transactions
Get Projection https://developers.wealthsimple.com/#operation/Get%20Projection Retrieves a projections of returns for an account based on deposits and frequency.
wealthsimple.getProjection(token, params).then(response=>console.log(response));Returns Promise Promise which will resolve with the projection
List Bank Accounts https://developers.wealthsimple.com/#operation/List%20Bank%20Accounts
wealthsimple.listBankAccounts(token, params).then(response=>console.log(response));Returns Promise Promise which will resolve with list of bank accounts
Create Deposit https://developers.wealthsimple.com/#operation/Create%20Deposit Initiates an electronic funds transfer to deposit funds to an Account from a Bank Account
wealthsimple.createDeposit(token, body).then(response=>console.log(response));Returns Promise Promise which will resolve with deposit info
List Deposits https://developers.wealthsimple.com/#operation/List%20Deposits
wealthsimple.listDeposits(token, body).then(response=>console.log(response));Returns Promise Promise which will resolve with deposit list
Get Deposit https://developers.wealthsimple.com/#operation/List%20Deposits
let fundsTransferId = "funds_transfer_id-r3e9c1w";
wealthsimple.getDeposit(token, fundsTransferId).then(response=>console.log(response));Returns Promise Promise which will resolve with a deposit entity.