yahoo-exchange
Advanced tools
Comparing version 1.6.2 to 1.7.0
47
index.js
@@ -12,24 +12,25 @@ "use strict"; | ||
const parseHTML = html => parseR(html.toString())(36); | ||
const parseHTML2 = (html, r) => { | ||
const parseHTML2 = (html) => { | ||
const list = []; | ||
list.push(parseFloat(remove(/<!-- react-text: 36 -->([0-9.,]+)/gmi.exec(html)[1], ','))); | ||
list.push(html.indexOf('react-text: 39 -->') === -1 ? | ||
parseFloat(parseReact(html, 38, 2).split(' ')[0]) : | ||
parseFloat(parseReact(html, 39, 1).split(' ')[0])); | ||
list.push(html.indexOf('react-text: 39 -->') === -1 ? | ||
parseFloat(parseReact(html, 38, 2).split('(')[1].split("\%")[0]) : | ||
parseFloat(parseReact(html, 39, 1).split('(')[1].split("\%")[0])); | ||
list.push(parseFloat(parseReact(html, 42, 2).split('<')[0])); | ||
list.push(r(48)); | ||
list.push(r(54)); | ||
list.push(r(71)); | ||
list.push(parseFloat(remove(html.split('data-reactid="61">')[2].split(' ')[0], ','))); | ||
list.push(parseFloat(remove(html.split('data-reactid="61">')[2].split(' ')[2].split('<')[0], ','))); | ||
list.push(parseFloat(remove(html.split('data-reactid="65">')[3].split(' ')[0], ','))); | ||
list.push(parseFloat(remove(html.split('data-reactid="65">')[3].split(' ')[2].split('<')[0], ','))); | ||
html = html['quoteSummary'].result[0]; | ||
const previousClose = html['summaryDetail']['previousClose'].raw; | ||
const open = html['summaryDetail']['open'].raw; | ||
list.push((previousClose + open) / 2); | ||
list.push(html['price']['regularMarketChange'].raw); | ||
list.push(html['price']['regularMarketChangePercent'].raw * 100); | ||
list.push(previousClose); | ||
list.push(open); | ||
list.push(html['summaryDetail']['bid'].raw); | ||
list.push(html['summaryDetail']['ask'].raw); | ||
list.push(html['summaryDetail']['dayLow'].raw); | ||
list.push(html['summaryDetail']['dayHigh'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekLow'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekHigh'].raw); | ||
return list; | ||
}; | ||
const req = (pair, errorHandler, callback) => request({ | ||
url: `https://finance.yahoo.com/quote/${pair}=X?p=${pair}=X`, | ||
encoding: null, | ||
url: `https://query2.finance.yahoo.com/v10/finance/quoteSummary/${pair}=X?formatted=true&crumb=sxCZygzUaUK&lang=en-US®ion=US&modules=price%2CsummaryDetail&corsDomain=finance.yahoo.com`, | ||
timeout: 10000, | ||
followRedirect: true, | ||
maxRedirects: 10 | ||
}, (err, response, html) => { | ||
@@ -40,3 +41,3 @@ try { | ||
else | ||
callback(parseHTML2(html.toString().replace(',', ''), parseR(html.toString())), pair); | ||
callback(parseHTML2(JSON.parse(html)), pair); | ||
} | ||
@@ -58,3 +59,3 @@ catch (e) { | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactspa/><\-]*[0-9.\-]+/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
resolve(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
@@ -77,3 +78,3 @@ } | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactspa/><\-]*[0-9.\-]+/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
callback(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
@@ -544,7 +545,5 @@ } | ||
} | ||
else { | ||
else | ||
return undefined; | ||
} | ||
} | ||
exports.getUnit = getUnit; | ||
//# sourceMappingURL=index.js.map |
49
index.ts
@@ -10,28 +10,29 @@ import request = require('request'); | ||
const parseHTML = html => parseR(html.toString())(36); | ||
const parseHTML2 = (html: string, r: Function) => { | ||
const parseHTML2 = (html: Object) => { | ||
const list = []; | ||
list.push(parseFloat(remove(/<!-- react-text: 36 -->([0-9.,]+)/gmi.exec(html)[1], ','))); | ||
list.push(html.indexOf('react-text: 39 -->') === -1 ? | ||
parseFloat(parseReact(html, 38, 2).split(' ')[0]) : | ||
parseFloat(parseReact(html, 39, 1).split(' ')[0])); | ||
list.push(html.indexOf('react-text: 39 -->') === -1 ? | ||
parseFloat(parseReact(html, 38, 2).split('(')[1].split("\%")[0]) : | ||
parseFloat(parseReact(html, 39, 1).split('(')[1].split("\%")[0])); | ||
list.push(parseFloat(parseReact(html, 42, 2).split('<')[0])); | ||
list.push(r(48)); | ||
list.push(r(54)); | ||
list.push(r(71)); | ||
list.push(parseFloat(remove(html.split('data-reactid="61">')[2].split(' ')[0], ','))); | ||
list.push(parseFloat(remove(html.split('data-reactid="61">')[2].split(' ')[2].split('<')[0], ','))); | ||
list.push(parseFloat(remove(html.split('data-reactid="65">')[3].split(' ')[0], ','))); | ||
list.push(parseFloat(remove(html.split('data-reactid="65">')[3].split(' ')[2].split('<')[0], ','))); | ||
html = html['quoteSummary'].result[0]; | ||
const previousClose = html['summaryDetail']['previousClose'].raw; | ||
const open = html['summaryDetail']['open'].raw; | ||
list.push((previousClose + open) / 2); | ||
list.push(html['price']['regularMarketChange'].raw); | ||
list.push(html['price']['regularMarketChangePercent'].raw * 100); | ||
list.push(previousClose); | ||
list.push(open); | ||
list.push(html['summaryDetail']['bid'].raw); | ||
list.push(html['summaryDetail']['ask'].raw); | ||
list.push(html['summaryDetail']['dayLow'].raw); | ||
list.push(html['summaryDetail']['dayHigh'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekLow'].raw); | ||
list.push(html['summaryDetail']['fiftyTwoWeekHigh'].raw); | ||
return list; | ||
}; | ||
const req = (pair, errorHandler, callback) => request({ | ||
url: `https://finance.yahoo.com/quote/${pair}=X?p=${pair}=X`, | ||
encoding: null, | ||
url: `https://query2.finance.yahoo.com/v10/finance/quoteSummary/${pair}=X?formatted=true&crumb=sxCZygzUaUK&lang=en-US®ion=US&modules=price%2CsummaryDetail&corsDomain=finance.yahoo.com`, | ||
timeout: 10000, | ||
followRedirect: true, | ||
maxRedirects: 10 | ||
}, (err, response, html) => { | ||
try { | ||
if (err) errorHandler(err, pair); | ||
else callback(parseHTML2(html.toString().replace(',', ''), parseR(html.toString())), pair); | ||
else callback(parseHTML2(JSON.parse(html)), pair); | ||
} catch (e) { | ||
@@ -43,2 +44,3 @@ errorHandler(e, pair); | ||
export function getExchangeDataLowTrafficP(): Promise<Array<Array<any>>> { | ||
return new Promise<Array<Array<any>>>(((resolve, reject) => request({ | ||
@@ -53,3 +55,3 @@ url: 'https://finance.yahoo.com/currencies', | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactspa/><\-]*[0-9.\-]+/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
resolve(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
@@ -71,3 +73,3 @@ } | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactspa/><\-]*[0-9.\-]+/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
callback(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
@@ -528,5 +530,4 @@ } | ||
} | ||
} else { | ||
return undefined; | ||
} | ||
} else return undefined; | ||
} |
@@ -14,3 +14,3 @@ { | ||
"main": "index.js", | ||
"version": "1.6.2", | ||
"version": "1.7.0", | ||
"license": "MIT", | ||
@@ -17,0 +17,0 @@ "dependencies": { |
@@ -10,3 +10,3 @@ # yahoo-exchange 疎開 | ||
[![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/yahoo-exchange/blob/master/README-JP.md) | ||
> Yahoo Financeのパーサーが壊れた. そこで,新しいYahoo Finaceのパーサーを作った. ですから,重要な注意点があります. 現在,為替レートは,"クローズ"と"オープン"の平均値として定義されている。 | ||
## getExchangeDataArray(pair, callback, errorHandler): void | ||
@@ -17,3 +17,3 @@ * pair : string または Array\<string\> | ||
> ### 警告! | ||
>Bid と Askは一部のフェアではNaNがリターンなります。 該当ペアを捜した方はイッシューに登録してください。 | ||
>Bid と Askは一部のフェアではundefinedがリターンなります。 該当ペアを捜した方はイッシューに登録してください。 | ||
#### 知られたエラー | ||
@@ -42,3 +42,3 @@ * JPYKRW | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] | ||
``` | ||
@@ -48,3 +48,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] または [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] または [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] または [Error] error message | ||
``` | ||
@@ -54,3 +54,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] USDKRW または [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW または [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW または [Error] error message | ||
``` | ||
@@ -60,3 +60,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] USDKRW または [Error:USDKRW] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW または [Error:JPYKRW] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW または [Error:JPYKRW] error message | ||
``` | ||
@@ -63,0 +63,0 @@ ### 警告 |
@@ -10,3 +10,3 @@ # yahoo-exchange 소개 | ||
[![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/yahoo-exchange/blob/master/README-JP.md) | ||
> 야휴 파이낸스를 파서가 작동하지 않아 새로운 파서를 만들었습니다. 이제 환율은 close와 open의 평균값으로 계산됩니다.(그외의 값은 정상입니다.) | ||
## getExchangeDataArray(pair, callback, errorHandler): void | ||
@@ -17,3 +17,3 @@ * pair : string 또는 Array\<string\> | ||
> ### 경고! | ||
>Bid 와 Ask는 일부 페어에서 NaN이 리턴됩니다. 해당 페어를 찾으신 분은 이슈에 등록하여 주시면 감사하겠습니다. | ||
>Bid 와 Ask는 일부 페어에서 undefined이 리턴됩니다. 해당 페어를 찾으신 분은 이슈에 등록하여 주시면 감사하겠습니다. | ||
#### 알려진 에러 | ||
@@ -42,3 +42,3 @@ * JPYKRW | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] | ||
``` | ||
@@ -48,3 +48,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] 또는 [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] 또는 [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] 또는 [Error] error message | ||
``` | ||
@@ -54,3 +54,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] USDKRW 또는 [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW 또는 [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW 또는 [Error] error message | ||
``` | ||
@@ -60,3 +60,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] USDKRW 또는 [Error:USDKRW] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW 또는 [Error:JPYKRW] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW 또는 [Error:JPYKRW] error message | ||
``` | ||
@@ -63,0 +63,0 @@ ### 경고 |
@@ -10,2 +10,3 @@ # yahoo-exchange | ||
[![npm](https://img.shields.io/badge/Readme-日本語-orange.svg?style=flat-square)](https://github.com/Shin-JaeHeon/yahoo-exchange/blob/master/README-JP.md) | ||
> Yahoo Finance parser was broken. So we created a new Yahoo Finace Parser. Now, the exchange rate is defined as the average value of close and open. | ||
## getExchangeDataArray(pair, callback, errorHandler): void | ||
@@ -16,3 +17,3 @@ * pair : string or Array\<string\> | ||
> ### Warning! | ||
>Bid and Ask can be returned NaN by some pair. If you find a pair that has errors, please write the pair at the issue. | ||
>Bid and Ask can be returned undefined by some pair. If you find a pair that has errors, please write the pair at the issue. | ||
#### A known error | ||
@@ -41,3 +42,3 @@ * JPYKRW | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] | ||
``` | ||
@@ -47,3 +48,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] or [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] or [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] or [Error] error message | ||
``` | ||
@@ -53,3 +54,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] USDKRW or [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW or [Error] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW or [Error] error message | ||
``` | ||
@@ -59,3 +60,3 @@ * ``` javascript | ||
// [ 1071.27, 0.88, 0.08, -0.11, 1070.22, 1071.27, 1072.27, 1069.13, 1072.45, 1055.21, 1158.36 ] USDKRW or [Error:USDKRW] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, NaN, NaN, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW or [Error:JPYKRW] error message | ||
// [ 10.08, 0.03, 0.34, -0.11, 10.047, undefined, undefined, 10.08, 10.065, 10.0245, 10.0968 ] JPYKRW or [Error:JPYKRW] error message | ||
``` | ||
@@ -62,0 +63,0 @@ ### Warning |
@@ -11,2 +11,3 @@ const index = require('../index'); | ||
index.getExchangeDataArray(['USDKRW', 'JPYKRW'], (data, pair) => console.log(data, pair), (error, pair) => console.log(`[Error] ${pair}\n${error}`)); | ||
index.getUnit('KRW'); | ||
index.getUnit('KRW'); | ||
index.getPairArray(['USD'], ['KRW', 'JPY']); |
@@ -5,3 +5,3 @@ { | ||
"target": "es2016", | ||
"sourceMap": true | ||
"sourceMap": false | ||
}, | ||
@@ -8,0 +8,0 @@ "exclude": [ |
Sorry, the diff of this file is not supported yet
174
76084
11