π What is a Market Data API?
A Market Data API is a programmatic interface that provides access to real-time and historical market data from a cryptocurrency exchange. It includes endpoints for:
- Price tickers β Current price, volume, and 24-hour statistics.
- Order books β The current buy and sell orders for a trading pair.
- Candlestick (K-line) data β Historical price data for technical analysis.
- Trade history β Recent trades executed on the exchange.
- Exchange information β Available trading pairs, limits, and fees.
Market Data APIs are the foundation of trading bots, dashboards, portfolio trackers, and quantitative analysis tools. They provide the raw data that powers trading decisions.
Most Market Data endpoints are public β they don't require an API key. You can access price data, order books, and candlesticks without authentication. This makes them easy to use for developers and analysts.
π Key Market Data Endpoints
Here are the most important Market Data endpoints across major exchanges.
| Endpoint | Description | Method | Public? |
|---|---|---|---|
/api/v3/exchangeInfo |
Get exchange info (trading pairs, limits) | GET | Yes |
/api/v3/ticker/price |
Get current price of a symbol | GET | Yes |
/api/v3/ticker/24hr |
Get 24-hour price statistics | GET | Yes |
/api/v3/klines |
Get candlestick (K-line) data | GET | Yes |
/api/v3/depth |
Get order book depth | GET | Yes |
/api/v3/trades |
Get recent trades | GET | Yes |
/api/v3/aggTrades |
Get aggregate trade data | GET | Yes |
/api/v3/bookTicker |
Get best bid/ask prices | GET | Yes |
Endpoint URLs vary by exchange. Binance uses /api/v3/, OKX uses /api/v5/, and Bybit uses /v5/. Always refer to the exchange's official API documentation for accurate endpoints.
π° Price Data
Price data is the most frequently accessed market data. Here's how to get it.
Current Price
24-Hour Statistics
Best Bid/Ask
For real-time price updates, use WebSocket instead of polling REST endpoints. WebSocket streams price updates as they happen, reducing latency and avoiding rate limits.
π Candlestick (K-Line) Data
Candlestick data is essential for technical analysis. Exchanges provide historical candlestick data at various intervals.
Get Candlestick Data
Supported Intervals
| Interval | Description | Common Use |
|---|---|---|
| 1m | 1 minute | Scalping, high-frequency |
| 5m | 5 minutes | Short-term trading |
| 15m | 15 minutes | Intraday trading |
| 1h | 1 hour | Day trading |
| 4h | 4 hours | Swing trading |
| 1d | 1 day | Long-term analysis |
| 1w | 1 week | Trend analysis |
Each candlestick (K-line) typically includes: Open Time, Open Price, High Price, Low Price, Close Price, Volume, Close Time, Quote Volume, Number of Trades, Taker Buy Base Volume, Taker Buy Quote Volume, Ignore. The exact structure varies by exchange.
π Order Book Data
The order book shows all open buy and sell orders for a trading pair. It's essential for understanding market depth and liquidity.
Get Order Book
The order book response typically includes:
- bids: List of [price, quantity] for buy orders (sorted by price descending).
- asks: List of [price, quantity] for sell orders (sorted by price ascending).
- lastUpdateId: The ID of the last update to the order book.
- Market Depth: Visualize liquidity at different price levels.
- Support/Resistance: Identify key price levels with large order clusters.
- Spread Analysis: The difference between best bid and best ask.
- Slippage Estimation: Estimate price impact of large orders.
π WebSocket for Real-Time Market Data
While REST APIs are great for one-off requests, WebSocket is the preferred choice for real-time market data. Here's what you can stream via WebSocket.
Real-time price updates for a symbol. Includes current price, 24-hour high/low, and volume.
Real-time order book updates (depth snapshots and delta updates).
Real-time trade execution data β every trade as it happens.
Real-time candlestick updates as new candles are formed.
- REST: Best for one-off requests, historical data, and simple queries.
- WebSocket: Best for real-time streaming, high-frequency data, and live applications.
- Recommendation: Use WebSocket for price updates and order books; use REST for historical data and infrequent queries.
π Best Practices for Market Data APIs
Follow these best practices to make the most of Market Data APIs.
-
1
Use WebSocket for Real-Time Data
Avoid polling REST endpoints for real-time data. WebSocket provides lower latency and eliminates rate limit issues.
-
2
Cache Frequently Requested Data
Store exchange info, trading pairs, and other static data locally. Refresh periodically rather than requesting every time.
-
3
Respect Rate Limits
Monitor rate limit headers and implement throttling. Don't exceed the limits β your application will be blocked.
-
4
Handle Errors Gracefully
Implement retry logic with exponential backoff for transient errors (HTTP 429, 5xx).
-
5
Use Symbol Filtering
When requesting data for multiple symbols, filter to only the ones you need. Avoid requesting data for all symbols if you only need a few.
-
6
Check Data Freshness
Ensure you're using up-to-date data. Check timestamps and ensure your application handles stale data gracefully.