longtrader-sdk (Python)
Tier-2 thin wrapper over the generated longtrader Connect stubs. Hand-written
code stays minimal — session handling plus overflow policies — while all
trading semantics live in the contract (proto/, buf-managed).
Installation
pip install longtrader-sdk
The published wheel bundles the generated protobuf stubs, so no code-generation
step is required for end users. Generate stubs locally only when building from
source (repo just sdk-generate).
Requirements: Python >= 3.10.
Canonical layout (design doc §6.8)
| Canonical dir | This SDK |
|---|---|
contract/ |
longtrader_sdk/proto/ — generated by just sdk-generate, never hand-edited |
session/ |
longtrader_sdk/session.py — attach / keep-alive / reconcile / kill-switch |
ports/ |
longtrader_sdk/ports.py — TradingPort, MarketPort, OverflowPolicy |
adapters/ |
thin by design: Connect-over-httpx inside session.py; mock adapter planned |
strategies/ |
examples/grid_strategy.py — the same grid ships in every language |
examples/ |
examples/ |
Concept names match the TypeScript/Rust wrappers 1:1 (Session,
TradingPort, MarketPort, sync_state(), OverflowPolicy).
Proto namespaces
| Service | Proto package | Stubs | Notes |
|---|---|---|---|
| market | longtrader.market.v1 |
longtrader_sdk/proto/longtrader/market/v1/ |
candles, ticker, order book |
| trading | longtrader.trading.v1 |
longtrader_sdk/proto/longtrader/trading/v1/ |
orders, positions, account |
| worker | longtrader.worker.v1 |
longtrader_sdk/proto/longtrader/worker/v1/ |
session lifecycle |
| data | longtrader.data.v1 |
longtrader_sdk/proto/longtrader/data/v1/ |
dataset download/list/validate/delete, streaming DownloadProgress with dataset_id |
| backtest | longtrader.backtest.v1 |
longtrader_sdk/proto/longtrader/backtest/v1/ |
Start/Cancel/ListRuns/GetReport/StartReplaySession, FinalReport.equity_curve_json + report_path persisted |
Generated stubs are produced by just sdk-generate into longtrader_sdk/proto/ (never hand-edit).
Quickstart
just sdk-generate # generates stubs into longtrader_sdk/proto/
pip install -e sdks/python
python sdks/python/examples/grid_strategy.py --help
Minimal use:
from longtrader_sdk import Session
s = Session.attach("http://127.0.0.1:8080", token="YOUR_TERMINAL_TOKEN")
s.start_heartbeat()
snapshot = s.reconcile_state() # gate to ACTIVE; pre-ACTIVE orders are rejected
print(s.session_id, s.state, snapshot.snapshot_sequence)
s.close()
Wire notes
- Unary calls:
POST {base}/longtrader.worker.v1.WorkerSessionService/{Method},Content-Type: application/proto; errors arrive as non-200 JSON bodies surfaced asConnectError(.code,.details). - Server-streaming uses
application/connect+protowith 5-byte envelopes (1 flag byte + u32 big-endian length; flag0x02= end-of-stream JSON). See../docs/bare-protocol-guide.mdsections 4–5. - Auth is the existing terminal API token passed to
AttachSession. OverflowPolicygoverns event-queue behavior under slow consumers (DROP_OLDESTpreserves newest,COALESCElast-writer-wins,BLOCKapplies backpressure); sequence gaps require snapshot resync/reconcile.common.v1.Decimalis one field: the number in base 10. There is no numeric twin beside it, so there is no precedence to get wrong and no silent zero when a producer picks the other form.to_decimalwrites it and validates the grammar the message documents;from_decimalreads it back into adecimal.Decimal, which is exact — a 96-bit coefficient over 28 decimal places survives it intact. A value too wide or too deep for a decimal is rejected, never truncated, and a payload nobody populated is an error rather than a zero.
License
Apache-2.0 — see the repository LICENSE.
Metadata
Release files for longtrader-sdk 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| longtrader_sdk-0.2.1.tar.gz | 75.7 kB | Without provenance | Details for longtrader_sdk-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| longtrader_sdk-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for longtrader_sdk-0.2.1-py3-none-any.whl |
Total release size: 159.8 kB
Release files / longtrader_sdk-0.2.1.tar.gz
| Download URL | longtrader_sdk-0.2.1.tar.gz |
|---|---|
| Size | 75.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6a89c6572ed28232d12edc2e8ef173d2a368d04afff305f27dc7c0a5320ace24
|
|
BLAKE2b-256 checksum How to use checksums |
34a598c5f2462e579894282ca4a0d5dce45e4c1d14c1166a678c779e6e0ba2f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Release files / longtrader_sdk-0.2.1-py3-none-any.whl
| Download URL | longtrader_sdk-0.2.1-py3-none-any.whl |
|---|---|
| Size | 84.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91bcbbb4ed7e52a617bf1b2f3db7e2ce9d0b6e7dd39b061050ba30f9c675b2eb
|
|
BLAKE2b-256 checksum How to use checksums |
cb8ad3ef692bfc216543273c375c5eb668021284194ecc0be88391646526b4dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.15
|
Security for longtrader-sdk 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.