1
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.

東証 J-Quants API

Last updated at Posted at 2023-06-26
1 / 2

J-Quants はJPX(日証券取引所)の提供するAPI
無料プランの場合、3か月遅れの情報までしか取得できないのがネック

alphavantage APIとか使って、以下のような株アプリを作ってる

1. まず最初にアカウント登録する

以下は動作確認したサンプルです

2. パスワードからトークンを取得するコード

import json
import requests
import pandas as pd


# POSTするデータを作る。
email  = "xxxxx@gmail.com"
password = "xxxx"
account_data = json.dumps({
        "mailaddress": email,
        "password": password,
    })

auth_user_url = "https://api.jquants.com/v1/token/auth_user"
auth_result = requests.post(auth_user_url, data=account_data)
refresh_token = auth_result.json()["refreshToken"]

auth_refresh_url=f"https://api.jquants.com/v1/token/auth_refresh?refreshtoken={refresh_token}"

refresh_result = requests.post(auth_refresh_url)
id_token = refresh_result.json()["idToken"]

3. 株式コードと期間を指定して投稿する

code = "7203" # 4桁のコードでも5桁のコード72030でもよい。
from_ = "2023-03-01"
to_ = "2023-03-01"

daily_quotes_url = f"https://api.jquants.com/v1/prices/daily_quotes?code={code}&from={from_}&to={to_}"
target_url= f"https://api.jquants.com/v1/fins/statements?code={code}"

4. idトークンはヘッダーにセットする


headers = {"Authorization": f"Bearer {id_token}"}
result = requests.get(target_url, headers=headers)
print(result.json())

まあ、無料じゃないのと、Alphavantege とかと比べると情報が貧弱なのがネック

いろんなAPIがある↓

1
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
1
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?