firstrate-data 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.
- firstrate_data-0.1.0/LICENSE +201 -0
- firstrate_data-0.1.0/PKG-INFO +449 -0
- firstrate_data-0.1.0/README.md +434 -0
- firstrate_data-0.1.0/pyproject.toml +39 -0
- firstrate_data-0.1.0/setup.cfg +4 -0
- firstrate_data-0.1.0/src/firstrate_data/__init__.py +38 -0
- firstrate_data-0.1.0/src/firstrate_data/config.py +49 -0
- firstrate_data-0.1.0/src/firstrate_data/domain/__init__.py +33 -0
- firstrate_data-0.1.0/src/firstrate_data/domain/bar_type.py +34 -0
- firstrate_data-0.1.0/src/firstrate_data/domain/enums.py +120 -0
- firstrate_data-0.1.0/src/firstrate_data/domain/ticker_listing.py +78 -0
- firstrate_data-0.1.0/src/firstrate_data/download/__init__.py +0 -0
- firstrate_data-0.1.0/src/firstrate_data/download/bundles.py +201 -0
- firstrate_data-0.1.0/src/firstrate_data/download/client.py +432 -0
- firstrate_data-0.1.0/src/firstrate_data/download/progress.py +45 -0
- firstrate_data-0.1.0/src/firstrate_data/download/requests.py +245 -0
- firstrate_data-0.1.0/src/firstrate_data/store/__init__.py +0 -0
- firstrate_data-0.1.0/src/firstrate_data/store/_parquet_table.py +78 -0
- firstrate_data-0.1.0/src/firstrate_data/store/_sql.py +399 -0
- firstrate_data-0.1.0/src/firstrate_data/store/store.py +630 -0
- firstrate_data-0.1.0/src/firstrate_data.egg-info/PKG-INFO +449 -0
- firstrate_data-0.1.0/src/firstrate_data.egg-info/SOURCES.txt +29 -0
- firstrate_data-0.1.0/src/firstrate_data.egg-info/dependency_links.txt +1 -0
- firstrate_data-0.1.0/src/firstrate_data.egg-info/requires.txt +6 -0
- firstrate_data-0.1.0/src/firstrate_data.egg-info/top_level.txt +1 -0
- firstrate_data-0.1.0/tests/test_bundle_requests.py +68 -0
- firstrate_data-0.1.0/tests/test_download_bundle_overlap.py +61 -0
- firstrate_data-0.1.0/tests/test_ingest_rule.py +104 -0
- firstrate_data-0.1.0/tests/test_read.py +82 -0
- firstrate_data-0.1.0/tests/test_refile.py +65 -0
- firstrate_data-0.1.0/tests/test_skip_filed.py +150 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: firstrate-data
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Download FirstRate Data market data into a partitioned DuckDB-backed Parquet store.
|
|
5
|
+
Requires-Python: >=3.13
|
|
6
|
+
Description-Content-Type: text/markdown
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Dist: duckdb>=1.5.4
|
|
9
|
+
Requires-Dist: python-dotenv>=1.2.2
|
|
10
|
+
Requires-Dist: pytz>=2026.2
|
|
11
|
+
Requires-Dist: requests>=2.34.2
|
|
12
|
+
Requires-Dist: tqdm>=4.67.1
|
|
13
|
+
Requires-Dist: urllib3>=2.0
|
|
14
|
+
Dynamic: license-file
|
|
15
|
+
|
|
16
|
+
# firstrate_data
|
|
17
|
+
|
|
18
|
+
Downloads [FirstRate Data](https://firstratedata.com) archives into a local
|
|
19
|
+
parquet store and queries them with DuckDB.
|
|
20
|
+
|
|
21
|
+
An active FirstRate Data subscription is required. The client fetches only the
|
|
22
|
+
data your own credentials entitle you to, and every download is subject to
|
|
23
|
+
FirstRate Data's terms of service and licence. Redistributing the downloaded
|
|
24
|
+
data is your responsibility, not this project's.
|
|
25
|
+
|
|
26
|
+
## Disclaimer
|
|
27
|
+
|
|
28
|
+
This is an unofficial, independent project. It is not affiliated with,
|
|
29
|
+
endorsed by, sponsored by, or supported by FirstRate Data. "FirstRate Data" and
|
|
30
|
+
any related marks belong to their owner and are used here to name the service
|
|
31
|
+
the client talks to.
|
|
32
|
+
|
|
33
|
+
The vendor's API can change without notice and break this client. The software
|
|
34
|
+
is provided as is, without warranty of any kind, and the authors accept no
|
|
35
|
+
liability for lost data, missed trades, or any other loss arising from its use.
|
|
36
|
+
|
|
37
|
+
## Setup
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
uv sync
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
`.env`:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
FIRSTRATE_DATA_PATH=/path/to/data # the store goes in FIRSTRATE_DATA_PATH/firstrate_data
|
|
47
|
+
FIRSTRATE_USERID=your-userid
|
|
48
|
+
FIRSTRATE_BASE_URL=... # optional; defaults to https://firstratedata.com/api
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
A missing setting raises `firstrate_data.config.MissingSettingError`, which is a
|
|
52
|
+
`KeyError`.
|
|
53
|
+
|
|
54
|
+
## Download
|
|
55
|
+
|
|
56
|
+
One `Client`. `from_env()` reads the credentials and builds the `Store` the
|
|
57
|
+
client files into. Every `download_*()` call returns an `Ingested`.
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
from firstrate_data import Client, EquitiesAdjustment, Period, Timeframe
|
|
61
|
+
|
|
62
|
+
client = Client.from_env()
|
|
63
|
+
|
|
64
|
+
# last trading day, 1-minute bars
|
|
65
|
+
client.download_stocks_bars(
|
|
66
|
+
Period.DAY, Timeframe.MIN_1, EquitiesAdjustment.UNADJUSTED
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
# full archive -- takes a ticker_range letter (A-Z)
|
|
70
|
+
client.download_stocks_bars(
|
|
71
|
+
Period.FULL,
|
|
72
|
+
Timeframe.DAY_1,
|
|
73
|
+
EquitiesAdjustment.SPLIT_AND_DIVIDEND,
|
|
74
|
+
ticker_range="C",
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
client.download_etf_bars(Period.WEEK, Timeframe.DAY_1, EquitiesAdjustment.SPLIT)
|
|
78
|
+
client.download_splits()
|
|
79
|
+
client.download_dividends()
|
|
80
|
+
client.close()
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Only stocks have a delisted endpoint. The pre-2026 history is five archives you
|
|
84
|
+
fetch one at a time. 2026 onward is an update:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from firstrate_data import DelistedArchive, DelistedUpdate
|
|
88
|
+
|
|
89
|
+
client.download_delisted_bars(
|
|
90
|
+
DelistedArchive.ARCHIVE_1, Timeframe.MIN_1, EquitiesAdjustment.SPLIT
|
|
91
|
+
)
|
|
92
|
+
client.download_delisted_bars(
|
|
93
|
+
DelistedUpdate.YEAR, Timeframe.MIN_1, EquitiesAdjustment.SPLIT
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Futures come as a continuous series and as the individual contracts behind it:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from firstrate_data import ContinuousFuturesAdjustment, ContractFiles
|
|
101
|
+
|
|
102
|
+
client.download_futures_continuous_bars(
|
|
103
|
+
Period.FULL, Timeframe.MIN_1, ContinuousFuturesAdjustment.RATIO
|
|
104
|
+
)
|
|
105
|
+
client.download_contract_dates() # which contracts were stitched, and when
|
|
106
|
+
|
|
107
|
+
client.download_futures_contract_bars(
|
|
108
|
+
ContractFiles.ARCHIVE, Timeframe.MIN_1
|
|
109
|
+
) # stopped before 2026
|
|
110
|
+
client.download_futures_contract_bars(
|
|
111
|
+
ContractFiles.UPDATE, Timeframe.DAY_1
|
|
112
|
+
) # trading since 2026
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
The contract endpoint takes no `period` and no `adjustment`. Indices take a
|
|
116
|
+
`period` and a `timeframe`, and no adjustment or `ticker_range`:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
client.download_index_bars(Period.FULL, Timeframe.DAY_1)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
Two endpoints serve text rather than an archive, and take the asset type:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
from firstrate_data import AssetType
|
|
126
|
+
|
|
127
|
+
client.last_update(AssetType.STOCK) # date, or datetime when the vendor states a time
|
|
128
|
+
client.download_ticker_listing(AssetType.STOCK)
|
|
129
|
+
# [TickerListing(ticker, full_name, start_date, end_date, is_delisted)]
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
The vendor marks a delisted listing row by suffixing its ticker,
|
|
133
|
+
`ACTU-DELISTED`, and marks a live one not at all. `TickerListing.ticker` is the
|
|
134
|
+
bare symbol and `is_delisted` carries the suffix, so a symbol that outlived the
|
|
135
|
+
company behind it comes back as two rows keyed on the same ticker. Only stocks
|
|
136
|
+
have a delisted endpoint.
|
|
137
|
+
|
|
138
|
+
`download_ticker_listing()` writes the rows to the store as well as returning
|
|
139
|
+
them, which is what `store.ticker_listing()` reads. The rows are stored as
|
|
140
|
+
served: the vendor lists 169 stock symbols twice and leaves the name empty on
|
|
141
|
+
14% of the rows, so the name is a label and not a key, and collapsing the rows
|
|
142
|
+
would be the library guessing on your behalf.
|
|
143
|
+
|
|
144
|
+
## The store
|
|
145
|
+
|
|
146
|
+
Every `download_*()` call:
|
|
147
|
+
|
|
148
|
+
1. fetches its archive to a spool file
|
|
149
|
+
2. unzips it into a temporary directory
|
|
150
|
+
3. copies the bars into parquet
|
|
151
|
+
4. deletes the unzipped files
|
|
152
|
+
|
|
153
|
+
The call returns an `Ingested`:
|
|
154
|
+
|
|
155
|
+
```python
|
|
156
|
+
ingested = client.download_stocks_bars(
|
|
157
|
+
Period.WEEK, Timeframe.DAY_1, EquitiesAdjustment.UNADJUSTED
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
ingested.tickers # int, tickers the archive named; None for a metafile, which has no ticker
|
|
161
|
+
ingested.rows # int, rows written
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
A `Store` holds one DuckDB connection from `Store.from_env()` until
|
|
165
|
+
`store.close()`. A `with` block closes it at the end of the block. The read
|
|
166
|
+
methods return lazy relations, so read them while the store is open. A client
|
|
167
|
+
never closes the store handed to it; `client.close()` closes the HTTP session.
|
|
168
|
+
|
|
169
|
+
> [!WARNING]
|
|
170
|
+
> Parquet is the only copy. Nothing keeps the vendor's CSV and there is no
|
|
171
|
+
> offline rebuild. Download a slice again to repair it.
|
|
172
|
+
|
|
173
|
+
### How the store partitions the bars
|
|
174
|
+
|
|
175
|
+
Bars land in a uniform seven-column schema: `ts, open, high, low, close,
|
|
176
|
+
volume, open_interest`, the last NULL where the source omits it. Every read
|
|
177
|
+
selector is also a directory level. The metafiles are tables at the store root,
|
|
178
|
+
the ticker listing one table per asset type under that asset type's level:
|
|
179
|
+
|
|
180
|
+
```
|
|
181
|
+
FIRSTRATE_DATA_PATH/firstrate_data/bars/asset_type=stock/adjustment={…}/timeframe={…}/ticker={…}/{date}_{ingest}_{uuid}.parquet
|
|
182
|
+
FIRSTRATE_DATA_PATH/firstrate_data/bars/asset_type=futures/adjustment={…}/timeframe={…}/ticker={…}/{date}_{ingest}_{uuid}.parquet
|
|
183
|
+
FIRSTRATE_DATA_PATH/firstrate_data/catalog.parquet
|
|
184
|
+
FIRSTRATE_DATA_PATH/firstrate_data/bars/asset_type={…}/ticker_listing.parquet
|
|
185
|
+
FIRSTRATE_DATA_PATH/firstrate_data/splits.parquet
|
|
186
|
+
FIRSTRATE_DATA_PATH/firstrate_data/dividends.parquet
|
|
187
|
+
FIRSTRATE_DATA_PATH/firstrate_data/contin_audit.parquet
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
A path names every level, including the ones no endpoint asks about: the store
|
|
191
|
+
files an index bar under `adjustment=UNADJUSTED`. A futures continuous series
|
|
192
|
+
and the individual contracts it was stitched from are told apart by their
|
|
193
|
+
adjustment, `contin_adj_ratio` against `UNADJUSTED`. The levels are the fields
|
|
194
|
+
of `BarType` in `firstrate_data.domain`, and a read answers with all four as
|
|
195
|
+
columns whatever it spans.
|
|
196
|
+
|
|
197
|
+
Each bar's own identity picks its directory, not the request that fetched it,
|
|
198
|
+
so two fetches of one ticker land in the same directory. A stock is filed under
|
|
199
|
+
its bare symbol whichever bundle carried it, listed or delisted, so a symbol
|
|
200
|
+
that two companies held over disjoint years reads back as one continuous
|
|
201
|
+
series. Which company held it over which days is `store.ticker_listing()`'s to
|
|
202
|
+
say.
|
|
203
|
+
|
|
204
|
+
The store writes only inside its own `firstrate_data/` subdirectory, so
|
|
205
|
+
the directory `FIRSTRATE_DATA_PATH` names can hold other tenants. `spool/`,
|
|
206
|
+
`.duckdb_temp/` and one `.ingest-*` per archive the store reads sit in there
|
|
207
|
+
too, since an archive needs as much free space as the bars it becomes.
|
|
208
|
+
|
|
209
|
+
### One ticker, one copy
|
|
210
|
+
|
|
211
|
+
A ticker is filed once. Every ingest weighs the span it carries for a ticker
|
|
212
|
+
against the span the catalog already holds:
|
|
213
|
+
|
|
214
|
+
- same first bar, last bar no earlier than the held one — an update, or the
|
|
215
|
+
same archive re-fetched. It replaces the ticker's files, which is what makes
|
|
216
|
+
a re-run of an interrupted bundle resume rather than refuse
|
|
217
|
+
- anything else — a different start under one name, or an archive ending before
|
|
218
|
+
what is filed — is a conflict. The ingest's own files are removed and it
|
|
219
|
+
raises `ConflictingBarsError`, a `ValueError`, having filed nothing
|
|
220
|
+
|
|
221
|
+
The last rule is what a shorter period runs into: a `WEEK` fetched on Wednesday
|
|
222
|
+
starts on Monday, not where the ticker's held history starts, so it is refused
|
|
223
|
+
rather than spliced. Re-fetch with `period=FULL`.
|
|
224
|
+
|
|
225
|
+
It is also what a stock symbol two companies held over *overlapping* years runs
|
|
226
|
+
into — 187 of them, where the vendor's listed and delisted bundles both carry
|
|
227
|
+
bars for the same minutes. The store cannot tell one company's re-served
|
|
228
|
+
history from another's, so it files neither.
|
|
229
|
+
`store.ticker_listing(ticker=...)` names the companies and the days each held
|
|
230
|
+
the symbol, which is what deciding between them takes.
|
|
231
|
+
|
|
232
|
+
### The catalog
|
|
233
|
+
|
|
234
|
+
`catalog.parquet` holds one row per ticker per bar type — the bar type's four
|
|
235
|
+
levels, the first and last bar filed, and how many. Every ingest keeps it in
|
|
236
|
+
step, and it is what makes the conflict check above cost a read of one small
|
|
237
|
+
file rather than a walk of the tree.
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
store.catalog() # the whole thing, as a relation
|
|
241
|
+
store.last_bar(BarType(AssetType.STOCK, timeframe=Timeframe.MIN_1))
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### Restated series take `period=FULL` only
|
|
245
|
+
|
|
246
|
+
The vendor rewrites the history of `adj_split`, `adj_splitdiv`,
|
|
247
|
+
`contin_adj_ratio` and `contin_adj_absolute` backwards when a corporate action
|
|
248
|
+
or a roll lands, so two fetches taken either side of one sit on different bases.
|
|
249
|
+
Asking for one of those four with any other period raises `NotOfferedError`, a
|
|
250
|
+
`ValueError`, before the request goes out. `UNADJUSTED` and `contin_UNadj` are
|
|
251
|
+
never restated.
|
|
252
|
+
|
|
253
|
+
### Damaged bars
|
|
254
|
+
|
|
255
|
+
A few vendor payloads have spliced bytes: a bar cut off mid-stamp with a bar
|
|
256
|
+
from days later running into it. Such a line aborts the scan and the ingest
|
|
257
|
+
raises, having filed nothing.
|
|
258
|
+
|
|
259
|
+
### Timestamps
|
|
260
|
+
|
|
261
|
+
`ts` is a `TIMESTAMPTZ` instant. The vendor delivers a naive stamp in Eastern
|
|
262
|
+
time, and UTC for crypto. Ingest localizes it once, on the way in, so the
|
|
263
|
+
repeated hour of the DST fall-back resolves to the standard-time offset.
|
|
264
|
+
|
|
265
|
+
The store pins the session timezone to `America/New_York`, because DuckDB reads
|
|
266
|
+
a naive literal in the session timezone and that otherwise comes from the
|
|
267
|
+
machine's locale. Pinned, `ts >= '2024-01-02 09:30:00'` selects the same bars in
|
|
268
|
+
Rome and in New York.
|
|
269
|
+
|
|
270
|
+
## Queries
|
|
271
|
+
|
|
272
|
+
One read method for every bar in the tree. Every omitted keyword spans all its
|
|
273
|
+
values, and the result is a lazy `duckdb.DuckDBPyRelation` you filter,
|
|
274
|
+
aggregate, join, or hand to pandas or Arrow.
|
|
275
|
+
|
|
276
|
+
```python
|
|
277
|
+
from firstrate_data import (
|
|
278
|
+
AssetType,
|
|
279
|
+
ContinuousFuturesAdjustment,
|
|
280
|
+
EquitiesAdjustment,
|
|
281
|
+
Store,
|
|
282
|
+
Timeframe,
|
|
283
|
+
TradingHours,
|
|
284
|
+
Unadjusted,
|
|
285
|
+
)
|
|
286
|
+
|
|
287
|
+
store = Store.from_env() # reads FIRSTRATE_DATA_PATH
|
|
288
|
+
|
|
289
|
+
aapl = store.bars(
|
|
290
|
+
asset_type=AssetType.STOCK,
|
|
291
|
+
timeframe=Timeframe.DAY_1,
|
|
292
|
+
adjustment=EquitiesAdjustment.SPLIT,
|
|
293
|
+
ticker="AAPL",
|
|
294
|
+
)
|
|
295
|
+
aapl.aggregate("min(ts), max(ts), count(*)").show()
|
|
296
|
+
frame = aapl.df() # pandas DataFrame, materialized only now (needs pandas installed)
|
|
297
|
+
|
|
298
|
+
store.bars(
|
|
299
|
+
asset_type=AssetType.FUTURES,
|
|
300
|
+
timeframe=Timeframe.DAY_1,
|
|
301
|
+
adjustment=ContinuousFuturesAdjustment.RATIO,
|
|
302
|
+
ticker="ES",
|
|
303
|
+
)
|
|
304
|
+
# the individual contracts, told apart from the continuous series by adjustment
|
|
305
|
+
store.bars(
|
|
306
|
+
asset_type=AssetType.FUTURES,
|
|
307
|
+
timeframe=Timeframe.DAY_1,
|
|
308
|
+
adjustment=Unadjusted.UNADJUSTED,
|
|
309
|
+
ticker=["ESH24", "ESM24"],
|
|
310
|
+
)
|
|
311
|
+
|
|
312
|
+
# across the whole tree; every level is also a column
|
|
313
|
+
store.bars(timeframe=Timeframe.DAY_1).aggregate(
|
|
314
|
+
"asset_type, adjustment, count(*)"
|
|
315
|
+
).show()
|
|
316
|
+
|
|
317
|
+
store.splits() # ticker, date, ratio
|
|
318
|
+
store.dividends() # ticker, date, amount
|
|
319
|
+
store.contract_dates()
|
|
320
|
+
|
|
321
|
+
store.ticker_listing(ticker="ABX") # who held the symbol, and over which days
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
`start`, `end` and `hours` narrow a read past the tree (`from datetime import date`). Both dates name a whole
|
|
325
|
+
day and both are kept; `hours=TradingHours.REGULAR` keeps 09:30–16:00 Eastern
|
|
326
|
+
and raises `ValueError` for an asset type that defines no session — crypto, FX,
|
|
327
|
+
futures, or a read that named no asset type at all:
|
|
328
|
+
|
|
329
|
+
```python
|
|
330
|
+
store.bars(
|
|
331
|
+
asset_type=AssetType.STOCK,
|
|
332
|
+
timeframe=Timeframe.MIN_1,
|
|
333
|
+
adjustment=EquitiesAdjustment.SPLIT,
|
|
334
|
+
ticker="AAPL",
|
|
335
|
+
start=date(2026, 1, 2),
|
|
336
|
+
end=date(2026, 3, 31),
|
|
337
|
+
hours=TradingHours.REGULAR,
|
|
338
|
+
)
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
The vendor serves splits and dividends as an archive of one headerless file per
|
|
342
|
+
ticker, and each file holds the ticker in its name alone. The store declares the
|
|
343
|
+
columns and takes the ticker from the file name. No fetch of
|
|
344
|
+
`contract_dates()` has run here, so its shape is whatever the DuckDB sniffer
|
|
345
|
+
reads (issue #15).
|
|
346
|
+
|
|
347
|
+
A bars selector that matches nothing returns an empty relation of the right
|
|
348
|
+
shape. A metafile or ticker listing that was never fetched raises
|
|
349
|
+
`FileNotFoundError`, having no fixed shape to return an empty relation of.
|
|
350
|
+
|
|
351
|
+
The selectors build the glob, which is what makes a fine slice fast: about 970x
|
|
352
|
+
over a wide glob with a `WHERE`, measured at 3000 partitions. Prefer a selector
|
|
353
|
+
over `.filter(...)` for anything that's a level of the tree. `start`, `end` and
|
|
354
|
+
`hours` are `WHERE` clauses, because neither the calendar nor the clock is a
|
|
355
|
+
level.
|
|
356
|
+
|
|
357
|
+
macOS writes an AppleDouble `._*` sidecar beside every parquet file on exFAT and
|
|
358
|
+
NTFS volumes, and `._2026-07-17_3f2a.parquet` matches a bare `*.parquet`. The
|
|
359
|
+
store names every file for the date that produced it, so the read glob leads
|
|
360
|
+
with a digit class, `[0-9]*.parquet`, which no dotfile matches.
|
|
361
|
+
|
|
362
|
+
## Progress
|
|
363
|
+
|
|
364
|
+
`firstrate_data.download.progress` draws one tqdm bar per fetch and disables
|
|
365
|
+
itself when stderr isn't a terminal. Nothing to configure, and nothing to pass.
|
|
366
|
+
|
|
367
|
+
## Bundles
|
|
368
|
+
|
|
369
|
+
A bundle is one asset type's universe, described as a config and swept in one
|
|
370
|
+
call. FirstRate sells its data in the same shape, so one config downloads the
|
|
371
|
+
bundle you bought. The config classes are plain frozen dataclasses in
|
|
372
|
+
`firstrate_data.download.bundles`, and need no credentials and no store to
|
|
373
|
+
build:
|
|
374
|
+
|
|
375
|
+
- `BundleConfig` — asset type and timeframes. Enough for indices, FX and crypto
|
|
376
|
+
- `EquitiesBundleConfig` — adds the adjustment, the ticker ranges, and the
|
|
377
|
+
splits and dividends metafiles. Use it for ETFs
|
|
378
|
+
- `StocksBundleConfig` — adds the pre-2026 delisted archives
|
|
379
|
+
- `FuturesBundleConfig` — adds the roll adjustment, the individual contracts,
|
|
380
|
+
and the contract-dates audit file
|
|
381
|
+
|
|
382
|
+
`None` timeframes means every timeframe, `None` ticker range means `A`–`Z`.
|
|
383
|
+
`include_delisted_archives` and `include_individual_contracts` take `True` for
|
|
384
|
+
all of them, `False` for none, or an iterable to select.
|
|
385
|
+
|
|
386
|
+
```python
|
|
387
|
+
from firstrate_data import AssetType, Client, EquitiesAdjustment, Timeframe
|
|
388
|
+
from firstrate_data.download.bundles import StocksBundleConfig
|
|
389
|
+
|
|
390
|
+
BUNDLE = StocksBundleConfig(
|
|
391
|
+
asset_type=AssetType.STOCK,
|
|
392
|
+
timeframes=[Timeframe.DAY_1, Timeframe.MIN_1],
|
|
393
|
+
adjustment=EquitiesAdjustment.UNADJUSTED,
|
|
394
|
+
ticker_range=None,
|
|
395
|
+
include_splits=True,
|
|
396
|
+
include_dividends=True,
|
|
397
|
+
include_company_profiles=False,
|
|
398
|
+
include_delisted_archives=True,
|
|
399
|
+
)
|
|
400
|
+
|
|
401
|
+
client = Client.from_env()
|
|
402
|
+
try:
|
|
403
|
+
for ingested in client.download_bundle(BUNDLE):
|
|
404
|
+
print(ingested)
|
|
405
|
+
finally:
|
|
406
|
+
client.close()
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
`download_bundle()` fetches the next archives on a small thread pool while the
|
|
410
|
+
current one is written, since a fetch waits on the vendor and a write on
|
|
411
|
+
DuckDB. Writes stay on the calling thread: the store holds one connection, and
|
|
412
|
+
an unbounded prefetch would spool the whole bundle to disk at once. `prefetch`
|
|
413
|
+
(default 2) is how many archives may be in flight.
|
|
414
|
+
|
|
415
|
+
A full-history archive whose last filed bar already reaches the vendor's
|
|
416
|
+
`last_update` is not fetched again, and is absent from what the call returns.
|
|
417
|
+
`refresh=True` fetches every archive the bundle names regardless. Delisted
|
|
418
|
+
archives, contract halves and metafiles are always fetched: their tickers stop
|
|
419
|
+
trading, or they leave no catalog row to judge from.
|
|
420
|
+
|
|
421
|
+
Combinations the vendor doesn't serve are dropped from the plan rather than
|
|
422
|
+
raised — `UNADJUSTED` outside 1min and 1day, the restated adjustments outside
|
|
423
|
+
`period=FULL`. Anything else that goes wrong propagates: a bad response or an
|
|
424
|
+
archive that won't file stops the sweep, and re-running resumes.
|
|
425
|
+
|
|
426
|
+
`bundle_requests(config)` yields the same plan as `Request` objects without
|
|
427
|
+
fetching anything, which is the dry run.
|
|
428
|
+
|
|
429
|
+
## Parameters
|
|
430
|
+
|
|
431
|
+
| Enum | Values |
|
|
432
|
+
| --- | --- |
|
|
433
|
+
| `Period` | `FULL`, `MONTH`, `WEEK`, `DAY` |
|
|
434
|
+
| `Timeframe` | `MIN_1`, `MIN_5`, `MIN_30`, `HOUR_1`, `DAY_1` |
|
|
435
|
+
| `EquitiesAdjustment` | `SPLIT`, `SPLIT_AND_DIVIDEND`, `UNADJUSTED` |
|
|
436
|
+
| `ContinuousFuturesAdjustment` | `RATIO`, `ABSOLUTE`, `UNADJUSTED` |
|
|
437
|
+
| `Unadjusted` | `UNADJUSTED`, for indices and futures contracts. The endpoint sends none |
|
|
438
|
+
| `AssetType` | `STOCK`, `ETF`, `INDEX`, `FUTURES`, `CRYPTO`, `FX`, `OPTIONS` |
|
|
439
|
+
| `TradingHours` | `ALL`, `REGULAR` |
|
|
440
|
+
| `DelistedArchive` | `ARCHIVE_1` .. `ARCHIVE_5` (pre-2026) |
|
|
441
|
+
| `DelistedUpdate` | `YEAR` (2026+), `WEEK` (last week only) |
|
|
442
|
+
| `ContractFiles` | `ARCHIVE` (pre-2026, frozen), `UPDATE` (2026+, daily) |
|
|
443
|
+
| `OtherData` | `SPLITS`, `DIVIDENDS`, `COMPANY_PROFILES`, `CONTRACT_DATES` |
|
|
444
|
+
|
|
445
|
+
The API differs across asset types, and one `download_*` method serves each.
|
|
446
|
+
Splits, dividends and `ticker_range` exist for stocks and ETFs only, and
|
|
447
|
+
`ticker_range` only with `period=FULL`. Each request is an object that carries
|
|
448
|
+
its own endpoint and refuses a combination the vendor doesn't serve. It tells
|
|
449
|
+
the store where the bars belong and whether they replace what's there.
|