Refactor interface of getQuotes() to object (#2570)

pull/2578/head
Thomas Kaul 1 year ago committed by GitHub
parent cf7ce64de7
commit a704378702
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -105,9 +105,11 @@ export class AlphaVantageService implements DataProviderInterface {
return DataSource.ALPHA_VANTAGE;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
return {};
}

@ -134,13 +134,15 @@ export class CoinGeckoService implements DataProviderInterface {
return DataSource.COINGECKO;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
const results: { [symbol: string]: IDataProviderResponse } = {};
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
const response: { [symbol: string]: IDataProviderResponse } = {};
if (aSymbols.length <= 0) {
return {};
if (symbols.length <= 0) {
return response;
}
try {
@ -151,7 +153,7 @@ export class CoinGeckoService implements DataProviderInterface {
}, DEFAULT_REQUEST_TIMEOUT);
const response = await got(
`${this.URL}/simple/price?ids=${aSymbols.join(
`${this.URL}/simple/price?ids=${symbols.join(
','
)}&vs_currencies=${DEFAULT_CURRENCY.toLowerCase()}`,
{
@ -162,7 +164,7 @@ export class CoinGeckoService implements DataProviderInterface {
for (const symbol in response) {
if (Object.prototype.hasOwnProperty.call(response, symbol)) {
results[symbol] = {
response[symbol] = {
currency: DEFAULT_CURRENCY,
dataProviderInfo: this.getDataProviderInfo(),
dataSource: DataSource.COINGECKO,
@ -175,7 +177,7 @@ export class CoinGeckoService implements DataProviderInterface {
Logger.error(error, 'CoinGeckoService');
}
return results;
return response;
}
public getTestSymbol() {

@ -311,7 +311,9 @@ export class DataProviderService {
i + maximumNumberOfSymbolsPerRequest
);
const promise = Promise.resolve(dataProvider.getQuotes(symbolsChunk));
const promise = Promise.resolve(
dataProvider.getQuotes({ symbols: symbolsChunk })
);
promises.push(
promise.then(async (result) => {

@ -131,17 +131,21 @@ export class EodHistoricalDataService implements DataProviderInterface {
return DataSource.EOD_HISTORICAL_DATA;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
const symbols = aSymbols.map((symbol) => {
return this.convertToEodSymbol(symbol);
});
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
let response: { [symbol: string]: IDataProviderResponse } = {};
if (symbols.length <= 0) {
return {};
return response;
}
const eodHistoricalDataSymbols = symbols.map((symbol) => {
return this.convertToEodSymbol(symbol);
});
try {
const abortController = new AbortController();
@ -150,9 +154,9 @@ export class EodHistoricalDataService implements DataProviderInterface {
}, DEFAULT_REQUEST_TIMEOUT);
const realTimeResponse = await got(
`${this.URL}/real-time/${symbols[0]}?api_token=${
`${this.URL}/real-time/${eodHistoricalDataSymbols[0]}?api_token=${
this.apiKey
}&fmt=json&s=${symbols.join(',')}`,
}&fmt=json&s=${eodHistoricalDataSymbols.join(',')}`,
{
// @ts-ignore
signal: abortController.signal
@ -160,10 +164,12 @@ export class EodHistoricalDataService implements DataProviderInterface {
).json<any>();
const quotes =
symbols.length === 1 ? [realTimeResponse] : realTimeResponse;
eodHistoricalDataSymbols.length === 1
? [realTimeResponse]
: realTimeResponse;
const searchResponse = await Promise.all(
symbols
eodHistoricalDataSymbols
.filter((symbol) => {
return !symbol.endsWith('.FOREX');
})
@ -176,7 +182,7 @@ export class EodHistoricalDataService implements DataProviderInterface {
return items[0];
});
const response = quotes.reduce(
response = quotes.reduce(
(
result: { [symbol: string]: IDataProviderResponse },
{ close, code, timestamp }

@ -113,13 +113,15 @@ export class FinancialModelingPrepService implements DataProviderInterface {
return DataSource.FINANCIAL_MODELING_PREP;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
const results: { [symbol: string]: IDataProviderResponse } = {};
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
const response: { [symbol: string]: IDataProviderResponse } = {};
if (aSymbols.length <= 0) {
return {};
if (symbols.length <= 0) {
return response;
}
try {
@ -130,7 +132,7 @@ export class FinancialModelingPrepService implements DataProviderInterface {
}, DEFAULT_REQUEST_TIMEOUT);
const response = await got(
`${this.URL}/quote/${aSymbols.join(',')}?apikey=${this.apiKey}`,
`${this.URL}/quote/${symbols.join(',')}?apikey=${this.apiKey}`,
{
// @ts-ignore
signal: abortController.signal
@ -138,7 +140,7 @@ export class FinancialModelingPrepService implements DataProviderInterface {
).json<any>();
for (const { price, symbol } of response) {
results[symbol] = {
response[symbol] = {
currency: DEFAULT_CURRENCY,
dataProviderInfo: this.getDataProviderInfo(),
dataSource: DataSource.FINANCIAL_MODELING_PREP,
@ -150,7 +152,7 @@ export class FinancialModelingPrepService implements DataProviderInterface {
Logger.error(error, 'FinancialModelingPrepService');
}
return results;
return response;
}
public getTestSymbol() {

@ -99,18 +99,20 @@ export class GoogleSheetsService implements DataProviderInterface {
return DataSource.GOOGLE_SHEETS;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
if (aSymbols.length <= 0) {
return {};
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
const response: { [symbol: string]: IDataProviderResponse } = {};
if (symbols.length <= 0) {
return response;
}
try {
const response: { [symbol: string]: IDataProviderResponse } = {};
const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
aSymbols.map((symbol) => {
symbols.map((symbol) => {
return {
symbol,
dataSource: this.getName()
@ -129,7 +131,7 @@ export class GoogleSheetsService implements DataProviderInterface {
const marketPrice = parseFloat(row['marketPrice']);
const symbol = row['symbol'];
if (aSymbols.includes(symbol)) {
if (symbols.includes(symbol)) {
response[symbol] = {
marketPrice,
currency: symbolProfiles.find((symbolProfile) => {

@ -36,9 +36,11 @@ export interface DataProviderInterface {
getName(): DataSource;
getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }>;
getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }>;
getTestSymbol(): string;

@ -133,18 +133,20 @@ export class ManualService implements DataProviderInterface {
return DataSource.MANUAL;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
const response: { [symbol: string]: IDataProviderResponse } = {};
if (aSymbols.length <= 0) {
if (symbols.length <= 0) {
return response;
}
try {
const symbolProfiles = await this.symbolProfileService.getSymbolProfiles(
aSymbols.map((symbol) => {
symbols.map((symbol) => {
return { symbol, dataSource: this.getName() };
})
);
@ -154,10 +156,10 @@ export class ManualService implements DataProviderInterface {
orderBy: {
date: 'desc'
},
take: aSymbols.length,
take: symbols.length,
where: {
symbol: {
in: aSymbols
in: symbols
}
}
});

@ -87,15 +87,17 @@ export class RapidApiService implements DataProviderInterface {
return DataSource.RAPID_API;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
if (aSymbols.length <= 0) {
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
if (symbols.length <= 0) {
return {};
}
try {
const symbol = aSymbols[0];
const symbol = symbols[0];
if (symbol === ghostfolioFearAndGreedIndexSymbol) {
const fgi = await this.getFearAndGreedIndex();

@ -156,20 +156,22 @@ export class YahooFinanceService implements DataProviderInterface {
return DataSource.YAHOO;
}
public async getQuotes(
aSymbols: string[]
): Promise<{ [symbol: string]: IDataProviderResponse }> {
if (aSymbols.length <= 0) {
return {};
public async getQuotes({
symbols
}: {
symbols: string[];
}): Promise<{ [symbol: string]: IDataProviderResponse }> {
const response: { [symbol: string]: IDataProviderResponse } = {};
if (symbols.length <= 0) {
return response;
}
const yahooFinanceSymbols = aSymbols.map((symbol) =>
const yahooFinanceSymbols = symbols.map((symbol) =>
this.yahooFinanceDataEnhancerService.convertToYahooFinanceSymbol(symbol)
);
try {
const response: { [symbol: string]: IDataProviderResponse } = {};
let quotes: Pick<
Quote,
'currency' | 'marketState' | 'regularMarketPrice' | 'symbol'

Loading…
Cancel
Save