@@ -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
128124function 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+
135135function getPrice ( entity ) {
136136 return entity . regularMarketPrice . fmt ;
137137}
0 commit comments