Skip to content

Instantly share code, notes, and snippets.

@ainvyu
Created December 27, 2015 11:17
Show Gist options
  • Save ainvyu/edfed818dbbf47b8a350 to your computer and use it in GitHub Desktop.
Save ainvyu/edfed818dbbf47b8a350 to your computer and use it in GitHub Desktop.
/**
* Created by eniv on 2015. 12. 27..
*/
let fetch = require('node-fetch');
let _ = require('lodash');
async function getCurrency(from, to) {
let res = await fetch('http://finance.yahoo.com/webservice/v1/symbols/allcurrencies/quote?format=json');
let currency_data = await res.json();
return _.find(
currency_data.list.resources,
r => r.resource.fields.name == `${from}/${to}`)
}
async function test() {
let price = await getCurrency('USD', 'KRW')
console.log(price)
}
test();
console.log("test");
/////////////////////////////////////
test
{ resource:
{ classname: 'Quote',
fields:
{ change: '0.000000',
chg_percent: '0.000000',
name: 'USD/KRW',
price: '1164.944946',
symbol: 'KRW=X',
ts: '1451134500',
type: 'currency',
utctime: '2015-12-26T12:55:00+0000',
volume: '0' } } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment