perp-md 0.1.4__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.
Files changed (35) hide show
  1. perp_md-0.1.4/CONTRIBUTING.md +13 -0
  2. perp_md-0.1.4/LICENSE +201 -0
  3. perp_md-0.1.4/MANIFEST.in +6 -0
  4. perp_md-0.1.4/PKG-INFO +66 -0
  5. perp_md-0.1.4/README.md +37 -0
  6. perp_md-0.1.4/SECURITY.md +9 -0
  7. perp_md-0.1.4/docs/ARCHITECTURE.md +67 -0
  8. perp_md-0.1.4/docs/CONTRACT.md +77 -0
  9. perp_md-0.1.4/docs/VERSIONING.md +11 -0
  10. perp_md-0.1.4/pyproject.toml +48 -0
  11. perp_md-0.1.4/setup.cfg +4 -0
  12. perp_md-0.1.4/src/perp_md/__init__.py +50 -0
  13. perp_md-0.1.4/src/perp_md/adapters/__init__.py +3 -0
  14. perp_md-0.1.4/src/perp_md/adapters/base.py +23 -0
  15. perp_md-0.1.4/src/perp_md/adapters/ccxt.py +236 -0
  16. perp_md-0.1.4/src/perp_md/adapters/native.py +528 -0
  17. perp_md-0.1.4/src/perp_md/client.py +79 -0
  18. perp_md-0.1.4/src/perp_md/errors.py +29 -0
  19. perp_md-0.1.4/src/perp_md/history.py +23 -0
  20. perp_md-0.1.4/src/perp_md/models.py +124 -0
  21. perp_md-0.1.4/src/perp_md/normalization.py +47 -0
  22. perp_md-0.1.4/src/perp_md/py.typed +1 -0
  23. perp_md-0.1.4/src/perp_md/transport.py +106 -0
  24. perp_md-0.1.4/src/perp_md.egg-info/PKG-INFO +66 -0
  25. perp_md-0.1.4/src/perp_md.egg-info/SOURCES.txt +33 -0
  26. perp_md-0.1.4/src/perp_md.egg-info/dependency_links.txt +1 -0
  27. perp_md-0.1.4/src/perp_md.egg-info/requires.txt +10 -0
  28. perp_md-0.1.4/src/perp_md.egg-info/top_level.txt +1 -0
  29. perp_md-0.1.4/tests/fixtures/mexc_ticker_malformed.json +13 -0
  30. perp_md-0.1.4/tests/fixtures/mexc_ticker_rejected.json +5 -0
  31. perp_md-0.1.4/tests/fixtures/mexc_ticker_success.json +68 -0
  32. perp_md-0.1.4/tests/fixtures/native_open_interest.json +64 -0
  33. perp_md-0.1.4/tests/test_adapters.py +331 -0
  34. perp_md-0.1.4/tests/test_models.py +54 -0
  35. perp_md-0.1.4/tests/test_transport.py +40 -0
@@ -0,0 +1,13 @@
1
+ # Contributing
2
+
3
+ Changes must preserve the public contract and application-neutral boundary.
4
+ Run the offline suite and artifact checks before proposing a release:
5
+
6
+ ```sh
7
+ python -m pytest -q
8
+ python -m build
9
+ python -m twine check dist/*
10
+ ```
11
+
12
+ Do not add credentials, private endpoints, consumer schemas, concrete market
13
+ identities, or network-dependent tests.
perp_md-0.1.4/LICENSE ADDED
@@ -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,6 @@
1
+ include CONTRIBUTING.md
2
+ include LICENSE
3
+ include README.md
4
+ include SECURITY.md
5
+ recursive-include docs *.md
6
+ recursive-include tests *.py *.json
perp_md-0.1.4/PKG-INFO ADDED
@@ -0,0 +1,66 @@
1
+ Metadata-Version: 2.4
2
+ Name: perp-md
3
+ Version: 0.1.4
4
+ Summary: Typed, asynchronous open-interest market data adapters
5
+ Author: perp-md contributors
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/latheiere/perp-md
8
+ Project-URL: Repository, https://github.com/latheiere/perp-md
9
+ Project-URL: Issues, https://github.com/latheiere/perp-md/issues
10
+ Keywords: market-data,open-interest,perpetuals,asyncio
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Typing :: Typed
17
+ Requires-Python: >=3.11
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: httpx<1,>=0.27
21
+ Provides-Extra: ccxt
22
+ Requires-Dist: ccxt<5,>=4.5; extra == "ccxt"
23
+ Provides-Extra: dev
24
+ Requires-Dist: build<2,>=1; extra == "dev"
25
+ Requires-Dist: ccxt<5,>=4.5; extra == "dev"
26
+ Requires-Dist: pytest<10,>=8; extra == "dev"
27
+ Requires-Dist: twine<7,>=6; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # perp-md
31
+
32
+ `perp-md` is a typed asynchronous Python library for current and historical
33
+ perpetual-market open interest. It presents one stable contract while keeping
34
+ venue protocols, pagination, validation, and optional CCXT integration behind
35
+ adapter boundaries.
36
+
37
+ The package contains no persistence, scheduling, catalog discovery,
38
+ aggregation, chart policy, or application APIs. Market identity, storage, and
39
+ observation use remain outside the library.
40
+
41
+ ## Status
42
+
43
+ The public API is alpha, follows Semantic Versioning, and covers open interest.
44
+
45
+ ## Behavior
46
+
47
+ - Venue-native symbols are accepted without symbol guessing or rewriting.
48
+ - Missing and unsupported values are never represented as zero.
49
+ - Current observations remain usable when optional history fails.
50
+ - Native quantities, units, marks, timestamps, and valuation methods are
51
+ preserved alongside normalized USD notional.
52
+ - History ranges are bounded, deduplicated, ordered, and protected by finite
53
+ pagination limits.
54
+ - Native adapters are preferred when registered; fallback is explicit.
55
+ - External I/O is asynchronous, bounded, injectable, and independently
56
+ testable.
57
+ - The package contains no consumer-specific storage or presentation behavior.
58
+
59
+ The complete contract is in [docs/CONTRACT.md](docs/CONTRACT.md), and package
60
+ boundaries are described in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
61
+
62
+ CCXT support is optional and selected through the `ccxt` extra.
63
+
64
+ ## License
65
+
66
+ Apache-2.0.
@@ -0,0 +1,37 @@
1
+ # perp-md
2
+
3
+ `perp-md` is a typed asynchronous Python library for current and historical
4
+ perpetual-market open interest. It presents one stable contract while keeping
5
+ venue protocols, pagination, validation, and optional CCXT integration behind
6
+ adapter boundaries.
7
+
8
+ The package contains no persistence, scheduling, catalog discovery,
9
+ aggregation, chart policy, or application APIs. Market identity, storage, and
10
+ observation use remain outside the library.
11
+
12
+ ## Status
13
+
14
+ The public API is alpha, follows Semantic Versioning, and covers open interest.
15
+
16
+ ## Behavior
17
+
18
+ - Venue-native symbols are accepted without symbol guessing or rewriting.
19
+ - Missing and unsupported values are never represented as zero.
20
+ - Current observations remain usable when optional history fails.
21
+ - Native quantities, units, marks, timestamps, and valuation methods are
22
+ preserved alongside normalized USD notional.
23
+ - History ranges are bounded, deduplicated, ordered, and protected by finite
24
+ pagination limits.
25
+ - Native adapters are preferred when registered; fallback is explicit.
26
+ - External I/O is asynchronous, bounded, injectable, and independently
27
+ testable.
28
+ - The package contains no consumer-specific storage or presentation behavior.
29
+
30
+ The complete contract is in [docs/CONTRACT.md](docs/CONTRACT.md), and package
31
+ boundaries are described in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
32
+
33
+ CCXT support is optional and selected through the `ccxt` extra.
34
+
35
+ ## License
36
+
37
+ Apache-2.0.
@@ -0,0 +1,9 @@
1
+ # Security
2
+
3
+ Report security issues privately through GitHub's security advisory interface.
4
+ Do not include credentials or private endpoint data in reports, fixtures, or
5
+ logs.
6
+
7
+ The library accesses public market-data endpoints only. Consumers remain
8
+ responsible for dependency locking, release-attestation verification, and
9
+ their own trust policy.
@@ -0,0 +1,67 @@
1
+ # Architecture
2
+
3
+ ## Modules
4
+
5
+ - `models` defines immutable instrument, history range, observation, result,
6
+ capability, and history-issue values.
7
+ - `errors` defines the public exception hierarchy.
8
+ - `normalization` validates numeric fields and converts contract-count OI to
9
+ normalized USD notional.
10
+ - `transport` implements bounded asynchronous JSON requests, per-host
11
+ concurrency, connection pooling, and short-lived request deduplication.
12
+ - `adapters.native` contains native endpoint selection, payload parsing,
13
+ current OI normalization, and historical pagination.
14
+ - `adapters.ccxt` contains the optional CCXT exchange lifecycle, symbol
15
+ resolution, unified OI parsing, and venue-specific CCXT extensions.
16
+ - `client` selects an adapter and owns transport and adapter shutdown.
17
+ - `history` calculates a resume timestamp from persisted observation times.
18
+
19
+ ## Request flow
20
+
21
+ 1. `OpenInterestClient.fetch` receives an `Instrument`, optional
22
+ `HistoryRange`, and history flag.
23
+ 2. The client selects a registered native adapter by normalized venue name. If
24
+ none is registered, it selects the configured fallback adapter.
25
+ 3. The adapter issues public requests through `JsonTransport` or its optional
26
+ provider runtime.
27
+ 4. The adapter validates the payload and constructs an
28
+ `OpenInterestObservation` for the current value.
29
+ 5. When history is enabled, the adapter fetches bounded pages, filters the
30
+ requested range, deduplicates timestamps, and sorts observations.
31
+ 6. A history failure after current success becomes `HistoryIssue`; a current
32
+ failure raises a `PerpMdError` subtype.
33
+
34
+ ## Resource lifecycle
35
+
36
+ `HttpxTransport` creates its `httpx.AsyncClient` on the first request. It owns
37
+ global and per-host semaphores and a cache of in-flight or recent identical
38
+ requests. `close` cancels unfinished cached requests and closes the HTTP client.
39
+ Symbol-independent aggregate snapshots use one identical transport key, so
40
+ concurrent instrument reads share the bounded request and parse their exact
41
+ venue-native rows independently.
42
+
43
+ `CcxtAdapter` imports CCXT on first fallback use, creates one exchange instance
44
+ per venue, loads each venue catalog once, and closes all exchange instances on
45
+ shutdown.
46
+
47
+ `OpenInterestClient` supports explicit `close` and asynchronous context-manager
48
+ cleanup. An injected transport remains owned by its caller.
49
+
50
+ ## Adapter contract
51
+
52
+ Each adapter implements:
53
+
54
+ - `supports(Instrument) -> bool`
55
+ - `capabilities(Instrument) -> OpenInterestCapabilities`
56
+ - `fetch(Instrument, HistoryRange | None, include_history=...)`
57
+ - `close()`
58
+
59
+ Native adapter tests use recorded JSON fixtures and injected transports. The
60
+ offline suite covers successful normalization, zero values, pagination,
61
+ deduplication, malformed history, partial results, and exact CCXT resolution.
62
+
63
+ ## Package boundaries
64
+
65
+ The package contains no scheduler, database, CSV format, retention policy,
66
+ market catalog, cross-market aggregation, completeness definition, web API,
67
+ retry queue, or visualization behavior.
@@ -0,0 +1,77 @@
1
+ # Public contract
2
+
3
+ ## Instrument identity
4
+
5
+ `Instrument` is supplied by the caller. `venue` and `symbol` are opaque,
6
+ venue-native identifiers. The library never derives a market by removing
7
+ multipliers, separators, settlement suffixes, or other symbol components.
8
+
9
+ Contract-count OI normalization requires explicit contract direction and
10
+ multiplier. Missing required metadata produces `InvalidInstrument`, never a
11
+ guessed conversion. For a linear contract, `contract_multiplier` is canonical
12
+ base units per contract and normalized value is contract count multiplied by
13
+ the multiplier and contemporaneous positive mark. For an inverse contract,
14
+ `contract_multiplier` is USD quote notional per contract and normalized value
15
+ is contract count multiplied by the multiplier.
16
+
17
+ An adapter reading a venue-wide aggregate response selects a row only by exact
18
+ equality with `Instrument.symbol`. No matching row or multiple matching rows
19
+ produce `DataUnavailable`; an invalid envelope, malformed row identity, or
20
+ invalid required observation field produces `InvalidResponse`.
21
+
22
+ ## Observations
23
+
24
+ `OpenInterestObservation` contains:
25
+
26
+ - the source observation time in Unix milliseconds;
27
+ - normalized non-negative USD notional;
28
+ - the venue-native quantity and unit when published;
29
+ - the mark used for conversion when applicable;
30
+ - a valuation method describing how normalization was obtained.
31
+
32
+ Zero is a valid observation. Absence, unsupported capabilities, malformed
33
+ payloads, and transport failures are errors and are never converted to zero.
34
+ All numeric values must be finite.
35
+
36
+ ## Current and history independence
37
+
38
+ `OpenInterestClient.fetch` always treats the current observation as primary.
39
+ When history is requested and fails after current succeeds, the result contains
40
+ the current observation plus a structured `HistoryIssue`. Callers decide
41
+ whether partial results are acceptable.
42
+
43
+ History output is ordered by timestamp and deduplicated by timestamp. An
44
+ explicit `HistoryRange` is inclusive at both endpoints. Adapters clamp ranges
45
+ to documented venue retention and the latest complete native bucket. A paged
46
+ adapter continues through a short response when source timestamps show that
47
+ the requested range has not yet been traversed; sparse native buckets do not
48
+ silently truncate later available history.
49
+
50
+ ## Capabilities
51
+
52
+ Capabilities report current and history availability, native history
53
+ granularity, maximum lookback when known, and required instrument metadata.
54
+ They describe adapter behavior, not caller configuration, storage coverage, or
55
+ rate-limit feasibility. A current-only aggregate contract-ticker adapter
56
+ reports `current=True`, `history=False`, and the generic contract fields needed
57
+ to normalize venue-reported contract counts.
58
+
59
+ ## Errors
60
+
61
+ All expected library failures derive from `PerpMdError`:
62
+
63
+ - `AdapterUnavailable`: no configured adapter can serve the venue.
64
+ - `DataUnavailable`: the metric is unsupported or absent.
65
+ - `InvalidInstrument`: caller-supplied identity or contract metadata is invalid.
66
+ - `InvalidResponse`: the venue returned an invalid or incomplete payload.
67
+ - `PaginationError`: a bounded history traversal could not safely progress.
68
+ - `RequestError`: bounded external I/O failed.
69
+
70
+ Error messages do not name or depend on any catalog, service, database, or UI.
71
+
72
+ ## Compatibility
73
+
74
+ The public imports re-exported from `perp_md` form the supported API. Adapter
75
+ internals and venue payload parsers are not public. In `0.x` releases, minor
76
+ versions may change the public API and patch versions preserve compatibility.
77
+ From `1.0.0`, breaking public changes increment the major version.
@@ -0,0 +1,11 @@
1
+ # Versioning and distribution
2
+
3
+ `perp-md` uses strict Semantic Versions and exposes its runtime version through
4
+ installed package metadata. A release tag is `vX.Y.Z` and must match
5
+ `project.version` exactly.
6
+
7
+ GitHub release assets are the distribution boundary. CI builds a universal
8
+ wheel and source distribution from the tagged tree, verifies them, and attaches
9
+ them to the release. Published assets are never replaced; corrections receive
10
+ a new patch version. Direct installations use a versioned wheel URL and its
11
+ SHA-256 digest.
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools>=75"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "perp-md"
7
+ version = "0.1.4"
8
+ description = "Typed, asynchronous open-interest market data adapters"
9
+ readme = "README.md"
10
+ license = "Apache-2.0"
11
+ requires-python = ">=3.11"
12
+ authors = [{name = "perp-md contributors"}]
13
+ keywords = ["market-data", "open-interest", "perpetuals", "asyncio"]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Typing :: Typed",
21
+ ]
22
+ dependencies = [
23
+ "httpx>=0.27,<1",
24
+ ]
25
+
26
+ [project.optional-dependencies]
27
+ ccxt = ["ccxt>=4.5,<5"]
28
+ dev = [
29
+ "build>=1,<2",
30
+ "ccxt>=4.5,<5",
31
+ "pytest>=8,<10",
32
+ "twine>=6,<7",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/latheiere/perp-md"
37
+ Repository = "https://github.com/latheiere/perp-md"
38
+ Issues = "https://github.com/latheiere/perp-md/issues"
39
+
40
+ [tool.setuptools.packages.find]
41
+ where = ["src"]
42
+
43
+ [tool.setuptools.package-data]
44
+ perp_md = ["py.typed"]
45
+
46
+ [tool.pytest.ini_options]
47
+ pythonpath = ["src"]
48
+ testpaths = ["tests"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,50 @@
1
+ from importlib.metadata import PackageNotFoundError, version
2
+
3
+ from perp_md.client import OpenInterestClient
4
+ from perp_md.errors import (
5
+ AdapterUnavailable,
6
+ DataUnavailable,
7
+ InvalidInstrument,
8
+ InvalidResponse,
9
+ PaginationError,
10
+ PerpMdError,
11
+ RequestError,
12
+ )
13
+ from perp_md.history import find_resume_time
14
+ from perp_md.models import (
15
+ ContractDirection,
16
+ HistoryIssue,
17
+ HistoryRange,
18
+ Instrument,
19
+ NativeUnit,
20
+ OpenInterestCapabilities,
21
+ OpenInterestObservation,
22
+ OpenInterestResult,
23
+ ValuationMethod,
24
+ )
25
+
26
+ try:
27
+ __version__ = version("perp-md")
28
+ except PackageNotFoundError:
29
+ __version__ = "0.0.0+uninstalled"
30
+
31
+ __all__ = [
32
+ "AdapterUnavailable",
33
+ "ContractDirection",
34
+ "DataUnavailable",
35
+ "HistoryIssue",
36
+ "HistoryRange",
37
+ "Instrument",
38
+ "InvalidInstrument",
39
+ "InvalidResponse",
40
+ "NativeUnit",
41
+ "OpenInterestCapabilities",
42
+ "OpenInterestClient",
43
+ "OpenInterestObservation",
44
+ "OpenInterestResult",
45
+ "PaginationError",
46
+ "PerpMdError",
47
+ "RequestError",
48
+ "ValuationMethod",
49
+ "find_resume_time",
50
+ ]
@@ -0,0 +1,3 @@
1
+ from perp_md.adapters.base import OpenInterestAdapter
2
+
3
+ __all__ = ["OpenInterestAdapter"]
@@ -0,0 +1,23 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Protocol
4
+
5
+ from perp_md.models import (
6
+ HistoryRange,
7
+ Instrument,
8
+ OpenInterestCapabilities,
9
+ OpenInterestResult,
10
+ )
11
+
12
+
13
+ class OpenInterestAdapter(Protocol):
14
+ def supports(self, instrument: Instrument) -> bool: ...
15
+ def capabilities(self, instrument: Instrument) -> OpenInterestCapabilities: ...
16
+ async def fetch(
17
+ self,
18
+ instrument: Instrument,
19
+ history: HistoryRange | None,
20
+ *,
21
+ include_history: bool,
22
+ ) -> OpenInterestResult: ...
23
+ async def close(self) -> None: ...