Overview
The Drift Common library provides several specialized client modules for interacting with market data feeds and executing orders:CandleClient
Fetch and subscribe to candlestick data from the Drift Data API
MarketDataFeed
Singleton websocket manager for candles and trades with subscription sharing
DlobWebsocketClient
Real-time orderbook data via websocket with reactive streams
SwiftClient
Fast order execution via the Swift server with confirmation tracking
Key Features
Market Data
- Historical & Real-time Candles: Fetch historical candle data and subscribe to live updates
- Trade Feeds: Subscribe to real-time trade execution data
- Orderbook Streaming: Real-time L2 orderbook depth data
- Subscription Sharing: Efficient websocket connection pooling
Order Execution
- Swift Orders: Lightning-fast order execution via specialized infrastructure
- Order Confirmation: Multiple confirmation strategies (polling, websocket)
- Event Streams: Observable-based order lifecycle events
Common Patterns
Websocket Management
All clients use sophisticated websocket management:- Automatic reconnection handling
- Subscription multiplexing (multiple subscribers share connections)
- Message filtering and routing
- Heartbeat monitoring
Reactive Streams
Clients use RxJS observables for data streaming:Caching Strategies
Clients implement intelligent caching:- CandleClient: Caches recent 1000 candles for instant retrieval
- URL Caching: Prevents repeated string concatenation overhead
- String Interning: Reduces memory allocation for frequently used keys
Usage Guidelines
Initialization
Most clients require initialization before use:Resource Cleanup
Always clean up resources when done:Error Handling
Clients use different error handling strategies:- Promises: Standard try/catch for async operations
- Observables: Error handlers in subscription callbacks
- Callbacks: Optional
onErrorconfiguration parameters
Next Steps
CandleClient API
Learn about fetching and subscribing to candle data
MarketDataFeed API
Understand websocket subscription management
DlobWebsocketClient API
Stream real-time orderbook data
SwiftClient API
Execute orders with Swift infrastructure