Add Investments to your app

Learn how to add Investments endpoints to your application

In this guide, we'll start from scratch and walk through how to use Investments to retrieve information on securities and holdings. If you are already familiar with using Plaid and are set up to make calls to the Plaid API, you can skip ahead to Fetching investment data.

Get Plaid API keys

If you don't already have one, you'll need to create a Plaid developer account. After creating your account, you can find your API keys under the Team Settings menu on the Plaid developer dashboard.

Install Plaid libraries

You can use our official libraries to connect to the Plaid API from your application:

1
2
# Install via npm
npm install --save plaid

Create an Item in Link

Plaid Link is a drop-in module that provides a secure, elegant authentication flow for each institution that Plaid supports. Link makes it secure and easy for users to connect their bank accounts to Plaid. Note that these instructions cover Link on the web. For instructions on using Link within mobile apps, see the Link documentation.

Using Link, we will create a Plaid Item, which is a Plaid term for a login at a financial institution. An Item is not the same as a financial institution account, although every account will be associated with an Item. For example, if a user has one login at their bank that allows them to access both their checking account and their savings account, a single Item would be associated with both of those accounts. If you want to customize Link's look and feel, you can do so from the Dashboard.

Before initializing Link, you will need to create a new link_token on the server side of your application. A link_token is a short-lived, one-time use token that is used to authenticate your app with Link. You can create one using the /link/token/create endpoint. Then, on the client side of your application, you'll need to initialize Link with the link_token that you just created.

In the code samples below, you will need to replace PLAID_CLIENT_ID and PLAID_SECRET with your own keys, which you can obtain from the Dashboard.

Create a link_token
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Using Express
const express = require('express');
const app = express();
app.use(express.json());
const plaid = require('plaid');
const client = new plaid.Client({
clientID: process.env.PLAID_CLIENT_ID,
secret: process.env.PLAID_SECRET,
env: plaid.environments.sandbox,
});
app.post('/create_link_token', async (request, response) => {
try {
// Get the client_user_id by searching for the current user
const user = await User.find(...);
const clientUserId = user.id;
// Create the link_token with all of your configurations
const tokenResponse = await client.createLinkToken({
user: {
client_user_id: clientUserId,
},
client_name: 'Plaid Test App',
products: ["auth"],
country_codes: ['US'],
language: 'en',
webhook: 'https://webhook.sample.com',
});
response.json(tokenResponse);
} catch (e) {
// Display error on client
return response.send({ error: e.message });
}
});
Install Link dependency
1
2
3
4
<head>
<title>Connect a bank</title>
<script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
</head>
Configure the client-side Link handler
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
const linkHandler = Plaid.create({
token: (await $.post('/create_link_token')).link_token,
onSuccess: (public_token, metadata) => {
// Send the public_token to your app server.
$.post('/exchange_public_token', {
public_token: public_token,
});
},
onExit: (err, metadata) => {
// Optionally capture when your user exited the Link flow.
// Storing this information can be helpful for support.
},
onEvent: (eventName, metadata) => {
// Optionally capture Link flow events, streamed through
// this callback as your users connect an Item to Plaid.
},
});
linkHandler.open();

Get a persistent access_token

Next, on the server side, we need to exchange our public_token for an access_token and item_id. The access_token will allow us to make authenticated calls to the Plaid API. Doing so is as easy as calling the /item/public_token/exchange endpoint from our server-side handler. We'll use the client library we configured earlier to make the API call.

Save the access_token and item_id in a secure datastore, as they’re used to access Item data and identify webhooks, respectively. The access_token will remain valid unless you actively chose to expire it via rotation or remove the corresponding Item via /item/remove. The access_token should be stored securely, and never in client-side code. A public_token is a one-time use token with a lifetime of 30 minutes, so there is no need to store it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Using Express
const express = require('express');
const app = express();
app.use(express.json());
const plaid = require('plaid');
const client = new plaid.Client({
clientID: process.env.PLAID_CLIENT_ID,
secret: process.env.PLAID_SECRET,
env: plaid.environments.sandbox,
});
app.post('/exchange_public_token', async (request, response) => {
try {
const publicToken = request.body.public_token;
// Exchange the client-side public_token for a server access_token
const tokenResponse = await client.exchangePublicToken(publicToken);
// Save the access_token and item_id to a persistent database
const accessToken = tokenResponse.access_token;
const itemId = tokenResponse.item_id;
} catch (e) {
// Display error on client
return response.send({ error: e.message });
}
});

Fetching investment data

Now that the authentication step is out of the way, we can begin using authenticated endpoints from the Plaid API. Once you've retrieved investment data for an account, you can then use it to analyze data such as trading activity, net worth, and asset alloctions.

Investments endpoints return two primary pieces of information about the investment account. The first is details on the holding itself (if using /investments/holdings/get) or the transaction (if using /investments/transactions/get). The second is details about the security itself. Each security, transaction, and holding contains a security_id field, which functions as a key for cross-referencing the holding or transaction with the security it pertains to. For more detailed information on the schema for information returned by /investments/holdings/get or /investments/transactions/get, see the Investments Reference.

Investments data is typically updated daily, after market close. To be alerted when new data is available to be retrieved, listen to Investments webhooks.

Fetching investment holdings
1
2
3
4
5
6
7
// Pull Holdings for an Item
const response = await client.getHoldings(accessToken).catch((err) => {
// handle error
});
const holdings = response.holdings;
const securities = response.securities;

Example response data is below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
{
"accounts": [
{
"account_id": "5Bvpj4QknlhVWk7GygpwfVKdd133GoCxB814g",
"balances": {
"available": 43200,
"current": 43200,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
},
"mask": "4444",
"name": "Plaid Money Market",
"official_name": "Plaid Platinum Standard 1.85% Interest Money Market",
"subtype": "money market",
"type": "depository"
},
{
"account_id": "JqMLm4rJwpF6gMPJwBqdh9ZjjPvvpDcb7kDK1",
"balances": {
"available": null,
"current": 320.76,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
},
"mask": "5555",
"name": "Plaid IRA",
"official_name": null,
"subtype": "ira",
"type": "investment"
},
{
"account_id": "k67E4xKvMlhmleEa4pg9hlwGGNnnEeixPolGm",
"balances": {
"available": null,
"current": 23631.9805,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
},
"mask": "6666",
"name": "Plaid 401k",
"official_name": null,
"subtype": "401k",
"type": "investment"
}
],
"holdings": [
{
"account_id": "JqMLm4rJwpF6gMPJwBqdh9ZjjPvvpDcb7kDK1",
"cost_basis": 0.01,
"institution_price": 0.011,
"institution_price_as_of": null,
"institution_value": 110,
"iso_currency_code": "USD",
"quantity": 10000,
"security_id": "8E4L9XLl6MudjEpwPAAgivmdZRdBPJuvMPlPb",
"unofficial_currency_code": null
},
{
"account_id": "k67E4xKvMlhmleEa4pg9hlwGGNnnEeixPolGm",
"cost_basis": 23,
"institution_price": 27,
"institution_price_as_of": null,
"institution_value": 636.309,
"iso_currency_code": "USD",
"quantity": 23.567,
"security_id": "JDdP7XPMklt5vwPmDN45t3KAoWAPmjtpaW7DP",
"unofficial_currency_code": null
}
],
"item": {
"available_products": [
"balance",
"credit_details",
"identity",
"investments",
"liabilities",
"transactions"
],
"billed_products": ["assets", "auth", "investments"],
"consent_expiration_time": null,
"error": null,
"institution_id": "ins_3",
"item_id": "4z9LPae1nRHWy8pvg9jrsgbRP4ZNQvIdbLq7g",
"webhook": "https://www.genericwebhookurl.com/webhook"
},
"request_id": "l68wb8zpS0hqmsJ",
"securities": [
{
"close_price": 0.011,
"close_price_as_of": null,
"cusip": null,
"institution_id": null,
"institution_security_id": null,
"is_cash_equivalent": false,
"isin": null,
"iso_currency_code": "USD",
"name": "Nflx Feb 01'18 $355 Call",
"proxy_security_id": null,
"security_id": "8E4L9XLl6MudjEpwPAAgivmdZRdBPJuvMPlPb",
"sedol": null,
"ticker_symbol": "NFLX180201C00355000",
"type": "derivative",
"unofficial_currency_code": null
},
{
"close_price": 27,
"close_price_as_of": null,
"cusip": "577130834",
"institution_id": null,
"institution_security_id": null,
"is_cash_equivalent": false,
"isin": "US5771308344",
"iso_currency_code": "USD",
"name": "Matthews Pacific Tiger Fund Insti Class",
"proxy_security_id": null,
"security_id": "JDdP7XPMklt5vwPmDN45t3KAoWAPmjtpaW7DP",
"sedol": null,
"ticker_symbol": "MIPTX",
"type": "mutual fund",
"unofficial_currency_code": null
}
]
}
Fetching investment transactions
1
2
3
4
5
6
7
8
9
10
const response = await client
.getInvestmentTransactions(accessToken, '2019-03-01', '2019-04-30', {
count: 250,
offset: 0,
})
.catch((err) => {
// handle error
});
const investmentTransactions = response.investment_transactions;

Sample response data is below.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
{
"accounts": [
{
"account_id": "5e66Dl6jNatx3nXPGwZ7UkJed4z6KBcZA4Rbe",
"balances": {
"available": 100,
"current": 110,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
},
"mask": "0000",
"name": "Plaid Checking",
"official_name": "Plaid Gold Standard 0% Interest Checking",
"subtype": "checking",
"type": "depository"
},
{
"account_id": "KqZZMoZmBWHJlz7yKaZjHZb78VNpaxfVa7e5z",
"balances": {
"available": null,
"current": 320.76,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
},
"mask": "5555",
"name": "Plaid IRA",
"official_name": null,
"subtype": "ira",
"type": "investment"
},
{
"account_id": "rz99ex9ZQotvnjXdgQLEsR81e3ArPgulVWjGj",
"balances": {
"available": null,
"current": 23631.9805,
"iso_currency_code": "USD",
"limit": null,
"unofficial_currency_code": null
},
"mask": "6666",
"name": "Plaid 401k",
"official_name": null,
"subtype": "401k",
"type": "investment"
}
],
"investment_transactions": [
{
"account_id": "rz99ex9ZQotvnjXdgQLEsR81e3ArPgulVWjGj",
"amount": -8.72,
"cancel_transaction_id": null,
"date": "2020-05-29",
"fees": 0,
"investment_transaction_id": "oq99Pz97joHQem4BNjXECev1E4B6L6sRzwANW",
"iso_currency_code": "USD",
"name": "INCOME DIV DIVIDEND RECEIVED",
"price": 0,
"quantity": 0,
"security_id": "eW4jmnjd6AtjxXVrjmj6SX1dNEdZp3Cy8RnRQ",
"subtype": "dividend",
"type": "cash",
"unofficial_currency_code": null
},
{
"account_id": "rz99ex9ZQotvnjXdgQLEsR81e3ArPgulVWjGj",
"amount": -1289.01,
"cancel_transaction_id": null,
"date": "2020-05-28",
"fees": 7.99,
"investment_transaction_id": "pK99jB9e7mtwjA435GpVuMvmWQKVbVFLWme57",
"iso_currency_code": "USD",
"name": "SELL Matthews Pacific Tiger Fund Insti Class",
"price": 27.53,
"quantity": -47.74104242992852,
"security_id": "JDdP7XPMklt5vwPmDN45t3KAoWAPmjtpaW7DP",
"subtype": "sell",
"type": "sell",
"unofficial_currency_code": null
},
{
"account_id": "rz99ex9ZQotvnjXdgQLEsR81e3ArPgulVWjGj",
"amount": 7.7,
"cancel_transaction_id": null,
"date": "2020-05-27",
"fees": 7.99,
"investment_transaction_id": "LKoo1ko93wtreBwM7yQnuQ3P5DNKbKSPRzBNv",
"iso_currency_code": "USD",
"name": "BUY DoubleLine Total Return Bond Fund",
"price": 10.42,
"quantity": 0.7388014749727547,
"security_id": "NDVQrXQoqzt5v3bAe8qRt4A7mK7wvZCLEBBJk",
"subtype": "buy",
"type": "buy",
"unofficial_currency_code": null
}
],
"item": {
"available_products": ["assets", "balance", "identity", "transactions"],
"billed_products": ["auth", "investments"],
"consent_expiration_time": null,
"error": null,
"institution_id": "ins_12",
"item_id": "8Mqq5rqQ7Pcxq9MGDv3JULZ6yzZDLMCwoxGDq",
"webhook": "https://www.genericwebhookurl.com/webhook"
},
"request_id": "iv4q3ZlytOOthkv",
"securities": [
{
"close_price": 27,
"close_price_as_of": null,
"cusip": "577130834",
"institution_id": null,
"institution_security_id": null,
"is_cash_equivalent": false,
"isin": "US5771308344",
"iso_currency_code": "USD",
"name": "Matthews Pacific Tiger Fund Insti Class",
"proxy_security_id": null,
"security_id": "JDdP7XPMklt5vwPmDN45t3KAoWAPmjtpaW7DP",
"sedol": null,
"ticker_symbol": "MIPTX",
"type": "mutual fund",
"unofficial_currency_code": null
},
{
"close_price": 10.42,
"close_price_as_of": null,
"cusip": "258620103",
"institution_id": null,
"institution_security_id": null,
"is_cash_equivalent": false,
"isin": "US2586201038",
"iso_currency_code": "USD",
"name": "DoubleLine Total Return Bond Fund",
"proxy_security_id": null,
"security_id": "NDVQrXQoqzt5v3bAe8qRt4A7mK7wvZCLEBBJk",
"sedol": null,
"ticker_symbol": "DBLTX",
"type": "mutual fund",
"unofficial_currency_code": null
}
],
"total_investment_transactions": 2
}