refactor: refactor future event list
This commit is contained in:
@@ -3,11 +3,6 @@ import { Injectable, ServiceUnavailableException } from '@nestjs/common';
|
||||
const baseUrl = 'https://iss.moex.com/iss';
|
||||
const timeoutMs = 10_000;
|
||||
|
||||
export type MoexDividend = {
|
||||
date: string;
|
||||
value: string;
|
||||
currency: string;
|
||||
};
|
||||
export type MoexBondEvent =
|
||||
| { type: 'coupon'; date: string; value: string; currency: string }
|
||||
| { type: 'maturity'; date: string; value: string; currency: string }
|
||||
@@ -18,19 +13,6 @@ type IssResponse = Record<string, IssBlock | undefined>;
|
||||
|
||||
@Injectable()
|
||||
export class MoexClient {
|
||||
async dividends(secid: string): Promise<MoexDividend[]> {
|
||||
const rows = await this.rows(
|
||||
`securities/${encodeURIComponent(secid)}/dividends.json`,
|
||||
'dividends',
|
||||
);
|
||||
return rows.flatMap((row) => {
|
||||
const date = text(row.registryclosedate);
|
||||
const value = numberText(row.value);
|
||||
const currency = currencyText(row.currencyid);
|
||||
return date && value && currency ? [{ date, value, currency }] : [];
|
||||
});
|
||||
}
|
||||
|
||||
async bondEvents(secid: string): Promise<MoexBondEvent[]> {
|
||||
const path = `securities/${encodeURIComponent(secid)}/bondization.json`;
|
||||
const [coupons, offers, description] = await Promise.all([
|
||||
@@ -122,7 +104,8 @@ export class MoexClient {
|
||||
}
|
||||
|
||||
function parseRows(block: IssBlock | undefined): Record<string, unknown>[] {
|
||||
if (!Array.isArray(block?.columns) || !Array.isArray(block.data))
|
||||
if (!block) return [];
|
||||
if (!Array.isArray(block.columns) || !Array.isArray(block.data))
|
||||
throw new ServiceUnavailableException({ code: 'MOEX_UNAVAILABLE' });
|
||||
const columns = block.columns;
|
||||
if (!columns.every((column) => typeof column === 'string'))
|
||||
|
||||
Reference in New Issue
Block a user