Stock Sentiment API
Retrieve AI-powered sentiment analysis scores derived from financial news. Get sentiment scores for any ticker.
Endpoint
Section titled “Endpoint”GET /v2/sentiment/{symbol}Authentication
Section titled “Authentication”Supports multiple authentication methods (in order of preference):
| Method | Example |
|---|---|
| Bearer token (recommended) | Authorization: Bearer YOUR_API_KEY |
| X-API-Key header | X-API-Key: YOUR_API_KEY |
| Query parameter | ?apiKey=YOUR_API_KEY |
| Legacy query parameter | ?token=YOUR_API_KEY |
Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
symbol | string | Yes | Stock ticker symbol (e.g., AAPL, MSFT) |
Query Parameters
Section titled “Query Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | No | Your API key (if not using header auth) |
startDate | string | No | Start date (YYYY-MM-DD) |
endDate | string | No | End date (YYYY-MM-DD) |
limit | integer | No | Maximum number of results to return |
Request
Section titled “Request”from finbrain import FinBrainClient
fb = FinBrainClient(api_key="YOUR_API_KEY")
df = fb.sentiments.ticker("AAPL", date_from="2025-01-01", date_to="2025-06-30", as_dataframe=True)print(df)# Get sentiment datacurl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.finbrain.tech/v2/sentiment/AAPL"
# With date range and limitcurl -H "Authorization: Bearer YOUR_API_KEY" \ "https://api.finbrain.tech/v2/sentiment/AAPL?startDate=2026-01-01&endDate=2026-01-31&limit=30"import requests
headers = {"Authorization": "Bearer YOUR_API_KEY"}
# Get sentiment dataresponse = requests.get( "https://api.finbrain.tech/v2/sentiment/AAPL", headers=headers)result = response.json()
# With date range and limitresponse = requests.get( "https://api.finbrain.tech/v2/sentiment/AAPL", headers=headers, params={"startDate": "2026-01-01", "endDate": "2026-01-31", "limit": 30})result = response.json()#include <iostream>#include <string>#include <curl/curl.h>#include <nlohmann/json.hpp>
using json = nlohmann::json;
size_t WriteCallback(void* contents, size_t size, size_t nmemb, std::string* userp) { userp->append((char*)contents, size * nmemb); return size * nmemb;}
json get_sentiment(const std::string& symbol, const std::string& api_key) { CURL* curl = curl_easy_init(); std::string response;
if (curl) { std::string url = "https://api.finbrain.tech/v2/sentiment/" + symbol;
struct curl_slist* headers = nullptr; std::string auth_header = "Authorization: Bearer " + api_key; headers = curl_slist_append(headers, auth_header.c_str());
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response); curl_easy_perform(curl); curl_slist_free_all(headers); curl_easy_cleanup(curl); }
return json::parse(response);}
int main() { auto result = get_sentiment("AAPL", "YOUR_API_KEY"); auto data = result["data"];
std::cout << "Symbol: " << data["symbol"].get<std::string>() << " (" << data["name"].get<std::string>() << ")" << std::endl;
for (auto& entry : data["data"]) { std::cout << entry["date"].get<std::string>() << ": " << entry["score"].get<double>() << std::endl; }
return 0;}use reqwest::blocking::Client;use reqwest::header::{AUTHORIZATION, HeaderValue};use serde::Deserialize;use std::error::Error;
#[derive(Debug, Deserialize)]struct ApiResponse { success: bool, data: SentimentData,}
#[derive(Debug, Deserialize)]struct SentimentData { symbol: String, name: String, data: Vec<SentimentEntry>,}
#[derive(Debug, Deserialize)]struct SentimentEntry { date: String, score: f64,}
fn get_sentiment(symbol: &str, api_key: &str) -> Result<ApiResponse, Box<dyn Error>> { let url = format!( "https://api.finbrain.tech/v2/sentiment/{}", symbol );
let client = Client::new(); let response: ApiResponse = client .get(&url) .header(AUTHORIZATION, HeaderValue::from_str(&format!("Bearer {}", api_key))?) .send()? .json()?;
Ok(response)}
fn main() -> Result<(), Box<dyn Error>> { let result = get_sentiment("AAPL", "YOUR_API_KEY")?; let data = result.data;
println!("Symbol: {} ({})", data.symbol, data.name); for entry in &data.data { println!("{}: {:.3}", entry.date, entry.score); }
Ok(())}const response = await fetch( "https://api.finbrain.tech/v2/sentiment/AAPL", { headers: { "Authorization": "Bearer YOUR_API_KEY" } });const result = await response.json();console.log(result.data);Response
Section titled “Response”Success Response (200 OK)
Section titled “Success Response (200 OK)”{ "success": true, "data": { "symbol": "AAPL", "name": "Apple Inc.", "data": [ { "date": "2026-01-19", "score": 0.265 }, { "date": "2026-01-16", "score": 0.346 }, { "date": "2026-01-15", "score": 0.279 }, { "date": "2026-01-14", "score": 0.17 }, { "date": "2026-01-13", "score": 0.128 } ] }, "meta": { "timestamp": "2026-01-19T15:06:13.240Z" }}Response Fields
Section titled “Response Fields”| Field | Type | Description |
|---|---|---|
success | boolean | Whether the request was successful |
data | object | Sentiment data container |
meta | object | Response metadata |
Data Object Fields
Section titled “Data Object Fields”| Field | Type | Description |
|---|---|---|
symbol | string | Stock ticker symbol |
name | string | Company name |
data | array | Array of sentiment score entries |
Sentiment Entry Fields
Section titled “Sentiment Entry Fields”Each item in the data array contains:
| Field | Type | Description |
|---|---|---|
date | string | Date of the sentiment score (YYYY-MM-DD) |
score | number | Sentiment score from -1 (bearish) to 1 (bullish) |
Sentiment Score Interpretation
Section titled “Sentiment Score Interpretation”| Score Range | Interpretation |
|---|---|
| 0.5 to 1.0 | Strong bullish sentiment |
| 0.2 to 0.5 | Moderate bullish sentiment |
| -0.2 to 0.2 | Neutral sentiment |
| -0.5 to -0.2 | Moderate bearish sentiment |
| -1.0 to -0.5 | Strong bearish sentiment |
Usage Examples
Section titled “Usage Examples”Basic Sentiment Check
Section titled “Basic Sentiment Check”import requests
headers = {"Authorization": "Bearer YOUR_API_KEY"}response = requests.get( "https://api.finbrain.tech/v2/sentiment/AAPL", headers=headers)result = response.json()entries = result["data"]["data"]
# Get latest sentiment (first entry in array)latest = entries[0]score = latest["score"]
if score > 0.5: print(f"AAPL sentiment is strongly bullish: {score:.3f}")elif score > 0: print(f"AAPL sentiment is mildly bullish: {score:.3f}")elif score > -0.5: print(f"AAPL sentiment is mildly bearish: {score:.3f}")else: print(f"AAPL sentiment is strongly bearish: {score:.3f}")Detect Sentiment Spikes
Section titled “Detect Sentiment Spikes”import requests
headers = {"Authorization": "Bearer YOUR_API_KEY"}
def detect_sentiment_spike(symbol): """Detect unusual sentiment activity""" response = requests.get( f"https://api.finbrain.tech/v2/sentiment/{symbol}", headers=headers ) result = response.json() entries = result["data"]["data"]
if len(entries) < 10: return None
# Calculate baseline from historical data historical_scores = [e["score"] for e in entries[1:10]] avg_score = sum(historical_scores) / len(historical_scores)
# Compare to latest latest_score = entries[0]["score"] score_change = latest_score - avg_score
alerts = [] if abs(score_change) > 0.2: direction = "improved" if score_change > 0 else "declined" alerts.append(f"Sentiment {direction} significantly ({score_change:+.3f})")
return alerts
alerts = detect_sentiment_spike("TSLA")if alerts: print("Sentiment Alerts:") for alert in alerts: print(f" - {alert}")Sentiment Trend Analysis
Section titled “Sentiment Trend Analysis”import requests
headers = {"Authorization": "Bearer YOUR_API_KEY"}
def analyze_sentiment_trend(symbol, days=14): """Analyze sentiment trend over time""" response = requests.get( f"https://api.finbrain.tech/v2/sentiment/{symbol}", headers=headers, params={"limit": days} ) result = response.json() entries = result["data"]["data"]
if len(entries) < days: return None
recent = entries[:days//2] older = entries[days//2:days]
recent_avg = sum(e["score"] for e in recent) / len(recent) older_avg = sum(e["score"] for e in older) / len(older)
change = recent_avg - older_avg
if change > 0.1: trend = "improving" elif change < -0.1: trend = "deteriorating" else: trend = "stable"
return { "symbol": symbol, "recent_sentiment": recent_avg, "older_sentiment": older_avg, "change": change, "trend": trend }
result = analyze_sentiment_trend("NVDA")print(f"Sentiment trend: {result['trend']} ({result['change']:+.3f})")Errors
Section titled “Errors”| Code | Error | Description |
|---|---|---|
| 400 | Bad Request | Invalid symbol |
| 401 | Unauthorized | Invalid or missing API key |
| 403 | Forbidden | Authenticated, but not authorized to access this resource |
| 404 | Not Found | Ticker not found |
| 429 | Too Many Requests | Rate limit exceeded — wait and retry |
| 500 | Internal Server Error | Server-side error |
Related
Section titled “Related”- News Sentiment Dataset - Use cases and analysis examples
- Ticker Predictions - Get price predictions
- Analyst Ratings - Get analyst recommendations
- Put/Call Data - Get options sentiment