Subscription Types
Drift Protocol v2 provides three primary subscription mechanisms:WebSocket Subscribers
WebSocket-based subscribers use Solana’s nativeaccountSubscribe RPC method to receive real-time updates. Best for:
- Low-latency requirements
- Real-time trading applications
- When using public RPC endpoints
WebSocketUserAccountSubscriber- Subscribe to user account updatesWebSocketDriftClientAccountSubscriber- Subscribe to markets, state, and oracle dataWebSocketProgramAccountSubscriber- Subscribe to multiple accounts by program
Polling Subscribers
Polling-based subscribers use theBulkAccountLoader to periodically fetch account data. Best for:
- Rate-limited RPC endpoints
- Batch processing scenarios
- When WebSocket connections are unreliable
PollingUserAccountSubscriber- Poll user account updatesPollingDriftClientAccountSubscriber- Poll markets, state, and oracle dataBulkAccountLoader- Efficient batch account loading
gRPC Subscribers
gRPC-based subscribers use Yellowstone or Laser gRPC streams for high-performance data streaming. Best for:- High-frequency trading
- Maximum throughput requirements
- When using dedicated gRPC infrastructure
grpcUserAccountSubscriber- Subscribe via gRPC to user accountsgrpcDriftClientAccountSubscriber- Subscribe via gRPC to markets and oraclesgrpcAccountSubscriber- Generic gRPC account subscriber
Core Interfaces
AccountSubscriber
Base interface for single account subscriptions:UserAccountSubscriber
Interface for user account subscriptions:DriftClientAccountSubscriber
Interface for subscribing to Drift protocol accounts (markets, state, oracles):Common Types
DataAndSlot
Wraps account data with its slot number:ResubOpts
Configuration for automatic resubscription:Event Types
UserAccountEvents
DriftClientAccountEvents
Choosing a Subscriber Type
| Feature | WebSocket | Polling | gRPC |
|---|---|---|---|
| Latency | Low | Medium | Very Low |
| Resource Usage | Medium | Low | High |
| Reliability | Medium | High | High |
| RPC Calls | Minimal | Frequent | None |
| Setup Complexity | Low | Low | High |
| Best For | General use | Rate limits | HFT |
Error Handling
All subscribers can throwNotSubscribedError if methods are called before subscribing:
Next Steps
WebSocket Subscribers
Learn about WebSocket-based subscriptions
Polling Subscribers
Learn about polling-based subscriptions
gRPC Subscribers
Learn about gRPC-based subscriptions