StockAPIS for Hedge Funds and Quants
Build, backtest, and run trading models on one normalized feed of clean historical and real-time market data across crypto exchanges, stock markets, and news.
Key Benefits
- Clean Historical Data: Survivorship-bias-free OHLCV and tick history for backtests
- Real-Time Feeds: Low-latency prices and order books from Binance, Coinbase, NYSE, and more
- Normalized Schema: One symbol model across exchanges and asset classes
- Alternative Data: News, sentiment, and on-chain signals as model features
- Point-in-Time Integrity: Timestamps you can trust, no look-ahead leakage
Use Cases
Historical OHLCV for Backtesting
Pull clean candle history to train and backtest signals:
from stockapis import StockAPIS
api = StockAPIS(api_key='your_api_key')
def load_ohlcv(symbol, exchange='binance', interval='1h', days=365):
candles = api.platforms.crypto_exchanges.get_ohlcv(
exchange=exchange,
symbol=symbol,
interval=interval,
lookback_days=days
)
print(f"OHLCV - {symbol} @ {exchange} ({interval})")
print(f"Bars: {len(candles)}")
print(f"Range: {candles[0].timestamp} -> {candles[-1].timestamp}")
# Simple returns series for modeling
closes = [c.close for c in candles]
returns = [(closes[i] / closes[i-1]) - 1 for i in range(1, len(closes))]
print(f"Mean return: {sum(returns)/len(returns):+.5f}")
return candlesReal-Time Price and Order-Book Feeds
Stream live quotes and depth into your execution layer:
def stream_market(symbol, exchange='coinbase'):
stream = api.platforms.crypto_exchanges.stream(
exchange=exchange,
symbol=symbol,
channels=['trades', 'orderbook']
)
for msg in stream:
if msg.type == 'trade':
print(f"{symbol} trade: {msg.price:,.2f} x {msg.size}")
elif msg.type == 'orderbook':
best_bid = msg.bids[0].price
best_ask = msg.asks[0].price
spread = best_ask - best_bid
mid = (best_bid + best_ask) / 2
print(f"{symbol} mid: {mid:,.2f} | spread: {spread:,.4f}")Cross-Exchange Spread Monitor
Detect dislocations between venues for stat-arb signals:
def cross_exchange_spread(symbol, venues=('binance', 'coinbase', 'kraken')):
quotes = {}
for venue in venues:
q = api.platforms.crypto_exchanges.get_ticker(
exchange=venue,
symbol=symbol
)
quotes[venue] = q.last
cheapest = min(quotes, key=quotes.get)
richest = max(quotes, key=quotes.get)
spread_bps = ((quotes[richest] / quotes[cheapest]) - 1) * 10_000
print(f"Cross-exchange spread - {symbol}")
for venue, price in quotes.items():
print(f" {venue}: {price:,.2f}")
print(f"\nCheapest: {cheapest} | Richest: {richest}")
print(f"Spread: {spread_bps:.1f} bps")
if spread_bps > 25:
print("Signal: dislocation above threshold")
return spread_bpsNews and Sentiment as Model Features
Turn headlines and social signals into structured factors:
def sentiment_features(symbol, hours=24):
news = api.platforms.financial_news.search(
symbol=symbol,
sources=['bloomberg', 'reuters'],
lookback_hours=hours
)
social = api.platforms.social_signals.get_sentiment(
symbol=symbol,
sources=['stocktwits', 'reddit'],
lookback_hours=hours
)
avg_news = sum(n.sentiment for n in news) / max(len(news), 1)
print(f"Sentiment Features - {symbol} ({hours}h)")
print(f"News items: {len(news)} | Avg sentiment: {avg_news:+.2f}")
print(f"Social score: {social.score:+.2f} | Volume: {social.mentions}")
# Feature row for the model
features = {
'news_sentiment': avg_news,
'news_volume': len(news),
'social_sentiment': social.score,
'social_mentions': social.mentions,
}
if avg_news < -0.3 and social.score < -0.3:
print("Signal: bearish sentiment cluster")
return featuresQuick Start
from stockapis import StockAPIS
api = StockAPIS(api_key='your_api_key')
# Historical OHLCV for a backtest
candles = api.platforms.crypto_exchanges.get_ohlcv(
exchange='binance',
symbol='BTC/USDT',
interval='1h',
lookback_days=365
)
print(f"Loaded {len(candles)} bars")
print(f"Latest close: {candles[-1].close:,.2f}")
# Live ticker
ticker = api.platforms.crypto_exchanges.get_ticker(
exchange='coinbase',
symbol='BTC/USD'
)
print(f"Live: {ticker.last:,.2f}")Where to Go Next
- Browse every source on the platforms overview.
- Plug in crypto exchanges like Binance, or normalized crypto data.
- Add equities via stock exchanges, brokers, and financial data APIs.
- Layer in alternative data from financial news and social signals.
- Get keys in the API getting-started guide, review pricing, or contact us about institutional feeds.
Last updated on