如何获得欧元 Node.js 的加密货币价格?

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

以 coinbase-api 为例,我可以通过这种方式获得加密货币的价格:

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

如您所见,我需要一对 cryptocurrency - eur,这很重要。那么,我该如何使用 binance api?

我正在尝试使用这样的东西:

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

但这不是我需要的。我需要欧元价格。

对于与 EUR 配对的基础货币,您可以使用“当前平均价格”端点 (docs)。

示例:

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);
});

使用superface npm包可以轻松获取汇率

示例

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();