Skip to content

Commit

Permalink
example有償版対応 (#75)
Browse files Browse the repository at this point in the history
* example有償版対応

* 無駄な空行を削除
  • Loading branch information
s-meitoma authored Apr 21, 2023
1 parent 16083c1 commit 77dab8b
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 9,009 deletions.
2 changes: 1 addition & 1 deletion examples/20220825-000-write-refresh_token.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"cells":[{"cell_type":"markdown","metadata":{"id":"8gKDRhrY0mrO"},"source":["# リフレッシュトークンの書き込み\n","\n","[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/J-Quants/jquants-api-client-python/blob/master/examples/20220825-000-write-refresh_token.ipynb)\n","\n","J-Quants API のリフレッシュトークンを Google Drive の MyDrive/drive_ws/secret/jquantsapi-key.txt に書き込みます。\n","\n","リフレッシュトークンは取得方法は以下のリンク先をご参照ください。\n","\n","https://jpx.gitbook.io/j-quants-api/api-reference#idtkunno\n","\n","\n","----\n","\n","**このノートブックはGoogle Driveを使用します。**\n","\n","- Google Drive の以下のファイルにリフレッシュトークンを書き込みます。\n"," - `MyDrive/drive_ws/secret/jquantsapi-key.txt`\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pQVIcLjryiMq"},"outputs":[],"source":["# Google drive をマウントします\n","from google.colab import drive\n","drive.mount('/content/drive')\n","\n","# 必要なモジュールを読み込みます\n","import os\n","from getpass import getpass\n","\n","\n","# refresh_token を入力します\n","refresh_token = getpass(\"Please input refresh token\")\n","\n","# refresh_token の書き込み先を指定します\n","OUTPUT_DIR = \"/content/drive/MyDrive/drive_ws/secret\"\n","OUTPUT_PATH = f\"{OUTPUT_DIR}/jquantsapi-key.txt\"\n","\n","# refresh_token を書き込みます\n","os.makedirs(OUTPUT_DIR, exist_ok=True)\n","with open(OUTPUT_PATH, mode=\"w\") as f:\n"," f.write(refresh_token)\n","\n","# 完了文字列を表示します\n","print(\"Done\")"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"S3wxpLKm0fGN"},"outputs":[],"source":[]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMvkFqt1b8LuOi5OXQ4CqdB","collapsed_sections":[],"name":"20220825-000-write-refresh_token.ipynb","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
{"cells":[{"attachments":{},"cell_type":"markdown","metadata":{"id":"8gKDRhrY0mrO"},"source":["# リフレッシュトークンの書き込み\n","\n","[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/J-Quants/jquants-api-client-python/blob/master/examples/20220825-000-write-refresh_token.ipynb)\n","\n","J-Quants API のリフレッシュトークンを Google Drive の MyDrive/drive_ws/secret/jquantsapi-key.txt に書き込みます。\n","\n","リフレッシュトークンは取得方法は以下のリンク先をご参照ください。\n","\n","https://jpx.gitbook.io/j-quants-ja/outline/getstarted#step2rifuresshutkunnoreapino\n","\n","\n","----\n","\n","**このノートブックはGoogle Driveを使用します。**\n","\n","- Google Drive の以下のファイルにリフレッシュトークンを書き込みます。\n"," - `MyDrive/drive_ws/secret/jquantsapi-key.txt`\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"pQVIcLjryiMq"},"outputs":[],"source":["# Google drive をマウントします\n","from google.colab import drive\n","drive.mount('/content/drive')\n","\n","# 必要なモジュールを読み込みます\n","import os\n","from getpass import getpass\n","\n","\n","# refresh_token を入力します\n","refresh_token = getpass(\"Please input refresh token\")\n","\n","# refresh_token の書き込み先を指定します\n","OUTPUT_DIR = \"/content/drive/MyDrive/drive_ws/secret\"\n","OUTPUT_PATH = f\"{OUTPUT_DIR}/jquantsapi-key.txt\"\n","\n","# refresh_token を書き込みます\n","os.makedirs(OUTPUT_DIR, exist_ok=True)\n","with open(OUTPUT_PATH, mode=\"w\") as f:\n"," f.write(refresh_token)\n","\n","# 完了文字列を表示します\n","print(\"Done\")"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"S3wxpLKm0fGN"},"outputs":[],"source":[]}],"metadata":{"colab":{"authorship_tag":"ABX9TyMvkFqt1b8LuOi5OXQ4CqdB","collapsed_sections":[],"name":"20220825-000-write-refresh_token.ipynb","provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.11.1"}},"nbformat":4,"nbformat_minor":0}
73 changes: 4 additions & 69 deletions examples/20220825-002-sector.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,6 @@
"japanize_matplotlib.japanize()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "8JRXB-JIQnDg"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -125,15 +116,6 @@
"STORAGE_DIR_PATH"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "rkEQDOUlQqCN"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -173,15 +155,6 @@
"refresh_token = get_refresh_token()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "CI9C-h6iQXsG"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -194,24 +167,6 @@
"jqapi = jquantsapi.Client(refresh_token=refresh_token)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "d6Y5q9AesDK0"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "xH2PYF0ENVYa"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -222,9 +177,7 @@
"source": [
"# 銘柄情報を取得します\n",
"now = pd.Timestamp.now(tz=\"Asia/Tokyo\")\n",
"if now.hour < 22:\n",
" # データ更新時間前の場合は日付を1日ずらします。\n",
" now -= pd.Timedelta(1, unit=\"D\")\n",
"\n",
"list_file = f\"{STORAGE_DIR_PATH}/list_{now.strftime('%Y%m%d')}.csv.gz\"\n",
"if not os.path.isfile(list_file):\n",
" # 保存されているデータが存在しない場合はAPIからデータを取得します\n",
Expand All @@ -250,15 +203,6 @@
"df_list.tail(2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "THYjJg2Xsb6I"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -289,15 +233,6 @@
" ax.annotate(str(p.get_height()), (p.get_x() * 1.005, p.get_height() * 1.005))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "KRrlEQABsb0L"
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -312,7 +247,7 @@
"# 過去6ヶ月のデータを取得\n",
"start_dt = now - pd.Timedelta(190, unit=\"D\") # 計算用に10日分多めに指定しています\n",
"end_dt = now\n",
"if end_dt.hour < 19:\n",
"if end_dt.hour < 18:\n",
" # データ更新時間前の場合は日付を1日ずらします。\n",
" end_dt -= pd.Timedelta(1, unit=\"D\")\n",
"price_file = f\"{STORAGE_DIR_PATH}/price_{start_dt.strftime('%Y%m%d')}_{end_dt.strftime('%Y%m%d')}.csv.gz\"\n",
Expand Down Expand Up @@ -440,7 +375,7 @@
"df_work = pd.merge(df_work, df_list[[\"Code\", \"Sector33Code\", \"Sector33CodeName\", \"MarketCode\"]], on=[\"Code\"])\n",
"\n",
"# プライム銘柄に絞り込みます\n",
"df_work = df_work.loc[df_work[\"MarketCode\"] == \"111\"]\n",
"df_work = df_work.loc[df_work[\"MarketCode\"] == \"0111\"]\n",
"\n",
"# 6ヶ月、3ヶ月、および基準日を出力します\n",
"display(base_6months_date, base_3months_date, evaluation_date)\n",
Expand Down Expand Up @@ -489,4 +424,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}
Loading

0 comments on commit 77dab8b

Please sign in to comment.