Market Data API Guide
The StockAPIS API gives you one consistent interface for prices, OHLCV candles, order books, news, and sentiment across crypto exchanges, stock markets, brokers, and data providers — authenticate once, then page through any source.
This guide walks through auth, the core endpoints, and pagination. For a copy-paste first request, see API Getting Started; for the full source catalog, see Platforms.
Authentication
Every request is authenticated with an API key sent in the Authorization header. Create a key from your dashboard, then pass it on init:
from stockapis import StockAPIS
api = StockAPIS(api_key='your_api_key')The same key works across all asset types — crypto exchanges, crypto data, stock exchanges, brokers, financial data APIs, financial news, and social signals. You never manage per-exchange credentials (Binance, Coinbase, Kraken) yourself — StockAPIS normalizes them behind one token.
Core Data Structures
Quote Object
A normalized quote returned for any symbol, on any venue:
{
'symbol': 'BTC/USDT',
'venue': 'binance',
'price': 67250.40,
'bid': 67250.10,
'ask': 67250.70,
'volume_24h': 18452.31,
'change_24h_pct': 2.14,
'timestamp': '2026-06-06T14:30:00Z'
}OHLCV Candle
Open/high/low/close/volume bars for charting and backtests:
{
'symbol': 'AAPL',
'venue': 'nyse',
'interval': '1h',
'open': 196.40,
'high': 197.85,
'low': 195.90,
'close': 197.12,
'volume': 4821300,
'timestamp': '2026-06-06T14:00:00Z'
}Core Endpoints
Latest Price
# Crypto from an exchange
quote = api.platforms.binance.get_quote('BTC/USDT')
print(f"{quote.symbol}: ${quote.price:,.2f}")
# Equity from a data provider (Polygon, Alpha Vantage, etc.)
quote = api.platforms.polygon.get_quote('AAPL')OHLCV Candles
candles = api.platforms.binance.get_ohlcv(
'ETH/USDT',
interval='1h',
limit=500
)
for c in candles:
print(c.timestamp, c.close, c.volume)Order Book
book = api.platforms.coinbase.get_order_book('BTC/USD', depth=50)
best_bid = book.bids[0]
best_ask = book.asks[0]
spread = best_ask.price - best_bid.price
print(f"Spread: ${spread:.2f}")News & Sentiment
# Headlines from Bloomberg, Reuters, CNBC, etc.
articles = api.platforms.bloomberg.get_news(symbol='TSLA', limit=20)
# Aggregated social sentiment
signal = api.platforms.stocktwits.get_sentiment('NVDA')
print(f"Bullish: {signal.bullish_pct}%")Pagination
List endpoints (news feeds, trade history, symbol catalogs) are paginated with a cursor. Pass the next_cursor from the previous response until it comes back empty:
def fetch_all_news(symbol):
results = []
cursor = None
while True:
page = api.platforms.reuters.get_news(
symbol=symbol,
limit=100,
cursor=cursor
)
results.extend(page.items)
cursor = page.next_cursor
if not cursor:
break
return results
articles = fetch_all_news('SPY')
print(f"Fetched {len(articles)} articles")For time-series endpoints (OHLCV, trades), paginate by time window instead of cursor:
def fetch_history(symbol, start, end, interval='1d'):
candles = []
window_start = start
while window_start < end:
batch = api.platforms.binance.get_ohlcv(
symbol,
interval=interval,
start=window_start,
limit=1000
)
if not batch:
break
candles.extend(batch)
window_start = batch[-1].timestamp # advance past last bar
return candlesError Handling
Try-Except Patterns
Handle API errors gracefully:
from stockapis import StockAPIS, APIError
import time
api = StockAPIS(api_key='your_api_key')
try:
quote = api.platforms.binance.get_quote('BTC/USDT')
except APIError as e:
if e.status_code == 404:
print("Symbol or venue not found")
elif e.status_code == 429:
print("Rate limit exceeded, backing off...")
time.sleep(60)
else:
print(f"API error: {e}")Handling Missing Fields
Not every venue reports every field — a stock exchange feed has no volume_24h, an order book snapshot has no change_24h_pct. Always read defensively:
quote = api.platforms.kraken.get_quote('ETH/USD')
bid = quote.bid if quote.bid else quote.price
vol = getattr(quote, 'volume_24h', 0)Retry With Exponential Backoff
def get_quote_with_retry(venue, symbol, max_retries=3):
for attempt in range(max_retries):
try:
return getattr(api.platforms, venue).get_quote(symbol)
except APIError:
if attempt < max_retries - 1:
time.sleep(2 ** attempt) # 1s, 2s, 4s
else:
raiseBatch & Parallel Requests
Snapshot Many Symbols
def snapshot(venue, symbols):
quotes = []
for i, sym in enumerate(symbols):
try:
quotes.append(getattr(api.platforms, venue).get_quote(sym))
except APIError as e:
print(f"Skipped {sym}: {e}")
if (i + 1) % 25 == 0:
print(f"Fetched {i + 1}/{len(symbols)}")
return quotes
watchlist = ['BTC/USDT', 'ETH/USDT', 'SOL/USDT']
quotes = snapshot('binance', watchlist)Parallel Fetch
from concurrent.futures import ThreadPoolExecutor
def fetch(sym):
try:
return api.platforms.binance.get_quote(sym)
except APIError:
return None
symbols = ['BTC/USDT', 'ETH/USDT', 'SOL/USDT', 'XRP/USDT']
with ThreadPoolExecutor(max_workers=5) as pool:
quotes = [q for q in pool.map(fetch, symbols) if q]Rate Limits
Each plan has a requests-per-minute ceiling. Throttle bulk jobs to stay under it:
def rate_limited(symbols, venue, requests_per_minute=300):
delay = 60.0 / requests_per_minute
for sym in symbols:
yield getattr(api.platforms, venue).get_quote(sym)
time.sleep(delay)
for quote in rate_limited(watchlist, 'binance'):
process(quote)See Pricing for per-plan limits, or contact us for high-throughput and enterprise tiers.
Exporting Data
To CSV
import csv
def export_ohlcv(candles, filename):
with open(filename, 'w', newline='') as f:
writer = csv.DictWriter(f, fieldnames=[
'timestamp', 'open', 'high', 'low', 'close', 'volume'
])
writer.writeheader()
for c in candles:
writer.writerow({
'timestamp': c.timestamp,
'open': c.open,
'high': c.high,
'low': c.low,
'close': c.close,
'volume': c.volume,
})
export_ohlcv(candles, 'eth_1h.csv')To JSON
import json
def export_quotes(quotes, filename):
data = [
{'symbol': q.symbol, 'venue': q.venue, 'price': q.price}
for q in quotes
]
with open(filename, 'w') as f:
json.dump(data, f, indent=2)
export_quotes(quotes, 'snapshot.json')Quick Start
from stockapis import StockAPIS
api = StockAPIS(api_key='your_api_key')
try:
quote = api.platforms.binance.get_quote('BTC/USDT')
if quote.price:
print(f"{quote.symbol} on {quote.venue}: ${quote.price:,.2f}")
else:
print("No price available")
except Exception as e:
print(f"Error: {e}")Next steps: explore the Binance source, browse all Platforms, or start with the API Getting Started guide.