Plaid logo
Docs
ALL DOCS

Investments

  • Introduction to Investments
  • Add Investments to your app
Plaid logo
Docs
Close search modal
Ask Bill!
Ask Bill!
Hi! I'm Bill! You can ask me all about the Plaid API. Try asking questions like:
    Note: Bill isn't perfect. He's just a robot platypus that reads our docs for fun. You should treat his answers with the same healthy skepticism you might treat any other answer on the internet. This chat may be logged for quality and training purposes. Please don't send Bill any PII -- he's scared of intimacy. All chats with Bill are subject to Plaid's Privacy Policy.
    Plaid.com
    Log in
    Get API Keys
    Open nav

    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 and complete application and company profile

    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 Dashboard.

    You will also need to complete your application profile and company profile on the Dashboard. The information in your profile will be shared with users of your application when they manage their connection on the Plaid Portal. Your application profile and company profile must be completed before connecting to certain institutions in Production.

    Install and initialize Plaid libraries

    You can use our official server-side client libraries to connect to the Plaid API from your application:

    Select Language
    1// Install via npm
    2npm install --save plaid

    After you've installed Plaid's client libraries, you can initialize them by passing in your client_id, secret, and the environment you wish to connect to (Sandbox or Production). This will make sure the client libraries pass along your client_id and secret with each request, and you won't need to explicitly include them in any other calls.

    Select Language
    1// Using Express
    2const express = require('express');
    3const app = express();
    4app.use(express.json());
    5
    6const { Configuration, PlaidApi, PlaidEnvironments } = require('plaid');
    7
    8const configuration = new Configuration({
    9 basePath: PlaidEnvironments.sandbox,
    10 baseOptions: {
    11 headers: {
    12 'PLAID-CLIENT-ID': process.env.PLAID_CLIENT_ID,
    13 'PLAID-SECRET': process.env.PLAID_SECRET,
    14 },
    15 },
    16});
    17
    18const client = new PlaidApi(configuration);

    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.

    Create a link_token
    Select Language
    1const request: LinkTokenCreateRequest = {
    2 loading_sample: true
    3};
    4try {
    5 const response = await plaidClient.linkTokenCreate(request);
    6 const linkToken = response.data.link_token;
    7} catch (error) {
    8 // handle error
    9}
    Install Link dependency
    Select Language
    1<head>
    2 <title>Connect a bank</title>
    3 <script src="https://cdn.plaid.com/link/v2/stable/link-initialize.js"></script>
    4</head>
    Configure the client-side Link handler
    1const linkHandler = Plaid.create({
    2 token: (await $.post('/create_link_token')).link_token,
    3 onSuccess: (public_token, metadata) => {
    4 // Send the public_token to your app server.
    5 $.post('/exchange_public_token', {
    6 public_token: public_token,
    7 });
    8 },
    9 onExit: (err, metadata) => {
    10 // Optionally capture when your user exited the Link flow.
    11 // Storing this information can be helpful for support.
    12 },
    13 onEvent: (eventName, metadata) => {
    14 // Optionally capture Link flow events, streamed through
    15 // this callback as your users connect an Item to Plaid.
    16 },
    17});
    18
    19linkHandler.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.

    Select group for content switcher
    Select Language
    1app.post('/api/exchange_public_token', async function (
    2 request,
    3 response,
    4 next,
    5) {
    6 const publicToken = request.body.public_token;
    7 try {
    8 const response = await client.itemPublicTokenExchange({
    9 public_token: publicToken,
    10 });
    11
    12 // These values should be saved to a persistent database and
    13 // associated with the currently signed-in user
    14 const accessToken = response.data.access_token;
    15 const itemID = response.data.item_id;
    16
    17 res.json({ public_token_exchange: 'complete' });
    18 } catch (error) {
    19 // handle error
    20 }
    21});

    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 allocations.

    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, see /investments/holdings/get or /investments/transactions/get.

    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
    Select group for content switcher
    Select Language
    1const { InvestmentsHoldingsGetRequest } = require('plaid');
    2
    3// Pull Holdings for an Item
    4const request: InvestmentsHoldingsGetRequest = {
    5 access_token: accessToken,
    6};
    7try {
    8 const response = await plaidClient.investmentsHoldingsGet(request);
    9 const holdings = response.data.holdings;
    10 const securities = response.data.securities;
    11} catch (error) {
    12 // handle error
    13}

    Example response data is below.

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

    Sample response data is below.

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

    Next steps

    If you're ready to launch to Production, see the Launch checklist.

    Launch checklist

    Recommended steps to take before launching in Production

    Launch

    Launch checklist

    Recommended steps to take before launching in Production

    Launch
    Was this helpful?
    Developer community
    GitHub
    GitHub
    Stack Overflow
    Stack Overflow
    YouTube
    YouTube
    Discord
    Discord