Skip to main content

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.pyTradingPort, 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 as ConnectError (.code, .details).
  • Server-streaming uses application/connect+proto with 5-byte envelopes (1 flag byte + u32 big-endian length; flag 0x02 = end-of-stream JSON). See docs/bare-protocol-guide.md sections 4–5.
  • Auth is the existing terminal API token passed to AttachSession.
  • OverflowPolicy governs event-queue behavior under slow consumers (DROP_OLDEST preserves newest, COALESCE last-writer-wins, BLOCK applies backpressure); sequence gaps require snapshot resync/reconcile.

License

Apache-2.0 — see the repository LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

longtrader_sdk-0.1.0.tar.gz (44.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

longtrader_sdk-0.1.0-py3-none-any.whl (64.2 kB view details)

Uploaded Python 3

File details

Details for the file longtrader_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: longtrader_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 44.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for longtrader_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5eb576eecdd4591829e3504e90d548798f5e9ffd85f9d62014303a3f5e850604
MD5 8a9f7cb23f48c977d6fc62127004dc60
BLAKE2b-256 908767ccab063fffccd08e4526537a2961e90759327983b40559ccee7a8acafa

See more details on using hashes here.

File details

Details for the file longtrader_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: longtrader_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 64.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.14.7

File hashes

Hashes for longtrader_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b953b6208e181192b40c4bc7d2bed0d6530f8196805da9199b9a015c1df2aa8
MD5 a65082c15c0e0e14849760d40a3ab7c0
BLAKE2b-256 8911807ed00aa0cbdb3d69f4d958249210e55f7fd666b141f2bdb967ffc3826f

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page