Skip to main content

Broker SDK for Python. Every broker. One schema. Your keys never leave your machine.

PyPI version CI MIT license

TypeScript SDK  ·  Schema  ·  PyPI  ·  MCP server

Broker SDK is a LuxAlgo open-source project. Official repository: github.com/LuxAlgo/broker-py

Connect Python to real brokerage and exchange accounts. The same normalized schema, the same 22 brokers, and the same golden conformance vectors as the TypeScript SDK, so the two SDKs are provably identical in behavior. Point it at Charles Schwab, Alpaca, Robinhood Crypto, Binance, Kraken, Interactive Brokers and more. Get back the same clean picture from every one of them: accounts, balances, positions, trade history, and computed performance stats.

It runs where your code runs: no hosted service, no telemetry, and zero dependencies (the standard library is the whole toolbox).

pip install luxalgo-broker-sdk

Your portfolio in five lines

from broker_sdk import connect

kraken = connect("kraken", {"apiKey": api_key, "apiSecret": api_secret})
snapshot = kraken.fetch_snapshot()
print(snapshot.accounts)  # normalized: equity, positions, trades

Every broker returns the same shape. Learn it once:

@dataclass
class Account:
    id: str                   # broker-side stable id, safe as an upsert key
    name: str
    currency: str             # ISO 4217
    equity: float             # total account value
    cash: float | None        # when the broker reports it separately
    environment: str | None   # "live" or "paper"
    positions: list[Position] # symbol, quantity (negative = short), market_value, ...
    trades: list[Trade]       # symbol, side, quantity, price, fee, executed_at

Account.to_dict() emits the canonical camelCase JSON shape shared with the TypeScript SDK, omitting unset fields. A missing value is more honest than a guessed one.

Your whole portfolio, every broker at once

from broker_sdk import create_portfolio
from broker_sdk.stats import compute_stats, stats_accounts

portfolio = create_portfolio()
portfolio.add("alpaca", {"apiKey": key, "apiSecret": secret})
portfolio.add("binance", {"apiKey": key2, "apiSecret": secret2})
portfolio.add("hyperliquid", {"walletAddress": address})

result = portfolio.fetch_all()
stats = compute_stats(stats_accounts(result.snapshots))
print(stats.total_equity, stats.trades.win_rate, stats.top_positions)

One broker failing never takes down the sweep: result.failures comes back alongside the snapshots that succeeded. The stats engine does FIFO round-trip matching, win rate, average win and loss, and per-symbol activity. A sell with no recorded buy is ignored, never guessed at.

Import any broker statement

No API? Any account at any institution is importable from a trade-history CSV. The parser is tolerant on headers (brokers disagree on column names) and strict on rows (anything unreadable is skipped and counted, never guessed):

from broker_sdk.statement_csv import parse_statement_csv, positions_from_trades

parsed = parse_statement_csv(csv_text)
print(len(parsed.trades), "trades,", parsed.skipped_rows, "rows skipped")
print(positions_from_trades(parsed.trades))  # net open positions

Supported brokers

The same 22 as the TypeScript SDK: Alpaca, Binance, Bybit, Charles Schwab, Coinbase, Crypto.com Exchange, E*TRADE, Gemini, Hyperliquid, Interactive Brokers (Flex), Kraken, KuCoin, OKX, Public.com, Questrade, Robinhood Crypto, tastytrade, Topstep (ProjectX), TradeStation, Tradier, Trading212, Webull (OpenAPI), plus any broker via CSV import. The full credentials table lives in the broker-sdk README.

list_brokers() returns every adapter with its exact credential fields and a one-line guide to creating the key with read-only scope, which is all this SDK ever needs.

Sanctioned APIs only. If a broker does not officially support programmatic access for its users, it is not in this repo: no scraping, no reverse-engineered private APIs, ever. OAuth brokers where you register your own free developer app (Charles Schwab, TradeStation, E*TRADE, Coinbase) are supported bring-your-own-app style.

Read-only, local-only, by design

  • Your keys stay yours. The SDK runs where your code runs. There is no LuxAlgo server in the path, no telemetry, no phoning home.
  • Read-only. The Python SDK reads accounts, balances, positions, and history. It has no order placement at all (the TypeScript SDK's experimental write layer has no Python counterpart yet).
  • Credential rotation is first-class. Brokers with single-use tokens (Questrade) hand the rotated credentials back through on_credentials_rotated so you can persist them before the old ones die.
  • Fail-soft, never fabricate. A position the broker can't price has no market_value rather than a made-up one. A history row that can't be read is skipped and counted, not guessed.

The conformance kit

The vectors in conformance/vectors/ are copied verbatim from the TypeScript SDK: one per adapter, pairing a raw provider payload with the exact normalized output. Every adapter splits into an IO-only fetch_raw and a pure normalize, and CI asserts normalize reproduces every vector byte-for-byte. That is what "the same SDK in two languages" means here: not a similar API, the same proven mapping.

Runtime

Python 3.10+. Zero runtime dependencies (urllib for HTTP, hmac/hashlib for request signing, and a pure-Python RFC 8032 Ed25519 signer for Robinhood Crypto). Fully typed (py.typed). Synchronous API; Portfolio.fetch_all() sweeps connections concurrently with a thread pool. Bring your own persistence: to_dict() makes every snapshot plain JSON.

The suite

Package What it is
@luxalgo/broker-sdk The TypeScript SDK and reference implementation
luxalgo-broker-sdk (this repo) The Python SDK, gated by the same conformance vectors
@luxalgo/mcp The LuxAlgo MCP server; its local broker_* tools give AI agents read-only portfolio access

Contributing

New adapters land in the TypeScript SDK first (that repo owns the schema and the vectors), then port here against the same vector. See CONTRIBUTING.md. Sign your commits with git commit -s.

Disclaimer

This software reports what your broker reports. It is not investment advice, and nothing in it recommends any trade. Use at your own risk; verify important numbers against your broker's own statements.

License

MIT © LuxAlgo Global, LLC. The "Broker SDK" and "LuxAlgo" names and the LuxAlgo logo are trademarks of LuxAlgo Global, LLC; see TRADEMARKS.md. Security reports: SECURITY.md.

Download files

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

Source Distribution

luxalgo_broker_sdk-0.2.0.tar.gz (74.9 kB view details)

Uploaded Source

Built Distribution

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

luxalgo_broker_sdk-0.2.0-py3-none-any.whl (79.8 kB view details)

Uploaded Python 3

File details

Details for the file luxalgo_broker_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: luxalgo_broker_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 74.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.7

File hashes

Hashes for luxalgo_broker_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 72040481b6a25ac88ee0cf63e692eaa1a7283756d9457cb77ce0c3768be493ea
MD5 56be0e0edf8355adcb2547b3de144947
BLAKE2b-256 cffcec8769331518615c8c04997da50d63a9454d914821f859e61d31ea7cd8e2

See more details on using hashes here.

File details

Details for the file luxalgo_broker_sdk-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for luxalgo_broker_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bf0c4cb6188994ecb21313e74ddfd29d36b951d8db94fbd20103cfc7d6b832e0
MD5 341d202b3d0c32b9989214ab25285a3b
BLAKE2b-256 e145070c1b5c338fb1cd5162721661db8ad49064a330e00d4dd76b8879ec8693

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.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