0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

exchangeratesapi.io APIから為替の全レートを取得する

Last updated at Posted at 2022-03-25

はじめに

@itTkmさんの

@ittkm/exchangeratesapiを使用してフリープラン(リクエスト上限 1000/月)で取得します。

What is an API Request?

Pricing is based on the number of monthly API Requests offered for each individual Subscription Plan. Accessing any type of exchangeratesapi.io forex data using a valid API Access Key counts as one "API Request". Unlike most other providers, any API Endpoint or feature requested (including Time-Frame & Currency-Change Queries, as well as requesting multiple currencies at once) counts as only one API Request.

Frequently Asked Questions

今回の取得方法の場合、全レートを取得してもリクエストのカウントは1です。

全レート取得

currencyExchange(とutilities)は公開されていない関数なので@ittkm/exchangeratesapiリポジトリからコピペするか、公開するように修正したフォークリポジトリからインストールしてください。

import {exchangeratesapi, IExchangeratesapiResponse, utilities} from "@ittkm/exchangeratesapi";
const {currencyExchange} = utilities;

      // const api = new exchangeratesapi(exchangeratesapiKey);
      // const result:IExchangeratesapiResponse = await api.latest();
      if (result.success) {
        const ratePairs:any = {};
        const rates = result.rates;
        const rateKeys = Object.keys(rates);
        rateKeys.forEach((key)=>{
          const newBase = rates[key];
          rateKeys.forEach((newKey)=>{
            const symbol = rates[newKey];
            ratePairs[key+newKey] = currencyExchange(newBase, symbol);
          });
        });

      console.log(ratePairs); //-> "{"AEDAED":1,"AEDAFN":23.927648,"AEDALL":30.172867,"AEDAMD":133.105265,"AEDANG":0.490964,"AEDAOA":124.060"...
    }

クロスレートでexchangeratesapi.ioから取得した通貨同士のレートを求めています。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?