yahoo-exchange
Advanced tools
Comparing version 1.7.3 to 2.0.0
65
index.js
@@ -9,29 +9,16 @@ "use strict"; | ||
}; | ||
const parseReact = (str, number, num) => str.split(`react-text: ${number} -->`)[num]; | ||
const parseR = (str) => number => parseFloat(remove(parseReact(str, number, 1).split('<')[0], ',')); | ||
const parseHTML = html => parseR(html.toString())(36); | ||
const getJSON = data => name => data[name]; | ||
const parseHTML2 = (html) => { | ||
const parseHTML = (html) => { | ||
const list = []; | ||
html = html['quoteSummary'].result[0]; | ||
const sd = getJSON(getJSON(html)('summaryDetail')); | ||
const previousClose = sd('previousClose').raw; | ||
const open = sd('open').raw; | ||
const bid = sd('bid').raw; | ||
const ask = sd('ask').raw; | ||
list.push((bid + ask) / 2); | ||
list.push(html['price']['regularMarketChange'].raw); | ||
list.push(html['price']['regularMarketChangePercent'].raw * 100); | ||
list.push(previousClose); | ||
list.push(open); | ||
list.push(bid); | ||
list.push(ask); | ||
list.push(sd('dayLow').raw); | ||
list.push(sd('dayHigh').raw); | ||
list.push(sd('fiftyTwoWeekLow').raw); | ||
list.push(sd('fiftyTwoWeekHigh').raw); | ||
const price = html['quoteSummary'].result[0]['price']; | ||
list.push(price.regularMarketPrice.raw); | ||
list.push(price.regularMarketChange.raw); | ||
list.push(price.regularMarketChangePercent.raw * 100); | ||
list.push(price.regularMarketPreviousClose.raw); | ||
list.push(price.regularMarketOpen.raw); | ||
list.push(price.regularMarketDayLow.raw); | ||
list.push(price.regularMarketDayHigh.raw); | ||
return list; | ||
}; | ||
const req = (pair, errorHandler, callback) => request({ | ||
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`, | ||
url: `https://query2.finance.yahoo.com/v10/finance/quoteSummary/${pair}=X?formatted=true&crumb=sxCZygzUaUK&lang=en-US®ion=US&modules=price&corsDomain=finance.yahoo.com`, | ||
timeout: 10000, | ||
@@ -45,3 +32,3 @@ followRedirect: true, | ||
else | ||
callback(parseHTML2(JSON.parse(html)), pair); | ||
callback(parseHTML(JSON.parse(html)), pair); | ||
} | ||
@@ -155,32 +142,2 @@ catch (e) { | ||
exports.getFxYahooJapan = getFxYahooJapan; | ||
/** | ||
* @deprecated Since version 1.0. Will be deleted in version 2.0. Use getExchangeDataArray instead. | ||
*/ | ||
function getData(pair, callback, errorHandler = err => console.log(err)) { | ||
request({ | ||
url: `https://finance.yahoo.com/quote/${pair}=X?p=${pair}=X`, | ||
encoding: null, | ||
}, (err, response, html) => { | ||
if (err) | ||
errorHandler(err, pair); | ||
else | ||
callback(parseHTML(html), pair); | ||
}); | ||
} | ||
exports.getData = getData; | ||
/** | ||
* @deprecated Since version 1.0. Will be deleted in version 2.0. Use getExchangeDataArray instead. | ||
*/ | ||
function getDataArray(pair, callback, errorHandler = err => console.log(err)) { | ||
pair.forEach(v => request({ | ||
url: `https://finance.yahoo.com/quote/${v}=X?p=${v}=X`, | ||
encoding: null, | ||
}, (err, response, html) => { | ||
if (err) | ||
errorHandler(err, v); | ||
else | ||
callback(parseHTML(html), v); | ||
})); | ||
} | ||
exports.getDataArray = getDataArray; | ||
function getExchangeDataArray(pair, callback, errorHandler = err => console.log(err)) { | ||
@@ -187,0 +144,0 @@ try { |
986
index.ts
@@ -5,41 +5,28 @@ import request = require('request'); | ||
const remove = (str: string, remove: string) => { | ||
if (typeof str === 'string') return str.replace(remove, ''); | ||
if (typeof str === 'string') return str.replace(remove, ''); | ||
}; | ||
const parseReact = (str: string, number, num: number) => str.split(`react-text: ${number} -->`)[num]; | ||
const parseR = (str: string) => number => parseFloat(remove(parseReact(str, number, 1).split('<')[0], ',')); | ||
const parseHTML = html => parseR(html.toString())(36); | ||
const getJSON = data => name => data[name]; | ||
const parseHTML2 = (html: Object) => { | ||
const list = []; | ||
html = html['quoteSummary'].result[0]; | ||
const sd = getJSON(getJSON(html)('summaryDetail')); | ||
const previousClose = sd('previousClose').raw; | ||
const open = sd('open').raw; | ||
const bid = sd('bid').raw; | ||
const ask = sd('ask').raw; | ||
list.push((bid + ask) / 2); | ||
list.push(html['price']['regularMarketChange'].raw); | ||
list.push(html['price']['regularMarketChangePercent'].raw * 100); | ||
list.push(previousClose); | ||
list.push(open); | ||
list.push(bid); | ||
list.push(ask); | ||
list.push(sd('dayLow').raw); | ||
list.push(sd('dayHigh').raw); | ||
list.push(sd('fiftyTwoWeekLow').raw); | ||
list.push(sd('fiftyTwoWeekHigh').raw); | ||
return list; | ||
const parseHTML = (html: Object) => { | ||
const list = []; | ||
const price= html['quoteSummary'].result[0]['price']; | ||
list.push(price.regularMarketPrice.raw); | ||
list.push(price.regularMarketChange.raw); | ||
list.push(price.regularMarketChangePercent.raw * 100); | ||
list.push(price.regularMarketPreviousClose.raw); | ||
list.push(price.regularMarketOpen.raw); | ||
list.push(price.regularMarketDayLow.raw); | ||
list.push(price.regularMarketDayHigh.raw); | ||
return list; | ||
}; | ||
const req = (pair, errorHandler, callback) => request({ | ||
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 | ||
url: `https://query2.finance.yahoo.com/v10/finance/quoteSummary/${pair}=X?formatted=true&crumb=sxCZygzUaUK&lang=en-US®ion=US&modules=price&corsDomain=finance.yahoo.com`, | ||
timeout: 10000, | ||
followRedirect: true, | ||
maxRedirects: 10 | ||
}, (err, response, html) => { | ||
try { | ||
if (err) errorHandler(err, pair); | ||
else callback(parseHTML2(JSON.parse(html)), pair); | ||
} catch (e) { | ||
errorHandler(e, pair); | ||
} | ||
try { | ||
if (err) errorHandler(err, pair); | ||
else callback(parseHTML(JSON.parse(html)), pair); | ||
} catch (e) { | ||
errorHandler(e, pair); | ||
} | ||
}); | ||
@@ -52,16 +39,16 @@ | ||
export function getExchangeDataLowTrafficP(): Promise<Array<Array<any>>> { | ||
return new Promise<Array<Array<any>>>(((resolve, reject) => request({ | ||
url: 'https://finance.yahoo.com/currencies', | ||
encoding: null | ||
}, (err, response, html) => { | ||
let h = html.toString().split(`data-reactid=\"75\"`)[2]; | ||
if (err) reject(err); | ||
else { | ||
const pair = h.match(/>(...\/...)/gmi); | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
if (changes === null) reject(new Error('Error code: GED-LTP')); | ||
else resolve(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
} | ||
}))); | ||
return new Promise<Array<Array<any>>>(((resolve, reject) => request({ | ||
url: 'https://finance.yahoo.com/currencies', | ||
encoding: null | ||
}, (err, response, html) => { | ||
let h = html.toString().split(`data-reactid=\"75\"`)[2]; | ||
if (err) reject(err); | ||
else { | ||
const pair = h.match(/>(...\/...)/gmi); | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
if (changes === null) reject(new Error('Error code: GED-LTP')); | ||
else resolve(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
} | ||
}))); | ||
} | ||
@@ -75,487 +62,458 @@ | ||
export function getExchangeDataLowTraffic(callback: (data: Array<Array<any>>) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
try { | ||
request({ | ||
url: 'https://finance.yahoo.com/currencies', | ||
encoding: null | ||
}, (err, response, html) => { | ||
let h = html.toString().split(`data-reactid=\"75\"`)[2]; | ||
if (err) errorHandler(err, 'getExchangeDataLowTraffic'); | ||
else { | ||
const pair = h.match(/>(...\/...)/gmi); | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
try { | ||
request({ | ||
url: 'https://finance.yahoo.com/currencies', | ||
encoding: null | ||
}, (err, response, html) => { | ||
let h = html.toString().split(`data-reactid=\"75\"`)[2]; | ||
if (err) errorHandler(err, 'getExchangeDataLowTraffic'); | ||
else { | ||
const pair = h.match(/>(...\/...)/gmi); | ||
const price = h.match(/">([0-9,.]+)/gmi); | ||
const changes = h.match(/ -->[^0-9reactsp/><\-]*[0-9.\-]+/gmi); | ||
if (changes === null) errorHandler(new Error('Error code: GED-LTC'), 'getExchangeDataLowTraffic'); | ||
else callback(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
} | ||
}); | ||
} catch (e) { | ||
errorHandler(e, 'getExchangeDataLowTraffic'); | ||
} | ||
if (changes === null) errorHandler(new Error('Error code: GED-LTC'), 'getExchangeDataLowTraffic'); | ||
else callback(arrayLen24.map((v, a) => [remove(pair[a], '>'), parseFloat(remove(price[a], '\">')), parseFloat(remove(changes[a * 2], " -->")), parseFloat(remove(changes[a * 2 + 1], ' -->'))])); | ||
} | ||
}); | ||
} catch (e) { | ||
errorHandler(e, 'getExchangeDataLowTraffic'); | ||
} | ||
} | ||
export function getFxYahooJapan(callback: (data: Object) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
try { | ||
request({ | ||
url: 'https://info.finance.yahoo.co.jp/fx/list/', | ||
encoding: null | ||
}, (err, response, html) => { | ||
let h = html.toString(); | ||
if (err) errorHandler(err, 'getFxYahooJapan'); | ||
else { | ||
const data = h.match(/......_chart_...">[0-9.]*/gmi); | ||
let dv = { | ||
USDJPY: {}, | ||
EURJPY: {}, | ||
AUDJPY: {}, | ||
GBPJPY: {}, | ||
NZDJPY: {}, | ||
CADJPY: {}, | ||
CHFJPY: {}, | ||
ZARJPY: {}, | ||
CNHJPY: {}, | ||
EURUSD: {}, | ||
GBPUSD: {}, | ||
AUDUSD: {}, | ||
NZDUSD: {}, | ||
HKDJPY: {}, | ||
EURGBP: {}, | ||
EURAUD: {}, | ||
USDCHF: {}, | ||
EURCHF: {}, | ||
GBPCHF: {}, | ||
AUDCHF: {}, | ||
CADCHF: {}, | ||
USDHKD: {} | ||
}; | ||
Object.keys(dv).map(v => | ||
dv[v] = data.reduce((prev, current) => { | ||
if (current.replace(/_.*/, '') === v) prev.push(parseFloat(current.replace(/......_chart_....>/, ''))); | ||
return prev; | ||
}, [])); | ||
callback(dv); | ||
} | ||
}); | ||
} catch (e) { | ||
errorHandler(e, 'getFxYahooJapan'); | ||
} | ||
} | ||
/** | ||
* @deprecated Since version 1.0. Will be deleted in version 2.0. Use getExchangeDataArray instead. | ||
*/ | ||
export function getData(pair: string, callback: (data: any, pair?: string) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
try { | ||
request({ | ||
url: `https://finance.yahoo.com/quote/${pair}=X?p=${pair}=X`, | ||
encoding: null, | ||
} | ||
, | ||
(err, response, html) => { | ||
if (err) errorHandler(err, pair); | ||
else callback(parseHTML(html), pair); | ||
} | ||
); | ||
} | ||
/** | ||
* @deprecated Since version 1.0. Will be deleted in version 2.0. Use getExchangeDataArray instead. | ||
*/ | ||
export function getDataArray(pair: Array<string>, callback: (data: any, pair?: string) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
pair.forEach(v => request({ | ||
url: `https://finance.yahoo.com/quote/${v}=X?p=${v}=X`, | ||
encoding: null, | ||
url: 'https://info.finance.yahoo.co.jp/fx/list/', | ||
encoding: null | ||
}, (err, response, html) => { | ||
if (err) errorHandler(err, v); | ||
else callback(parseHTML(html), v); | ||
})); | ||
let h = html.toString(); | ||
if (err) errorHandler(err, 'getFxYahooJapan'); | ||
else { | ||
const data = h.match(/......_chart_...">[0-9.]*/gmi); | ||
let dv = { | ||
USDJPY: {}, | ||
EURJPY: {}, | ||
AUDJPY: {}, | ||
GBPJPY: {}, | ||
NZDJPY: {}, | ||
CADJPY: {}, | ||
CHFJPY: {}, | ||
ZARJPY: {}, | ||
CNHJPY: {}, | ||
EURUSD: {}, | ||
GBPUSD: {}, | ||
AUDUSD: {}, | ||
NZDUSD: {}, | ||
HKDJPY: {}, | ||
EURGBP: {}, | ||
EURAUD: {}, | ||
USDCHF: {}, | ||
EURCHF: {}, | ||
GBPCHF: {}, | ||
AUDCHF: {}, | ||
CADCHF: {}, | ||
USDHKD: {} | ||
}; | ||
Object.keys(dv).map(v => | ||
dv[v] = data.reduce((prev, current) => { | ||
if (current.replace(/_.*/, '') === v) prev.push(parseFloat(current.replace(/......_chart_....>/, ''))); | ||
return prev; | ||
}, [])); | ||
callback(dv); | ||
} | ||
}); | ||
} catch (e) { | ||
errorHandler(e, 'getFxYahooJapan'); | ||
} | ||
} | ||
export function getExchangeDataArray(pair: any, callback: (data: Array<number>, pair?: string) => any, errorHandler: (error: Error, pair?: String) => any = err => console.log(err)): void { | ||
try { | ||
if (typeof pair === 'string') req(pair, errorHandler, callback); | ||
else if (Array.isArray(pair)) pair.forEach(v => req(v, errorHandler, callback)); | ||
else errorHandler(new Error('A pair must be "string" or "array".'), 'getExchangeArray'); | ||
} catch (e) { | ||
errorHandler(e, 'getExchangeDataArray'); | ||
} | ||
try { | ||
if (typeof pair === 'string') req(pair, errorHandler, callback); | ||
else if (Array.isArray(pair)) pair.forEach(v => req(v, errorHandler, callback)); | ||
else errorHandler(new Error('A pair must be "string" or "array".'), 'getExchangeArray'); | ||
} catch (e) { | ||
errorHandler(e, 'getExchangeDataArray'); | ||
} | ||
} | ||
export function getPairArray(currency: Array<string>, base: Array<string>): Array<string> { | ||
let list: Array<string> = []; | ||
currency.forEach(v => base.forEach(v2 => { | ||
if (v2 !== v) list.push(v + v2); | ||
})); | ||
return list; | ||
let list: Array<string> = []; | ||
currency.forEach(v => base.forEach(v2 => { | ||
if (v2 !== v) list.push(v + v2); | ||
})); | ||
return list; | ||
} | ||
const whatCurrency = currency => { | ||
{ | ||
switch (currency) { | ||
case 'AED': | ||
return 'د.إ'; | ||
case 'AFN': | ||
return '؋'; | ||
case 'ALL': | ||
return 'L'; | ||
case 'AMD': | ||
return '֏'; | ||
case 'ANG': | ||
return 'ƒ'; | ||
case 'AOA': | ||
return 'Kz'; | ||
case 'ARS': | ||
return '$'; | ||
case 'AUD': | ||
return '$'; | ||
case 'AWG': | ||
return 'ƒ'; | ||
case 'AZN': | ||
return '₼'; | ||
case 'BAM': | ||
return 'KM'; | ||
case 'BBD': | ||
return '$'; | ||
case 'BDT': | ||
return '৳'; | ||
case 'BGN': | ||
return 'лв'; | ||
case 'BHD': | ||
return '.د.ب'; | ||
case 'BIF': | ||
return 'FBu'; | ||
case 'BMD': | ||
return '$'; | ||
case 'BND': | ||
return '$'; | ||
case 'BOB': | ||
return '$b'; | ||
case 'BRL': | ||
return 'R$'; | ||
case 'BSD': | ||
return '$'; | ||
case 'BTC': | ||
return '฿'; | ||
case 'BTN': | ||
return 'Nu.'; | ||
case 'BWP': | ||
return 'P'; | ||
case 'BYR': | ||
return 'Br'; | ||
case 'BYN': | ||
return 'Br'; | ||
case 'BZD': | ||
return 'BZ$'; | ||
case 'CAD': | ||
return '$'; | ||
case 'CDF': | ||
return 'FC'; | ||
case 'CHF': | ||
return 'CHF'; | ||
case 'CLP': | ||
return '$'; | ||
case 'CNY': | ||
return '¥'; | ||
case 'COP': | ||
return '$'; | ||
case 'CRC': | ||
return '₡'; | ||
case 'CUC': | ||
return '$'; | ||
case 'CUP': | ||
return '₱'; | ||
case 'CVE': | ||
return '$'; | ||
case 'CZK': | ||
return 'Kč'; | ||
case 'DJF': | ||
return 'Fdj'; | ||
case 'DKK': | ||
return 'kr'; | ||
case 'DOP': | ||
return 'RD$'; | ||
case 'DZD': | ||
return 'دج'; | ||
case 'EEK': | ||
return 'kr'; | ||
case 'EGP': | ||
return '£'; | ||
case 'ERN': | ||
return 'Nfk'; | ||
case 'ETB': | ||
return 'Br'; | ||
case 'ETH': | ||
return 'Ξ'; | ||
case 'EUR': | ||
return '€'; | ||
case 'FJD': | ||
return '$'; | ||
case 'FKP': | ||
return '£'; | ||
case 'GBP': | ||
return '£'; | ||
case 'GEL': | ||
return '₾'; | ||
case 'GGP': | ||
return '£'; | ||
case 'GHC': | ||
return '₵'; | ||
case 'GHS': | ||
return 'GH₵'; | ||
case 'GIP': | ||
return '£'; | ||
case 'GMD': | ||
return 'D'; | ||
case 'GNF': | ||
return 'FG'; | ||
case 'GTQ': | ||
return 'Q'; | ||
case 'GYD': | ||
return '$'; | ||
case 'HKD': | ||
return '$'; | ||
case 'HNL': | ||
return 'L'; | ||
case 'HRK': | ||
return 'kn'; | ||
case 'HTG': | ||
return 'G'; | ||
case 'HUF': | ||
return 'Ft'; | ||
case 'IDR': | ||
return 'Rp'; | ||
case 'ILS': | ||
return '₪'; | ||
case 'IMP': | ||
return '£'; | ||
case 'INR': | ||
return '₹'; | ||
case 'IQD': | ||
return 'ع.د'; | ||
case 'IRR': | ||
return '﷼'; | ||
case 'ISK': | ||
return 'kr'; | ||
case 'JEP': | ||
return '£'; | ||
case 'JMD': | ||
return 'J$'; | ||
case 'JOD': | ||
return 'JD'; | ||
case 'JPY': | ||
return '¥'; | ||
case 'KES': | ||
return 'KSh'; | ||
case 'KGS': | ||
return 'лв'; | ||
case 'KHR': | ||
return '៛'; | ||
case 'KMF': | ||
return 'CF'; | ||
case 'KPW': | ||
return '₩'; | ||
case 'KRW': | ||
return '₩'; | ||
case 'KWD': | ||
return 'KD'; | ||
case 'KYD': | ||
return '$'; | ||
case 'KZT': | ||
return 'лв'; | ||
case 'LAK': | ||
return '₭'; | ||
case 'LBP': | ||
return '£'; | ||
case 'LKR': | ||
return '₨'; | ||
case 'LRD': | ||
return '$'; | ||
case 'LSL': | ||
return 'M'; | ||
case 'LTC': | ||
return 'Ł'; | ||
case 'LTL': | ||
return 'Lt'; | ||
case 'LVL': | ||
return 'Ls'; | ||
case 'LYD': | ||
return 'LD'; | ||
case 'MAD': | ||
return 'MAD'; | ||
case 'MDL': | ||
return 'lei'; | ||
case 'MGA': | ||
return 'Ar'; | ||
case 'MKD': | ||
return 'ден'; | ||
case 'MMK': | ||
return 'K'; | ||
case 'MNT': | ||
return '₮'; | ||
case 'MOP': | ||
return 'MOP$'; | ||
case 'MRO': | ||
return 'UM'; | ||
case 'MRU': | ||
return 'UM'; | ||
case 'MUR': | ||
return '₨'; | ||
case 'MVR': | ||
return 'Rf'; | ||
case 'MWK': | ||
return 'MK'; | ||
case 'MXN': | ||
return '$'; | ||
case 'MYR': | ||
return 'RM'; | ||
case 'MZN': | ||
return 'MT'; | ||
case 'NAD': | ||
return '$'; | ||
case 'NGN': | ||
return '₦'; | ||
case 'NIO': | ||
return 'C$'; | ||
case 'NOK': | ||
return 'kr'; | ||
case 'NPR': | ||
return '₨'; | ||
case 'NZD': | ||
return '$'; | ||
case 'OMR': | ||
return '﷼'; | ||
case 'PAB': | ||
return 'B/.'; | ||
case 'PEN': | ||
return 'S/.'; | ||
case 'PGK': | ||
return 'K'; | ||
case 'PHP': | ||
return '₱'; | ||
case 'PKR': | ||
return '₨'; | ||
case 'PLN': | ||
return 'zł'; | ||
case 'PYG': | ||
return 'Gs'; | ||
case 'QAR': | ||
return '﷼'; | ||
case 'RMB': | ||
return '¥'; | ||
case 'RON': | ||
return 'lei'; | ||
case 'RSD': | ||
return 'Дин.'; | ||
case 'RUB': | ||
return '₽'; | ||
case 'RWF': | ||
return 'R₣'; | ||
case 'SAR': | ||
return '﷼'; | ||
case 'SBD': | ||
return '$'; | ||
case 'SCR': | ||
return '₨'; | ||
case 'SDG': | ||
return 'ج.س.'; | ||
case 'SEK': | ||
return 'kr'; | ||
case 'SGD': | ||
return '$'; | ||
case 'SHP': | ||
return '£'; | ||
case 'SLL': | ||
return 'Le'; | ||
case 'SOS': | ||
return 'S'; | ||
case 'SRD': | ||
return '$'; | ||
case 'SSP': | ||
return '£'; | ||
case 'STD': | ||
return 'Db'; | ||
case 'STN': | ||
return 'Db'; | ||
case 'SVC': | ||
return '$'; | ||
case 'SYP': | ||
return '£'; | ||
case 'SZL': | ||
return 'E'; | ||
case 'THB': | ||
return '฿'; | ||
case 'TJS': | ||
return 'SM'; | ||
case 'TMT': | ||
return 'T'; | ||
case 'TND': | ||
return 'د.ت'; | ||
case 'TOP': | ||
return 'T$'; | ||
case 'TRL': | ||
return '₤'; | ||
case 'TRY': | ||
return '₺'; | ||
case 'TTD': | ||
return 'TT$'; | ||
case 'TVD': | ||
return '$'; | ||
case 'TWD': | ||
return 'NT$'; | ||
case 'TZS': | ||
return 'TSh'; | ||
case 'UAH': | ||
return '₴'; | ||
case 'UGX': | ||
return 'USh'; | ||
case 'USD': | ||
return '$'; | ||
case 'UYU': | ||
return '$U'; | ||
case 'UZS': | ||
return 'лв'; | ||
case 'VEF': | ||
return 'Bs'; | ||
case 'VND': | ||
return '₫'; | ||
case 'VUV': | ||
return 'VT'; | ||
case 'WST': | ||
return 'WS$'; | ||
case 'XAF': | ||
return 'FCFA'; | ||
case 'XBT': | ||
return 'Ƀ'; | ||
case 'XCD': | ||
return '$'; | ||
case 'XOF': | ||
return 'CFA'; | ||
case 'XPF': | ||
return '₣'; | ||
case 'YER': | ||
return '﷼'; | ||
case 'ZAR': | ||
return 'R'; | ||
case 'ZWD': | ||
return 'Z$'; | ||
default: | ||
return undefined; | ||
} | ||
{ | ||
switch (currency) { | ||
case 'AED': | ||
return 'د.إ'; | ||
case 'AFN': | ||
return '؋'; | ||
case 'ALL': | ||
return 'L'; | ||
case 'AMD': | ||
return '֏'; | ||
case 'ANG': | ||
return 'ƒ'; | ||
case 'AOA': | ||
return 'Kz'; | ||
case 'ARS': | ||
return '$'; | ||
case 'AUD': | ||
return '$'; | ||
case 'AWG': | ||
return 'ƒ'; | ||
case 'AZN': | ||
return '₼'; | ||
case 'BAM': | ||
return 'KM'; | ||
case 'BBD': | ||
return '$'; | ||
case 'BDT': | ||
return '৳'; | ||
case 'BGN': | ||
return 'лв'; | ||
case 'BHD': | ||
return '.د.ب'; | ||
case 'BIF': | ||
return 'FBu'; | ||
case 'BMD': | ||
return '$'; | ||
case 'BND': | ||
return '$'; | ||
case 'BOB': | ||
return '$b'; | ||
case 'BRL': | ||
return 'R$'; | ||
case 'BSD': | ||
return '$'; | ||
case 'BTC': | ||
return '฿'; | ||
case 'BTN': | ||
return 'Nu.'; | ||
case 'BWP': | ||
return 'P'; | ||
case 'BYR': | ||
return 'Br'; | ||
case 'BYN': | ||
return 'Br'; | ||
case 'BZD': | ||
return 'BZ$'; | ||
case 'CAD': | ||
return '$'; | ||
case 'CDF': | ||
return 'FC'; | ||
case 'CHF': | ||
return 'CHF'; | ||
case 'CLP': | ||
return '$'; | ||
case 'CNY': | ||
return '¥'; | ||
case 'COP': | ||
return '$'; | ||
case 'CRC': | ||
return '₡'; | ||
case 'CUC': | ||
return '$'; | ||
case 'CUP': | ||
return '₱'; | ||
case 'CVE': | ||
return '$'; | ||
case 'CZK': | ||
return 'Kč'; | ||
case 'DJF': | ||
return 'Fdj'; | ||
case 'DKK': | ||
return 'kr'; | ||
case 'DOP': | ||
return 'RD$'; | ||
case 'DZD': | ||
return 'دج'; | ||
case 'EEK': | ||
return 'kr'; | ||
case 'EGP': | ||
return '£'; | ||
case 'ERN': | ||
return 'Nfk'; | ||
case 'ETB': | ||
return 'Br'; | ||
case 'ETH': | ||
return 'Ξ'; | ||
case 'EUR': | ||
return '€'; | ||
case 'FJD': | ||
return '$'; | ||
case 'FKP': | ||
return '£'; | ||
case 'GBP': | ||
return '£'; | ||
case 'GEL': | ||
return '₾'; | ||
case 'GGP': | ||
return '£'; | ||
case 'GHC': | ||
return '₵'; | ||
case 'GHS': | ||
return 'GH₵'; | ||
case 'GIP': | ||
return '£'; | ||
case 'GMD': | ||
return 'D'; | ||
case 'GNF': | ||
return 'FG'; | ||
case 'GTQ': | ||
return 'Q'; | ||
case 'GYD': | ||
return '$'; | ||
case 'HKD': | ||
return '$'; | ||
case 'HNL': | ||
return 'L'; | ||
case 'HRK': | ||
return 'kn'; | ||
case 'HTG': | ||
return 'G'; | ||
case 'HUF': | ||
return 'Ft'; | ||
case 'IDR': | ||
return 'Rp'; | ||
case 'ILS': | ||
return '₪'; | ||
case 'IMP': | ||
return '£'; | ||
case 'INR': | ||
return '₹'; | ||
case 'IQD': | ||
return 'ع.د'; | ||
case 'IRR': | ||
return '﷼'; | ||
case 'ISK': | ||
return 'kr'; | ||
case 'JEP': | ||
return '£'; | ||
case 'JMD': | ||
return 'J$'; | ||
case 'JOD': | ||
return 'JD'; | ||
case 'JPY': | ||
return '¥'; | ||
case 'KES': | ||
return 'KSh'; | ||
case 'KGS': | ||
return 'лв'; | ||
case 'KHR': | ||
return '៛'; | ||
case 'KMF': | ||
return 'CF'; | ||
case 'KPW': | ||
return '₩'; | ||
case 'KRW': | ||
return '₩'; | ||
case 'KWD': | ||
return 'KD'; | ||
case 'KYD': | ||
return '$'; | ||
case 'KZT': | ||
return 'лв'; | ||
case 'LAK': | ||
return '₭'; | ||
case 'LBP': | ||
return '£'; | ||
case 'LKR': | ||
return '₨'; | ||
case 'LRD': | ||
return '$'; | ||
case 'LSL': | ||
return 'M'; | ||
case 'LTC': | ||
return 'Ł'; | ||
case 'LTL': | ||
return 'Lt'; | ||
case 'LVL': | ||
return 'Ls'; | ||
case 'LYD': | ||
return 'LD'; | ||
case 'MAD': | ||
return 'MAD'; | ||
case 'MDL': | ||
return 'lei'; | ||
case 'MGA': | ||
return 'Ar'; | ||
case 'MKD': | ||
return 'ден'; | ||
case 'MMK': | ||
return 'K'; | ||
case 'MNT': | ||
return '₮'; | ||
case 'MOP': | ||
return 'MOP$'; | ||
case 'MRO': | ||
return 'UM'; | ||
case 'MRU': | ||
return 'UM'; | ||
case 'MUR': | ||
return '₨'; | ||
case 'MVR': | ||
return 'Rf'; | ||
case 'MWK': | ||
return 'MK'; | ||
case 'MXN': | ||
return '$'; | ||
case 'MYR': | ||
return 'RM'; | ||
case 'MZN': | ||
return 'MT'; | ||
case 'NAD': | ||
return '$'; | ||
case 'NGN': | ||
return '₦'; | ||
case 'NIO': | ||
return 'C$'; | ||
case 'NOK': | ||
return 'kr'; | ||
case 'NPR': | ||
return '₨'; | ||
case 'NZD': | ||
return '$'; | ||
case 'OMR': | ||
return '﷼'; | ||
case 'PAB': | ||
return 'B/.'; | ||
case 'PEN': | ||
return 'S/.'; | ||
case 'PGK': | ||
return 'K'; | ||
case 'PHP': | ||
return '₱'; | ||
case 'PKR': | ||
return '₨'; | ||
case 'PLN': | ||
return 'zł'; | ||
case 'PYG': | ||
return 'Gs'; | ||
case 'QAR': | ||
return '﷼'; | ||
case 'RMB': | ||
return '¥'; | ||
case 'RON': | ||
return 'lei'; | ||
case 'RSD': | ||
return 'Дин.'; | ||
case 'RUB': | ||
return '₽'; | ||
case 'RWF': | ||
return 'R₣'; | ||
case 'SAR': | ||
return '﷼'; | ||
case 'SBD': | ||
return '$'; | ||
case 'SCR': | ||
return '₨'; | ||
case 'SDG': | ||
return 'ج.س.'; | ||
case 'SEK': | ||
return 'kr'; | ||
case 'SGD': | ||
return '$'; | ||
case 'SHP': | ||
return '£'; | ||
case 'SLL': | ||
return 'Le'; | ||
case 'SOS': | ||
return 'S'; | ||
case 'SRD': | ||
return '$'; | ||
case 'SSP': | ||
return '£'; | ||
case 'STD': | ||
return 'Db'; | ||
case 'STN': | ||
return 'Db'; | ||
case 'SVC': | ||
return '$'; | ||
case 'SYP': | ||
return '£'; | ||
case 'SZL': | ||
return 'E'; | ||
case 'THB': | ||
return '฿'; | ||
case 'TJS': | ||
return 'SM'; | ||
case 'TMT': | ||
return 'T'; | ||
case 'TND': | ||
return 'د.ت'; | ||
case 'TOP': | ||
return 'T$'; | ||
case 'TRL': | ||
return '₤'; | ||
case 'TRY': | ||
return '₺'; | ||
case 'TTD': | ||
return 'TT$'; | ||
case 'TVD': | ||
return '$'; | ||
case 'TWD': | ||
return 'NT$'; | ||
case 'TZS': | ||
return 'TSh'; | ||
case 'UAH': | ||
return '₴'; | ||
case 'UGX': | ||
return 'USh'; | ||
case 'USD': | ||
return '$'; | ||
case 'UYU': | ||
return '$U'; | ||
case 'UZS': | ||
return 'лв'; | ||
case 'VEF': | ||
return 'Bs'; | ||
case 'VND': | ||
return '₫'; | ||
case 'VUV': | ||
return 'VT'; | ||
case 'WST': | ||
return 'WS$'; | ||
case 'XAF': | ||
return 'FCFA'; | ||
case 'XBT': | ||
return 'Ƀ'; | ||
case 'XCD': | ||
return '$'; | ||
case 'XOF': | ||
return 'CFA'; | ||
case 'XPF': | ||
return '₣'; | ||
case 'YER': | ||
return '﷼'; | ||
case 'ZAR': | ||
return 'R'; | ||
case 'ZWD': | ||
return 'Z$'; | ||
default: | ||
return undefined; | ||
} | ||
} | ||
}; | ||
export function getUnit(currency: string): any { | ||
currency = currency.trim().toUpperCase(); | ||
if (currency.length === 3) return whatCurrency(currency); | ||
else { | ||
let temp = ""; | ||
let list = []; | ||
for (let a of currency) { | ||
temp += a; | ||
if (temp.length === 3) { | ||
list.push(whatCurrency(temp)); | ||
temp = ""; | ||
} | ||
} | ||
return list; | ||
currency = currency.trim().toUpperCase(); | ||
if (currency.length === 3) return whatCurrency(currency); | ||
else { | ||
let temp = ""; | ||
let list = []; | ||
for (let a of currency) { | ||
temp += a; | ||
if (temp.length === 3) { | ||
list.push(whatCurrency(temp)); | ||
temp = ""; | ||
} | ||
} | ||
return list; | ||
} | ||
} |
@@ -14,3 +14,3 @@ { | ||
"main": "index.js", | ||
"version": "1.7.3", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -17,0 +17,0 @@ "dependencies": { |
@@ -10,3 +10,8 @@ # 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のパーサーを作った. ですから,重要な注意点があります. 現在,為替レートは,"クローズ"と"オープン"の平均値として定義されている。 | ||
> 従来のParserの問題点を解決したバージョンであるyahoo-exchange 2.0.0が発売されました。 | ||
> 以前のバージョンと互換されません。 | ||
> deprecatedされたメソッドが除去されました。 | ||
> Warning : getExchangeDataLowTrafficとgetExchangeDataLowTrafficPがいつもエラーを返還します。 今は使用しないでください。 | ||
@@ -17,6 +22,4 @@ ## getExchangeDataArray(pair, callback, errorHandler): void | ||
* errorHandler : オプションです。 基本メソッドは ```console.log(error)``` です。 | ||
> ### 警告! | ||
>Bid と Askは一部のフェアではundefinedがリターンなります。 該当ペアを捜した方はイッシューに登録してください。 | ||
#### 知られたエラー | ||
* JPYKRW | ||
>###v2.0.0の案内 | ||
>返還した項目で52 Week Range Min、52 Week Range MaxとBid、Askが除去されました。 | ||
@@ -162,8 +165,2 @@ Array\<number\>Kは次のような項目が含まれます。 [Now, Changes, Changes percent, Previous Close, Open, Bid, Ask, Day's Range Min, Day's Range Max, 52 Week Range Min, 52 Week Range Max] | ||
## getData(pair, callback, errorHandler): void @deprecated | ||
> 1.0で除去されたメソッドです。 2.0で削除される予定ですので、getExchangeDataArrayを使用してください。 | ||
## getDataArray(pair, callback, errorHandler): void @deprecated | ||
> 1.0で除去されたメソッドです。 2.0で削除される予定ですので、getExchangeDataArrayを使用してください。 | ||
## test.js | ||
@@ -170,0 +167,0 @@ * ``` javascript |
@@ -1,2 +0,2 @@ | ||
# yahoo-exchange 소개 | ||
# yahoo-exchange | ||
@@ -10,14 +10,18 @@ [![npm](https://img.shields.io/npm/v/yahoo-exchange.svg?style=flat-square)](https://www.npmjs.com/package/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의 평균값으로 계산됩니다.(그외의 값은 정상입니다.) | ||
> Warning : getExchangeDataLowTraffic 와 getExchangeDataLowTrafficP가 항상 에러를 반환합니다. 지금은 사용하지 마십시오. | ||
> 기존 파서의 문제점을 해결한 버전인 yahoo-exchange 2.0.0이 출시되었습니다. | ||
> 이전버전과 호환되지 않습니다. | ||
> deprecated된 메소드가 제거되었습니다. | ||
> 경고 : getExchangeDataLowTraffic 와 getExchangeDataLowTrafficP가 항상 에러를 반환합니다. 지금은 사용하지 마십시오. | ||
## getExchangeDataArray(pair, callback, errorHandler): void | ||
> ### v2.0.0 안내 | ||
> 반환하는 항목에서 52 Week Range Min, 52 Week Range Max와 Bid, Ask가 제거되었습니다. | ||
* pair : string 또는 Array\<string\> | ||
* callback : (Array\<number\>, pair) => any | ||
* errorHandler : 옵션입니다. 기본 메소드는 ```console.log(error)``` 입니다. | ||
> ### 경고! | ||
>Bid 와 Ask는 일부 페어에서 undefined이 리턴됩니다. 해당 페어를 찾으신 분은 이슈에 등록하여 주시면 감사하겠습니다. | ||
#### 알려진 에러 | ||
* JPYKRW | ||
Array\<number\>는 다음과 같은 항목이 포함됩니다. [Now, Changes, Changes percent, Previous Close, Open, Bid, Ask, Day's Range Min, Day's Range Max, 52 Week Range Min, 52 Week Range Max] | ||
### 예시 코드 | ||
@@ -60,3 +64,3 @@ * ``` javascript | ||
### 경고 | ||
getExchangeDataArray는 전체 데이터를 넘겨주지 않습니다. | ||
getExchangeDataArray는 Callback에 전체 데이터를 넘겨주지 않습니다. | ||
@@ -161,8 +165,2 @@ ## getExchangeDataLowTraffic(callback, errorHandler): void | ||
## getData(pair, callback, errorHandler): void @deprecated | ||
> 1.0에서 제거된 메소드입니다. 2.0에서 삭제될 예정이오니, getExchangeDataArray를 사용하세요. | ||
## getDataArray(pair, callback, errorHandler): void @deprecated | ||
> 1.0에서 제거된 메소드입니다. 2.0에서 삭제될 예정이오니, getExchangeDataArray를 사용하세요. | ||
## test.js | ||
@@ -181,3 +179,3 @@ * ``` javascript | ||
## 사용된 라이브러리에 대한 저작권 고지 | ||
아래의 라이브러리의 일부코드가 이 프로젝트에 포함되었습니다. | ||
아래의 라이브러리의 일부 코드가 이 프로젝트에 포함되었습니다. | ||
* [currency-symbol-map](https://github.com/bengourley/currency-symbol-map) |
@@ -10,3 +10,8 @@ # 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. | ||
> yahoo-exchange 2.0.0, a version that solves the problem of existing parser, has been released. | ||
>Not backward compatible. | ||
> The deprecated method has been removed. | ||
> Warning : getExchangeDataLowTraffic and getExchangeDataLowTrafficP returns error. Don't use now. | ||
@@ -17,6 +22,4 @@ ## getExchangeDataArray(pair, callback, errorHandler): void | ||
* errorHandler : options (A default method is ```console.log(error)```) | ||
> ### Warning! | ||
>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 | ||
* JPYKRW | ||
> ### Introduction to v2.0.0 | ||
> 52 Week Range Min, 52 Week Range Max, Bid, Ask have been removed from the returned items. | ||
@@ -159,9 +162,3 @@ Array\<number\> : [Now, Changes, Changes percent, Previous Close, Open, Bid, Ask, Day's Range Min, Day's Range Max, 52 Week Range Min, 52 Week Range Max] | ||
``` | ||
## getData(pair, callback, errorHandler): void @deprecated | ||
> deprecated Since version 1.0. Will be deleted in version 2.0. Use getExchangeDataArray instead. | ||
## getDataArray(pair, callback, errorHandler): void @deprecated | ||
> deprecated Since version 1.0. Will be deleted in version 2.0. Use getExchangeDataArray instead. | ||
## test.js | ||
@@ -168,0 +165,0 @@ * ``` javascript |
70617
10
1052
175