447
558

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 5 years have passed since last update.

無料で使える公開 API のリスト:48 カテゴリ

Last updated at Posted at 2019-11-05

A collective list of free APIs

API Key の登録なし+無料で株価情報が取れる API ないかなーと探していたら、面白いリストが見つかりました。48 カテゴリにわたり数百もの API がリストされています。545 contributors (2019/11/6 時点) によるまさに集合知(?)ですね。

Github: https://github.com/public-apis/public-apis

A collective list of free APIs for use in software and web development.

の説明通り、

  • Animals
  • Anime
  • Anti-Malware
  • Art & Design
  • Books

など、どんなデータ?と思うようなカテゴリから、 GeocodingJobsMusic まで、全部見ることができていませんがどんなネタにも対応できそうな気がします。

Financial Modeling Prep

Finance 系は ここから。今回はとりあえず最新の株価が分かればよかったので、シンプルな Financial Modeling Prep のサービスを使うことにします。参考まで実行例をば。

MATLAB例

singleQuote.m
symbol = "amzn";
url = "https://financialmodelingprep.com/api/company/real-time-price/" + symbol + "?datatype=json";
jsontxt = webread(url)
value = jsondecode(jsontxt)

結果はこんな形。

jsontxt =
    '{
         "symbol": "AMZN",
         "price": 1800.57,
         "updated_at": "2019-11-05 16:32:13"
     }'

value = 
  struct with fields:

        symbol: 'AMZN'
         price: 1.8006e+03
    updated_at: '2019-11-05 16:32:13'

webread の出力は文字列(char) ですが、jsondecode を使うと構造体になります。R2019b 使いました。

JavaScript例

singleQuote.html
<!DOCTYPE html>

<head>
    <title>getting quotes</title>

<body>
    <h1>getting quotes</h1>
    <p id="quotes"></p>
    <p id="updated_at"></p>

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            let symbol = 'amzn';
            let callback = function (data) {
                let strPrice = data.price.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
                // From https://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-currency-string-in-javascript

                document.getElementById('quotes').textContent = data.symbol + ": $" + strPrice;
                document.getElementById('updated_at').textContent = data.updated_at + '(UTC)';
                alert('Stock Price: $' + strPrice + ' at ' + data.updated_at + '(UTC)');
            };

            // https://financialmodelingprep.com/developer/docs/realtime-stock-quote-api
            let url = "https://financialmodelingprep.com/api/company/real-time-price/" + symbol + "?datatype=json";
            $.getJSON(url, callback);
        });
    </script>
</body>
</head>

Capture.PNG

こんな感じ。使いやすそう。

447
558
1

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
447
558

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?