NewConnect Claude, Cursor, ChatGPT, and other AI agents to API Ninjas via our MCP server

How to Get Cryptocurrency Prices in Python

Crypto Price APIUpdated May 23, 2026
To get a cryptocurrency price in Python, send a GET request to the API Ninjas Crypto Price endpoint with a trading-pair symbol like BTCUSDT:
crypto.py
import requests

API_KEY = 'YOUR_API_KEY'
response = requests.get(
    'https://api.api-ninjas.com/v1/cryptoprice',
    params={'symbol': 'BTCUSDT'},
    headers={'X-Api-Key': API_KEY},
)
print(response.json())

Prerequisites

Step 1: Get your API key

Sign up at api-ninjas.com/register.

Step 2: Make the API request

Symbols use the concatenated pair format — for example, BTCUSDT for Bitcoin quoted in Tether, or ETHBTC for Ether priced in Bitcoin.

crypto.py
import requests

API_KEY = 'YOUR_API_KEY'
response = requests.get(
    'https://api.api-ninjas.com/v1/cryptoprice',
    params={'symbol': 'BTCUSDT'},
    headers={'X-Api-Key': API_KEY},
)
print(response.json())

Step 3: Use the response

JSON
{
  "symbol": "BTCUSDT",
  "price": "67234.89000000",
  "timestamp": 1717603200
}

price is returned as a string to preserve precision — cast it to float for display or arithmetic.

Complete example

crypto.py
import os
import requests

API_KEY = os.environ['API_NINJAS_KEY']
URL = 'https://api.api-ninjas.com/v1/cryptoprice'


def get_crypto_price(symbol: str) -> dict:
    response = requests.get(
        URL,
        params={'symbol': symbol},
        headers={'X-Api-Key': API_KEY},
        timeout=10,
    )
    response.raise_for_status()
    return response.json()


if __name__ == '__main__':
    btc = get_crypto_price('BTCUSDT')
    eth = get_crypto_price('ETHUSDT')
    print(f"BTC/USDT: ${float(btc['price']):>10,.2f}")
    print(f"ETH/USDT: ${float(eth['price']):>10,.2f}")

Fetching multiple pairs

Python
symbols = ['BTCUSDT', 'ETHUSDT', 'SOLUSDT', 'DOGEUSDT', 'XRPUSDT']

for symbol in symbols:
    data = get_crypto_price(symbol)
    print(f"{symbol:10} ${float(data['price']):>12,.4f}")

Polling for live price updates

For a simple ticker, poll the endpoint on a schedule:

Python
import time

while True:
    data = get_crypto_price('BTCUSDT')
    print(f"BTC: ${float(data['price']):,.2f}")
    time.sleep(60)  # Poll once per minute

Be mindful of rate limits — poll every 60 seconds or longer for the free tier. For high-frequency data, use a WebSocket feed from an exchange.

Error handling

Python
from requests.exceptions import HTTPError

try:
    data = get_crypto_price('BTCUSDT')
except HTTPError as e:
    if e.response.status_code == 400:
        print('Invalid symbol — check the trading pair format')
    elif e.response.status_code == 401:
        print('Invalid or missing API key')
    elif e.response.status_code == 429:
        print('Rate limit exceeded')

Use the Crypto Symbols API to list all supported trading pairs, or the Bitcoin API for Bitcoin-specific data.

Frequently asked questions

What symbol format does the API use?

Symbols are formatted as the trading pair without a separator — for example, BTCUSDT for Bitcoin/Tether or ETHBTC for Ether/Bitcoin. Use the Crypto Symbols API to list supported pairs.

How frequently are crypto prices updated?

The Crypto Price API returns the most recent ticker price from major exchanges. Prices are updated in real time.

Why is the price returned as a string?

Prices are returned as strings to preserve full precision. Cast to float with float(data["price"]) before doing arithmetic, or use Decimal for financial calculations.

Can I get historical prices?

The endpoint returns current prices only. For historical OHLCV data, use a dedicated exchange API.

Is there a free tier?

Yes. Every API Ninjas account includes a free tier — no credit card required.