Twelve Data provides robust cryptocurrency APIs for accessing real-time and historical market data. This guide demonstrates how to integrate their APIs across multiple programming languages, enabling developers to fetch time-series data, stream live prices, and build financial applications.
Core Features of Twelve Data APIs
- Real-time market data: Get live cryptocurrency prices with low latency.
- Historical data: Access OHLCV (Open, High, Low, Close, Volume) data for backtesting.
- WebSocket support: Stream live price updates for instant alerts.
- Multi-language SDKs: Native support for Python, Java, C++, C#, R, and more.
👉 Explore Twelve Data API documentation
How to Fetch Time-Series Data
Python Example
from twelvedata import TDClient
td = TDClient(apikey="YOUR_API_KEY_HERE")
ts = td.time_series(
symbol="BTC/USD", # Cryptocurrency pair
interval="1min",
outputsize=12,
)
print(ts.as_json())Key Parameters
| Parameter | Description | Example Value |
|---|---|---|
symbol | Cryptocurrency pair | BTC/USD |
interval | Data granularity | 1min, 1h |
outputsize | Number of data points returned | 12, 1000 |
WebSocket Streaming for Real-Time Prices
Python WebSocket Implementation
from twelvedata import TDClient
def on_event(e):
print("Live price update:", e)
td = TDClient(apikey="YOUR_API_KEY_HERE")
ws = td.websocket(symbols="BTC/USD", on_event=on_event)
ws.connect()Supported Events
- subscribe-status: Confirms successful subscription.
- price: Live price updates with timestamp and currency.
- error: Handles connection issues.
FAQ Section
Q1: How do I get started with Twelve Data APIs?
A1: Register for an API key on their developer portal, then install the language-specific SDK.
Q2: What’s the rate limit for free tier?
A2: Free tier allows 8 requests/minute and 800/day. Pro tiers offer higher limits.
Q3: Can I get historical Bitcoin data?
A3: Yes! Use the time_series endpoint with parameters like symbol=BTC/USD&interval=1day&outputsize=365.
Q4: How reliable is WebSocket streaming?
A4: Twelve Data’s WebSocket maintains >99.9% uptime with automatic reconnection.
👉 Start building with Twelve Data APIs today
Best Practices for API Usage
- Cache historical data to minimize API calls.
- Use WebSockets for real-time apps instead of polling.
- Handle errors gracefully with retry logic for rate limits.
- Monitor usage to stay within tier limits.
Advanced Use Cases
- Algorithmic trading: Combine real-time streams with trading logic.
- Portfolio trackers: Sync live prices across multiple coins.
- Tax reporting: Export historical transactions for accounting.
👉 [Need high-volume access? Check enterprise solutions](https://www.okx.com/join/BLOCKSTAR)Note: Replace YOUR_API_KEY_HERE with your actual Twelve Data API key. All examples use BTC/USD for illustration—adapt symbols as needed.