Чтобы получить цены на криптовалюту, вы можете использовать различные методы в зависимости от ваших требований и языка программирования. Вот некоторые распространенные методы с примерами кода на Python:
-
API CoinGecko:
- Пример кода:
import requests def get_cryptocurrency_prices(): url = 'https://api.coingecko.com/api/v3/simple/price' params = { 'ids': 'bitcoin,ethereum,ripple', 'vs_currencies': 'usd' } response = requests.get(url, params=params) if response.status_code == 200: data = response.json() return data return None # Usage prices = get_cryptocurrency_prices() print(prices)
- Пример кода:
-
API CoinMarketCap:
- Пример кода:
import requests def get_cryptocurrency_prices(): url = 'https://pro-api.coinmarketcap.com/v1/cryptocurrency/quotes/latest' headers = { 'X-CMC_PRO_API_KEY': 'YOUR_API_KEY' } params = { 'symbol': 'BTC,ETH,XRP', 'convert': 'USD' } response = requests.get(url, headers=headers, params=params) if response.status_code == 200: data = response.json() return data['data'] return None # Usage prices = get_cryptocurrency_prices() print(prices)
- Пример кода:
-
API Binance:
- Пример кода:
from binance.client import Client def get_cryptocurrency_prices(): api_key = 'YOUR_API_KEY' api_secret = 'YOUR_API_SECRET' client = Client(api_key, api_secret) prices = client.get_all_tickers() return prices # Usage prices = get_cryptocurrency_prices() print(prices)
- Пример кода: