Supported Oracle Sources
Drift supports multiple oracle providers:Pyth
Primary oracle source
- Pyth V1 (pull-based)
- Pyth Lazer (low-latency)
- Pyth Pull Oracle
Switchboard
Alternative oracle source
- Switchboard V2
- Switchboard On-Demand
Quote Asset
$1.00 fixed price for stablecoins
Prelaunch
For pre-launch markets
Getting Oracle Data
For Perpetual Markets
For Spot Markets
Oracle Price Data Structure
BN
Current oracle price with
PRICE_PRECISION (10^6)number
Solana slot when price was updated
BN
Price confidence interval (lower is better)
BN | null
Time-weighted average price for manipulation resistance
boolean
Whether oracle has enough data points for reliability
Validating Oracle Data
Check Oracle Validity
Check Price Divergence
Oracle Guard Rails
Drift uses oracle guard rails to protect against invalid or manipulated prices:Guard Rail Parameters
number
Number of slots before oracle is considered stale (typically 25-50)
BN
Maximum allowed confidence interval as percent of price
BN
Maximum percent divergence between oracle and mark price
Working with Pyth Oracles
Pyth Pull Oracles
Pyth pull oracles require price updates to be pushed on-chain:Pyth Lazer
Pyth Lazer provides ultra-low latency price feeds:Calculating Prices
Bid and Ask Prices
Mark Price (Fair Value)
Monitoring Oracle Health
TWAP for Manipulation Resistance
Drift uses TWAP (Time-Weighted Average Price) to prevent oracle manipulation:Drift may use TWAP instead of spot price for certain operations like liquidations to prevent manipulation attacks.
Oracle Events
Listen for oracle price updates:Best Practices
Always validate oracle data
Always validate oracle data
Monitor confidence intervals
Monitor confidence intervals
High confidence intervals indicate uncertainty. Consider wider price bounds or reduced position sizes when confidence is high.
Check oracle staleness
Check oracle staleness
Stale oracles can lead to inaccurate pricing. Always check the slot difference before using oracle data.
Use TWAP for manipulation resistance
Use TWAP for manipulation resistance
When available, prefer TWAP over spot price for critical operations to prevent flash loan attacks.
Next Steps
Advanced Features
Explore advanced SDK capabilities
Oracle Concepts
Deep dive into oracle mechanics
Oracle API
Oracle data structures and methods
Market Data
Access market and oracle data