rulebook-sdk 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.
Files changed (32) hide show
  1. rulebook_sdk-0.1.0/.gitignore +219 -0
  2. rulebook_sdk-0.1.0/.python-version +1 -0
  3. rulebook_sdk-0.1.0/LICENSE +21 -0
  4. rulebook_sdk-0.1.0/PKG-INFO +254 -0
  5. rulebook_sdk-0.1.0/README.md +220 -0
  6. rulebook_sdk-0.1.0/pyproject.toml +70 -0
  7. rulebook_sdk-0.1.0/src/rulebook/__init__.py +65 -0
  8. rulebook_sdk-0.1.0/src/rulebook/_base_client.py +582 -0
  9. rulebook_sdk-0.1.0/src/rulebook/_client.py +243 -0
  10. rulebook_sdk-0.1.0/src/rulebook/_constants.py +16 -0
  11. rulebook_sdk-0.1.0/src/rulebook/_exceptions.py +129 -0
  12. rulebook_sdk-0.1.0/src/rulebook/_models.py +18 -0
  13. rulebook_sdk-0.1.0/src/rulebook/_resource.py +41 -0
  14. rulebook_sdk-0.1.0/src/rulebook/_response.py +67 -0
  15. rulebook_sdk-0.1.0/src/rulebook/_types.py +68 -0
  16. rulebook_sdk-0.1.0/src/rulebook/resources/__init__.py +27 -0
  17. rulebook_sdk-0.1.0/src/rulebook/resources/exchanges.py +296 -0
  18. rulebook_sdk-0.1.0/src/rulebook/resources/fee_schedule_results.py +740 -0
  19. rulebook_sdk-0.1.0/src/rulebook/types/__init__.py +21 -0
  20. rulebook_sdk-0.1.0/src/rulebook/types/date_range.py +15 -0
  21. rulebook_sdk-0.1.0/src/rulebook/types/exchange.py +23 -0
  22. rulebook_sdk-0.1.0/src/rulebook/types/exchange_detail.py +45 -0
  23. rulebook_sdk-0.1.0/src/rulebook/types/fee_schedule_result.py +89 -0
  24. rulebook_sdk-0.1.0/src/rulebook/types/fee_schedule_result_filters.py +35 -0
  25. rulebook_sdk-0.1.0/src/rulebook/types/paginated_response.py +36 -0
  26. rulebook_sdk-0.1.0/tests/__init__.py +0 -0
  27. rulebook_sdk-0.1.0/tests/conftest.py +30 -0
  28. rulebook_sdk-0.1.0/tests/test_exchanges.py +540 -0
  29. rulebook_sdk-0.1.0/tests/test_fee_schedule_results.py +721 -0
  30. rulebook_sdk-0.1.0/tests/test_integration.py +444 -0
  31. rulebook_sdk-0.1.0/tests/test_smoke.py +111 -0
  32. rulebook_sdk-0.1.0/uv.lock +947 -0
@@ -0,0 +1,219 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+
18
+ parts/
19
+ sdist/
20
+ var/
21
+ wheels/
22
+ share/python-wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .nox/
42
+ .coverage
43
+ .coverage.*
44
+ .cache
45
+ nosetests.xml
46
+ coverage.xml
47
+ *.cover
48
+ *.py.cover
49
+ .hypothesis/
50
+ .pytest_cache/
51
+ cover/
52
+
53
+ # Translations
54
+ *.mo
55
+ *.pot
56
+
57
+ # Django stuff:
58
+ *.log
59
+ local_settings.py
60
+ db.sqlite3
61
+ db.sqlite3-journal
62
+
63
+ # Flask stuff:
64
+ instance/
65
+ .webassets-cache
66
+
67
+ # Scrapy stuff:
68
+ .scrapy
69
+
70
+ # Sphinx documentation
71
+ docs/_build/
72
+
73
+ # PyBuilder
74
+ .pybuilder/
75
+ target/
76
+
77
+ # Jupyter Notebook
78
+ .ipynb_checkpoints
79
+
80
+ # IPython
81
+ profile_default/
82
+ ipython_config.py
83
+
84
+ # pyenv
85
+ # For a library or package, you might want to ignore these files since the code is
86
+ # intended to run in multiple environments; otherwise, check them in:
87
+ # .python-version
88
+
89
+ # pipenv
90
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
91
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
92
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
93
+ # install all needed dependencies.
94
+ # Pipfile.lock
95
+
96
+ # UV
97
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
98
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
99
+ # commonly ignored for libraries.
100
+ # uv.lock
101
+
102
+ # poetry
103
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
105
+ # commonly ignored for libraries.
106
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107
+ # poetry.lock
108
+ # poetry.toml
109
+
110
+ # pdm
111
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
113
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
114
+ # pdm.lock
115
+ # pdm.toml
116
+ .pdm-python
117
+ .pdm-build/
118
+
119
+ # pixi
120
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
121
+ # pixi.lock
122
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
123
+ # in the .venv directory. It is recommended not to include this directory in version control.
124
+ .pixi
125
+
126
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
127
+ __pypackages__/
128
+
129
+ # Celery stuff
130
+ celerybeat-schedule
131
+ celerybeat.pid
132
+
133
+ # Redis
134
+ *.rdb
135
+ *.aof
136
+ *.pid
137
+
138
+ # RabbitMQ
139
+ mnesia/
140
+ rabbitmq/
141
+ rabbitmq-data/
142
+
143
+ # ActiveMQ
144
+ activemq-data/
145
+
146
+ # SageMath parsed files
147
+ *.sage.py
148
+
149
+ # Environments
150
+ .env
151
+ .envrc
152
+ .venv
153
+ env/
154
+ venv/
155
+ ENV/
156
+ env.bak/
157
+ venv.bak/
158
+
159
+ # Spyder project settings
160
+ .spyderproject
161
+ .spyproject
162
+
163
+ # Rope project settings
164
+ .ropeproject
165
+
166
+ # mkdocs documentation
167
+ /site
168
+
169
+ # mypy
170
+ .mypy_cache/
171
+ .dmypy.json
172
+ dmypy.json
173
+
174
+ # Pyre type checker
175
+ .pyre/
176
+
177
+ # pytype static type analyzer
178
+ .pytype/
179
+
180
+ # Cython debug symbols
181
+ cython_debug/
182
+
183
+ # PyCharm
184
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
185
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
186
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
187
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
188
+ # .idea/
189
+
190
+ # Abstra
191
+ # Abstra is an AI-powered process automation framework.
192
+ # Ignore directories containing user credentials, local state, and settings.
193
+ # Learn more at https://abstra.io/docs
194
+ .abstra/
195
+
196
+ # Visual Studio Code
197
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
198
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
199
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
200
+ # you could uncomment the following to ignore the entire vscode folder
201
+ # .vscode/
202
+
203
+ # Ruff stuff:
204
+ .ruff_cache/
205
+
206
+ # PyPI configuration file
207
+ .pypirc
208
+
209
+ # Marimo
210
+ marimo/_static/
211
+ marimo/_lsp/
212
+ __marimo__/
213
+
214
+ # Streamlit
215
+ .streamlit/secrets.toml
216
+ ops-portal/tsconfig.tsbuildinfo
217
+ .claude/settings.local.json
218
+ rulebook-crawler/.env.local
219
+ .worktrees/
@@ -0,0 +1 @@
1
+ 3.11
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Codeaza Technologies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,254 @@
1
+ Metadata-Version: 2.4
2
+ Name: rulebook-sdk
3
+ Version: 0.1.0
4
+ Summary: Python SDK for the Rulebook Company API — exchange fee schedule and rebate data
5
+ Project-URL: Documentation, https://docs.rulebookcompany.com
6
+ Project-URL: Changelog, https://docs.rulebookcompany.com/changelog
7
+ Author-email: Muhammad Haris Azaz Khan <harris.khan.1596@gmail.com>
8
+ Maintainer-email: Muhammad Haris Azaz Khan <harris.khan.1596@gmail.com>
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: api-client,exchange,fee-schedule,fintech,rebate,rulebook,sdk,trading
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: License :: OSI Approved :: MIT License
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
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: anyio>=4.0.0
25
+ Requires-Dist: httpx>=0.25.0
26
+ Requires-Dist: pydantic>=2.0.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
29
+ Requires-Dist: pytest-httpx>=0.30.0; extra == 'dev'
30
+ Requires-Dist: pytest>=7.0; extra == 'dev'
31
+ Requires-Dist: ruff>=0.4.0; extra == 'dev'
32
+ Requires-Dist: vcrpy>=8.1.1; extra == 'dev'
33
+ Description-Content-Type: text/markdown
34
+
35
+ # Rulebook Python SDK
36
+
37
+ The official Python client for the [Rulebook Company API](https://api.rulebook.company) — access exchange fee schedule and rebate data across US trading venues.
38
+
39
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/downloads/)
40
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install rulebooksdk
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ```python
51
+ from rulebook import Rulebook
52
+
53
+ client = Rulebook(api_key="your-api-key")
54
+
55
+ # List all exchanges
56
+ exchanges = client.exchanges.list()
57
+ for exchange in exchanges:
58
+ print(f"{exchange.name}: {exchange.display_name} ({exchange.record_count} records)")
59
+
60
+ # Get details for a specific exchange
61
+ detail = client.exchanges.retrieve("NYSE")
62
+ print(f"Date range: {detail.date_range.earliest} to {detail.date_range.latest}")
63
+ print(f"Fee types: {detail.fee_types}")
64
+ print(f"Actions: {detail.actions}")
65
+
66
+ # List fee schedule results (with filtering)
67
+ results = client.fee_schedule_results.list(
68
+ exchange_name=["fee_cboe_us_options"],
69
+ fee_type=["Option"],
70
+ latest_only=True,
71
+ page_size=10,
72
+ )
73
+ for item in results.data:
74
+ print(f"{item.exchange_name} | {item.fee_type} | {item.fee_amount}")
75
+
76
+ # Get a single fee schedule result
77
+ result = client.fee_schedule_results.retrieve("some-uuid")
78
+
79
+ # Get available filter values
80
+ filters = client.fee_schedule_results.get_filters()
81
+ print(f"Exchanges: {filters.exchange_names}")
82
+ print(f"Fee types: {filters.fee_types}")
83
+
84
+ # Get results by extraction version
85
+ version_results = client.fee_schedule_results.get_results_by_version("version-uuid")
86
+
87
+ client.close()
88
+ ```
89
+
90
+ ## Authentication
91
+
92
+ Pass your API key directly or set the `RULEBOOK_API_KEY` environment variable:
93
+
94
+ ```python
95
+ # Option 1: Pass directly
96
+ client = Rulebook(api_key="rb-...")
97
+
98
+ # Option 2: Environment variable
99
+ # export RULEBOOK_API_KEY=rb-...
100
+ client = Rulebook()
101
+ ```
102
+
103
+ ## Async support
104
+
105
+ Every method has an async counterpart via `AsyncRulebook`:
106
+
107
+ ```python
108
+ import asyncio
109
+ from rulebook import AsyncRulebook
110
+
111
+ async def main():
112
+ async with AsyncRulebook(api_key="your-api-key") as client:
113
+ exchanges = await client.exchanges.list()
114
+ detail = await client.exchanges.retrieve("NYSE")
115
+
116
+ asyncio.run(main())
117
+ ```
118
+
119
+ ## Error handling
120
+
121
+ The SDK raises typed exceptions for all API errors:
122
+
123
+ ```python
124
+ from rulebook import Rulebook, NotFoundError, AuthenticationError, RateLimitError
125
+
126
+ client = Rulebook()
127
+
128
+ try:
129
+ detail = client.exchanges.retrieve("UNKNOWN")
130
+ except NotFoundError:
131
+ print("Exchange not found")
132
+ except AuthenticationError:
133
+ print("Invalid API key")
134
+ except RateLimitError as e:
135
+ print(f"Rate limited — retry after: {e.response.headers.get('retry-after')}")
136
+ ```
137
+
138
+ **Exception hierarchy:**
139
+
140
+ | Exception | Status Code | Description |
141
+ |---|---|---|
142
+ | `BadRequestError` | 400 | Invalid request parameters |
143
+ | `AuthenticationError` | 401 | Missing or invalid API key |
144
+ | `PermissionDeniedError` | 403 | Insufficient access for this resource |
145
+ | `NotFoundError` | 404 | Resource does not exist |
146
+ | `UnprocessableEntityError` | 422 | Request validation failed |
147
+ | `RateLimitError` | 429 | Too many requests |
148
+ | `InternalServerError` | 5xx | Server-side error |
149
+ | `APIConnectionError` | — | Network failure |
150
+ | `APITimeoutError` | — | Request timed out |
151
+
152
+ ## Raw response access
153
+
154
+ Access HTTP status codes, headers, and the raw response via `with_raw_response`:
155
+
156
+ ```python
157
+ raw = client.exchanges.with_raw_response.retrieve("NYSE")
158
+ print(raw.status_code) # 200
159
+ print(raw.headers.get("content-type")) # application/json
160
+
161
+ detail = raw.parse() # ExchangeDetail
162
+ ```
163
+
164
+ ## Client configuration
165
+
166
+ ```python
167
+ client = Rulebook(
168
+ api_key="rb-...",
169
+ base_url="https://api.rulebook.company/api/v1", # default
170
+ timeout=30.0, # seconds (default: 30)
171
+ max_retries=2, # retry transient failures (default: 2)
172
+ default_headers={}, # headers sent on every request
173
+ )
174
+ ```
175
+
176
+ ### Per-request overrides
177
+
178
+ Override timeout or add headers for a single request without modifying the client:
179
+
180
+ ```python
181
+ exchanges = client.exchanges.list(
182
+ extra_headers={"X-Request-Id": "abc-123"},
183
+ timeout=60.0,
184
+ )
185
+ ```
186
+
187
+ ### Immutable client copies
188
+
189
+ Create a new client with different settings using `with_options()`:
190
+
191
+ ```python
192
+ slow_client = client.with_options(timeout=120.0)
193
+ ```
194
+
195
+ ## Retries
196
+
197
+ The SDK automatically retries transient errors (408, 409, 429, 500, 502, 503, 504) with exponential backoff and jitter. Configure with `max_retries`:
198
+
199
+ ```python
200
+ client = Rulebook(max_retries=5) # default is 2
201
+ ```
202
+
203
+ ## Response types
204
+
205
+ All responses are strongly typed with Pydantic models:
206
+
207
+ ```python
208
+ from rulebook.types import (
209
+ Exchange,
210
+ ExchangeDetail,
211
+ DateRange,
212
+ FeeScheduleResult,
213
+ FeeScheduleResultFilters,
214
+ PaginatedResponse,
215
+ )
216
+ ```
217
+
218
+ **`Exchange`** — returned by `list()`
219
+
220
+ | Field | Type | Description |
221
+ |---|---|---|
222
+ | `name` | `str` | Exchange identifier (e.g., `"NYSE"`) |
223
+ | `display_name` | `str` | Full name (e.g., `"New York Stock Exchange"`) |
224
+ | `fee_types` | `List[str]` | Available fee types (e.g., `["Equity", "Option"]`) |
225
+ | `record_count` | `int` | Total fee schedule records |
226
+
227
+ **`ExchangeDetail`** — returned by `retrieve()`
228
+
229
+ | Field | Type | Description |
230
+ |---|---|---|
231
+ | `name` | `str` | Exchange identifier |
232
+ | `display_name` | `str` | Full name |
233
+ | `date_range` | `DateRange` | Earliest and latest dates of available data |
234
+ | `fee_types` | `List[str]` | Available fee types |
235
+ | `fee_categories` | `List[str]` | Fee categories (e.g., `["Fee And Rebates"]`) |
236
+ | `actions` | `List[str]` | Trade actions (e.g., `["Make", "Take", "Open"]`) |
237
+ | `participants` | `List[str]` | Participant types (e.g., `["Market Maker", "Customer"]`) |
238
+ | `symbol_classifications` | `List[str]` | Symbol classifications (e.g., `["ETF", "Equity"]`) |
239
+ | `symbol_types` | `List[str]` | Symbol types (e.g., `["Penny", "Non Penny"]`) |
240
+ | `trade_types` | `List[str]` | Trade types (e.g., `["Simple Order"]`) |
241
+ | `record_count` | `int` | Total fee schedule records |
242
+
243
+ ## Maintainers
244
+
245
+ - [Muhammad Haris Azaz Khan](https://github.com/haris-khan1596)
246
+
247
+ ## Requirements
248
+
249
+ - Python 3.11+
250
+ - Dependencies: `httpx`, `pydantic`, `anyio`
251
+
252
+ ## License
253
+
254
+ MIT — see [LICENSE](LICENSE) for details.
@@ -0,0 +1,220 @@
1
+ # Rulebook Python SDK
2
+
3
+ The official Python client for the [Rulebook Company API](https://api.rulebook.company) — access exchange fee schedule and rebate data across US trading venues.
4
+
5
+ [![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue)](https://www.python.org/downloads/)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ pip install rulebooksdk
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ ```python
17
+ from rulebook import Rulebook
18
+
19
+ client = Rulebook(api_key="your-api-key")
20
+
21
+ # List all exchanges
22
+ exchanges = client.exchanges.list()
23
+ for exchange in exchanges:
24
+ print(f"{exchange.name}: {exchange.display_name} ({exchange.record_count} records)")
25
+
26
+ # Get details for a specific exchange
27
+ detail = client.exchanges.retrieve("NYSE")
28
+ print(f"Date range: {detail.date_range.earliest} to {detail.date_range.latest}")
29
+ print(f"Fee types: {detail.fee_types}")
30
+ print(f"Actions: {detail.actions}")
31
+
32
+ # List fee schedule results (with filtering)
33
+ results = client.fee_schedule_results.list(
34
+ exchange_name=["fee_cboe_us_options"],
35
+ fee_type=["Option"],
36
+ latest_only=True,
37
+ page_size=10,
38
+ )
39
+ for item in results.data:
40
+ print(f"{item.exchange_name} | {item.fee_type} | {item.fee_amount}")
41
+
42
+ # Get a single fee schedule result
43
+ result = client.fee_schedule_results.retrieve("some-uuid")
44
+
45
+ # Get available filter values
46
+ filters = client.fee_schedule_results.get_filters()
47
+ print(f"Exchanges: {filters.exchange_names}")
48
+ print(f"Fee types: {filters.fee_types}")
49
+
50
+ # Get results by extraction version
51
+ version_results = client.fee_schedule_results.get_results_by_version("version-uuid")
52
+
53
+ client.close()
54
+ ```
55
+
56
+ ## Authentication
57
+
58
+ Pass your API key directly or set the `RULEBOOK_API_KEY` environment variable:
59
+
60
+ ```python
61
+ # Option 1: Pass directly
62
+ client = Rulebook(api_key="rb-...")
63
+
64
+ # Option 2: Environment variable
65
+ # export RULEBOOK_API_KEY=rb-...
66
+ client = Rulebook()
67
+ ```
68
+
69
+ ## Async support
70
+
71
+ Every method has an async counterpart via `AsyncRulebook`:
72
+
73
+ ```python
74
+ import asyncio
75
+ from rulebook import AsyncRulebook
76
+
77
+ async def main():
78
+ async with AsyncRulebook(api_key="your-api-key") as client:
79
+ exchanges = await client.exchanges.list()
80
+ detail = await client.exchanges.retrieve("NYSE")
81
+
82
+ asyncio.run(main())
83
+ ```
84
+
85
+ ## Error handling
86
+
87
+ The SDK raises typed exceptions for all API errors:
88
+
89
+ ```python
90
+ from rulebook import Rulebook, NotFoundError, AuthenticationError, RateLimitError
91
+
92
+ client = Rulebook()
93
+
94
+ try:
95
+ detail = client.exchanges.retrieve("UNKNOWN")
96
+ except NotFoundError:
97
+ print("Exchange not found")
98
+ except AuthenticationError:
99
+ print("Invalid API key")
100
+ except RateLimitError as e:
101
+ print(f"Rate limited — retry after: {e.response.headers.get('retry-after')}")
102
+ ```
103
+
104
+ **Exception hierarchy:**
105
+
106
+ | Exception | Status Code | Description |
107
+ |---|---|---|
108
+ | `BadRequestError` | 400 | Invalid request parameters |
109
+ | `AuthenticationError` | 401 | Missing or invalid API key |
110
+ | `PermissionDeniedError` | 403 | Insufficient access for this resource |
111
+ | `NotFoundError` | 404 | Resource does not exist |
112
+ | `UnprocessableEntityError` | 422 | Request validation failed |
113
+ | `RateLimitError` | 429 | Too many requests |
114
+ | `InternalServerError` | 5xx | Server-side error |
115
+ | `APIConnectionError` | — | Network failure |
116
+ | `APITimeoutError` | — | Request timed out |
117
+
118
+ ## Raw response access
119
+
120
+ Access HTTP status codes, headers, and the raw response via `with_raw_response`:
121
+
122
+ ```python
123
+ raw = client.exchanges.with_raw_response.retrieve("NYSE")
124
+ print(raw.status_code) # 200
125
+ print(raw.headers.get("content-type")) # application/json
126
+
127
+ detail = raw.parse() # ExchangeDetail
128
+ ```
129
+
130
+ ## Client configuration
131
+
132
+ ```python
133
+ client = Rulebook(
134
+ api_key="rb-...",
135
+ base_url="https://api.rulebook.company/api/v1", # default
136
+ timeout=30.0, # seconds (default: 30)
137
+ max_retries=2, # retry transient failures (default: 2)
138
+ default_headers={}, # headers sent on every request
139
+ )
140
+ ```
141
+
142
+ ### Per-request overrides
143
+
144
+ Override timeout or add headers for a single request without modifying the client:
145
+
146
+ ```python
147
+ exchanges = client.exchanges.list(
148
+ extra_headers={"X-Request-Id": "abc-123"},
149
+ timeout=60.0,
150
+ )
151
+ ```
152
+
153
+ ### Immutable client copies
154
+
155
+ Create a new client with different settings using `with_options()`:
156
+
157
+ ```python
158
+ slow_client = client.with_options(timeout=120.0)
159
+ ```
160
+
161
+ ## Retries
162
+
163
+ The SDK automatically retries transient errors (408, 409, 429, 500, 502, 503, 504) with exponential backoff and jitter. Configure with `max_retries`:
164
+
165
+ ```python
166
+ client = Rulebook(max_retries=5) # default is 2
167
+ ```
168
+
169
+ ## Response types
170
+
171
+ All responses are strongly typed with Pydantic models:
172
+
173
+ ```python
174
+ from rulebook.types import (
175
+ Exchange,
176
+ ExchangeDetail,
177
+ DateRange,
178
+ FeeScheduleResult,
179
+ FeeScheduleResultFilters,
180
+ PaginatedResponse,
181
+ )
182
+ ```
183
+
184
+ **`Exchange`** — returned by `list()`
185
+
186
+ | Field | Type | Description |
187
+ |---|---|---|
188
+ | `name` | `str` | Exchange identifier (e.g., `"NYSE"`) |
189
+ | `display_name` | `str` | Full name (e.g., `"New York Stock Exchange"`) |
190
+ | `fee_types` | `List[str]` | Available fee types (e.g., `["Equity", "Option"]`) |
191
+ | `record_count` | `int` | Total fee schedule records |
192
+
193
+ **`ExchangeDetail`** — returned by `retrieve()`
194
+
195
+ | Field | Type | Description |
196
+ |---|---|---|
197
+ | `name` | `str` | Exchange identifier |
198
+ | `display_name` | `str` | Full name |
199
+ | `date_range` | `DateRange` | Earliest and latest dates of available data |
200
+ | `fee_types` | `List[str]` | Available fee types |
201
+ | `fee_categories` | `List[str]` | Fee categories (e.g., `["Fee And Rebates"]`) |
202
+ | `actions` | `List[str]` | Trade actions (e.g., `["Make", "Take", "Open"]`) |
203
+ | `participants` | `List[str]` | Participant types (e.g., `["Market Maker", "Customer"]`) |
204
+ | `symbol_classifications` | `List[str]` | Symbol classifications (e.g., `["ETF", "Equity"]`) |
205
+ | `symbol_types` | `List[str]` | Symbol types (e.g., `["Penny", "Non Penny"]`) |
206
+ | `trade_types` | `List[str]` | Trade types (e.g., `["Simple Order"]`) |
207
+ | `record_count` | `int` | Total fee schedule records |
208
+
209
+ ## Maintainers
210
+
211
+ - [Muhammad Haris Azaz Khan](https://github.com/haris-khan1596)
212
+
213
+ ## Requirements
214
+
215
+ - Python 3.11+
216
+ - Dependencies: `httpx`, `pydantic`, `anyio`
217
+
218
+ ## License
219
+
220
+ MIT — see [LICENSE](LICENSE) for details.