Client Initialization
Use Environment Variables
Keep configuration out of source code. The SDK does not auto-load environment variables — read them yourself and pass them tocreate().
For the conventional variable names and a full snippet in both languages, see Installation.
Use a Singleton Client
Create one client instance and reuse it throughout your application:Error Handling
Always Handle Errors
Wrap SDK calls in try/catch blocks and handle specific error types. The minimum worth branching on is shown below; Troubleshooting has the exhaustive version.Check Retryability
Never retry blindly. Every error exposesisRetryable() / is_retryable(), which already encodes which failures can succeed on a second attempt — use it instead of matching on status codes yourself.
For the full exception hierarchy, the per-status retryability table, and a ready-made exponential-backoff wrapper, see Troubleshooting.
Async Patterns
TypeScript: Parallel Requests
UsePromise.all for independent requests:
Promise.allSettled when you want partial results:
Python: Sequential with Error Recovery
Amount Handling
Always Use Raw Units for API Calls
The API works in raw (smallest unit) amounts, never display amounts. Convert withparseRawAmount / parse_raw_amount before building a quote request, and convert back with toDisplayAmount / to_display_amount before showing anything to the user.
Both functions are documented in Utilities.
Use PrecisionHandler for Multi-Asset Apps
With more than one asset in play, passing a precision by hand on every call is how rounding bugs get in.PrecisionHandler reads the precision from asset metadata, so you convert by asset ID instead.
See Utilities for how to create one and the full method list.
Node Operations
client.rln is only usable when the client was created with a node URL, so guard every node call with hasNode() / has_node(). In Python, accessing client.rln without a node URL raises NodeNotConfiguredError.
See Getting Started for the guard pattern in both languages.
WebSocket
Unsubscribe When Done
streamQuotes / streamQuotesByTicker return an unsubscribe function. Call it as soon as you stop needing quotes — on unmount, on navigation, or when the user closes the pair. Skipping it leaks memory and keeps quote traffic flowing that nobody reads.
See WebSocket for this and the other streaming guidelines.
Handle Reconnection
TheWSClient reconnects on its own with exponential backoff, so the work on your side is surfacing state to the user: show a “reconnecting” indicator on disconnected, re-request quotes on connected, and treat maxReconnectExceeded as a hard error rather than a transient blip.
For the event list and the reconnection configuration, see WebSocket.
Security
Never Expose API Keys in Client Code
API keys should only be used server-side. For browser applications, proxy API calls through your backend.Validate User Input
Always validate amounts and addresses before sending to the API:endpoints list (TradingLimits per layer); pair.routes only tells you which from_layer -> to_layer combinations exist.