qtsurfer-sdk 0.2.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.
- qtsurfer_sdk-0.2.0/.gitignore +26 -0
- qtsurfer_sdk-0.2.0/CHANGELOG.md +79 -0
- qtsurfer_sdk-0.2.0/LICENSE +201 -0
- qtsurfer_sdk-0.2.0/PKG-INFO +285 -0
- qtsurfer_sdk-0.2.0/README.md +254 -0
- qtsurfer_sdk-0.2.0/pyproject.toml +75 -0
- qtsurfer_sdk-0.2.0/src/qtsurfer_sdk/__init__.py +42 -0
- qtsurfer_sdk-0.2.0/src/qtsurfer_sdk/_errors.py +71 -0
- qtsurfer_sdk-0.2.0/src/qtsurfer_sdk/_session.py +369 -0
- qtsurfer_sdk-0.2.0/src/qtsurfer_sdk/_tokens.py +51 -0
- qtsurfer_sdk-0.2.0/src/qtsurfer_sdk/_workflows.py +477 -0
- qtsurfer_sdk-0.2.0/tests/__init__.py +0 -0
- qtsurfer_sdk-0.2.0/tests/integration/__init__.py +0 -0
- qtsurfer_sdk-0.2.0/tests/integration/test_auth_integration.py +157 -0
- qtsurfer_sdk-0.2.0/tests/unit/__init__.py +0 -0
- qtsurfer_sdk-0.2.0/tests/unit/test_auth.py +331 -0
- qtsurfer_sdk-0.2.0/tests/unit/test_workflows.py +280 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Python build artifacts
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
build/
|
|
7
|
+
dist/
|
|
8
|
+
.eggs/
|
|
9
|
+
.pytest_cache/
|
|
10
|
+
.coverage
|
|
11
|
+
htmlcov/
|
|
12
|
+
.tox/
|
|
13
|
+
|
|
14
|
+
# uv / virtual envs
|
|
15
|
+
.venv/
|
|
16
|
+
.python-version
|
|
17
|
+
|
|
18
|
+
# IDE
|
|
19
|
+
.vscode/
|
|
20
|
+
.idea/
|
|
21
|
+
*.swp
|
|
22
|
+
*.swo
|
|
23
|
+
|
|
24
|
+
# pdoc output; hand-written Markdown guides remain tracked.
|
|
25
|
+
docs/*
|
|
26
|
+
!docs/*.md
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to `qtsurfer-sdk` are documented here.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `open_dataset_upload(dataset_id)` opens a dataset's current upload session or
|
|
12
|
+
its next version's session after finalization.
|
|
13
|
+
- `upload_dataset_file(upload, source)` streams a `Path` or open binary file to
|
|
14
|
+
the session's presigned URL without sending the SDK JWT or API key. Failed PUTs
|
|
15
|
+
and unreadable local files raise `QTSUploadError` without exposing the URL.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Public reads now use explicit names: `list_exchanges`, `list_instruments`,
|
|
20
|
+
`get_strategy`, `get_prepare_status`, `get_backtest_result`,
|
|
21
|
+
`get_sweep_result`, `get_sweep_sensitivity`, `get_sweep_run_equity_curve`,
|
|
22
|
+
`finalize_dataset_upload`, and `get_dataset_upload` replace their terse
|
|
23
|
+
predecessors.
|
|
24
|
+
- The generated client dependency is pinned to `qtsurfer-api-client==0.111.2`.
|
|
25
|
+
A spent upload session now has the API's documented `409` finalization response;
|
|
26
|
+
open a new session instead of reusing that upload id.
|
|
27
|
+
|
|
28
|
+
## [0.2.0] — 2026-08-27
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- High-level workflow surface over `qtsurfer-api-client`, parity with the Java /
|
|
33
|
+
TypeScript SDKs (module `qtsurfer_sdk._workflows`):
|
|
34
|
+
- Strategy: `compile_strategy`, `validate_strategy`, `strategy_state`,
|
|
35
|
+
`list_strategies`, `delete_strategy`, `get_strategy_code`.
|
|
36
|
+
- Catalog: `exchanges`, `instruments` (with optional segment).
|
|
37
|
+
- Backtest: `prepare`, `prepare_status`, `execute`, `backtest_result`,
|
|
38
|
+
`cancel_backtest`.
|
|
39
|
+
- Sweep: `sweep`, `sweep_result`, `sweep_sensitivity`,
|
|
40
|
+
`sweep_run_equity_curve`, `cancel_sweep`.
|
|
41
|
+
- Dataset: `create_dataset`, `list_datasets`, `get_dataset`,
|
|
42
|
+
`delete_dataset`, `finalize_upload`, `dataset_upload`.
|
|
43
|
+
- Error hierarchy parity: `QTSCompileError`, `QTSPreparationError`,
|
|
44
|
+
`QTSExecutionError`, `QTSTimeoutError`, `QTSCanceledError`, `QTSDownloadError`.
|
|
45
|
+
- `backtest_result` returns a raw `httpx.Response` (not the generated
|
|
46
|
+
`sync` value), so poll loops can handle the `202`-running state without
|
|
47
|
+
the generated parser KeyError'ing on a partially-populated `results`
|
|
48
|
+
body (missing `strategyId` while running).
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- Workflows exposed as methods on `AuthenticatedSession`
|
|
53
|
+
(`session.exchanges()`, `session.prepare(...)`, `session.backtest_result(...)`,
|
|
54
|
+
...) in addition to the `_workflows` module functions — parity with the
|
|
55
|
+
Java/TS SDK `AuthenticatedClient` surface.
|
|
56
|
+
- README rewritten to document the full workflow surface with reproducible
|
|
57
|
+
examples.
|
|
58
|
+
- Dependency pinned to `qtsurfer-api-client==0.110.3` (OpenAPI spec 0.110.3;
|
|
59
|
+
adds the Dataset feature and dataset-backed prepare/execute).
|
|
60
|
+
- `import` fixed for the generated auth endpoint moved to
|
|
61
|
+
`qtsurfer.api.client._generated.api.auth.authenticate` in 0.110.3.
|
|
62
|
+
|
|
63
|
+
### Fixed
|
|
64
|
+
|
|
65
|
+
- `AuthenticatedSession` now imports the auth operation from its new module
|
|
66
|
+
path, restoring `auth()` against `qtsurfer-api-client` 0.110.x.
|
|
67
|
+
|
|
68
|
+
## [0.1.0] — 2026-05-25
|
|
69
|
+
|
|
70
|
+
### Added
|
|
71
|
+
|
|
72
|
+
- Initial release. `auth(apikey)` helper exchanges a long-lived API key for a short-lived JWT in one call and returns an `AuthenticatedSession`.
|
|
73
|
+
- Reads `QTSURFER_APIKEY` from the environment when no apikey is passed.
|
|
74
|
+
- Caches the JWT in memory by default; adopters can plug in a custom `TokenStore` (file, secret manager, desktop keychain).
|
|
75
|
+
- `session.call(fn)` wraps any `qtsurfer-api-client` call with refresh-on-401: refresh once, retry once, surface the error otherwise.
|
|
76
|
+
- `session.client` exposes the underlying `qtsurfer-api-client` `AuthenticatedClient` for direct typed calls; its `token` attribute is mutated on refresh so in-flight references see the latest JWT.
|
|
77
|
+
- `TokenStore` protocol (`load` / `save` / `clear`) with the default `InMemoryTokenStore`.
|
|
78
|
+
- `QTSAuthError` (subclass of `QTSError`) for missing-apikey and JWT-exchange failures.
|
|
79
|
+
- Depends on `qtsurfer-api-client >= 0.95.1` (provides the `auth` operation and `AuthTokenResponse` / `AuthTokenError` schemas).
|
|
@@ -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 describing the origin of the Work and
|
|
141
|
+
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 Support. While redistributing the Work or
|
|
166
|
+
Derivative Works thereof, You may choose to offer, and charge a
|
|
167
|
+
fee for, acceptance of support, warranty, indemnity, or other
|
|
168
|
+
liability obligations and/or rights consistent with this License.
|
|
169
|
+
However, in accepting such obligations, You may act only on Your
|
|
170
|
+
own behalf and on Your sole responsibility, not on behalf of any
|
|
171
|
+
other Contributor, and only if You agree to indemnify, defend,
|
|
172
|
+
and hold each Contributor harmless for any liability incurred by,
|
|
173
|
+
or claims asserted against, such Contributor by reason of your
|
|
174
|
+
accepting any such warranty or support.
|
|
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 2026 Wualabs LTD
|
|
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
|
|
200
|
+
implied. See the License for the specific language governing
|
|
201
|
+
permissions and limitations under the License.
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: qtsurfer-sdk
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Opinionated Python SDK for QTSurfer — auth helper with refresh, pluggable token storage, and high-level workflows (strategies, backtest, sweep, datasets) over qtsurfer-api-client.
|
|
5
|
+
Project-URL: Homepage, https://github.com/QTSurfer/sdk-python
|
|
6
|
+
Project-URL: Repository, https://github.com/QTSurfer/sdk-python
|
|
7
|
+
Project-URL: Issues, https://github.com/QTSurfer/sdk-python/issues
|
|
8
|
+
Project-URL: OpenAPI Spec, https://github.com/QTSurfer/qtsurfer-api
|
|
9
|
+
Project-URL: API Client, https://github.com/QTSurfer/api-client-python
|
|
10
|
+
Project-URL: SDK (Java), https://github.com/QTSurfer/sdk-java
|
|
11
|
+
Project-URL: SDK (TypeScript), https://github.com/QTSurfer/sdk-ts
|
|
12
|
+
Author-email: Manuel Polo <mrmx@users.noreply.github.com>
|
|
13
|
+
License-Expression: Apache-2.0
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Keywords: auth,backtest,jwt,qtsurfer,sdk,trading
|
|
16
|
+
Classifier: Development Status :: 3 - Alpha
|
|
17
|
+
Classifier: Intended Audience :: Developers
|
|
18
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
25
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.11
|
|
28
|
+
Requires-Dist: httpx<1,>=0.23
|
|
29
|
+
Requires-Dist: qtsurfer-api-client==0.111.2
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# qtsurfer-sdk
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<a href="https://github.com/QTSurfer/sdk-python/actions/workflows/ci.yml"><img src="https://github.com/QTSurfer/sdk-python/actions/workflows/ci.yml/badge.svg" alt="CI"></a>
|
|
36
|
+
<a href="https://pypi.org/project/qtsurfer-sdk/"><img src="https://img.shields.io/pypi/v/qtsurfer-sdk.svg" alt="PyPI"></a>
|
|
37
|
+
<img src="https://img.shields.io/pypi/pyversions/qtsurfer-sdk.svg" alt="Python versions">
|
|
38
|
+
<a href="https://qtsurfer.github.io/sdk-python/"><img src="https://img.shields.io/badge/docs-pdoc-blue" alt="pdoc"></a>
|
|
39
|
+
<a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" alt="License"></a>
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
Opinionated Python SDK for [QTSurfer](https://qtsurfer.com), built on top of
|
|
43
|
+
[`qtsurfer-api-client`](https://github.com/QTSurfer/api-client-python).
|
|
44
|
+
|
|
45
|
+
Where `qtsurfer-api-client` gives you one function per API endpoint, this package
|
|
46
|
+
adds **auth helpers**, **token refresh**, **pluggable token storage**, and
|
|
47
|
+
**high-level workflows** (strategies, backtest, sweep, datasets) — go from an API
|
|
48
|
+
key to a typed backtest in a few lines.
|
|
49
|
+
|
|
50
|
+
> The strategy code itself stays on the JVM — QTSurfer's backtest engine is Java.
|
|
51
|
+
> This SDK is for orchestration: minting tokens, calling endpoints, processing results.
|
|
52
|
+
|
|
53
|
+
## Guides
|
|
54
|
+
|
|
55
|
+
The hand-written guides mirror the SDK family structure.
|
|
56
|
+
|
|
57
|
+
- [Authentication](docs/auth.md)
|
|
58
|
+
- [Exchanges and instruments](docs/exchange.md)
|
|
59
|
+
- [Strategies and validation](docs/strategy.md)
|
|
60
|
+
- [Backtests and parameter sweeps](docs/backtesting.md)
|
|
61
|
+
- [Dataset uploads](docs/datasets.md)
|
|
62
|
+
- [API coverage](docs/api-coverage.md)
|
|
63
|
+
|
|
64
|
+
## Installation
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install qtsurfer-sdk
|
|
68
|
+
# or, with uv:
|
|
69
|
+
uv add qtsurfer-sdk
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Requires Python 3.11+. The transitive [`qtsurfer-api-client`](https://github.com/QTSurfer/api-client-python)
|
|
73
|
+
(auto-generated from the OpenAPI spec) comes along automatically.
|
|
74
|
+
|
|
75
|
+
> **Import path**: this package imports as `qtsurfer_sdk` (sibling to the
|
|
76
|
+
> auto-generated `qtsurfer.api.client.*` tree). Two top-level names keep the SDK
|
|
77
|
+
> and the raw client cleanly separate.
|
|
78
|
+
|
|
79
|
+
## Quick start
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from qtsurfer_sdk import auth
|
|
83
|
+
|
|
84
|
+
# Reads QTSURFER_APIKEY from env when no argument is passed.
|
|
85
|
+
session = auth()
|
|
86
|
+
|
|
87
|
+
# Or point at a different API base (defaults to production):
|
|
88
|
+
# session = auth("ak_...", base_url="https://api.qtsurfer.net/v1")
|
|
89
|
+
|
|
90
|
+
exchanges = session.list_exchanges()
|
|
91
|
+
for ex in exchanges:
|
|
92
|
+
print(ex.id, ex.name)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
JWT refresh on 401 is handled for you (refresh once, retry once).
|
|
96
|
+
|
|
97
|
+
## Workflows
|
|
98
|
+
|
|
99
|
+
The SDK exposes a workflow surface mirroring `sdk-java` / `sdk-ts`. Every method
|
|
100
|
+
is routed through the session (refresh-on-401) and returns the api-client's
|
|
101
|
+
typed model objects.
|
|
102
|
+
|
|
103
|
+
### Strategy
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
src = '''public class EmaCross extends AbstractTickerStrategy { ... }'''
|
|
107
|
+
|
|
108
|
+
comp = session.compile_strategy(src) # CompileStrategyResponse200
|
|
109
|
+
sid = comp.strategy_id
|
|
110
|
+
|
|
111
|
+
session.validate_strategy(sid) # 202/pending or already-recorded verdict
|
|
112
|
+
state = session.get_strategy(sid) # validation, notices, requiredSources
|
|
113
|
+
session.list_strategies() # your registered strategies
|
|
114
|
+
code = session.get_strategy_code(sid) # read back the exact source
|
|
115
|
+
session.delete_strategy(sid) # release it
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### Catalog
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
session.list_exchanges() # [Exchange, ...]
|
|
122
|
+
session.list_instruments("binance") # 1876 instruments
|
|
123
|
+
session.list_instruments("binance", segment="spot") # a specific segment
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Backtest
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
# 1. prepare a data window -> a job id
|
|
130
|
+
acc = session.prepare(
|
|
131
|
+
exchange_id="binance", type_="ticker",
|
|
132
|
+
instrument="BTC/USDT", from_="2026-08-18", to="2026-08-19",
|
|
133
|
+
)
|
|
134
|
+
pid = acc.job_id
|
|
135
|
+
|
|
136
|
+
# 2. poll until Completed
|
|
137
|
+
import time
|
|
138
|
+
while True:
|
|
139
|
+
st = session.get_prepare_status(exchange_id="binance", type_="ticker", job_id=pid)
|
|
140
|
+
if st.status == "Completed":
|
|
141
|
+
break
|
|
142
|
+
time.sleep(3)
|
|
143
|
+
|
|
144
|
+
# 3. execute a compiled strategy over the prepared window
|
|
145
|
+
ex = session.execute(
|
|
146
|
+
exchange_id="binance", type_="ticker",
|
|
147
|
+
prepare_job_id=pid, strategy_id=sid,
|
|
148
|
+
)
|
|
149
|
+
jid = ex.job_id
|
|
150
|
+
|
|
151
|
+
# 4. poll the raw result (202 while running; parse results only on 200)
|
|
152
|
+
while True:
|
|
153
|
+
resp = session.get_backtest_result(exchange_id="binance", type_="ticker", job_id=jid)
|
|
154
|
+
if resp.status_code == 202:
|
|
155
|
+
time.sleep(3)
|
|
156
|
+
continue
|
|
157
|
+
resp.raise_for_status()
|
|
158
|
+
results = resp.json()["results"] # pnl, totalTrades, sharpeRatio, equityCurve...
|
|
159
|
+
break
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Sweep
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
accepted = session.sweep(
|
|
166
|
+
exchange_id="binance", type_="ticker",
|
|
167
|
+
request_id=pid, # the prepare job id
|
|
168
|
+
strategy_id=sid,
|
|
169
|
+
params={"cycle.seconds": {"values": [10, 20, 30]}}, # note: annotation name, not field
|
|
170
|
+
objective="sharpe",
|
|
171
|
+
)
|
|
172
|
+
swid = accepted.sweep_id
|
|
173
|
+
|
|
174
|
+
res = session.get_sweep_result(exchange_id="binance", type_="ticker", request_id=pid, sweep_id=swid)
|
|
175
|
+
for row in res.leaderboard:
|
|
176
|
+
print(row.rank, row.sharpe, row.params)
|
|
177
|
+
|
|
178
|
+
session.get_sweep_sensitivity(exchange_id="binance", type_="ticker", request_id=pid, sweep_id=swid)
|
|
179
|
+
session.get_sweep_run_equity_curve(..., run_ix=0) # a retained trial's curve
|
|
180
|
+
session.cancel_sweep(...)
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Datasets (bring your own data)
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
created = session.create_dataset(name="My BTC ticks", instrument="BTC/USDT")
|
|
187
|
+
# created.dataset_id, created.upload_id, created.upload.url (presigned R2 URL)
|
|
188
|
+
# PUT your CSV to created.upload.url (no auth header needed), then:
|
|
189
|
+
session.finalize_dataset_upload(dataset_id=created.dataset_id, upload_id=created.upload_id)
|
|
190
|
+
# poll:
|
|
191
|
+
state = session.get_dataset_upload(dataset_id=created.dataset_id, upload_id=created.upload_id)
|
|
192
|
+
# state.status == "ready" -> backtest against it with exchange_id="user":
|
|
193
|
+
acc = session.prepare(
|
|
194
|
+
exchange_id="user", type_="ticker", dataset_id=created.dataset_id,
|
|
195
|
+
dataset_version_id=state.version.id, from_=..., to=...,
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
session.list_datasets()
|
|
199
|
+
session.get_dataset(dataset_id)
|
|
200
|
+
session.delete_dataset(dataset_id)
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
To upload the file itself, pass the creation result or an upload session together
|
|
204
|
+
with a `pathlib.Path` (or an open binary file) to `upload_dataset_file`. The PUT
|
|
205
|
+
goes directly to the presigned URL without the session JWT or API key. A successful
|
|
206
|
+
PUT only stores the bytes; call `finalize_dataset_upload` to queue ingest.
|
|
207
|
+
|
|
208
|
+
```python
|
|
209
|
+
from pathlib import Path
|
|
210
|
+
|
|
211
|
+
session.upload_dataset_file(created, Path("BTC_USDT.csv"))
|
|
212
|
+
session.finalize_dataset_upload(dataset_id=created.dataset_id, upload_id=created.upload_id)
|
|
213
|
+
|
|
214
|
+
# Add a subsequent version after the earlier upload has finalized:
|
|
215
|
+
next_upload = session.open_dataset_upload(created.dataset_id)
|
|
216
|
+
session.upload_dataset_file(next_upload, Path("BTC_USDT_corrected.csv"))
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
`open_dataset_upload` is safe to retry while an upload is open: it returns the
|
|
220
|
+
same session. Once an upload has produced a version, its `upload_id` is spent;
|
|
221
|
+
`finalize_dataset_upload` returns `409` and a new session is required.
|
|
222
|
+
|
|
223
|
+
### Raw client access
|
|
224
|
+
|
|
225
|
+
Every workflow goes through the session's underlying generated
|
|
226
|
+
`AuthenticatedClient`. To call an endpoint the workflows don't wrap, or to
|
|
227
|
+
inspect a raw `Response`:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
from qtsurfer.api.client._generated.api.exchange import get_exchanges
|
|
231
|
+
|
|
232
|
+
session.call(lambda c: get_exchanges.sync(client=c)) # plain
|
|
233
|
+
resp = session.call(lambda c: get_exchanges.sync_detailed(client=c)) # raw Response
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
## Environment
|
|
237
|
+
|
|
238
|
+
| Variable | Purpose |
|
|
239
|
+
| ----------------- | ---------------------------------------------------- |
|
|
240
|
+
| `QTSURFER_APIKEY` | API key consumed by `auth()` when no arg is passed |
|
|
241
|
+
|
|
242
|
+
## Pluggable token storage
|
|
243
|
+
|
|
244
|
+
Tokens are kept in memory by default. Implement `TokenStore` (a `Protocol`) to
|
|
245
|
+
back them by file, secret manager, or keychain:
|
|
246
|
+
|
|
247
|
+
```python
|
|
248
|
+
import json
|
|
249
|
+
from pathlib import Path
|
|
250
|
+
from qtsurfer.api.client._generated.models import AuthTokenResponse
|
|
251
|
+
from qtsurfer_sdk import TokenStore, auth
|
|
252
|
+
|
|
253
|
+
class FileStore(TokenStore):
|
|
254
|
+
def __init__(self, path: Path): self.path = path
|
|
255
|
+
def load(self) -> AuthTokenResponse | None:
|
|
256
|
+
return AuthTokenResponse.from_dict(json.loads(self.path.read_text())) if self.path.exists() else None
|
|
257
|
+
def save(self, token: AuthTokenResponse) -> None: self.path.write_text(json.dumps(token.to_dict()))
|
|
258
|
+
def clear(self) -> None: self.path.unlink(missing_ok=True)
|
|
259
|
+
|
|
260
|
+
session = auth(store=FileStore(Path.home() / ".qtsurfer" / "token.json"))
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Error hierarchy
|
|
264
|
+
|
|
265
|
+
```python
|
|
266
|
+
from qtsurfer_sdk import QTSError, QTSAuthError, QTSPreparationError, QTSExecutionError
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
* `QTSError` — base for all SDK errors (carries optional `.status`).
|
|
270
|
+
* `QTSAuthError` — missing/invalid apikey, or non-2xx from `POST /auth/token`.
|
|
271
|
+
* `QTSCompileError` — `POST /strategy` could not compile/register.
|
|
272
|
+
* `QTSPreparationError` — a `prepare` stage failed.
|
|
273
|
+
* `QTSExecutionError` — a backtest/sweep execution failed.
|
|
274
|
+
* `QTSTimeoutError`, `QTSCanceledError`, `QTSDownloadError` — reserved (poll deadline, cancel, downloads).
|
|
275
|
+
|
|
276
|
+
## Roadmap
|
|
277
|
+
|
|
278
|
+
* **v0.1 — auth helper** ✅
|
|
279
|
+
* **v0.2 — high-level workflows** ✅ (strategies, catalog, backtest, sweep, datasets)
|
|
280
|
+
* **v0.3 — async overload** mirroring `*_asyncio` api-client variants
|
|
281
|
+
* **v0.4 — domain handles** (`Strategy`, `Backtest`) with progress callbacks
|
|
282
|
+
|
|
283
|
+
## License
|
|
284
|
+
|
|
285
|
+
Apache-2.0 — see [LICENSE](./LICENSE).
|