Skip to content

anthfran/wealthsimple-node

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wealthsimple-node

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

Installation

npm install --save https://github.com/anthfran/wealthsimple-node

Examples of Usage

See /examples folder for more

Load wealthsimple-node into your project

const credentials = {
  "client_id": "XXXXXXXXX",
  "client_secret": "XXXXXXXXX",
  "redirect_uri": "https://localhost:3000/auth"
};
const wealthsimple = require('wealthsimple-node').appId(credentials);

Exchange an auth code for a token object response

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
});

Call an API example (List Accounts)

// 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
});

Refresh tokens

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
});

Utilize "Refresh Token if Expired"

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
});

Table of Contents

tokenExchange

Exchanges an auth code for OAuth2 tokens

Parameters

  • code String Auth string from Wealthsimple redirect

Examples

wealthsimple.tokenExchange(authCode).then(response=>console.log(response));

Returns Promise Promise which will resolve containing OAuth2 Tokens

tokenRefresh

Refreshes OAuth2 tokens

Parameters

  • tokens Object Tokens object from Wealthsimple

Examples

wealthsimple.tokenRefresh(refreshToken).then(response=>console.log(response));

Returns Promise Promise which will resolve containing OAuth2 Tokens

refreshTokenIfExpired

If the token is not expired, return the tokens object. Otherwise refreshes the tokens

Parameters

  • tokens Object Tokens object from Wealthsimple

Returns Promise Promise which will resolve containing OAuth2 Tokens

createUser

Create a User https://developers.wealthsimple.com/#operation/Create%20User

Parameters

Examples

wealthsimple.createUser(body).then(response=>console.log(response));

Returns Promise Promise which will resolve with newly created user

listUsers

List Users https://developers.wealthsimple.com/#operation/List%20Users This API will return a list of Users scoped by the authorization credentials.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? See Wealthsimple website for an example of the request parameters

Examples

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

getUser

Get User https://developers.wealthsimple.com/#operation/Get%20User

Parameters

  • tokens Object Tokens object from Wealthsimple
  • userId String Example "user-12398ud"

Examples

wealthsimple.getUser(token, userId).then(response=>console.log(response));

Returns Promise Promise which will resolve with user info

createPerson

Create Person https://developers.wealthsimple.com/#operation/Create%20Person

Parameters

  • tokens Object Tokens object from Wealthsimple
  • body Object See Wealthsimple website for an example of the request body

Examples

wealthsimple.createPerson(token, body).then(response=>console.log(response));

Returns Promise Promise which will resolve with the created Person

listPeople

List People https://developers.wealthsimple.com/#operation/List%20People This API will return a list of People scoped by the authorization credentials.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object See Wealthsimple website for an example of the request parameters

Examples

wealthsimple.createPerson(token, body).then(response=>console.log(response));

Returns Promise Promise which will resolve with the list of people

getPerson

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.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • personId String Example "person-12398ud"

Examples

wealthsimple.getPerson(token, "person-12398ud").then(response=>console.log(response));

Returns Promise Promise which will resolve with the Person details

updatePerson

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.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • personId String Example "person-12398ud"
  • body Object See Wealthsimple website for an example of the body

Examples

wealthsimple.updatePerson(token, "person-12398ud", body).then(response=>console.log(response));

Returns Promise Promise which will resolve with the updated Person

createAccount

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.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • personId String Example "person-12398ud"
  • body Object See Wealthsimple website for an example of the body

Examples

wealthsimple.createAccount(token, body).then(response=>console.log(response));

Returns Promise Promise which will resolve with the created Account

listAccounts

List Accounts https://developers.wealthsimple.com/#operation/List%20Accounts

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? Optional filter params, See Wealthsimple website for an example of the request parameters

Examples

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

getAccount

Get Account https://developers.wealthsimple.com/#operation/Get%20Account

Parameters

  • tokens Object Tokens object from Wealthsimple
  • accountId String Account ID String

Examples

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

getAccountTypes

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

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? Optional filter params, See Wealthsimple website for an example of the request parameters

Examples

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

getDailyValues

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.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? Optional filter params, See Wealthsimple website for an example of the request parameters
    • params.accound_id Object Required account_id param

Examples

wealthsimple.getDailyValues(token,{ params.accound_id: "rrsp-r3e9c1w" }).then(response=>console.log(response));

Returns Promise Promise which will resolve with the account daily values

listPositions

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.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? Optional filter params, See Wealthsimple website for an example of the request parameters
    • params.accound_id Object Required account_id param

Examples

wealthsimple.listPositions(token,{ params.accound_id: "rrsp-r3e9c1w" }).then(response=>console.log(response));

Returns Promise Promise which will resolve with the account positions

listTransactions

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.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? Optional filter params, See Wealthsimple website for an example of the request parameters
    • params.accound_id Object Required account_id param

Examples

wealthsimple.listTransactions(token,{ params.accound_id: "rrsp-r3e9c1w" }).then(response=>console.log(response));

Returns Promise Promise which will resolve with the account transactions

getProjection

Get Projection https://developers.wealthsimple.com/#operation/Get%20Projection Retrieves a projections of returns for an account based on deposits and frequency.

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object Projection params
    • params.accound_id Object Required account_id param
    • params.amount Object Required deposit amount
    • params.frequency Object Required deposit frequency
    • params.start_date Object Required deposit start date

Examples

wealthsimple.getProjection(token, params).then(response=>console.log(response));

Returns Promise Promise which will resolve with the projection

listBankAccounts

List Bank Accounts https://developers.wealthsimple.com/#operation/List%20Bank%20Accounts

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? See website for optional query params

Examples

wealthsimple.listBankAccounts(token, params).then(response=>console.log(response));

Returns Promise Promise which will resolve with list of bank accounts

createDeposit

Create Deposit https://developers.wealthsimple.com/#operation/Create%20Deposit Initiates an electronic funds transfer to deposit funds to an Account from a Bank Account

Parameters

  • tokens Object Tokens object from Wealthsimple
  • body Object Required deposit details
    • body.bank_account_id Object The unique id of the Bank Account
    • body.account_id Object The unique id of the Account
    • body.amount Object Dollar amount
    • body.currency Object Currency

Examples

wealthsimple.createDeposit(token, body).then(response=>console.log(response));

Returns Promise Promise which will resolve with deposit info

listDeposits

List Deposits https://developers.wealthsimple.com/#operation/List%20Deposits

Parameters

  • tokens Object Tokens object from Wealthsimple
  • params Object? See website for optional query params

Examples

wealthsimple.listDeposits(token, body).then(response=>console.log(response));

Returns Promise Promise which will resolve with deposit list

getDeposit

Get Deposit https://developers.wealthsimple.com/#operation/List%20Deposits

Parameters

  • tokens Object Tokens object from Wealthsimple
  • fundsTransferId String funds_transfer_id

Examples

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.

About

Wealthsimple API integration for Node

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published