alphaboard 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,84 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ .venv/
8
+ venv/
9
+ env/
10
+ ENV/
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ *.egg-info/
18
+ *.egg
19
+ MANIFEST
20
+
21
+ # uv
22
+ .uv-cache/
23
+
24
+ # Testing / coverage
25
+ .pytest_cache/
26
+ .coverage
27
+ .coverage.*
28
+ htmlcov/
29
+ .tox/
30
+ .nox/
31
+ coverage.xml
32
+ *.cover
33
+ .hypothesis/
34
+
35
+ # Type checkers / linters
36
+ .mypy_cache/
37
+ .dmypy.json
38
+ .pyre/
39
+ .ruff_cache/
40
+
41
+ # Environment / secrets
42
+ .env
43
+ .env.local
44
+ .env.*.local
45
+ *.pem
46
+ *.key
47
+ secrets/
48
+
49
+ # IDE
50
+ .vscode/
51
+ .idea/
52
+ *.swp
53
+ *.swo
54
+ *~
55
+ .DS_Store
56
+ Thumbs.db
57
+
58
+ # Docker / data
59
+ postgres-data/
60
+ pgdata/
61
+ grafana-data/
62
+
63
+ # Logs
64
+ *.log
65
+ logs/
66
+
67
+ # Streamlit
68
+ .streamlit/secrets.toml
69
+
70
+ # Node (for future React dashboard)
71
+ node_modules/
72
+ .next/
73
+ out/
74
+ dist-frontend/
75
+
76
+ # OS / misc
77
+ *.bak
78
+ *.tmp
79
+
80
+ # Claude Code session config (personal permission allowlists)
81
+ .claude/
82
+
83
+ # VS Code workspace files (editor-local)
84
+ *.code-workspace
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,190 @@
1
+ Metadata-Version: 2.5
2
+ Name: alphaboard
3
+ Version: 0.1.0
4
+ Summary: AlphaBoard SDK — strategy-level monitoring for algorithmic traders. Pushes trades, positions, equity, and heartbeats to an AlphaBoard server without ever blocking your trading loop.
5
+ Project-URL: Homepage, https://github.com/opmau/AlphaBoard
6
+ Project-URL: Repository, https://github.com/opmau/AlphaBoard
7
+ Project-URL: Issues, https://github.com/opmau/AlphaBoard/issues
8
+ Project-URL: Documentation, https://github.com/opmau/AlphaBoard/tree/main/docs
9
+ Author-email: Adam King <adm.king@gmail.com>
10
+ License: Apache-2.0
11
+ License-File: LICENSE
12
+ Keywords: algotrading,monitoring,observability,quant,trading
13
+ Classifier: Development Status :: 3 - Alpha
14
+ Classifier: Intended Audience :: Financial and Insurance Industry
15
+ Classifier: License :: OSI Approved :: Apache Software License
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Office/Business :: Financial :: Investment
23
+ Classifier: Typing :: Typed
24
+ Requires-Python: >=3.10
25
+ Requires-Dist: httpx>=0.28.0
26
+ Requires-Dist: tomli>=2.0; python_version < '3.11'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # alphaboard
30
+
31
+ Python SDK for [AlphaBoard](https://github.com/opmau/AlphaBoard) — strategy-level monitoring and reconciliation for algorithmic traders. (Formerly `stratops`; renamed to the single brand in OPM-762.)
32
+
33
+ ```python
34
+ from alphaboard import AlphaBoard
35
+
36
+ tracker = AlphaBoard(
37
+ strategy="momentum_eth",
38
+ broker="hyperliquid",
39
+ account="main",
40
+ )
41
+
42
+ # Inside your trade execution function:
43
+ tracker.log_trade(symbol="ETH-PERP", side="buy", quantity=0.5, price=3800)
44
+
45
+ # Periodic sync:
46
+ tracker.sync_positions([{"symbol": "ETH-PERP", "quantity": 1.5, "avg_entry_price": 3750}])
47
+ tracker.log_equity(equity=50_000, cash=10_000)
48
+ tracker.heartbeat(open_positions=1)
49
+ ```
50
+
51
+ ## Configuration
52
+
53
+ Connection settings resolve in this order (highest priority first):
54
+
55
+ 1. **Constructor parameters** — `AlphaBoard(api_url=..., api_key=...)`
56
+ 2. **Environment variables** — `ALPHABOARD_API_URL`, `ALPHABOARD_API_KEY`
57
+ 3. **Config file** — `~/.alphaboard/config.toml` (override path via `ALPHABOARD_CONFIG`)
58
+ 4. **Built-in defaults** — `http://localhost:8000`, no key
59
+
60
+ The legacy `STRATOPS_*` env vars and `~/.stratops/config.toml` are still read
61
+ as a fallback (one-time deprecation warning) — switch to the new names.
62
+
63
+ Example `~/.alphaboard/config.toml`:
64
+
65
+ ```toml
66
+ api_url = "https://alphaboard.example.com"
67
+ api_key = "sk_..."
68
+ # Optional: turn on the durable spool (see below)
69
+ spool_dir = "C:/alphaboard-spool"
70
+ ```
71
+
72
+ ## Is it actually connected? (`alphaboard doctor`)
73
+
74
+ Installing the SDK and seeing no errors proves nothing — the SDK never raises,
75
+ by design, so a completely misconfigured client looks exactly like a working
76
+ one from inside your strategy. `alphaboard doctor` is the one command that
77
+ answers *am I being watched?*:
78
+
79
+ ```bash
80
+ alphaboard doctor
81
+ alphaboard doctor --api-url https://alphaboard.example.com --api-key sk_...
82
+ ```
83
+
84
+ It runs four checks in order and stops at the first failure, so you fix causes
85
+ rather than symptoms:
86
+
87
+ | Check | Answers |
88
+ | --- | --- |
89
+ | `api` | Is the server reachable, and is its database connected? |
90
+ | `auth` | Does your API key authenticate? |
91
+ | `probe` | Does ingestion accept a real write? |
92
+ | `coverage` | The census: every strategy and account, the age of each stream, and a verdict of LIVE / DEGRADED / SILENT. |
93
+
94
+ Exit codes make it usable from a scheduled task or a CI step: **2** if the API
95
+ or the key is broken, **1** if everything is reachable but something is not
96
+ reporting, **0** if all four pass.
97
+
98
+ Two properties are worth knowing about, because they are the difference between
99
+ a diagnostic and a placebo:
100
+
101
+ - **It creates nothing.** The write probe is a single infrastructure heartbeat
102
+ that deliberately carries **no strategy name**. A probe posted under a real
103
+ strategy would refresh that strategy's heartbeat stream *and* forward a
104
+ success ping to its external monitor — so a strategy that had been dead for a
105
+ day would read LIVE on the very next line of the diagnostic's own output, and
106
+ its real alert would be silenced. Pass `--no-probe` to skip the write
107
+ entirely and run read-only.
108
+ - **Zero strategies is a failure, not a pass.** "0/0 live" is technically full
109
+ coverage and is exactly the reassuring lie that hides a pipe that was never
110
+ connected.
111
+
112
+ ## Durable spool (no-data-loss mode)
113
+
114
+ By default the SDK buffers events in memory only — a crash or an extended
115
+ server outage can drop events (your trading is never affected either way).
116
+ Setting a `spool_dir` (constructor param, `ALPHABOARD_SPOOL_DIR`, or the config
117
+ file) turns on a disk-backed outbox:
118
+
119
+ ```python
120
+ tracker = AlphaBoard(strategy="momentum_eth", spool_dir="C:/alphaboard-spool")
121
+ ```
122
+
123
+ - Events are mirrored to a SQLite WAL file by the background worker and
124
+ deleted only after the server confirms receipt — they survive `SIGKILL`,
125
+ power loss, and outages of any length.
126
+ - Replays reuse the **same** idempotency keys and carry the **original**
127
+ event timestamps, so the server deduplicates them: at-least-once on the
128
+ wire, effectively-once end-to-end.
129
+ - The spool is bounded by rows, bytes, and age (defaults: 1M rows / 512 MB /
130
+ 7 days; tune via `spool_max_rows`, `spool_max_bytes`, `spool_max_age_s`).
131
+ On breach it drops oldest and surfaces the count via
132
+ `tracker.spool_dropped_count` — an indefinite outage can't fill your disk.
133
+ - Any spool failure (disk full, locked, corrupt) degrades the SDK back to
134
+ memory-only. Durability never becomes a new way to crash the host.
135
+
136
+ ## Backfill (historical seeding + gap recovery)
137
+
138
+ `alphaboard backfill` replays a historical CSV — a broker statement, a Zorro
139
+ log, your engine's own journal — through the server's batch endpoints with
140
+ **deterministic** idempotency keys (UUIDv5 of each row's business key), so
141
+ re-running the same file or window is a no-op, never a duplicate:
142
+
143
+ ```bash
144
+ alphaboard backfill trades.csv --kind trades --strategy momo --broker ib --account main
145
+ alphaboard backfill equity.csv --kind equity --strategy momo --mapping '{"Time": "snapshot_at", "Equity": "equity"}'
146
+ alphaboard backfill positions.csv --kind positions --strategy momo --broker ib --account main --dry-run
147
+ ```
148
+
149
+ - `--kind` is `trades`, `equity`, or `positions`; `--mapping` renames CSV
150
+ headers to canonical fields (same convention as the server's CSV import).
151
+ - `--strategy/--broker/--account` fill in routing fields the CSV doesn't
152
+ carry; columns present in the file win.
153
+ - `--since/--until` window on the row's *event* time; `--dry-run` validates
154
+ and counts without sending.
155
+ - Rows must carry their original `executed_at`/`snapshot_at` — backfill
156
+ refuses to stamp wall-clock-at-import times onto history.
157
+ - Also available in code: `tracker.backfill("trades.csv", kind="trades")`.
158
+
159
+ ## Design
160
+
161
+ The SDK is **observation-path only**. It never sits between your strategy and the broker. The single hard guarantee:
162
+
163
+ > `tracker.log_trade(...)` returns in microseconds, never blocks, and never raises.
164
+
165
+ Every public method enqueues an event into a bounded in-memory deque (default 10 000 items, drop-oldest on overflow), and returns immediately. A daemon background thread batches events, posts them to the AlphaBoard API with exponential backoff, and never lets an exception escape back to user code.
166
+
167
+ If the AlphaBoard server is unreachable, events back up in the queue until it returns or the queue overflows. **Your trading continues unaffected.**
168
+
169
+ On process shutdown, an `atexit` hook drains the queue with a bounded timeout (default 5s) so events from the final loop iteration aren't lost.
170
+
171
+ ## Install
172
+
173
+ ```bash
174
+ pip install alphaboard
175
+ ```
176
+
177
+ That pulls in `httpx` and its transitive dependencies and nothing else —
178
+ eight packages total. The SDK deliberately has no dependency on the API server,
179
+ the dashboard, or anything else in the workspace, so it installs cleanly into a
180
+ strategy process that shares none of them.
181
+
182
+ Working on the SDK itself? Install it from a checkout instead:
183
+
184
+ ```bash
185
+ pip install ./packages/sdk
186
+ ```
187
+
188
+ ## Licence
189
+
190
+ Apache 2.0.
@@ -0,0 +1,162 @@
1
+ # alphaboard
2
+
3
+ Python SDK for [AlphaBoard](https://github.com/opmau/AlphaBoard) — strategy-level monitoring and reconciliation for algorithmic traders. (Formerly `stratops`; renamed to the single brand in OPM-762.)
4
+
5
+ ```python
6
+ from alphaboard import AlphaBoard
7
+
8
+ tracker = AlphaBoard(
9
+ strategy="momentum_eth",
10
+ broker="hyperliquid",
11
+ account="main",
12
+ )
13
+
14
+ # Inside your trade execution function:
15
+ tracker.log_trade(symbol="ETH-PERP", side="buy", quantity=0.5, price=3800)
16
+
17
+ # Periodic sync:
18
+ tracker.sync_positions([{"symbol": "ETH-PERP", "quantity": 1.5, "avg_entry_price": 3750}])
19
+ tracker.log_equity(equity=50_000, cash=10_000)
20
+ tracker.heartbeat(open_positions=1)
21
+ ```
22
+
23
+ ## Configuration
24
+
25
+ Connection settings resolve in this order (highest priority first):
26
+
27
+ 1. **Constructor parameters** — `AlphaBoard(api_url=..., api_key=...)`
28
+ 2. **Environment variables** — `ALPHABOARD_API_URL`, `ALPHABOARD_API_KEY`
29
+ 3. **Config file** — `~/.alphaboard/config.toml` (override path via `ALPHABOARD_CONFIG`)
30
+ 4. **Built-in defaults** — `http://localhost:8000`, no key
31
+
32
+ The legacy `STRATOPS_*` env vars and `~/.stratops/config.toml` are still read
33
+ as a fallback (one-time deprecation warning) — switch to the new names.
34
+
35
+ Example `~/.alphaboard/config.toml`:
36
+
37
+ ```toml
38
+ api_url = "https://alphaboard.example.com"
39
+ api_key = "sk_..."
40
+ # Optional: turn on the durable spool (see below)
41
+ spool_dir = "C:/alphaboard-spool"
42
+ ```
43
+
44
+ ## Is it actually connected? (`alphaboard doctor`)
45
+
46
+ Installing the SDK and seeing no errors proves nothing — the SDK never raises,
47
+ by design, so a completely misconfigured client looks exactly like a working
48
+ one from inside your strategy. `alphaboard doctor` is the one command that
49
+ answers *am I being watched?*:
50
+
51
+ ```bash
52
+ alphaboard doctor
53
+ alphaboard doctor --api-url https://alphaboard.example.com --api-key sk_...
54
+ ```
55
+
56
+ It runs four checks in order and stops at the first failure, so you fix causes
57
+ rather than symptoms:
58
+
59
+ | Check | Answers |
60
+ | --- | --- |
61
+ | `api` | Is the server reachable, and is its database connected? |
62
+ | `auth` | Does your API key authenticate? |
63
+ | `probe` | Does ingestion accept a real write? |
64
+ | `coverage` | The census: every strategy and account, the age of each stream, and a verdict of LIVE / DEGRADED / SILENT. |
65
+
66
+ Exit codes make it usable from a scheduled task or a CI step: **2** if the API
67
+ or the key is broken, **1** if everything is reachable but something is not
68
+ reporting, **0** if all four pass.
69
+
70
+ Two properties are worth knowing about, because they are the difference between
71
+ a diagnostic and a placebo:
72
+
73
+ - **It creates nothing.** The write probe is a single infrastructure heartbeat
74
+ that deliberately carries **no strategy name**. A probe posted under a real
75
+ strategy would refresh that strategy's heartbeat stream *and* forward a
76
+ success ping to its external monitor — so a strategy that had been dead for a
77
+ day would read LIVE on the very next line of the diagnostic's own output, and
78
+ its real alert would be silenced. Pass `--no-probe` to skip the write
79
+ entirely and run read-only.
80
+ - **Zero strategies is a failure, not a pass.** "0/0 live" is technically full
81
+ coverage and is exactly the reassuring lie that hides a pipe that was never
82
+ connected.
83
+
84
+ ## Durable spool (no-data-loss mode)
85
+
86
+ By default the SDK buffers events in memory only — a crash or an extended
87
+ server outage can drop events (your trading is never affected either way).
88
+ Setting a `spool_dir` (constructor param, `ALPHABOARD_SPOOL_DIR`, or the config
89
+ file) turns on a disk-backed outbox:
90
+
91
+ ```python
92
+ tracker = AlphaBoard(strategy="momentum_eth", spool_dir="C:/alphaboard-spool")
93
+ ```
94
+
95
+ - Events are mirrored to a SQLite WAL file by the background worker and
96
+ deleted only after the server confirms receipt — they survive `SIGKILL`,
97
+ power loss, and outages of any length.
98
+ - Replays reuse the **same** idempotency keys and carry the **original**
99
+ event timestamps, so the server deduplicates them: at-least-once on the
100
+ wire, effectively-once end-to-end.
101
+ - The spool is bounded by rows, bytes, and age (defaults: 1M rows / 512 MB /
102
+ 7 days; tune via `spool_max_rows`, `spool_max_bytes`, `spool_max_age_s`).
103
+ On breach it drops oldest and surfaces the count via
104
+ `tracker.spool_dropped_count` — an indefinite outage can't fill your disk.
105
+ - Any spool failure (disk full, locked, corrupt) degrades the SDK back to
106
+ memory-only. Durability never becomes a new way to crash the host.
107
+
108
+ ## Backfill (historical seeding + gap recovery)
109
+
110
+ `alphaboard backfill` replays a historical CSV — a broker statement, a Zorro
111
+ log, your engine's own journal — through the server's batch endpoints with
112
+ **deterministic** idempotency keys (UUIDv5 of each row's business key), so
113
+ re-running the same file or window is a no-op, never a duplicate:
114
+
115
+ ```bash
116
+ alphaboard backfill trades.csv --kind trades --strategy momo --broker ib --account main
117
+ alphaboard backfill equity.csv --kind equity --strategy momo --mapping '{"Time": "snapshot_at", "Equity": "equity"}'
118
+ alphaboard backfill positions.csv --kind positions --strategy momo --broker ib --account main --dry-run
119
+ ```
120
+
121
+ - `--kind` is `trades`, `equity`, or `positions`; `--mapping` renames CSV
122
+ headers to canonical fields (same convention as the server's CSV import).
123
+ - `--strategy/--broker/--account` fill in routing fields the CSV doesn't
124
+ carry; columns present in the file win.
125
+ - `--since/--until` window on the row's *event* time; `--dry-run` validates
126
+ and counts without sending.
127
+ - Rows must carry their original `executed_at`/`snapshot_at` — backfill
128
+ refuses to stamp wall-clock-at-import times onto history.
129
+ - Also available in code: `tracker.backfill("trades.csv", kind="trades")`.
130
+
131
+ ## Design
132
+
133
+ The SDK is **observation-path only**. It never sits between your strategy and the broker. The single hard guarantee:
134
+
135
+ > `tracker.log_trade(...)` returns in microseconds, never blocks, and never raises.
136
+
137
+ Every public method enqueues an event into a bounded in-memory deque (default 10 000 items, drop-oldest on overflow), and returns immediately. A daemon background thread batches events, posts them to the AlphaBoard API with exponential backoff, and never lets an exception escape back to user code.
138
+
139
+ If the AlphaBoard server is unreachable, events back up in the queue until it returns or the queue overflows. **Your trading continues unaffected.**
140
+
141
+ On process shutdown, an `atexit` hook drains the queue with a bounded timeout (default 5s) so events from the final loop iteration aren't lost.
142
+
143
+ ## Install
144
+
145
+ ```bash
146
+ pip install alphaboard
147
+ ```
148
+
149
+ That pulls in `httpx` and its transitive dependencies and nothing else —
150
+ eight packages total. The SDK deliberately has no dependency on the API server,
151
+ the dashboard, or anything else in the workspace, so it installs cleanly into a
152
+ strategy process that shares none of them.
153
+
154
+ Working on the SDK itself? Install it from a checkout instead:
155
+
156
+ ```bash
157
+ pip install ./packages/sdk
158
+ ```
159
+
160
+ ## Licence
161
+
162
+ Apache 2.0.
@@ -0,0 +1,30 @@
1
+ """alphaboard — Python SDK for AlphaBoard.
2
+
3
+ Quick start:
4
+
5
+ from alphaboard import AlphaBoard
6
+
7
+ tracker = AlphaBoard(
8
+ strategy="momentum_eth",
9
+ broker="hyperliquid",
10
+ account="main",
11
+ # api_url and api_key fall back to ALPHABOARD_API_URL / ALPHABOARD_API_KEY
12
+ )
13
+
14
+ tracker.log_trade(symbol="ETH-PERP", side="buy", quantity=0.5, price=3800)
15
+ tracker.heartbeat(open_positions=1)
16
+
17
+ The SDK is observation-path only. `log_trade()` enqueues and returns in
18
+ microseconds — it never blocks the trading loop and never raises. A daemon
19
+ background thread batches events, posts them with exponential backoff, and
20
+ suppresses all exceptions.
21
+ """
22
+
23
+ from alphaboard._backfill import BackfillError, BackfillResult
24
+
25
+ # `StratOps` is the deprecated pre-rename alias (OPM-762), re-exported only so
26
+ # the burn-in VPS keeps importing until it picks up the rename.
27
+ from alphaboard.client import AlphaBoard, StratOps
28
+
29
+ __version__ = "0.1.0"
30
+ __all__ = ["AlphaBoard", "BackfillError", "BackfillResult", "StratOps", "__version__"]