Skip to content

Commit ac075bd

Browse files
authored
Merge pull request #10 from chris-hmmr/main
Fixes display issue with missing or mismatched asset name property for certain assets on historical data
2 parents 8c668ae + 935a53d commit ac075bd

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

app/services/yahooService.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,10 @@ function getHistoricalPrices(ticker, options) {
106106
}
107107

108108
try {
109-
var longName = body.split(`"${ticker}":{"sourceInterval"`)[1]
110-
.split("longName")[1]
111-
.split(":")[1]
112-
.split(",")[0].replace(/"/g, '');
113-
114-
var prices = body.split("HistoricalPriceStore\":{\"prices\"\:")[1].split("}]")[0] + '}]';
115-
116-
jsonPrices = JSON.parse(prices);
109+
var json = getQuoteDataFromBodyAsJson(body)
110+
var entity = json[ticker]
111+
var longName = (getLongName(entity)) ? getLongName(entity) : getShortName(entity)
112+
jsonPrices = getHistoricalDataFromBodyAsJson(body)
117113

118114
const array = jsonPrices.slice((page - 1) * limit, page * limit);
119115
resolve({ longName, ticker, array });
@@ -127,11 +123,15 @@ function getHistoricalPrices(ticker, options) {
127123
// Helper functions
128124
function getQuoteDataFromBodyAsJson(body) {
129125
const dataStore = body
130-
.split(`"StreamDataStore":`)[1]
131-
.split(`,"QuoteSummaryStore"`)[0];
126+
.split(`"StreamDataStore":`)[1]
127+
.split(`,"QuoteSummaryStore"`)[0];
132128
return JSON.parse(dataStore)['quoteData'];
133129
}
134130

131+
function getHistoricalDataFromBodyAsJson(body) {
132+
return JSON.parse(body.split("HistoricalPriceStore\":{\"prices\"\:")[1].split("}]")[0] + '}]');
133+
}
134+
135135
function getPrice(entity) {
136136
return entity.regularMarketPrice.fmt;
137137
}

0 commit comments

Comments
 (0)