Available Examples
Market Maker
Build automated market making bots with WebSocket or gRPC subscriptions
DLOB Builder
Build and serve a live decentralized limit order book with REST API
Event Subscriber
Subscribe to and process real-time Drift protocol events
Swift Taker
Place swift taker orders with isolated positions and deposits
Swift Maker
Fill swift orders as a maker and earn fees
Place and Take
Place orders and match with top makers in one transaction
DLOB Matching
Understand L3 order retrieval and oracle price importance
Drift Client Callbacks
Monitor market updates using account subscription callbacks
Simple Margin Calculation
Calculate simplified margin requirements for positions
Running Examples
All examples are located in theexamples/ directory of the drift-rs repository. To run an example:
Common Prerequisites
Most examples require:- RPC_URL: Solana RPC endpoint (MainNet or DevNet)
- PRIVATE_KEY: Base58-encoded private key for signing transactions
- GRPC_URL (optional): gRPC endpoint for real-time data
- GRPC_X_TOKEN (optional): Authentication token for gRPC
Example Categories
Trading Bots
- Market Maker: Automated market making with continuous quoting
- Swift Maker: Fill swift orders as a maker
- Swift Taker: Place swift orders as a taker
Order Book & Data
- DLOB Builder: Build and serve a live order book
- DLOB Matching: Work with L3 order data
- Event Subscriber: Process protocol events in real-time
Advanced Features
- Place and Take: Atomic order placement and matching
- Drift Client Callbacks: Custom subscription handlers
- Simple Margin Calculation: Calculate margin requirements