Skip to content

Instantly share code, notes, and snippets.

@grant
Created April 12, 2019 17:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grant/be5b6f12589dee8be1cefe5db591a7b5 to your computer and use it in GitHub Desktop.
Save grant/be5b6f12589dee8be1cefe5db591a7b5 to your computer and use it in GitHub Desktop.
BTC API – GCF
const rp = require('request-promise');
const DEFAULT_DATE = '2019-04-10';
exports.btc = async (req, res) => {
const date = req.query.date || DEFAULT_DATE;
async function getBTC(date) {
const res = await rp(`https://api.coinbase.com/v2/prices/BTC-USD/spot?date=${date}`, {
headers: {
'CB-VERSION': '2016-10-10',
Authorization: `Bearer ${process.env.COINBASE_TOKEN}`
}
});
return res;
}
const btc = await getBTC(date);
res.send(btc);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment