Orderbook & DLOB
To quote well, you usually need current best bid/ask, depth, and recent flow. Drift exposes multiple ways to access orderbook state:
- SDK (local DLOB) via
UserMap/DLOB - SDK (subscription) via
DLOBSubscriber - Hosted DLOB server (HTTP) for convenience
UserMap + DLOB (local)
This approach subscribes to user accounts and builds an in-memory orderbook (DLOB). It’s powerful, but can be heavier than calling a hosted DLOB endpoint.
import { UserMap } from "@drift-labs/sdk";Class UserMapReference ↗import { DLOB } from "@drift-labs/sdk";Class DLOBReference ↗import { DLOBSubscriber, OrderSubscriber, SlotSubscriber } from "@drift-labs/sdk";
const slotSubscriber = new SlotSubscriber(connection);
await slotSubscriber.subscribe();
const orderSubscriber = new OrderSubscriber({
driftClient,
subscriptionConfig: { type: "websocket" },
fastDecode: true,
decodeData: true,
});
await orderSubscriber.subscribe();
const dlobSubscriber = new DLOBSubscriber({
driftClient,
dlobSource: orderSubscriber,
slotSource: slotSubscriber,
updateFrequency: 1000,
});
await dlobSubscriber.subscribe();Auction subscriber (on-chain auctions)
If your workflow is centered around on-chain auctions / JIT, you can subscribe to auction-related updates.
import { AuctionSubscriber } from "@drift-labs/sdk";Class AuctionSubscriberReference ↗| Name | Type | Default |
|---|---|---|
driftClient | any | |
opts | any | |
resubOpts | any | |
eventEmitter | StrictEventEmitter<EventEmitter, AuctionSubscriberEvents> | |
subscriber | any | |
subscribe | () => Promise<void> | |
unsubscribe | () => Promise<void> |
Detecting Swift orders in on-chain feeds
If you also integrate Swift, you may see the same order “twice”: once off-chain via Swift, and again after it lands on-chain. Use isSignedMsgOrder(...) to filter Swift-origin orders.
import { isSignedMsgOrder } from "@drift-labs/sdk";Function isSignedMsgOrderReference ↗| Name | Type | Default |
|---|---|---|
order | Order |
Last updated on