import { Injectable } from "@angular/core"; import { of as observableOf, Observable, throwError } from "rxjs"; import { HttpClient, HttpHeaders } from "@angular/common/http"; import { retry, catchError, map, timeout } from "rxjs/operators"; import { environment } from "@environments/environment"; @Injectable({ providedIn: "root" }) export class InstrumentCalculations { time: number = 6000; constructor(private http: HttpClient) {} // Calculos para lete leteCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: string }, info_instrumento: { valor_nominal: number; plazo: number; comision_casa_porcentaje: number; comision_bolsa_porcentaje: number; rendimiento_bruto: number; fecha_operacion: string; fecha_liquidacion?: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete/lete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } ceteCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: string; id_periodicidad: string; id_formato_ingreso: string; }, info_instrumento: { valor_nominal: number; comision_casa_porcentaje: number; comision_bolsa_porcentaje: number; plazo: number; rendimiento_bruto: number; otros_costos: number; fecha_operacion: string; fecha_liquidacion: string; fecha_ultima_cupon: string; fecha_vencimiento: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete/cete`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } // Para vcn y papel bursatil vcnCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: string; id_periodicidad: string; id_formato_ingreso: string; }, info_instrumento: { valor_par: boolean; valor_nominal: number; comision_casa_porcentaje: number; comision_bolsa_porcentaje: number; rendimiento_bruto: number; otros_costos: number; plazo: number; renta_porcentaje: number; fecha_operacion: string; fecha_liquidacion: string; fecha_ultima_cupon: string; fecha_vencimiento: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete/vcn`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } dapCalc( codigo_instrumento: string, info_inversion: { id_tipo_base: string; id_periodicidad: string; id_formato_ingreso: string; }, info_instrumento: { monto_inversion: number; tasa_porcentaje: number; renta_porcentaje: number; plazo: number; fecha_operacion: string; fecha_vencimiento: string; } ): Observable { return this.http .post(`${environment.productionApiUrl}/autocomplete/dap`, { codigo_instrumento, info_inversion, info_instrumento }) .pipe( map(response => { return response; }), catchError(this.errorHandl) ); } errorHandl(error) { let errorMessage = ""; if (error.error) { // Get client-side error errorMessage = error.error; } else { // Get server-side error errorMessage = `Error Code: ${error.status}\nMessage: ${error.message}`; } return throwError(errorMessage); } }