Python SDK for the Smartbroker+ B2B API
Project description
smartbroker-plus-sdk
Typed Python SDK and CLI for the for the Smartbroker+ B2B API.
[!WARNING] Alpha — the public surface may still change. Unofficial project, not affiliated with Smartbroker+.
Features
- OAuth2 Authorization Code + PKCE helpers — full RFC 7636 implementation; the SDK handles token exchange, refresh, and revocation.
- Sync and async parity —
SmartbrokerClientandAsyncSmartbrokerClientexpose identical resource surfaces. - Full B2B resource coverage — orders, order modifications, portfolios, positions, account transactions, market state, tradeability, cost report, and profile.
- 2FA token header support — automatic
X-2fa-Tokeninjection for order-modifying endpoints. - Typed end-to-end — Pydantic v2 models throughout, ships
py.typed. - RFC 9457 error mapping — HTTP problem details mapped to a typed exception hierarchy.
- Python 3.11+
Quick Start (sync)
from smartbroker_plus_sdk import SmartbrokerClient, generate_code_verifier, generate_code_challenge
# 1. Generate PKCE pair before starting the authorization flow
verifier = generate_code_verifier()
challenge = generate_code_challenge(verifier)
# → Send `challenge` as `code_challenge` in the authorization URL
# 2. Create a client — it handles token exchange and refresh internally
client = SmartbrokerClient(
base_url="https://api.smartbroker.de",
token_url="https://auth.smartbroker.de/.../token",
api_key="your_api_key",
client_id="your_client_id",
client_secret="your_client_secret",
)
# 3. Exchange the authorization code for tokens
tokens = client.exchange_authorization_code(
code="authorization_code_from_callback",
redirect_uri="https://your-app.com/callback",
code_verifier=verifier,
)
# 4. Use resources
profile = client.profile.get_account_numbers()
print(profile.account_number)
Quick Start (async)
import asyncio
from smartbroker_plus_sdk import AsyncSmartbrokerClient, generate_code_verifier, generate_code_challenge
async def main() -> None:
verifier = generate_code_verifier()
challenge = generate_code_challenge(verifier)
client = AsyncSmartbrokerClient(
base_url="https://api.smartbroker.de",
token_url="https://auth.smartbroker.de/.../token",
api_key="your_api_key",
client_id="your_client_id",
client_secret="your_client_secret",
)
await client.exchange_authorization_code(
code="authorization_code_from_callback",
redirect_uri="https://your-app.com/callback",
code_verifier=verifier,
)
profile = await client.profile.get_account_numbers()
print(profile.account_number)
asyncio.run(main())
Error Handling
All SDK errors extend SmartbrokerApiError:
SmartbrokerApiError
├── AuthenticationError # HTTP 401 — invalid/expired credentials
├── AuthorizationError # HTTP 403 — insufficient permissions
├── NotFoundError # HTTP 404 — resource does not exist
├── ValidationError # HTTP 400/412 — request validation failed
│ ├── OrderRejectedError # messageKey: ORDER_REJECTED
│ ├── InsufficientBalanceError # messageKey: INSUFFICIENT_BALANCE
│ └── BuyingPowerExceededError # messageKey: BUYINGPOWER_EXCEEDED
├── ServerError # HTTP 5xx — vendor server-side failure
├── TwoFactorError # 2FA token flow failed (timeout, rejection)
└── RetryExhaustedError # all retry attempts exhausted
from smartbroker_plus_sdk.exceptions import SmartbrokerApiError, ValidationError
try:
client.orders.create(...)
except ValidationError as e:
print(f"Validation failed: {e}")
except SmartbrokerApiError as e:
print(f"API error: {e}")
CLI Quick Start
Install the package and run the CLI with sbplus:
# 1. Set credentials (or use env vars — see table below)
export SMARTBROKER_CLIENT_ID=my-client-id
export SMARTBROKER_CLIENT_SECRET=my-client-secret # or enter at the prompt
# 2. Log in — prompts for environment (sand/prod), then opens browser for PKCE flow
sbplus auth login
# > Environment [sand/prod] (prod): prod
# > Credentials will be stored at ~/.cache/smartbroker-plus-sdk/tokens.json. Continue? [Y/n]:
# 3. Check status and browse data
sbplus auth status
sbplus portfolios list
sbplus orders list --portfolio <portfolioId>
# 4. Log out
sbplus auth logout
Use --output (or -o) to change the format: table (default), wide, detail, json.
For terminal demo recordings see docs/cast/.
Environment Variables
| Variable | Flag | Description |
|---|---|---|
SMARTBROKER_BASE_URL |
--base-url |
API base URL |
SMARTBROKER_ENV |
--env |
Deployment environment (sand or prod) |
SMARTBROKER_AUTH_BASE_URL |
--auth-base-url |
Auth/IdP base URL (defaults to --base-url) |
SMARTBROKER_API_KEY |
--api-key |
API key |
SMARTBROKER_CLIENT_ID |
--client-id |
OAuth2 client ID |
SMARTBROKER_CLIENT_SECRET |
--client-secret |
OAuth2 client secret |
SMARTBROKER_REDIRECT_URI |
--redirect-uri |
OAuth2 redirect URI (default: http://127.0.0.1:8765/callback) |
SMARTBROKER_CACHE_DIR |
--cache-dir |
Token cache directory |
SMARTBROKER_OUTPUT |
--output / -o |
Default output format (table, wide, detail, json) |
SMARTBROKER_TIMEOUT |
--timeout |
HTTP request timeout in seconds (default: 30) |
Exit Codes
| Code | Meaning |
|---|---|
0 |
Success |
1 |
General error / unexpected exception |
2 |
Authentication or authorization failure |
3 |
Resource not found |
4 |
Validation error |
5 |
Server error |
6 |
2FA required |
7 |
Retry limit exhausted |
130 |
Interrupted (Ctrl-C) |
Troubleshooting
See docs/troubleshooting.md for common gotchas.
Changelog
See CHANGELOG.md.
Development
See docs/development.md for the full development guide.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file smartbroker_plus_sdk-0.4.0.tar.gz.
File metadata
- Download URL: smartbroker_plus_sdk-0.4.0.tar.gz
- Upload date:
- Size: 98.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52421d11c445a0f98ec1242e4260b8d3777281bd1694718b301bcea2d8ca8c9d
|
|
| MD5 |
731bc81107f97b2b077f9411582ab70f
|
|
| BLAKE2b-256 |
9ab901a02ad72d8d67b0875277c937a5ce80b57b1cb9200ad7d72950f3c365f0
|
Provenance
The following attestation bundles were made for smartbroker_plus_sdk-0.4.0.tar.gz:
Publisher:
release_publishing.yml on stevenengland/smartbroker-plus-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smartbroker_plus_sdk-0.4.0.tar.gz -
Subject digest:
52421d11c445a0f98ec1242e4260b8d3777281bd1694718b301bcea2d8ca8c9d - Sigstore transparency entry: 1447553786
- Sigstore integration time:
-
Permalink:
stevenengland/smartbroker-plus-sdk@3e0af433cff982d28c9c2977d21d981e33857a89 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stevenengland
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_publishing.yml@3e0af433cff982d28c9c2977d21d981e33857a89 -
Trigger Event:
push
-
Statement type:
File details
Details for the file smartbroker_plus_sdk-0.4.0-py3-none-any.whl.
File metadata
- Download URL: smartbroker_plus_sdk-0.4.0-py3-none-any.whl
- Upload date:
- Size: 127.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
85db927fe6481dbb3feb9e56ee1a0dcd3e3b75fdfa0da2a6d36a3b3b0ea72d90
|
|
| MD5 |
b6137f47eaa43138a15fe2a3c7926747
|
|
| BLAKE2b-256 |
1b5c5f1c83acd3c2220da576b07913d3d02f77fc1f22baf2026ba5c3a4e65f86
|
Provenance
The following attestation bundles were made for smartbroker_plus_sdk-0.4.0-py3-none-any.whl:
Publisher:
release_publishing.yml on stevenengland/smartbroker-plus-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
smartbroker_plus_sdk-0.4.0-py3-none-any.whl -
Subject digest:
85db927fe6481dbb3feb9e56ee1a0dcd3e3b75fdfa0da2a6d36a3b3b0ea72d90 - Sigstore transparency entry: 1447553872
- Sigstore integration time:
-
Permalink:
stevenengland/smartbroker-plus-sdk@3e0af433cff982d28c9c2977d21d981e33857a89 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/stevenengland
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release_publishing.yml@3e0af433cff982d28c9c2977d21d981e33857a89 -
Trigger Event:
push
-
Statement type: