Skip to main content
πŸ“– Tronsell Wiki

Market Data API Guide: Real-Time Crypto Market Data

Complete guide to Market Data APIs on cryptocurrency exchanges β€” learn how to access real-time price data, order books, candlestick charts, and market statistics for building trading applications.

πŸ“Š Market Data API at a Glance
What It Is Programmatic access to market data
Data Types Prices, order books, candlesticks, trades
Authentication Public endpoints (no API key)
Best For Trading bots, dashboards, analysis
API Types REST + WebSocket
Rate Limits Varies by exchange

πŸ“Š 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.

πŸ’‘ Public vs Private Endpoints

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.

100+
Trading pairs per exchange
1s
Real-time data frequency
10+
Candlestick intervals
24/7
Data availability

πŸ“‹ 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
πŸ’‘ Note

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

GET /api/v3/ticker/price
Parameters: symbol=BTCUSDT

24-Hour Statistics

GET /api/v3/ticker/24hr
Parameters: symbol=BTCUSDT (returns price change, high, low, volume)

Best Bid/Ask

GET /api/v3/bookTicker
Parameters: symbol=BTCUSDT (returns best bid and ask prices)
πŸ’‘ Pro Tip

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

GET /api/v3/klines
Parameters: symbol=BTCUSDT, interval=1h, limit=100 (returns 100 hourly candles)

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
πŸ“Œ Candlestick Data Structure

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

GET /api/v3/depth
Parameters: symbol=BTCUSDT, limit=100 (returns 100 best bids and asks)

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.
πŸ’‘ Order Book Use Cases
  • 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.

πŸ“‘
Ticker Stream

Real-time price updates for a symbol. Includes current price, 24-hour high/low, and volume.

πŸ“‹
Order Book Stream

Real-time order book updates (depth snapshots and delta updates).

πŸ’±
Trade Stream

Real-time trade execution data β€” every trade as it happens.

πŸ“Š
K-Line Stream

Real-time candlestick updates as new candles are formed.

πŸ“Œ REST vs WebSocket for Market Data
  • 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.

❓ Frequently Asked Questions About Market Data APIs

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, order books, candlestick (K-line) data, trade history, and exchange statistics.

What data can I get from a Market Data API?

You can get: real-time price tickers, 24-hour price statistics, order book depth snapshots, candlestick (K-line) data for technical analysis, recent trade history, exchange information (trading pairs, limits), and sometimes derivatives data like funding rates and open interest.

Do I need an API key to access market data?

Most exchanges offer public market data endpoints that do NOT require an API key. These are freely accessible for reading market data. However, for authenticated endpoints (like account-specific data), you need an API key with Read permissions.

Should I use REST or WebSocket for market data?

Use REST for one-off requests like getting current price or historical candlesticks. Use WebSocket for real-time streaming of price updates, order book changes, and trade streams. WebSocket is more efficient for live applications and avoids rate limit issues.

How often should I poll market data?

For REST APIs, polling frequency depends on your needs and rate limits. A common approach is to poll every 1-2 seconds for price updates, but this can hit rate limits. WebSocket is recommended for real-time data. For historical data, you can poll less frequently.

What are the rate limits for market data APIs?

Rate limits vary by exchange and are typically lower for public endpoints than authenticated endpoints. Binance has 1200 weight/min, OKX has 50 requests/sec, Bybit has 50 requests/sec. Always check the exchange's API documentation for current limits.

How do I get historical candlestick data?

Use the candlestick (K-line) endpoint: GET /api/v3/klines with parameters symbol, interval (e.g., 1h, 1d), and limit (max number of candles). You can also use startTime and endTime to get data for a specific date range.

Can I get market data for all trading pairs at once?

Yes, some exchanges offer endpoints that return data for all trading pairs. For example, GET /api/v3/ticker/price without the symbol parameter returns prices for all symbols. However, be mindful of rate limits β€” requesting all symbols consumes more weight.

πŸ“Š Start Building with Market Data APIs

Access real-time and historical market data to power your trading applications, dashboards, and analysis tools. Start with public endpoints and scale as your application grows.