komachi 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,228 @@
1
+ # License
2
+
3
+ Komachi is licensed under the **Apache License, Version 2.0**.
4
+
5
+ Komachi は **Apache License 2.0** のもとで公開しています。
6
+
7
+ Copyright 2026 Kamakura Quant Lab / 鎌倉クオンツラボ
8
+
9
+ ## Why Apache 2.0 rather than MIT
10
+
11
+ Two clauses matter for a tool like this one, and MIT has neither.
12
+
13
+ **Section 6 withholds trademark rights explicitly.** Komachi is published so a
14
+ buyer can read what it does with their purchase token before running it, which
15
+ only works if the name means something. The licence grants the code and not the
16
+ name.
17
+
18
+ **Section 4(b) requires a modified file to say it was modified.** A fork that
19
+ changes what this tool does with a credential has to declare it. That is worth
20
+ more here than the brevity MIT would buy.
21
+
22
+ Neither clause restricts ordinary use. Fork it, ship it, sell something built
23
+ on it; the terms below are the standard Apache 2.0 text.
24
+
25
+ ---
26
+
27
+
28
+ Apache License
29
+ Version 2.0, January 2004
30
+ http://www.apache.org/licenses/
31
+
32
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
33
+
34
+ 1. Definitions.
35
+
36
+ "License" shall mean the terms and conditions for use, reproduction,
37
+ and distribution as defined by Sections 1 through 9 of this document.
38
+
39
+ "Licensor" shall mean the copyright owner or entity authorized by
40
+ the copyright owner that is granting the License.
41
+
42
+ "Legal Entity" shall mean the union of the acting entity and all
43
+ other entities that control, are controlled by, or are under common
44
+ control with that entity. For the purposes of this definition,
45
+ "control" means (i) the power, direct or indirect, to cause the
46
+ direction or management of such entity, whether by contract or
47
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
48
+ outstanding shares, or (iii) beneficial ownership of such entity.
49
+
50
+ "You" (or "Your") shall mean an individual or Legal Entity
51
+ exercising permissions granted by this License.
52
+
53
+ "Source" form shall mean the preferred form for making modifications,
54
+ including but not limited to software source code, documentation
55
+ source, and configuration files.
56
+
57
+ "Object" form shall mean any form resulting from mechanical
58
+ transformation or translation of a Source form, including but
59
+ not limited to compiled object code, generated documentation,
60
+ and conversions to other media types.
61
+
62
+ "Work" shall mean the work of authorship, whether in Source or
63
+ Object form, made available under the License, as indicated by a
64
+ copyright notice that is included in or attached to the work
65
+ (an example is provided in the Appendix below).
66
+
67
+ "Derivative Works" shall mean any work, whether in Source or Object
68
+ form, that is based on (or derived from) the Work and for which the
69
+ editorial revisions, annotations, elaborations, or other modifications
70
+ represent, as a whole, an original work of authorship. For the purposes
71
+ of this License, Derivative Works shall not include works that remain
72
+ separable from, or merely link (or bind by name) to the interfaces of,
73
+ the Work and Derivative Works thereof.
74
+
75
+ "Contribution" shall mean any work of authorship, including
76
+ the original version of the Work and any modifications or additions
77
+ to that Work or Derivative Works thereof, that is intentionally
78
+ submitted to Licensor for inclusion in the Work by the copyright owner
79
+ or by an individual or Legal Entity authorized to submit on behalf of
80
+ the copyright owner. For the purposes of this definition, "submitted"
81
+ means any form of electronic, verbal, or written communication sent
82
+ to the Licensor or its representatives, including but not limited to
83
+ communication on electronic mailing lists, source code control systems,
84
+ and issue tracking systems that are managed by, or on behalf of, the
85
+ Licensor for the purpose of discussing and improving the Work, but
86
+ excluding communication that is conspicuously marked or otherwise
87
+ designated in writing by the copyright owner as "Not a Contribution."
88
+
89
+ "Contributor" shall mean Licensor and any individual or Legal Entity
90
+ on behalf of whom a Contribution has been received by Licensor and
91
+ subsequently incorporated within the Work.
92
+
93
+ 2. Grant of Copyright License. Subject to the terms and conditions of
94
+ this License, each Contributor hereby grants to You a perpetual,
95
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
96
+ copyright license to reproduce, prepare Derivative Works of,
97
+ publicly display, publicly perform, sublicense, and distribute the
98
+ Work and such Derivative Works in Source or Object form.
99
+
100
+ 3. Grant of Patent License. Subject to the terms and conditions of
101
+ this License, each Contributor hereby grants to You a perpetual,
102
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
103
+ (except as stated in this section) patent license to make, have made,
104
+ use, offer to sell, sell, import, and otherwise transfer the Work,
105
+ where such license applies only to those patent claims licensable
106
+ by such Contributor that are necessarily infringed by their
107
+ Contribution(s) alone or by combination of their Contribution(s)
108
+ with the Work to which such Contribution(s) was submitted. If You
109
+ institute patent litigation against any entity (including a
110
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
111
+ or a Contribution incorporated within the Work constitutes direct
112
+ or contributory patent infringement, then any patent licenses
113
+ granted to You under this License for that Work shall terminate
114
+ as of the date such litigation is filed.
115
+
116
+ 4. Redistribution. You may reproduce and distribute copies of the
117
+ Work or Derivative Works thereof in any medium, with or without
118
+ modifications, and in Source or Object form, provided that You
119
+ meet the following conditions:
120
+
121
+ (a) You must give any other recipients of the Work or
122
+ Derivative Works a copy of this License; and
123
+
124
+ (b) You must cause any modified files to carry prominent notices
125
+ stating that You changed the files; and
126
+
127
+ (c) You must retain, in the Source form of any Derivative Works
128
+ that You distribute, all copyright, patent, trademark, and
129
+ attribution notices from the Source form of the Work,
130
+ excluding those notices that do not pertain to any part of
131
+ the Derivative Works; and
132
+
133
+ (d) If the Work includes a "NOTICE" text file as part of its
134
+ distribution, then any Derivative Works that You distribute must
135
+ include a readable copy of the attribution notices contained
136
+ within such NOTICE file, excluding those notices that do not
137
+ pertain to any part of the Derivative Works, in at least one
138
+ of the following places: within a NOTICE text file distributed
139
+ as part of the Derivative Works; within the Source form or
140
+ documentation, if provided along with the Derivative Works; or,
141
+ within a display generated by the Derivative Works, if and
142
+ wherever such third-party notices normally appear. The contents
143
+ of the NOTICE file are for informational purposes only and
144
+ do not modify the License. You may add Your own attribution
145
+ notices within Derivative Works that You distribute, alongside
146
+ or as an addendum to the NOTICE text from the Work, provided
147
+ that such additional attribution notices cannot be construed
148
+ as modifying the License.
149
+
150
+ You may add Your own copyright statement to Your modifications and
151
+ may provide additional or different license terms and conditions
152
+ for use, reproduction, or distribution of Your modifications, or
153
+ for any such Derivative Works as a whole, provided Your use,
154
+ reproduction, and distribution of the Work otherwise complies with
155
+ the conditions stated in this License.
156
+
157
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
158
+ any Contribution intentionally submitted for inclusion in the Work
159
+ by You to the Licensor shall be under the terms and conditions of
160
+ this License, without any additional terms or conditions.
161
+ Notwithstanding the above, nothing herein shall supersede or modify
162
+ the terms of any separate license agreement you may have executed
163
+ with Licensor regarding such Contributions.
164
+
165
+ 6. Trademarks. This License does not grant permission to use the trade
166
+ names, trademarks, service marks, or product names of the Licensor,
167
+ except as required for reasonable and customary use in describing the
168
+ origin of the Work and reproducing the content of the NOTICE file.
169
+
170
+ 7. Disclaimer of Warranty. Unless required by applicable law or
171
+ agreed to in writing, Licensor provides the Work (and each
172
+ Contributor provides its Contributions) on an "AS IS" BASIS,
173
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
174
+ implied, including, without limitation, any warranties or conditions
175
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
176
+ PARTICULAR PURPOSE. You are solely responsible for determining the
177
+ appropriateness of using or redistributing the Work and assume any
178
+ risks associated with Your exercise of permissions under this License.
179
+
180
+ 8. Limitation of Liability. In no event and under no legal theory,
181
+ whether in tort (including negligence), contract, or otherwise,
182
+ unless required by applicable law (such as deliberate and grossly
183
+ negligent acts) or agreed to in writing, shall any Contributor be
184
+ liable to You for damages, including any direct, indirect, special,
185
+ incidental, or consequential damages of any character arising as a
186
+ result of this License or out of the use or inability to use the
187
+ Work (including but not limited to damages for loss of goodwill,
188
+ work stoppage, computer failure or malfunction, or any and all
189
+ other commercial damages or losses), even if such Contributor
190
+ has been advised of the possibility of such damages.
191
+
192
+ 9. Accepting Warranty or Additional Liability. While redistributing
193
+ the Work or Derivative Works thereof, You may choose to offer,
194
+ and charge a fee for, acceptance of support, warranty, indemnity,
195
+ or other liability obligations and/or rights consistent with this
196
+ License. However, in accepting such obligations, You may act only
197
+ on Your own behalf and on Your sole responsibility, not on behalf
198
+ of any other Contributor, and only if You agree to indemnify,
199
+ defend, and hold each Contributor harmless for any liability
200
+ incurred by, or claims asserted against, such Contributor by reason
201
+ of your accepting any such warranty or additional liability.
202
+
203
+ END OF TERMS AND CONDITIONS
204
+
205
+ APPENDIX: How to apply the Apache License to your work.
206
+
207
+ To apply the Apache License to your work, attach the following
208
+ boilerplate notice, with the fields enclosed by brackets "[]"
209
+ replaced with your own identifying information. (Don't include
210
+ the brackets!) The text should be enclosed in the appropriate
211
+ comment syntax for the file format. We also recommend that a
212
+ file or class name and description of purpose be included on the
213
+ same "printed page" as the copyright notice for easier
214
+ identification within third-party archives.
215
+
216
+ Copyright [yyyy] [name of copyright owner]
217
+
218
+ Licensed under the Apache License, Version 2.0 (the "License");
219
+ you may not use this file except in compliance with the License.
220
+ You may obtain a copy of the License at
221
+
222
+ http://www.apache.org/licenses/LICENSE-2.0
223
+
224
+ Unless required by applicable law or agreed to in writing, software
225
+ distributed under the License is distributed on an "AS IS" BASIS,
226
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
227
+ See the License for the specific language governing permissions and
228
+ limitations under the License.
komachi-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,314 @@
1
+ Metadata-Version: 2.4
2
+ Name: komachi
3
+ Version: 0.1.0
4
+ Summary: Kamakura Quant Lab command line client for historical market data
5
+ Author-email: Kamakura Quant Lab <support@kamakuraquantlab.jp>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://kamakuraquantlab.jp
8
+ Project-URL: Documentation, https://kamakuraquantlab.jp/support/
9
+ Project-URL: Source, https://github.com/kamakuraquantlab/Komachi
10
+ Project-URL: The data, https://kamakuraquantlab.jp/data/
11
+ Keywords: cryptocurrency,market-data,order-book,japan,quantitative-finance
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: Intended Audience :: Science/Research
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Office/Business :: Financial :: Investment
21
+ Classifier: Topic :: Scientific/Engineering :: Information Analysis
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE.md
25
+ Requires-Dist: httpx>=0.27
26
+ Provides-Extra: duckdb
27
+ Requires-Dist: duckdb>=1.0.0; extra == "duckdb"
28
+ Requires-Dist: pyarrow>=15.0; extra == "duckdb"
29
+ Requires-Dist: pandas; extra == "duckdb"
30
+ Provides-Extra: dev
31
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
32
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
33
+ Requires-Dist: duckdb>=1.0.0; extra == "dev"
34
+ Requires-Dist: pyarrow>=15.0; extra == "dev"
35
+ Requires-Dist: pandas; extra == "dev"
36
+ Dynamic: license-file
37
+
38
+ # Komachi
39
+
40
+ **鎌倉クオンツラボ**のコマンドラインクライアントです。
41
+ ヒストリカル市場データを取得し、DuckDB からそのまま参照できる構成で保存します。
42
+
43
+ *[English README](README-en.md)*
44
+
45
+ [Kamakura Quant Lab](https://kamakuraquantlab.jp) のデータは、2 つの方法で取得できます。
46
+ 収録範囲、スキーマ、品質基準は[データのページ](https://kamakuraquantlab.jp/data/)に記載しています。
47
+
48
+ **ブラウザ** — [tsurugaoka](https://kamakuraquantlab.jp/tsurugaoka/)
49
+
50
+ 数日分を確認する用途に適しています。1 ファイルずつ、ブラウザの保存先に保存されます。
51
+
52
+ **コマンドライン** — Komachi(本リポジトリ)
53
+
54
+ Yukinoshita API(`yukinoshita.kamakuraquantlab.jp`)を呼び出すクライアントです。
55
+ まとまった量を扱う場合はこちらを使用します。
56
+
57
+ | 機能 | 内容 |
58
+ |---|---|
59
+ | 残高と配信状況の確認 | 利用できるマーケット、日付ごとの収録状況と品質を、取得前に確認できます |
60
+ | 一括取得 | 範囲を指定してまとめて取得します。中断後は同じコマンドで再開し、チェックサムで検証します |
61
+ | Hive 形式での保存 | 収集時と同じディレクトリ構成で保存するため、DuckDB から取り込み処理なしに参照できます |
62
+ | 無償公開データの取り込み | Binance Vision と GMO コインの公開データを、日本時間の日付へ再分割して取り込みます。配信データと同一の条件で比較できます |
63
+ | ローカル参照 | 手元のファイルの一覧、約定と気配の表示、DuckDB ビューの作成 |
64
+
65
+ 権限の判断と URL の署名は Yukinoshita が行います。
66
+ ファイルの実体はオブジェクトストレージから直接取得するため、
67
+ API がデータ本体を中継することはありません。
68
+
69
+ ## 1 クイックスタート
70
+
71
+ 28 market-day を使う場合の例
72
+
73
+ ### 1.1 サインイン
74
+
75
+ トークンは
76
+ [kamakuraquantlab.jp/tsurugaoka/](https://kamakuraquantlab.jp/tsurugaoka/)
77
+ で発行します。
78
+ 手元にある注文番号とメールアドレスでサインインし、「トークンを表示」を押してください。
79
+ 表示はその 1 回だけですが、必要になればいつでも発行し直せます。
80
+ 発行し直すと、それまでのトークンは使えなくなります。
81
+
82
+ ```bash
83
+ pip install 'komachi[duckdb]'
84
+ komachi token set --token hk_...
85
+ ```
86
+
87
+ 最小構成は `pip install komachi`(`httpx` のみ)です。
88
+ 取り込み、DuckDB 連携、ファイル検査を使う場合は上記の `duckdb` エクストラを指定します。
89
+
90
+ 初回はデータの保存先を尋ねられ、実行ディレクトリの `.env` に記録されます。
91
+ トークンは `.env` ではなく `~/.komachi/config.json`(パーミッション 0600)に保存されます。
92
+ データディレクトリをそのままバージョン管理下に置いても、資格情報が混入しません。
93
+
94
+ ### 1.2 残高と期限の確認
95
+
96
+ ```bash
97
+ komachi token status
98
+ ```
99
+
100
+ ```text
101
+ Product starter-4w
102
+ Token status active
103
+ Access active
104
+ First used 2026-09-11T05:54:23+00:00
105
+ Access until 2026-09-25T05:54:23+00:00
106
+ Allowance 28 market-days (4 market-weeks)
107
+ Remaining 28 market-days (4 market-weeks)
108
+
109
+ Markets BITBANK:BTC_SPOT, BITBANK:ETH_SPOT, ... COINCHECK:XRP_SPOT
110
+
111
+ Active until 2026-09-25. Until then you can unlock market-days and re-download
112
+ anything already unlocked as often as you like, at no further cost.
113
+ ```
114
+
115
+ 期限は 2 つあり、順番に効きます。
116
+
117
+ | | 期間 | 起点 | 過ぎると |
118
+ |---|---|---|---|
119
+ | 利用開始期限 | 1 か月 | トークンの発行時 | 利用期間が始まらず、以後は使えません |
120
+ | 利用期間 | 14 日 | **最初に使った時** | 新たなアンロックも配信も行われません |
121
+
122
+ **利用開始期限**までに、一度 tsurugaoka にサインインする必要があります。
123
+ この最初のサインインでトークンが発行され、同時に利用期間が始まります。
124
+ 期限を過ぎてからサインインしても利用期間は始まりません。
125
+
126
+ **利用期間**はその最初の 1 回から数えます。
127
+ 受け取ってすぐに作業を始められなくても不利にならないよう、
128
+ 発行時ではなく初回利用時を起点にしています。
129
+
130
+ 利用期間の中では、アンロックした market-day を何度でも取得できます。
131
+ ファイルを削除しても、ダウンロードに失敗しても、取り直しに残高は消費しません。
132
+ 回数の上限はありません。
133
+ ダウンロードのたびに新しい URL を発行し、その URL は 1 時間で失効します。
134
+ `komachi download` は未アンロックの日付をその場でアンロックしてから取得するため、
135
+ アンロックのための操作は必要ありません。
136
+
137
+ 利用期間を過ぎると、新しい market-day のアンロックも、ダウンロード用 URL の発行も停止します。
138
+ 残高が残っていても使えません。
139
+ `komachi download` は取得を始める前に、その旨を表示して終了します。
140
+ tsurugaoka にはサインインでき、利用状況と終了日を確認できます。
141
+ 消費済みの market-day は消費済みのまま残り、返還はありません。
142
+ 期間内に必要なファイルを保存してください。
143
+
144
+ 実際には、ここに来た時点ですでに利用期間が始まっています。
145
+ `komachi token set` がトークンを確認するために行う通信も「使った」1 回に数えるためです。
146
+ そのため `komachi token status` には、期限の日付と残り日数が表示されます。
147
+
148
+ 日付も残り日数もサーバーが計算して返したものをそのまま表示しています。
149
+ 残り日数の計算には時計が必要ですが、その時計は手元のものではないからです。
150
+ このツールが独自に期限を判断することはありません。
151
+
152
+ ### 1.3 収録状況の確認
153
+
154
+ どのマーケットが使えるかを確認します。
155
+
156
+ ```bash
157
+ komachi markets
158
+ komachi catalog --market COINCHECK:BTC_SPOT --days 3
159
+ ```
160
+
161
+ ```text
162
+ date datasets rows size gap note
163
+ 2026-09-01 OrderBook,Trade 264,447 24.8MB 8m
164
+ 2026-09-02 OrderBook,Trade 274,792 26.7MB 1m
165
+ 2026-09-03 OrderBook,Trade 280,067 27.9MB 9m
166
+
167
+ 3 market-day(s). 'gap' is minutes with no record in the JST day.
168
+ ```
169
+
170
+ `gap` は、その日のうち記録のない分数です。取得前に品質を確認できます。
171
+
172
+ ### 1.4 取得
173
+
174
+ ```bash
175
+ komachi download --market COINCHECK:BTC_SPOT --start 2025-07-01 --days 28
176
+ ```
177
+
178
+ 実行前に、対象期間・ファイル数・容量・消費する market-day 数を表示して確認を求めます。
179
+ 中断した場合は同じコマンドを再実行すれば、取得済みのファイルは飛ばして続きから再開します。
180
+ すでに手元にあるファイルに対して残高を再消費することはありません。
181
+
182
+ ### 1.5 無償公開データの取り込み
183
+
184
+ 同じ期間の Binance と GMO コインの約定データを、無償公開元から取り込みます。
185
+ 残高は消費しません。
186
+
187
+ ```bash
188
+ komachi binance-import --symbol BTC_USDT --start 2025-07-01 --end 2025-07-28
189
+ komachi gmo-import --symbol BTC_JPY --start 2025-07-01 --end 2025-07-28
190
+ ```
191
+
192
+ 取り込み時に日本時間の日付へ再分割するため、配信データと同じ基準で比較できます。
193
+
194
+ ### 1.6 保存先の確認
195
+
196
+ ```bash
197
+ komachi local
198
+ ```
199
+
200
+ ```text
201
+ market dataset days range
202
+ COINCHECK:BTC_SPOT OrderBook 28 2025-07-01 .. 2025-07-28
203
+ COINCHECK:BTC_SPOT Trade 28 2025-07-01 .. 2025-07-28
204
+ BINANCE:BTC_USDT Trade 28 2025-07-01 .. 2025-07-28
205
+ GMO:BTC_JPY Trade 28 2025-07-01 .. 2025-07-28
206
+ ```
207
+
208
+ ### 1.7 中身の確認
209
+
210
+ ```bash
211
+ komachi trades --market COINCHECK:BTC_SPOT --date 2025-07-01 --rows 3
212
+ komachi book --market COINCHECK:BTC_SPOT --date 2025-07-01 --rows 3
213
+ ```
214
+
215
+ ```text
216
+ time (JST) side price size
217
+ 00:00:00.000 buy 15,456,978.0000 0.03000000
218
+ 00:00:01.000 buy 15,458,282.0000 0.03102218
219
+
220
+ time (JST) best bid best ask spread
221
+ 00:00:00.000 15,456,905.0000 15,456,978.0000 73.0000
222
+ 00:00:00.000 15,453,307.0000 15,458,283.0000 4,976.0000
223
+ ```
224
+
225
+ ### 1.8 分析へ
226
+
227
+ ```bash
228
+ komachi duckdb
229
+ duckdb ~/kql-data/kql.duckdb
230
+ ```
231
+
232
+ ```sql
233
+ SELECT date, count(*) AS trades, avg(price) AS vwap
234
+ FROM trade
235
+ WHERE exchange = 'COINCHECK' AND symbol = 'BTC_SPOT'
236
+ GROUP BY date ORDER BY date;
237
+ ```
238
+
239
+ 作図と派生データの作成は Komachi の範囲外です。
240
+ 分析ツールキットの Hase が担当します(公開準備中)。
241
+
242
+ ## 2 コマンド一覧
243
+
244
+ ### 2.1 リモート操作
245
+
246
+ Yukinoshita API または無償公開元との通信を伴うコマンドです。
247
+
248
+ | コマンド | 内容 | 残高の消費 |
249
+ |---|---|---|
250
+ | `komachi token set --token TOKEN` | トークンを検証して保存 | なし |
251
+ | `komachi token status` | 付与数、使用済み、残高、2 つの期限 | なし |
252
+ | `komachi markets` | 利用できるマーケットと、無償公開元の案内 | なし |
253
+ | `komachi calendar --market MARKET` | 公開済みの日付と、取得済みの日付 | なし |
254
+ | `komachi catalog --market MARKET` | 日ごとの収録状況と品質 | なし |
255
+ | `komachi download --market MARKET --start DATE [--days N]` | 範囲を指定して取得(中断後は再開) | **あり** |
256
+ | `komachi binance-import --symbol SYMBOL --start DATE --end DATE` | Binance Vision から取り込み | なし |
257
+ | `komachi gmo-import --symbol SYMBOL --start DATE --end DATE` | GMO コインの公開データから取り込み | なし |
258
+
259
+ 残高を消費するのは `download` のみです。
260
+ 取得前に、対象期間・ファイル数・容量・消費数を表示して確認を求めます。
261
+ market-day は 1 マーケットの 1 日分で、同じ日の板と約定を合わせて 1 と数えます。
262
+
263
+ ### 2.2 ローカル操作
264
+
265
+ 手元のファイルだけを参照します。通信も残高の消費もありません。
266
+
267
+ | コマンド | 内容 |
268
+ |---|---|
269
+ | `komachi local` | 保存済みファイルの一覧 |
270
+ | `komachi trades --market MARKET --date DATE` | 約定データの表示 |
271
+ | `komachi book --market MARKET --date DATE` | 最良気配とスプレッドの表示 |
272
+ | `komachi stats --path PATH` | 行数と時間範囲 |
273
+ | `komachi decode --path PATH` | スキーマと先頭数行 |
274
+ | `komachi duckdb` | DuckDB のビューを作成・更新 |
275
+ | `komachi sql` | ビュー定義の SQL を出力 |
276
+
277
+ ## 3 保存先の構成
278
+
279
+ データは、収集時と同じ Hive 形式のディレクトリに保存されます。
280
+
281
+ ```text
282
+ $KQL_ROOT_PATH/bronze/dataset=Trade/exchange=GMO/symbol=BTC_JPY/date=2026-01-15/data.parquet
283
+ ```
284
+
285
+ DuckDB、PyArrow、Spark、Athena のいずれも `dataset`・`exchange`・`symbol`・`date` を
286
+ パスから列として認識します。1 年分でも次の 1 行で読み込めます。
287
+
288
+ ```sql
289
+ SELECT * FROM read_parquet('~/kql-data/bronze/dataset=Trade/**/*.parquet', hive_partitioning = 1);
290
+ ```
291
+
292
+ ## 4 日付の扱い
293
+
294
+ `date=` は**日本時間の 1 日**です。`date=2026-01-15` は 2026-01-15 00:00〜23:59 JST、
295
+ UTC では 2026-01-14 15:00〜2026-01-15 14:59 にあたります。
296
+ ファイル内のタイムスタンプは UTC エポック秒のため、実行環境のタイムゾーンに依存しません。
297
+
298
+ 取り込み元の日付区切りは取引所ごとに異なります。
299
+ Binance Vision は 00:00 UTC、GMO コインは取引日の切り替えである 21:00 UTC を基準としています。
300
+ Komachi は取り込み時に日本時間の日付へ再分割するため、
301
+ 配信データと無償公開データを同じ基準で比較できます。
302
+
303
+ このため、ある 1 日を取り込むには前日分の元ファイルも必要です。
304
+ どちらか一方しか取得できない日は、不完全なまま書き出さずに保留します。
305
+
306
+ ## 5 Komachi が行わないこと
307
+
308
+ 1. 取引所 API への直接接続。接続先は Yukinoshita API、Binance Vision、GMO コインの公開データのみです。
309
+ 2. データの加工・導出。silver 以降は [Hase](https://github.com/kamakuraquantlab) が担当します。
310
+ 3. Kamakura Quant Lab の API 以外に対する資格情報の保持。
311
+
312
+ ## 6 ライセンス
313
+
314
+ Apache License 2.0。[LICENSE.md](LICENSE.md)