Skip to main content
The drift-rs SDK includes a comprehensive set of examples demonstrating different use cases and features. Each example is a complete, runnable application that you can use as a starting point for your own projects.

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 the examples/ directory of the drift-rs repository. To run an example:
# Clone the repository
git clone https://github.com/drift-labs/drift-rs.git
cd drift-rs

# Set up environment variables
cp .env.example .env
# Edit .env with your configuration

# Run an example
cargo run --example market-maker

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

Next Steps

Explore each example in detail to learn how to implement specific features in your application.

Build docs developers (and LLMs) love