Client Initialization
Use Environment Variables
Keep configuration out of source code: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; Error Handling 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 Error Handling.
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 with raw (smallest unit) amounts. Convert display amounts before sending:Use PrecisionHandler for Multi-Asset Apps
When working with multiple assets, usePrecisionHandler to avoid precision errors:
Node Operations
Check Node Before Using RLN
Always verify the node is configured:WebSocket
Unsubscribe When Done
Always clean up WebSocket subscriptions: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.