Skip to content

Commit

Permalink
Merge pull request #10 from chris-hmmr/main
Browse files Browse the repository at this point in the history
Fixes display issue with missing or mismatched asset name property for certain assets on historical data
  • Loading branch information
shweshi authored Nov 7, 2022
2 parents 8c668ae + 935a53d commit ac075bd
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions app/services/yahooService.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,10 @@ function getHistoricalPrices(ticker, options) {
}

try {
var longName = body.split(`"${ticker}":{"sourceInterval"`)[1]
.split("longName")[1]
.split(":")[1]
.split(",")[0].replace(/"/g, '');

var prices = body.split("HistoricalPriceStore\":{\"prices\"\:")[1].split("}]")[0] + '}]';

jsonPrices = JSON.parse(prices);
var json = getQuoteDataFromBodyAsJson(body)
var entity = json[ticker]
var longName = (getLongName(entity)) ? getLongName(entity) : getShortName(entity)
jsonPrices = getHistoricalDataFromBodyAsJson(body)

const array = jsonPrices.slice((page - 1) * limit, page * limit);
resolve({ longName, ticker, array });
Expand All @@ -127,11 +123,15 @@ function getHistoricalPrices(ticker, options) {
// Helper functions
function getQuoteDataFromBodyAsJson(body) {
const dataStore = body
.split(`"StreamDataStore":`)[1]
.split(`,"QuoteSummaryStore"`)[0];
.split(`"StreamDataStore":`)[1]
.split(`,"QuoteSummaryStore"`)[0];
return JSON.parse(dataStore)['quoteData'];
}

function getHistoricalDataFromBodyAsJson(body) {
return JSON.parse(body.split("HistoricalPriceStore\":{\"prices\"\:")[1].split("}]")[0] + '}]');
}

function getPrice(entity) {
return entity.regularMarketPrice.fmt;
}
Expand Down

0 comments on commit ac075bd

Please sign in to comment.