Skip to content

Instantly share code, notes, and snippets.

@fayazara
Last active May 19, 2020 09:27
Show Gist options
  • Select an option

  • Save fayazara/c0b7a09b567b253e8173a259fac09620 to your computer and use it in GitHub Desktop.

Select an option

Save fayazara/c0b7a09b567b253e8173a259fac09620 to your computer and use it in GitHub Desktop.
Get Cryptocurrency Prices from Binance
const express = require("express");
const app = express();
const axios = require("axios");
app.get("/", async (req, res) => {
let BTC = "https://api.binance.com/api/v3/ticker/price?symbol=BTCUSDT";
let ETH = "https://api.binance.com/api/v3/ticker/price?symbol=ETHUSDT";
let LTC = "https://api.binance.com/api/v3/ticker/price?symbol=LTCUSDT";
let XRP = "https://api.binance.com/api/v3/ticker/price?symbol=XRPUSDT";
const promise1 = axios.get(BTC);
const promise2 = axios.get(ETH);
const promise3 = axios.get(LTC);
const promise4 = axios.get(XRP);
const responses = await axios.all([promise1, promise2, promise3, promise4]);
let prices = {
Bitcoin: responses[0].data.price,
Ethereum: responses[1].data.price,
Litecoin: responses[2].data.price,
Ripple: responses[3].data.price
};
console.log(prices);
});
const listener = app.listen(process.env.PORT, () => {
console.log("Your app is listening on port " + listener.address().port);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment