|
@ -1,14 +1,19 @@ |
|
|
|
|
|
import { ConfigurationService } from '@ghostfolio/api/services/configuration/configuration.service'; |
|
|
import { DataEnhancerInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-enhancer.interface'; |
|
|
import { DataEnhancerInterface } from '@ghostfolio/api/services/data-provider/interfaces/data-enhancer.interface'; |
|
|
import { DEFAULT_REQUEST_TIMEOUT } from '@ghostfolio/common/config'; |
|
|
import { DEFAULT_REQUEST_TIMEOUT } from '@ghostfolio/common/config'; |
|
|
import { parseSymbol } from '@ghostfolio/common/helper'; |
|
|
import { parseSymbol } from '@ghostfolio/common/helper'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { Injectable } from '@nestjs/common'; |
|
|
import { SymbolProfile } from '@prisma/client'; |
|
|
import { SymbolProfile } from '@prisma/client'; |
|
|
import got from 'got'; |
|
|
import got, { Headers } from 'got'; |
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class OpenFigiDataEnhancerService implements DataEnhancerInterface { |
|
|
export class OpenFigiDataEnhancerService implements DataEnhancerInterface { |
|
|
private static baseUrl = 'https://api.openfigi.com'; |
|
|
private static baseUrl = 'https://api.openfigi.com'; |
|
|
|
|
|
|
|
|
|
|
|
public constructor( |
|
|
|
|
|
private readonly configurationService: ConfigurationService |
|
|
|
|
|
) {} |
|
|
|
|
|
|
|
|
public async enhance({ |
|
|
public async enhance({ |
|
|
response, |
|
|
response, |
|
|
symbol |
|
|
symbol |
|
@ -29,6 +34,12 @@ export class OpenFigiDataEnhancerService implements DataEnhancerInterface { |
|
|
symbol, |
|
|
symbol, |
|
|
dataSource: response.dataSource |
|
|
dataSource: response.dataSource |
|
|
}); |
|
|
}); |
|
|
|
|
|
const headers: Headers = {}; |
|
|
|
|
|
|
|
|
|
|
|
if (this.configurationService.get('OPEN_FIGI_API_KEY')) { |
|
|
|
|
|
headers['X-OPENFIGI-APIKEY'] = |
|
|
|
|
|
this.configurationService.get('OPEN_FIGI_API_KEY'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
let abortController = new AbortController(); |
|
|
let abortController = new AbortController(); |
|
|
|
|
|
|
|
@ -38,6 +49,7 @@ export class OpenFigiDataEnhancerService implements DataEnhancerInterface { |
|
|
|
|
|
|
|
|
const mappings = await got |
|
|
const mappings = await got |
|
|
.post(`${OpenFigiDataEnhancerService.baseUrl}/v3/mapping`, { |
|
|
.post(`${OpenFigiDataEnhancerService.baseUrl}/v3/mapping`, { |
|
|
|
|
|
headers, |
|
|
json: [{ exchCode: exchange, idType: 'TICKER', idValue: ticker }], |
|
|
json: [{ exchCode: exchange, idType: 'TICKER', idValue: ticker }], |
|
|
// @ts-ignore
|
|
|
// @ts-ignore
|
|
|
signal: abortController.signal |
|
|
signal: abortController.signal |
|
|