Skip to main content
Account subscribers provide real-time updates for on-chain account data in Drift Protocol. The SDK offers three subscription mechanisms: WebSocket, Polling, and gRPC, each optimized for different use cases.

Subscription Types

Drift Protocol v2 provides three primary subscription mechanisms:

WebSocket Subscribers

WebSocket-based subscribers use Solana’s native accountSubscribe RPC method to receive real-time updates. Best for:
  • Low-latency requirements
  • Real-time trading applications
  • When using public RPC endpoints
Key Classes:
  • WebSocketUserAccountSubscriber - Subscribe to user account updates
  • WebSocketDriftClientAccountSubscriber - Subscribe to markets, state, and oracle data
  • WebSocketProgramAccountSubscriber - Subscribe to multiple accounts by program

Polling Subscribers

Polling-based subscribers use the BulkAccountLoader to periodically fetch account data. Best for:
  • Rate-limited RPC endpoints
  • Batch processing scenarios
  • When WebSocket connections are unreliable
Key Classes:
  • PollingUserAccountSubscriber - Poll user account updates
  • PollingDriftClientAccountSubscriber - Poll markets, state, and oracle data
  • BulkAccountLoader - 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
Key Classes:
  • grpcUserAccountSubscriber - Subscribe via gRPC to user accounts
  • grpcDriftClientAccountSubscriber - Subscribe via gRPC to markets and oracles
  • grpcAccountSubscriber - 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

Error Handling

All subscribers can throw NotSubscribedError if methods are called before subscribing:
Handle errors using event emitters:

Next Steps

WebSocket Subscribers

Learn about WebSocket-based subscriptions

Polling Subscribers

Learn about polling-based subscriptions

gRPC Subscribers

Learn about gRPC-based subscriptions