fastify-xplaid
investments.getTransactions(accessToken, startDate, endDate, options?)
Get investment transaction history by date range for a Plaid Item.
investments.getTransactions(accessToken, startDate, endDate, options?)
Returns investment transaction history — buys, sells, dividends, fees, and transfers — within a date range. Paginate using count and offset against totalInvestmentTransactions. Requires the investments product to have been enabled in the Link token.
Signature
fastify.xplaid.investments.getTransactions(
accessToken: string,
startDate: string,
endDate: string,
options?: {
accountIds?: string[]
count?: number // max 500
offset?: number
}
): Promise<{
accounts: PlaidAccount[]
investmentTransactions: InvestmentTransaction[]
securities: Security[]
totalInvestmentTransactions: number
item: PlaidItem
requestId: string
}>
Params
| Name | Type | Required | Description |
|---|---|---|---|
accessToken | string | Yes | The Item's permanent access token. |
startDate | string | Yes | Start date in YYYY-MM-DD format (inclusive). |
endDate | string | Yes | End date in YYYY-MM-DD format (inclusive). |
options.accountIds | string[] | No | Restrict to specific account IDs. |
options.count | number | No | Max results per page (max 500). |
options.offset | number | No | Pagination offset for subsequent pages. |
Returns
Promise<{ accounts, investmentTransactions, securities, totalInvestmentTransactions, item, requestId }>
| Field | Description |
|---|---|
investmentTransactions | Investment activity — each includes type, subtype, amount, date, quantity, price, and security_id. |
securities | Security metadata for all referenced security IDs. |
totalInvestmentTransactions | Total transaction count across all pages — use with offset to paginate. |
Throws
[xPlaid] accessToken is required and must be a non-empty string[xPlaid] startDate is required and must be a non-empty string[xPlaid] endDate is required and must be a non-empty string- Plaid API errors — shape:
{ message, statusCode, plaidError }. PRODUCTS_NOT_SUPPORTEDPlaid error ifinvestmentswas not enabled.
Examples
Basic — last 30 days of investment activity
const end = new Date().toISOString().slice(0, 10);
const start = new Date(Date.now() - 30 * 86400000).toISOString().slice(0, 10);
const { investmentTransactions, securities } =
await fastify.xplaid.investments.getTransactions(accessToken, start, end);
Realistic — paginated investment history route
fastify.get("/investments/transactions", async (request, reply) => {
const { startDate, endDate, page = 0 } = request.query;
const item = await db.plaidItems.findFirst({ where: { userId: request.user.id } });
if (!item) return reply.status(404).send({ error: "No linked account" });
try {
const { investmentTransactions, securities, totalInvestmentTransactions } =
await fastify.xplaid.investments.getTransactions(
decrypt(item.accessToken),
startDate,
endDate,
{ count: 100, offset: page * 100 }
);
const securityMap = Object.fromEntries(securities.map((s) => [s.security_id, s]));
return {
total: totalInvestmentTransactions,
transactions: investmentTransactions.map((t) => ({
date: t.date,
type: t.type,
subtype: t.subtype,
amount: t.amount,
quantity: t.quantity,
price: t.price,
ticker: securityMap[t.security_id]?.ticker_symbol,
name: securityMap[t.security_id]?.name,
})),
};
} catch (error) {
if (error.plaidError) {
request.log.error({ code: error.plaidError.error_code }, "Investment transactions failed");
return reply.status(error.statusCode ?? 500).send({ error: error.message });
}
throw error;
}
});
Full paginated fetch
async function fetchAllInvestmentTransactions(accessToken, startDate, endDate) {
const PAGE = 500;
let offset = 0;
let all = [];
while (true) {
const { investmentTransactions, totalInvestmentTransactions } =
await fastify.xplaid.investments.getTransactions(accessToken, startDate, endDate, {
count: PAGE,
offset,
});
all = all.concat(investmentTransactions);
offset += investmentTransactions.length;
if (offset >= totalInvestmentTransactions) break;
}
return all;
}
See also
- investments.getHoldings(accessToken, options?) — Current portfolio positions and securities.
- accounts.get(accessToken, options?) — All accounts including investment accounts.
- liabilities.get(accessToken) — Credit card, mortgage, and student loan data.
- link.createToken(options) — Must include
"investments"inproducts. - fastify-xplaid overview — Plugin setup and options.
AI Context
package: "@xenterprises/fastify-xplaid"
method: fastify.xplaid.investments.getTransactions(accessToken, startDate, endDate, options?)
use-when: Get investment transaction history (buys, sells, dividends, fees) by date range — requires "investments" product
params: accessToken, startDate (YYYY-MM-DD), endDate (YYYY-MM-DD), options (accountIds, count, offset)
returns: { investmentTransactions, securities, totalInvestmentTransactions, accounts, item, requestId }
