'How to get cryptocurrency's price in EUR Node.js?

As a example in coinbase-api I can get cryptocurrency's price this way:

const eth_eur = await publicClient.getProductOrderBook('ETH-EUR', { level: 1 });

As you can see, I need pair cryptocurrency - eur, and that's important. So, how can I do it using binance api?

I was trying to use something like this:

const price = await binance.futuresFundingRate("ETHUSDT");

But this is not what I need. I need price in euro.



Solution 1:[1]

You can use the "Current average price" endpoint (docs) for base currencies that have pair against EUR.

Example:

const axios = require('axios');

axios.get('https://api.binance.com/api/v3/avgPrice?symbol=BTCEUR').then(response => {
    const body = response.data;
    console.log(body.price);
});

Solution 2:[2]

You can get the exchange rate easily with superface npm package

Example

npm install @superfaceai/one-sdk

npx @superfaceai/cli install crypto/exchange-rate

const { SuperfaceClient } = require("@superfaceai/one-sdk");

const sdk = new SuperfaceClient();

async function run() {
  // Load the installed profile
  const profile = await sdk.getProfile("crypto/exchange-rate");

  // Use the profile
  const result = await profile.getUseCase("GetExchangeRate").perform({
    from: "ETH",
    to: "EUR",
  });

  console.log(result.unwrap());
}

run();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr Hejda
Solution 2 Henok