Browse Source

Add MCP tool to get performance

pull/7994/head
Thomas Kaul 2 weeks ago
parent
commit
f25d472853
  1. 28
      apps/api/src/services/portfolio-table/portfolio-table.service.spec.ts
  2. 22
      apps/api/src/services/portfolio-table/portfolio-table.service.ts

28
apps/api/src/services/portfolio-table/portfolio-table.service.spec.ts

@ -159,14 +159,12 @@ function createWatchlistItem({
function createPortfolioTableService({
accounts = [],
chart = [{ date: '2024-01-01' }],
errors = [],
holdings = [],
performance = createPerformance(),
watchlist = []
}: {
accounts?: AccountWithValue[];
chart?: HistoricalDataItem[];
errors?: PortfolioPerformanceResponse['errors'];
holdings?: PortfolioPosition[];
performance?: PortfolioPerformanceResponse['performance'];
watchlist?: WatchlistResponse['watchlist'];
@ -182,12 +180,7 @@ function createPortfolioTableService({
const portfolioService = {
getAccountsWithAggregations: jest.fn().mockResolvedValue({ accounts }),
getDetails: jest.fn().mockResolvedValue({ holdings }),
getPerformance: jest.fn().mockResolvedValue({
chart,
errors,
performance,
hasErrors: errors.length > 0
})
getPerformance: jest.fn().mockResolvedValue({ chart, performance })
} as unknown as PortfolioService;
const watchlistService = {
@ -415,25 +408,6 @@ describe('PortfolioTableService', () => {
}
});
it('tells the asset profiles of which the market data is delayed', async () => {
const result = await getPerformanceTable({
errors: [
{ dataSource: DataSource.MANUAL, symbol: 'AAPL' },
{ dataSource: DataSource.YAHOO, symbol: 'AAPL' }
]
});
expect(result).toContain(
'Market data is delayed for: AAPL (MANUAL), AAPL (YAHOO)'
);
});
it('tells no delay of the market data if there is no error', async () => {
const result = await getPerformanceTable();
expect(result).not.toContain('Market data is delayed');
});
it('tells that no performance is found if the chart is empty', async () => {
const result = await getPerformanceTable({ chart: [] });

22
apps/api/src/services/portfolio-table/portfolio-table.service.ts

@ -458,12 +458,11 @@ export class PortfolioTableService {
filters?: Filter[];
userId: string;
}) {
const { chart, errors, performance } =
await this.portfolioService.getPerformance({
dateRange,
filters,
userId
});
const { chart, performance } = await this.portfolioService.getPerformance({
dateRange,
filters,
userId
});
const performanceSection = ['## Performance', ''];
@ -475,17 +474,6 @@ export class PortfolioTableService {
rows: [performance]
})
);
if (errors?.length > 0) {
performanceSection.push(
'',
`Market data is delayed for: ${errors
.map(({ dataSource, symbol }) => {
return `${symbol} (${dataSource})`;
})
.join(', ')}`
);
}
} else {
performanceSection.push('No performance found.');
}

Loading…
Cancel
Save