A tiny Unofficial WealthSimple Trade API Wrapper for JavaScript, supporting the core abilities of the WealthSimple Trade application including placing orders, viewing and cancelling orders, and more.
USE AT YOUR OWN RISK. This is an unofficial WealthSimple Trade API Wrapper, and it is new. While i did (to my best ability) test the functions, there is absolutely no guarantee that there are no bugs in the code. The API Wrapper will be improved over time.
DO NOT LEVERAGE THIS IN ATTEMPT TO DISRUPT ORDERLY MARKET FUNCTIONS. This package is provided to you so you can build cool shit with it, but you should understand that you have a responsibility to not engage in illegal trading behaviours that can disrupt orderly market functions. This means that you should not flood the API with orders in a fast manner. You might even get banned or locked out by WealthSimple Trade if you abuse their endpoints.
You would be abusing this tool if you are leveraging it to carry out tactics that would provide you illegitimate personal gains. For example, Spoofing is a forbidden tactic that has demonstrable negative effects on the operation of the markets.
My recommendation is to be very conservative on how many orders you place within a small timeframe. I have no idea what the maximum amount of orders is by any timeframe, but if you have a gut feeling that it is too much, then it is too much.
Before playing with wstrade-api, you must have a valid WealthSimple Trade account to authenticate against. If you have not signed up for WealthSimple Trade, you may download the iOS application here or the android application here.
You just need node.js — and npm, obviously.
Install wstrade-api from the npm registry
npm i wstrade-api
You could also clone the GitHub repository
git clone [email protected]:ahmedsakr/wstrade-api.git
The dependency list is tiny — node-fetch and http-status. That's it.
- node-fetch - Used for interacting with the WealthSimple Trade API
- http-status - Used for well-known HTTP status codes.
After installing wstrade-api from the npm registry, import it into your JavaScript file.
import trade from 'wstrade-api';
This wrapper will not work when executed on the client-side due to the underlying CORS security limitation imposed by the WealthSimple Trade endpoints. If you wish to build a front-end application, you will have to design an architecture where the server does all of the API calls.
- trade.login()
- trade.refresh()
- trade.addHeader()
- trade.removeHeader()
- trade.clearHeaders()
- trade.getAccounts()
- trade.getAccountData()
- trade.getHistory()
- trade.getBankAccounts()
- trade.getDeposits()
- trade.getExchangeRates()
- trade.getOrdersByPage()
- trade.getOrders()
- trade.getPendingOrders()
- trade.getFilledOrders()
- trade.getCancelledOrders()
- trade.cancelOrder()
- trade.cancelPendingOrders()
- trade.getSecurity()
- trade.placeLimitBuy()
- trade.placeLimitSell()
For all API Calls, the failure return is standardized to the following:
{
status, // HTTP status
reason, // Failure reason,
// The body of the response
body: {
...
}
}
Attempts to login to the WealthSimple Trade platform using the email and password combination.
Parameters | Required |
---|---|
username | Yes |
password | Yes |
{
tokens: {
access, // Authentication token
refresh // Token to refresh authentication
},
// General information of the account
accountInfo: {
...
}
}
Generates a new set of access and refresh tokens.
Parameters | Required |
---|---|
tokens | Yes |
{
// A new generated set of access and refresh tokens
access: 'XXXXX',
refresh: 'YYYY'
}
Appends a custom header to all requests made with this wrapper.
Parameters | Required |
---|---|
name | Yes |
value | Yes |
Removes a custom header.
Parameters | Required |
---|---|
name | Yes |
Deletes all custom headers.
Grabs all account ids under this WealthSimple Trade account (i.e., all personal, TFSA, and RRSP account ids).
Parameters | Required |
---|---|
tokens | Yes |
// A list of account ids
['non-registered-XXXXX', 'tfsa-XXXXX', ...]
Provides the general state information of the overall WealthSimple Trade account, including current balance, net deposits, available to withdraw, creation date, and more.
Parameters | Required |
---|---|
tokens | Yes |
{
// General information of the overall WealthSimple Trade account
...
}
Captures a snapshot of the performance for a specific account in the provided time interval.
Parameters | Required | Acceptable values |
---|---|---|
tokens | Yes | |
interval | Yes | 1d, 1w, 1m, 3m, 1y |
accountId | Yes |
{
// Day basis performance of the account
results: [
// Day 1...
{
...
},
// Day 2...
{
...
},
...
]
// Current performance
...
}
Provides a list of the bank accounts that have been linked to the WealthSimple Trade account.
Parameters | Required |
---|---|
tokens | Yes |
[
// Bank account 1
{
...
},
// Bank account 2
{
...
},
...
]
All deposits (in progress, completed, and cancelled) made to the WealthSimple Trade account.
Parameters | Required |
---|---|
tokens | Yes |
[
// Deposit 1
{
...
},
// Deposit 2
{
...
},
...
]
Provides the current USD/CAD conversion rates for the WealthSimple Trade platform.
Parameters | Required |
---|---|
tokens | Yes |
{
"USD": {
"buy_rate": 1.xxx,
"sell_rate": 1.xxx,
"spread": 0.xxx,
"fx_rate": 1.xxx
}
}
Grabs a page (20) of orders (filled, pending, and cancelled) from a specific account under the WealthSimple Trade account.
Note: The pages of orders are sorted by most recent. If you specify a page that exceeds the number of pages, the results list will be empty.
Parameters | Required | Acceptable Values |
---|---|---|
tokens | Yes | |
accountID | Yes | |
page | Yes | >=1 |
{
orders: [
// Order 1
{
...
},
// Order 2
{
...
},
...
],
// Total number of orders
total: XXX
}
Grabs all orders (filled, pending, and cancelled) from a specific account under the WealthSimple Trade account.
Parameters | Required |
---|---|
tokens | Yes |
accountID | Yes |
{
orders: [
// Order 1
{
...
},
// Order 2
{
...
},
...
],
// Total number of orders
total: XXX
}
Grabs all pending orders for the specified account under the WealthSimple Trade account.
Note: You may restrict the pending orders to a specific security by providing the ticker.
Parameters | Required |
---|---|
tokens | Yes |
accountID | Yes |
ticker | No |
{
orders: [
// Pending Order 1
{
...
},
// Pending Order 2
{
...
},
...
],
// Total number of pending orders
total: XXX
}
Grabs all filled orders for the specified account under the WealthSimple Trade account.
Note: You may restrict the filled orders to a specific security by providing the ticker.
Parameters | Required |
---|---|
tokens | Yes |
accountID | Yes |
ticker | No |
{
orders: [
// Filled Order 1
{
...
},
// Filled Order 2
{
...
},
...
],
// Total number of filled orders
total: XXX
}
Grabs all cancelled orders for the specified account under the WealthSimple Trade account.
Note: You may restrict the cancelled orders to a specific security by providing the ticker.
Parameters | Required |
---|---|
tokens | Yes |
accountID | Yes |
ticker | No |
{
orders: [
// Cancelled Order 1
{
...
},
// Cancelled Order 2
{
...
},
...
],
// Total number of cancelled orders
total: XXX
}
Attempts to cancel the order associated with the provided orderId.
Note: The order might NOT be cancelled if it was filled by WealthSimple Trade. This has nothing to do with this wrapper; be cautious!
Parameters | Required |
---|---|
tokens | Yes |
orderId | Yes |
{
order: 'order-XXXX',
response: {} // The API returns nothing.
}
Place a cancellation order for all pending orders in the provided account.
Note: The orders might NOT be cancelled if it was filled by WealthSimple Trade. This has nothing to do with this wrapper; be cautious!
Parameters | Required |
---|---|
tokens | Yes |
accountId | Yes |
[
// Cancelled Order 1
{
order: 'order-XXXXXXXX',
response: {} // The API returns nothing.
},
// Cancelled Order 2
{
order: 'order-XXXXXXXX',
response: {} // The API returns nothing.
},
...
]
Information about a security on the WealthSimple Trade Platform.
Parameters | Required |
---|---|
tokens | Yes |
ticker | Yes |
{
// A lot of information about the security
...
}
Attempts to purchase a given quantity of a security at a maximum price.
Parameters | Required |
---|---|
tokens | Yes |
accountId | Yes |
ticker | Yes |
limit | Yes |
quantity | Yes |
{
// Confirmation and details of the limit buy
...
}
Attempts to sell a given quantity of a security at a minimum price.
Parameters | Required |
---|---|
tokens | Yes |
accountId | Yes |
ticker | Yes |
limit | Yes |
quantity | Yes |
{
// Confirmation and details of the limit sell
...
}
Feel free to fork the GitHub repository, make any changes, and contribute by setting up a pull request. This project is new and help is greatly appreciated.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Ahmed Sakr - Owner - @ahmedsakr
This project is licensed under the MIT License.
A huge thanks to the contributors of this repository for providing an elegant API documentation.