Skip to main content
Swift orders enable fast, off-chain order matching on Drift Protocol. This page covers both taking and making swift orders.

Overview

Swift orders are pre-signed orders that can be executed by anyone who has the signature. They enable:
  • Fast execution - Orders are signed off-chain and submitted by fillers
  • MEV protection - Orders can specify auction parameters to protect against front-running
  • Deposit trades - Users can deposit collateral and trade in a single transaction

Swift Taker

Place swift taker orders with deposit trades

Swift Maker

Fill swift orders as a maker to earn fees

Swift Taker Example

The swift taker example shows how to place swift orders that can be filled by makers.

Key Features

  • Subscribe to swift order feed via WebSocket
  • Place taker orders with deposit collateral
  • Configure auction parameters for MEV protection
  • Handle order sanitization

Basic Usage

use drift_rs::{DriftClient, Context, Wallet};
use solana_sdk::signature::Keypair;

#[tokio::main]
async fn main() {
    let wallet = Wallet::from(Keypair::new());
    let client = DriftClient::new(
        Context::MainNet,
        RpcClient::new("https://api.mainnet-beta.solana.com"),
        wallet.clone(),
    ).await.unwrap();

    // Subscribe to swift orders
    let markets = vec![MarketId::perp(0)];
    let mut swift_stream = client
        .subscribe_swift_orders(
            &markets,
            Some(true),  // Accept sanitized orders
            Some(true),  // Accept deposit trades
            None,        // Use default swift WS URL
        )
        .await
        .unwrap();

    // Process swift orders
    while let Some(order_info) = swift_stream.next().await {
        println!("Received swift order: {:?}", order_info);
        // Add your order matching logic here
    }
}
View full swift-taker example →

Swift Maker Example

The swift maker example demonstrates how to fill swift orders as a liquidity provider.

Key Features

  • Subscribe to real-time swift order feed
  • Evaluate order profitability
  • Fill orders to earn maker fees
  • Handle both regular and deposit+trade orders

Basic Usage

use drift_rs::{DriftClient, Wallet};

#[tokio::main]
async fn main() {
    let client = DriftClient::new(
        Context::MainNet,
        rpc_client,
        wallet,
    ).await.unwrap();

    // Subscribe to all perp markets for swift orders
    let markets = client.get_all_perp_market_ids();
    
    let mut swift_stream = client
        .subscribe_swift_orders(&markets, None, None, None)
        .await
        .unwrap();

    while let Some(order_info) = swift_stream.next().await {
        // Evaluate if order is profitable to fill
        if is_profitable(&order_info) {
            // Fill the order
            fill_swift_order(&client, &order_info).await;
        }
    }
}
View full swift-maker example →

Order Verification

When working with swift orders, always verify:
Security Checks
  • Verify the order signature is valid
  • Check the order hasn’t expired
  • Validate auction parameters
  • Ensure sufficient collateral for deposit trades
// Verify order signature
let is_valid = order_info.verify_signature();

// Check if order uses authority or delegate signature
let signature_type = order_info.signature_type();

// Get the underlying order data
let order = order_info.order();

Auction Parameters

Swift orders can specify auction parameters to protect against MEV:
let order_params = OrderParams {
    // ... other fields
    auction_duration: Some(30),      // 30 slots
    auction_start_price: Some(price - 10),  // Start 10 ticks below
    auction_end_price: Some(price + 10),    // End 10 ticks above
    // ...
};

Next Steps

Swift Taker Details

Complete swift taker implementation

Swift Maker Details

Complete swift maker implementation

Order API

Order struct reference

Swift Subscriber

Swift order subscriber API

Build docs developers (and LLMs) love