get-acoes-datas-pagamento
Retrieve payment dates for stocks within a date range, optionally filtering by specific stocks.
Instructions
Buscar datas de pagamento de ações
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| initialDate | Yes | Data inicial | |
| finalDate | Yes | Data final | |
| stocks | No | Ação |
Implementation Reference
- Handler method that orchestrates fetching stock payment dates, calling the private helper getDatesPayment for each stock (or all if none specified).
async getStockPaymentDates(paymentDatesInput: GetPaymentDatesInput) { const { initialDate, finalDate, stocks } = paymentDatesInput; if (!stocks || stocks.length === 0) { const response = await this.getDatesPayment(initialDate, finalDate); return response; } const data = []; for (const stock of stocks) { const response = await this.getDatesPayment( initialDate, finalDate, stock.toUpperCase(), ); if (response && response.length > 0) { data.push(...response); } } return data; } - API service handler that makes the actual HTTP request to the external API to get earnings/payment dates.
async getStockPaymentDates( paymentDatesInput: GetPaymentDatesInput, ): Promise<GetEarnings | null> { const { initialDate, finalDate, stock } = paymentDatesInput; let url = `/acao/getearnings?IndiceCode=Ibovespa&Start=${initialDate}&End=${finalDate}`; if (stock) { url += `&Filter=${stock}`; } const data = await this.makeJsonRequest<GetEarnings>(url); if (!data) return null; return data; } - Input schema for the API service layer (with optional single stock).
export interface GetPaymentDatesInput { initialDate: string; finalDate: string; stock?: string; } - Input and output schemas for the service layer (input has optional stocks array, output has payment details).
export interface GetPaymentDatesInput { initialDate: string; finalDate: string; stocks?: string[]; } export interface GetPaymentDatesOutput { code: string; companyName: string; price: number; dateCom: string; paymentDate: string; type: string; dy: string; url: string; } - Registration of the tool named 'get-acoes-datas-pagamento' with Zod schema validation for initialDate, finalDate, and optional stocks array.
private registerGetStockPaymentDatesToolHandler(): void { this.server.tool( 'get-acoes-datas-pagamento', 'Buscar datas de pagamento de ações', { initialDate: z .string() .refine((date) => dayjs(date, 'YYYY-MM-DD', true).isValid(), { message: 'Data inicial inválida. Formato esperado: YYYY-MM-DD', }) .describe('Data inicial'), finalDate: z .string() .refine((date) => dayjs(date, 'YYYY-MM-DD', true).isValid(), { message: 'Data final inválida. Formato esperado: YYYY-MM-DD', }) .describe('Data final'), stocks: z .array( z.string().regex(/^[A-Z]{4}(3|4|11)$/, { message: 'Código de ação inválido. Deve seguir o padrão: 4 letras + 3, 4 ou 11.', }), ) .optional() .describe('Ação'), }, async (args) => { const paymentDatesInput = args as GetPaymentDatesInput; const infos = await this.service.getStockPaymentDates(paymentDatesInput); return { content: [ { type: 'text', text: JSON.stringify(infos, null, 2), }, ], }; }, ); }