|
@ -16,7 +16,6 @@ import { |
|
|
DataSource, |
|
|
DataSource, |
|
|
SymbolProfile |
|
|
SymbolProfile |
|
|
} from '@prisma/client'; |
|
|
} from '@prisma/client'; |
|
|
import * as bent from 'bent'; |
|
|
|
|
|
import Big from 'big.js'; |
|
|
import Big from 'big.js'; |
|
|
import { countries } from 'countries-list'; |
|
|
import { countries } from 'countries-list'; |
|
|
import { addDays, format, isSameDay } from 'date-fns'; |
|
|
import { addDays, format, isSameDay } from 'date-fns'; |
|
@ -25,8 +24,6 @@ import type { Price } from 'yahoo-finance2/dist/esm/src/modules/quoteSummary-ifa |
|
|
|
|
|
|
|
|
@Injectable() |
|
|
@Injectable() |
|
|
export class YahooFinanceService implements DataProviderInterface { |
|
|
export class YahooFinanceService implements DataProviderInterface { |
|
|
private readonly yahooFinanceHostname = 'https://query1.finance.yahoo.com'; |
|
|
|
|
|
|
|
|
|
|
|
public constructor( |
|
|
public constructor( |
|
|
private readonly cryptocurrencyService: CryptocurrencyService |
|
|
private readonly cryptocurrencyService: CryptocurrencyService |
|
|
) {} |
|
|
) {} |
|
@ -244,16 +241,7 @@ export class YahooFinanceService implements DataProviderInterface { |
|
|
const items: LookupItem[] = []; |
|
|
const items: LookupItem[] = []; |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
const get = bent( |
|
|
const searchResult = await yahooFinance.search(aQuery); |
|
|
`${this.yahooFinanceHostname}/v1/finance/search?q=${encodeURIComponent( |
|
|
|
|
|
aQuery |
|
|
|
|
|
)}&lang=en-US®ion=US"esCount=8&newsCount=0&enableFuzzyQuery=false"esQueryId=tss_match_phrase_query&multiQuoteQueryId=multi_quote_single_token_query&newsQueryId=news_cie_vespa&enableCb=true&enableNavLinks=false&enableEnhancedTrivialQuery=true`,
|
|
|
|
|
|
'GET', |
|
|
|
|
|
'json', |
|
|
|
|
|
200 |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const searchResult = await get(); |
|
|
|
|
|
|
|
|
|
|
|
const quotes = searchResult.quotes |
|
|
const quotes = searchResult.quotes |
|
|
.filter((quote) => { |
|
|
.filter((quote) => { |
|
@ -279,20 +267,24 @@ export class YahooFinanceService implements DataProviderInterface { |
|
|
return true; |
|
|
return true; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const marketData = await this.getQuotes( |
|
|
const marketData = await yahooFinance.quote( |
|
|
quotes.map(({ symbol }) => { |
|
|
quotes.map(({ symbol }) => { |
|
|
return symbol; |
|
|
return symbol; |
|
|
}) |
|
|
}) |
|
|
); |
|
|
); |
|
|
|
|
|
|
|
|
for (const [symbol, value] of Object.entries(marketData)) { |
|
|
for (const marketDataItem of marketData) { |
|
|
const quote = quotes.find((currentQuote: any) => { |
|
|
const quote = quotes.find((currentQuote) => { |
|
|
return currentQuote.symbol === symbol; |
|
|
return currentQuote.symbol === marketDataItem.symbol; |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
const symbol = this.convertFromYahooFinanceSymbol( |
|
|
|
|
|
marketDataItem.symbol |
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
items.push({ |
|
|
items.push({ |
|
|
symbol, |
|
|
symbol, |
|
|
currency: value.currency, |
|
|
currency: marketDataItem.currency, |
|
|
dataSource: this.getName(), |
|
|
dataSource: this.getName(), |
|
|
name: quote?.longname || quote?.shortname || symbol |
|
|
name: quote?.longname || quote?.shortname || symbol |
|
|
}); |
|
|
}); |
|
|