Skip to content
xai-financial-integration logo

xAI Financial Integration

xai-financial-integration

Integrate xAI Grok sentiment with FinnHub, Twelve Data, Alpha Vantage, and FMP financial APIs. Use when combining social sentiment with price data, fundamentals, and news for comprehensive analysis.

NeverSight/skills_feed0installs215stars

SKILL.md

Full skill instructions

xAI Financial Integration

Combine Grok's real-time Twitter/​X sentiment with traditional financial data APIs for comprehensive analysis.

Architecture

┌─────────────────────────────────────────────────────────────┐
│                      xAI Grok API                           │
│         (Real-time X sentiment, web search)                 │
└─────────────────────────────────────────────────────────────┘
                             │
                             ▼
┌─────────────────────────────────────────────────────────────┐
│                   Integration Layer                          │
│   Combine sentiment + price + fundamentals + news           │
└─────────────────────────────────────────────────────────────┘
                             │
        ┌────────────────────┼────────────────────┐
        ▼                    ▼                    ▼
┌───────────────┐   ┌───────────────┐   ┌───────────────┐
│   FinnHub     │   │  Twelve Data  │   │     FMP       │
│  (Quotes,     │   │  (Indicators, │   │ (Fundamentals,│
│   News)       │   │   History)    │   │   DCF)        │
└───────────────┘   └───────────────┘   └───────────────┘

Quick Start

import os
from openai import OpenAI
import requests

# Initialize clients
xai_client = OpenAI(
    api_key=os.getenv("XAI_API_KEY"),
    base_url="https://api.x.ai/​v1"
)

FINNHUB_KEY = os.getenv("FINNHUB_API_KEY")
TWELVEDATA_KEY = os.getenv("TWELVEDATA_API_KEY")
FMP_KEY = os.getenv("FMP_API_KEY")

def comprehensive_analysis(ticker: str) -> dict:
    """Complete analysis combining sentiment + price + fundamentals."""

    # 1. Get price data from FinnHub
    price = requests.get(
        f"https://finnhub.io/​api/​v1/​quote?symbol={ticker}&token={FINNHUB_KEY}"
    ).json()

    # 2. Get fundamentals from FMP
    fundamentals = requests.get(
        f"https://financialmodelingprep.com/​stable/​key-metrics?symbol={ticker}&apikey={FMP_KEY}"
    ).json()

    # 3. Get sentiment from xAI
    sentiment_response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Analyze X sentiment for ${ticker} given this context:

            Current Price: ${price.get('c', 'N/​A')}
            Change: {price.get('dp', 0):.2f}%

            Return JSON with sentiment analysis and trading signals."""
        }]
    )
    sentiment = sentiment_response.choices[0].message.content

    return {
        "ticker": ticker,
        "price": price,
        "fundamentals": fundamentals[0] if fundamentals else {},
        "sentiment": sentiment
    }

Integration Functions

Price + Sentiment Correlation

def price_sentiment_analysis(ticker: str) -> dict:
    """Analyze correlation between price action and sentiment."""

    # Get price data
    price = requests.get(
        f"https://finnhub.io/​api/​v1/​quote?symbol={ticker}&token={FINNHUB_KEY}"
    ).json()

    # Get sentiment with price context
    response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Analyze ${ticker} sentiment in context of price:

            Current: ${price['c']:.2f}
            Change: {price['dp']:.2f}%
            High: ${price['h']:.2f}
            Low: ${price['l']:.2f}

            Return JSON:
            {{
                "sentiment_score": -1 to 1,
                "price_sentiment_alignment": "aligned/​divergent/​neutral",
                "divergence_signal": {{
                    "detected": true/​false,
                    "type": "bullish divergence/​bearish divergence/​none",
                    "interpretation": "..."
                }},
                "trading_signal": "buy/​sell/​hold",
                "confidence": 0 to 1,
                "rationale": "..."
            }}"""
        }]
    )
    return response.choices[0].message.content

Technical + Sentiment

def technical_sentiment_analysis(ticker: str) -> dict:
    """Combine technical indicators with sentiment."""

    # Get RSI from Twelve Data
    rsi = requests.get(
        f"https://api.twelvedata.com/​rsi?symbol={ticker}&interval=1day&outputsize=1&apikey={TWELVEDATA_KEY}"
    ).json()

    # Get SMA
    sma = requests.get(
        f"https://api.twelvedata.com/​sma?symbol={ticker}&interval=1day&time_period=20&outputsize=1&apikey={TWELVEDATA_KEY}"
    ).json()

    rsi_value = rsi.get('values', [{}])[0].get('rsi', 'N/​A')
    sma_value = sma.get('values', [{}])[0].get('sma', 'N/​A')

    # Combine with sentiment
    response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Analyze ${ticker} combining technicals and X sentiment:

            Technical Indicators:
            - RSI(14): {rsi_value}
            - SMA(20): ${sma_value}

            Search X for sentiment and return JSON:
            {{
                "technical_signal": "overbought/​neutral/​oversold",
                "sentiment_signal": "bullish/​neutral/​bearish",
                "confluence": {{
                    "signals_aligned": true/​false,
                    "strength": "strong/​moderate/​weak"
                }},
                "recommendation": {{
                    "action": "buy/​sell/​hold",
                    "entry_zone": "...",
                    "stop_loss": "...",
                    "confidence": 0 to 1
                }}
            }}"""
        }]
    )
    return response.choices[0].message.content

Fundamental + Sentiment

def fundamental_sentiment_analysis(ticker: str) -> dict:
    """Combine fundamental data with sentiment."""

    # Get fundamentals from FMP
    metrics = requests.get(
        f"https://financialmodelingprep.com/​stable/​key-metrics?symbol={ticker}&period=annual&limit=1&apikey={FMP_KEY}"
    ).json()

    ratios = requests.get(
        f"https://financialmodelingprep.com/​stable/​financial-ratios?symbol={ticker}&period=annual&limit=1&apikey={FMP_KEY}"
    ).json()

    m = metrics[0] if metrics else {}
    r = ratios[0] if ratios else {}

    # Combine with sentiment
    response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Analyze ${ticker} combining fundamentals and X sentiment:

            Fundamentals:
            - P/​E Ratio: {r.get('priceEarningsRatio', 'N/​A')}
            - P/​B Ratio: {r.get('priceToBookRatio', 'N/​A')}
            - ROE: {r.get('returnOnEquity', 'N/​A')}
            - Debt/​Equity: {r.get('debtEquityRatio', 'N/​A')}

            Search X for what investors are saying about valuation.

            Return JSON:
            {{
                "fundamental_view": "undervalued/​fairly valued/​overvalued",
                "sentiment_on_valuation": {{
                    "score": -1 to 1,
                    "key_concerns": [...],
                    "bullish_arguments": [...]
                }},
                "smart_money_sentiment": "...",
                "retail_sentiment": "...",
                "valuation_consensus": "...",
                "investment_thesis": "..."
            }}"""
        }]
    )
    return response.choices[0].message.content

News + Sentiment Validation

def news_sentiment_validation(ticker: str) -> dict:
    """Validate news sentiment against X reaction."""

    # Get news from FinnHub
    from datetime import datetime, timedelta
    end = datetime.now()
    start = end - timedelta(days=3)

    news = requests.get(
        f"https://finnhub.io/​api/​v1/​company-news?symbol={ticker}"
        f"&from={start.strftime('%Y-%m-%d')}&to={end.strftime('%Y-%m-%d')}"
        f"&token={FINNHUB_KEY}"
    ).json()

    headlines = [n['headline'] for n in news[:5]] if news else []

    # Compare with X reaction
    response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Compare these news headlines for ${ticker} with X reaction:

            Recent Headlines:
            {chr(10).join(['- ' + h for h in headlines])}

            Search X for reaction to these news items.

            Return JSON:
            {{
                "news_sentiment": "positive/​negative/​neutral",
                "x_reaction": "positive/​negative/​neutral",
                "alignment": "aligned/​divergent/​mixed",
                "notable_reactions": [...],
                "market_interpretation": "...",
                "trading_implication": "..."
            }}"""
        }]
    )
    return response.choices[0].message.content

Multi-Asset Correlation

def multi_asset_sentiment(tickers: list) -> dict:
    """Analyze sentiment correlation across multiple assets."""

    tickers_str = ", ".join([f"${t}" for t in tickers])

    # Get all quotes
    quotes = {}
    for ticker in tickers:
        quote = requests.get(
            f"https://finnhub.io/​api/​v1/​quote?symbol={ticker}&token={FINNHUB_KEY}"
        ).json()
        quotes[ticker] = f"${quote['c']:.2f} ({quote['dp']:+.2f}%)"

    quote_summary = "\n".join([f"- {t}: {p}" for t, p in quotes.items()])

    response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Analyze X sentiment correlation for: {tickers_str}

            Current Prices:
{quote_summary}

            Return JSON:
            {{
                "individual_sentiment": [
                    {{"ticker": "...", "score": -1 to 1}}
                ],
                "correlations": [
                    {{"pair": "X-Y", "sentiment_correlation": "positive/​negative/​none"}}
                ],
                "sector_theme": "...",
                "rotation_signals": "...",
                "best_opportunity": "...",
                "relative_strength": [...]
            }}"""
        }]
    )
    return response.choices[0].message.content

Earnings Reaction Analysis

def earnings_reaction_analysis(ticker: str) -> dict:
    """Comprehensive post-earnings analysis."""

    # Get earnings data from FinnHub
    earnings = requests.get(
        f"https://finnhub.io/​api/​v1/​stock/​earnings?symbol={ticker}&token={FINNHUB_KEY}"
    ).json()

    latest = earnings[0] if earnings else {}

    response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Analyze post-earnings reaction for ${ticker}:

            Last Earnings:
            - EPS Actual: {latest.get('actual', 'N/​A')}
            - EPS Estimate: {latest.get('estimate', 'N/​A')}
            - Surprise: {latest.get('surprisePercent', 'N/​A')}%

            Search X for investor reaction and return JSON:
            {{
                "earnings_result": "beat/​met/​missed",
                "x_reaction": {{
                    "immediate": "positive/​negative/​mixed",
                    "sentiment_score": -1 to 1
                }},
                "key_topics": {{
                    "positives": [...],
                    "concerns": [...]
                }},
                "guidance_reaction": "...",
                "analyst_mentions": [...],
                "price_target_sentiment": "...",
                "trading_recommendation": "..."
            }}"""
        }]
    )
    return response.choices[0].message.content

Complete Dashboard

def full_stock_dashboard(ticker: str) -> dict:
    """Complete stock analysis dashboard."""

    # Gather all data
    quote = requests.get(
        f"https://finnhub.io/​api/​v1/​quote?symbol={ticker}&token={FINNHUB_KEY}"
    ).json()

    profile = requests.get(
        f"https://finnhub.io/​api/​v1/​stock/​profile2?symbol={ticker}&token={FINNHUB_KEY}"
    ).json()

    metrics = requests.get(
        f"https://financialmodelingprep.com/​stable/​key-metrics?symbol={ticker}&limit=1&apikey={FMP_KEY}"
    ).json()

    # Create comprehensive prompt
    response = xai_client.chat.completions.create(
        model="grok-4-1-fast",
        messages=[{
            "role": "user",
            "content": f"""Create comprehensive dashboard for ${ticker}:

            Company: {profile.get('name', ticker)}
            Sector: {profile.get('finnhubIndustry', 'N/​A')}
            Market Cap: ${profile.get('marketCapitalization', 0):,.0f}M

            Price Data:
            - Current: ${quote['c']:.2f}
            - Change: {quote['dp']:.2f}%
            - High/​Low: ${quote['h']:.2f} / ${quote['l']:.2f}

            Search X for sentiment and create dashboard JSON:
            {{
                "summary": {{
                    "ticker": "{ticker}",
                    "name": "...",
                    "price": ...,
                    "change_percent": ...
                }},
                "sentiment_analysis": {{
                    "overall_score": -1 to 1,
                    "label": "...",
                    "volume": "high/​med/​low",
                    "trend": "improving/​stable/​declining"
                }},
                "key_metrics": {{
                    "pe_ratio": ...,
                    "market_cap": ...,
                    "sector": "..."
                }},
                "social_signals": {{
                    "retail_sentiment": "...",
                    "influencer_sentiment": "...",
                    "news_reaction": "..."
                }},
                "catalysts": {{
                    "upcoming": [...],
                    "recent": [...]
                }},
                "risks": [...],
                "opportunities": [...],
                "recommendation": {{
                    "action": "buy/​sell/​hold",
                    "confidence": 0 to 1,
                    "rationale": "..."
                }}
            }}"""
        }]
    )
    return response.choices[0].message.content

Environment Setup

# .env file
XAI_API_KEY=xai-your-key
FINNHUB_API_KEY=your-finnhub-key
TWELVEDATA_API_KEY=your-twelvedata-key
ALPHAVANTAGE_API_KEY=your-alphavantage-key
FMP_API_KEY=your-fmp-key

Related Skills

  • xai-stock-sentiment - Stock sentiment
  • xai-crypto-sentiment - Crypto sentiment
  • finnhub-api - FinnHub integration
  • twelvedata-api - Twelve Data integration
  • fmp-api - FMP integration
  • alphavantage-api - Alpha Vantage integration

References

More skills from NeverSight

devops-deployer logo
NeverSight/skills_feed

devops-deployer

Comprehensive DevOps and deployment workflow that orchestrates infrastructure automation, CI/CD pipelines, container orchestration, and cloud deployment. Handles everything from infrastructure as code and pipeline setup to monitoring, scaling, and disaster recovery.

215 1
View
avnu logo
NeverSight/skills_feed

avnu

Integrate avnu SDK for Starknet DeFi: token swaps with best-price routing, DCA recurring buys, native staking, gasless transactions via paymaster, and market data. Use when building Starknet trading, DEX aggregation, or DeFi automation features.

215 0
View
post-to-x logo
NeverSight/skills_feed

post-to-x

发布内容和文章到 X (Twitter)。支持带图片的普通推文和 X Articles(长文)。使用真实的 Chrome 和 CDP 来绕过自动化检测。

215 0
View
ralph-prompt-builder logo
NeverSight/skills_feed

ralph-prompt-builder

Master orchestrator for generating Ralph Wiggum-compatible prompts. Analyzes task requirements and routes to appropriate generator (single-task, multi-task, project, or research). Use when you need to create any Ralph loop prompt and want automatic selection of the right generator.

215 0
View
branch-comparison logo
NeverSight/skills_feed

branch-comparison

Use when the user asks to compare branches, analyze git diffs, review changes between branches, update specifications based on code changes, or analyze what changed. Triggers on keywords like "compare branches", "git diff", "what changed", "branch comparison", "code changes", "spec update".

215 0
View
fastapi-development logo
NeverSight/skills_feed

fastapi-development

Build high-performance FastAPI applications with async routes, validation, dependency injection, security, and automatic API documentation. Use when developing modern Python APIs with async support, automatic OpenAPI documentation, and high performance requirements.

215 0
View
zendesk-chat logo
NeverSight/skills_feed

zendesk-chat

Enables Claude to manage Zendesk Chat conversations, support tickets, and customer service operations

215 0
View
forge logo
NeverSight/skills_feed

forge

Mine transcripts for knowledge - decisions, learnings, failures, patterns. Triggers: "forge insights", "mine transcripts", "extract knowledge".

215 0
View
mixpanel logo
NeverSight/skills_feed

mixpanel

Track product analytics and user behavior with Mixpanel's event-based platform.

215 0
View
ocpp logo
NeverSight/skills_feed

ocpp

OCPP protocol reference for EV charging infrastructure development. Covers OCPP 2.0.1 and OCPP 1.6J. Use when working with OCPP messages, charging station code, CSMS/Central System backends, smart charging, transaction handling, or EV charging protocols. Activates on keywords: OCPP, charging stat...

215 0
View
bee-collect logo
NeverSight/skills_feed

bee-collect

Gather scattered ideas into organized GitHub issues. The bee collects pollen from every flower, checks if the hive already has it, and carefully deposits new work in the comb for later. Never edits code—only organizes the work ahead. Use when creating issues from TODOs or planning work.

215 0
View
vercel-react-native-skills logo
NeverSight/skills_feed

vercel-react-native-skills

Comprehensive best practices for React Native and Expo applications. Contains rules across multiple categories covering performance, animations, UI patterns, and platform-specific optimizations.

215 0
View

Popular AI tools

Kaiber logo
Video

Kaiber

Generate, edit, and beat-sync AI video with leading models in one workspace.

Paid
View
Vimcal logo
Productivity

Vimcal

The world's fastest calendar for remote work

Free
View

Transform Your Design with AI Designer by ImgCreator.ai

Freemium
View
Akool AI logo
Content & writing

Akool AI

Revolutionizing Video Production with AI-Powered Creativity

Paid
View

Extend an image past the frame and let AI fill the new aspect ratio.

Freemium
View
StarByFace logo
Security

StarByFace

Discover your celebrity doppelgänger with StarByFace!

Free
View
C

ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.

Freemium
View
Opus Clip logo
Coding & apps

Opus Clip

Opus.ai: Revolutionize Your Web Experience

Free
View