Quick Start Guide
This guide walks you through making your first FinBrain API calls. By the end, you’ll know how to retrieve AI price predictions, insider trading data, and sentiment scores.
Prerequisites
Section titled “Prerequisites”- A FinBrain API key (sign up here)
- Python 3.7+ (for SDK) or any HTTP client
Step 1: Install the Python SDK
Section titled “Step 1: Install the Python SDK”The fastest way to get started is with our official Python SDK:
pip install finbrain-pythonStep 2: Initialize the Client
Section titled “Step 2: Initialize the Client”from finbrain import FinBrainClient
# Replace with your actual API keyfb = FinBrainClient(api_key="YOUR_API_KEY")Step 3: Fetch Data
Section titled “Step 3: Fetch Data”Get AI Price Predictions
Section titled “Get AI Price Predictions”Retrieve deep learning price forecasts for any ticker:
from finbrain import FinBrainClient
fb = FinBrainClient(api_key="YOUR_API_KEY")
# Get daily predictions for Apple as DataFrame (recommended)df = fb.predictions.ticker("AAPL", prediction_type="daily", as_dataframe=True)print(df)# main lower upper# date# 2024-11-04 201.33 197.21 205.45# 2024-11-05 202.77 196.92 208.61# 2024-11-06 203.99 196.90 211.08
# Or get raw JSON responsepredictions = fb.predictions.ticker("AAPL", prediction_type="daily")print(predictions)Sample JSON Output:
{ "ticker": "AAPL", "name": "Apple Inc.", "prediction": { "2024-11-04": "201.33,197.21,205.45", "2024-11-05": "202.77,196.92,208.61", "2024-11-06": "203.99,196.90,211.08", "expectedShort": "0.22", "expectedMid": "0.58", "expectedLong": "0.25", "type": "daily", "lastUpdate": "2024-11-01T23:24:18.371Z" }, "sentimentAnalysis": { "2024-11-04": "0.186", "2024-11-01": "0.339", "2024-10-31": "0.565" }}const response = await fetch( "https://api.finbrain.tech/v1/ticker/AAPL/predictions/daily?token=YOUR_API_KEY");const data = await response.json();console.log(data);curl "https://api.finbrain.tech/v1/ticker/AAPL/predictions/daily?token=YOUR_API_KEY"Get Insider Trading Data
Section titled “Get Insider Trading Data”Track executive purchases and sales from SEC Form 4 filings:
from finbrain import FinBrainClient
fb = FinBrainClient(api_key="YOUR_API_KEY")
# Get insider transactions for Tesla as DataFrame (recommended)df = fb.insider_transactions.ticker("S&P 500", "TSLA", as_dataframe=True)print(df.head())# insiderTradings relationship transaction shares cost USDValue# date# 2024-01-10 Elon Musk CEO Sale 50000 245.50 12275000
# Or get raw JSON responseinsiders = fb.insider_transactions.ticker("S&P 500", "TSLA")print(insiders)Sample JSON Output:
{ "ticker": "TSLA", "name": "Tesla Inc.", "insiderTransactions": [ { "date": "2024-01-10", "insiderTradings": "Elon Musk", "relationship": "CEO", "transaction": "Sale", "cost": 245.50, "shares": 50000, "USDValue": 12275000, "totalShares": 715000000, "SECForm4Date": "2024-01-11", "SECForm4Link": "https://sec.gov/..." } ]}const response = await fetch( "https://api.finbrain.tech/v1/insidertransactions/S%26P%20500/TSLA?token=YOUR_API_KEY");const data = await response.json();console.log(data);curl "https://api.finbrain.tech/v1/insidertransactions/S%26P%20500/TSLA?token=YOUR_API_KEY"Get Sentiment Scores
Section titled “Get Sentiment Scores”Access AI-powered sentiment analysis from financial news:
from finbrain import FinBrainClient
fb = FinBrainClient(api_key="YOUR_API_KEY")
# Get sentiment for Microsoft as DataFrame (recommended)df = fb.sentiments.ticker("S&P 500", "MSFT", as_dataframe=True)print(df.tail())# sentiment# date# 2024-01-15 0.72# 2024-01-14 0.68
# Or get raw JSON responsesentiment = fb.sentiments.ticker("S&P 500", "MSFT")print(sentiment)Sample JSON Output:
{ "ticker": "MSFT", "name": "Microsoft Corporation", "sentimentAnalysis": { "2024-01-15": "0.72", "2024-01-14": "0.68", "2024-01-13": "0.65", "2024-01-12": "0.70", "2024-01-11": "0.63" }}const response = await fetch( "https://api.finbrain.tech/v1/sentiments/S%26P%20500/MSFT?token=YOUR_API_KEY");const data = await response.json();console.log(data);curl "https://api.finbrain.tech/v1/sentiments/S%26P%20500/MSFT?token=YOUR_API_KEY"Get Congressional Trades
Section titled “Get Congressional Trades”Monitor US House Representatives trading activity:
from finbrain import FinBrainClient
fb = FinBrainClient(api_key="YOUR_API_KEY")
# Get congressional trades for NVIDIA as DataFrame (recommended)df = fb.house_trades.ticker("S&P 500", "NVDA", as_dataframe=True)print(df.head())# representative type amount# date# 2024-01-08 Nancy Pelosi Purchase $1,000,001 - $5,000,000
# Or get raw JSON responsetrades = fb.house_trades.ticker("S&P 500", "NVDA")print(trades)Sample JSON Output:
{ "ticker": "NVDA", "name": "NVIDIA Corporation", "houseTrades": [ { "date": "2024-01-08", "representative": "Nancy Pelosi", "type": "Purchase", "amount": "$1,000,001 - $5,000,000" } ]}const response = await fetch( "https://api.finbrain.tech/v1/housetrades/S%26P%20500/NVDA?token=YOUR_API_KEY");const data = await response.json();console.log(data);curl "https://api.finbrain.tech/v1/housetrades/S%26P%20500/NVDA?token=YOUR_API_KEY"Step 4: Filter by Date Range
Section titled “Step 4: Filter by Date Range”Most endpoints support date filtering:
from finbrain import FinBrainClient
fb = FinBrainClient(api_key="YOUR_API_KEY")
# Get sentiment for a specific date range as DataFramedf = fb.sentiments.ticker( "S&P 500", "AAPL", date_from="2024-01-01", date_to="2024-01-31", as_dataframe=True)print(df)Or with the REST API:
curl "https://api.finbrain.tech/v1/ticker/AAPL/predictions/daily?token=YOUR_API_KEY&dateFrom=2024-01-01&dateTo=2024-01-31"Complete Example
Section titled “Complete Example”Here’s a complete script that fetches multiple datasets as DataFrames:
from finbrain import FinBrainClient
# Initialize clientfb = FinBrainClient(api_key="YOUR_API_KEY")
# Define ticker to analyzeticker = "AAPL"market = "S&P 500"
print(f"Analyzing {ticker}...\n")
# AI Predictionspredictions_df = fb.predictions.ticker(ticker, prediction_type="daily", as_dataframe=True)print("AI Predictions:")print(predictions_df.head())
# Insider Transactionsinsiders_df = fb.insider_transactions.ticker(market, ticker, as_dataframe=True)print("\nInsider Transactions:")print(insiders_df.head())
# Sentimentsentiment_df = fb.sentiments.ticker(market, ticker, as_dataframe=True)print("\nSentiment Scores:")print(sentiment_df.tail())
# Analyst Ratingsratings_df = fb.analyst_ratings.ticker(market, ticker, as_dataframe=True)print("\nAnalyst Ratings:")print(ratings_df.head())Next Steps
Section titled “Next Steps”Now that you’ve made your first API calls, explore more:
- Datasets - Detailed dataset documentation
- API Reference - Complete endpoint reference
- Python SDK - Full SDK documentation
- Guides - Build trading strategies