CandleClient
TheCandleClient fetches and subscribes to historical and real-time candle (OHLCV) data from the Drift Data API.
Features
- Fetch historical candles with automatic pagination
- Subscribe to real-time candle updates via WebSocket
- Intelligent caching for recent candles (last 1000)
- Support for multiple concurrent subscriptions
- Event-driven architecture
Basic Usage
Supported Resolutions
The CandleClient supports these time resolutions:| Resolution | Description |
|---|---|
'1' | 1 minute |
'5' | 5 minutes |
'15' | 15 minutes |
'60' | 1 hour |
'240' | 4 hours |
'D' | 1 day |
Caching Behavior
The CandleClient implements intelligent caching:- Recent candles (last 1000): Cached in memory, fetched without
startTsparameter for better API caching - Historical candles: Fetched with pagination using
startTsparameter
SwiftClient
TheSwiftClient enables fast order execution through Drift’s Swift infrastructure. Swift orders are off-chain signed messages that are verified and executed on-chain.
Initialization
Swift Order Events
Swift orders emit three types of events:Error Handling
MarketDataFeed
TheMarketDataFeed provides a unified interface for subscribing to various market data streams.
Subscribing to Market Data
Client Configuration
Environment-Specific URLs
Best Practices
Managing Subscriptions
Managing Subscriptions
Always clean up subscriptions when components unmount:
Error Handling
Error Handling
Implement robust error handling for network failures:
Rate Limiting
Rate Limiting
Be mindful of API rate limits when fetching data:
Next Steps
WebSocket Integration
Learn about real-time WebSocket clients
Utility Functions
Explore helper functions and utilities