|
| 1 | +--- |
| 2 | +title: Financial News Tracker |
| 3 | +description: A real-time financial news monitoring tool that fetches and analyzes market news using Perplexity's Sonar API |
| 4 | +sidebar_position: 5 |
| 5 | +keywords: [financial-news, market-analysis, stocks, cryptocurrency, investment, sonar-api] |
| 6 | +--- |
| 7 | + |
| 8 | +# Financial News Tracker |
| 9 | + |
| 10 | +A command-line tool that fetches and analyzes real-time financial news using Perplexity's Sonar API. Get comprehensive market insights, news summaries, and investment analysis for any financial topic. |
| 11 | + |
| 12 | +## Features |
| 13 | + |
| 14 | +- Real-time financial news aggregation from multiple sources |
| 15 | +- Market sentiment analysis (Bullish/Bearish/Neutral) |
| 16 | +- Impact assessment for news items (High/Medium/Low) |
| 17 | +- Sector and company-specific analysis |
| 18 | +- Investment insights and recommendations |
| 19 | +- Customizable time ranges (24h to 1 year) |
| 20 | +- Structured JSON output support |
| 21 | +- Beautiful emoji-enhanced CLI output |
| 22 | + |
| 23 | +## Installation |
| 24 | + |
| 25 | +### 1. Install required dependencies |
| 26 | + |
| 27 | +```bash |
| 28 | +# Install from requirements file (recommended) |
| 29 | +pip install -r requirements.txt |
| 30 | + |
| 31 | +# Or install manually |
| 32 | +pip install requests pydantic |
| 33 | +``` |
| 34 | + |
| 35 | +### 2. Make the script executable |
| 36 | + |
| 37 | +```bash |
| 38 | +chmod +x financial_news_tracker.py |
| 39 | +``` |
| 40 | + |
| 41 | +## API Key Setup |
| 42 | + |
| 43 | +The tool requires a Perplexity API key. You can provide it in one of these ways: |
| 44 | + |
| 45 | +### 1. As an environment variable (recommended) |
| 46 | + |
| 47 | +```bash |
| 48 | +export PPLX_API_KEY=YOUR_API_KEY |
| 49 | +``` |
| 50 | + |
| 51 | +### 2. As a command-line argument |
| 52 | + |
| 53 | +```bash |
| 54 | +./financial_news_tracker.py "tech stocks" --api-key YOUR_API_KEY |
| 55 | +``` |
| 56 | + |
| 57 | +### 3. In a file |
| 58 | + |
| 59 | +Create a file named `pplx_api_key` or `.pplx_api_key` in the same directory: |
| 60 | + |
| 61 | +```bash |
| 62 | +echo "YOUR_API_KEY" > .pplx_api_key |
| 63 | +chmod 600 .pplx_api_key |
| 64 | +``` |
| 65 | + |
| 66 | +## Quick Start |
| 67 | + |
| 68 | +Get the latest tech stock news: |
| 69 | + |
| 70 | +```bash |
| 71 | +./financial_news_tracker.py "tech stocks" |
| 72 | +``` |
| 73 | + |
| 74 | +This will fetch recent financial news about tech stocks, analyze market sentiment, and provide actionable insights. |
| 75 | + |
| 76 | +## Usage Examples |
| 77 | + |
| 78 | +### Basic usage - Get news for a specific topic |
| 79 | + |
| 80 | +```bash |
| 81 | +./financial_news_tracker.py "S&P 500" |
| 82 | +``` |
| 83 | + |
| 84 | +### Get cryptocurrency news from the past week |
| 85 | + |
| 86 | +```bash |
| 87 | +./financial_news_tracker.py "cryptocurrency" --time-range 1w |
| 88 | +``` |
| 89 | + |
| 90 | +### Track specific company news |
| 91 | + |
| 92 | +```bash |
| 93 | +./financial_news_tracker.py "AAPL Apple stock" |
| 94 | +``` |
| 95 | + |
| 96 | +### Get news about market sectors |
| 97 | + |
| 98 | +```bash |
| 99 | +./financial_news_tracker.py "energy sector oil prices" |
| 100 | +``` |
| 101 | + |
| 102 | +### Output as JSON for programmatic use |
| 103 | + |
| 104 | +```bash |
| 105 | +./financial_news_tracker.py "inflation rates" --json |
| 106 | +``` |
| 107 | + |
| 108 | +### Use a different model |
| 109 | + |
| 110 | +```bash |
| 111 | +./financial_news_tracker.py "Federal Reserve interest rates" --model sonar |
| 112 | +``` |
| 113 | + |
| 114 | +### Enable structured output (requires Tier 3+ API access) |
| 115 | + |
| 116 | +```bash |
| 117 | +./financial_news_tracker.py "tech earnings" --structured-output |
| 118 | +``` |
| 119 | + |
| 120 | +## Time Range Options |
| 121 | + |
| 122 | +- `24h` - Last 24 hours (default) |
| 123 | +- `1w` - Last week |
| 124 | +- `1m` - Last month |
| 125 | +- `3m` - Last 3 months |
| 126 | +- `1y` - Last year |
| 127 | + |
| 128 | +## Output Format |
| 129 | + |
| 130 | +The tool provides comprehensive financial analysis including: |
| 131 | + |
| 132 | +### 1. Executive Summary |
| 133 | +A brief overview of the key financial developments |
| 134 | + |
| 135 | +### 2. Market Analysis |
| 136 | +- **Market Sentiment**: Overall market mood (🐂 Bullish, 🐻 Bearish, ⚖️ Neutral) |
| 137 | +- **Key Drivers**: Factors influencing the market |
| 138 | +- **Risks**: Current market risks and concerns |
| 139 | +- **Opportunities**: Potential investment opportunities |
| 140 | + |
| 141 | +### 3. News Items |
| 142 | +Each news item includes: |
| 143 | +- **Headline**: The main news title |
| 144 | +- **Impact**: Market impact level (🔴 High, 🟡 Medium, 🟢 Low) |
| 145 | +- **Summary**: Brief description of the news |
| 146 | +- **Affected Sectors**: Industries or companies impacted |
| 147 | +- **Source**: News source attribution |
| 148 | + |
| 149 | +### 4. Investment Insights |
| 150 | +Actionable recommendations and analysis based on the news |
| 151 | + |
| 152 | +## Example Output |
| 153 | + |
| 154 | +``` |
| 155 | +📊 FINANCIAL NEWS REPORT: tech stocks |
| 156 | +📅 Period: Last 24 hours |
| 157 | +
|
| 158 | +📝 EXECUTIVE SUMMARY: |
| 159 | +Tech stocks showed mixed performance today as AI-related companies surged while |
| 160 | +semiconductor stocks faced pressure from supply chain concerns... |
| 161 | +
|
| 162 | +📈 MARKET ANALYSIS: |
| 163 | + Sentiment: 🐂 BULLISH |
| 164 | +
|
| 165 | + Key Drivers: |
| 166 | + • Strong Q4 earnings from major tech companies |
| 167 | + • AI sector momentum continues |
| 168 | + • Federal Reserve signals potential rate cuts |
| 169 | +
|
| 170 | + ⚠️ Risks: |
| 171 | + • Semiconductor supply chain disruptions |
| 172 | + • Regulatory scrutiny on big tech |
| 173 | + • Valuation concerns in AI sector |
| 174 | +
|
| 175 | + 💡 Opportunities: |
| 176 | + • Cloud computing growth |
| 177 | + • AI infrastructure plays |
| 178 | + • Cybersecurity demand surge |
| 179 | +
|
| 180 | +📰 KEY NEWS ITEMS: |
| 181 | +
|
| 182 | +1. Microsoft Hits All-Time High on AI Growth |
| 183 | + Impact: 🔴 HIGH |
| 184 | + Summary: Microsoft stock reached record levels following strong Azure AI revenue... |
| 185 | + Sectors: Cloud Computing, AI, Software |
| 186 | + Source: Bloomberg |
| 187 | +
|
| 188 | +💼 INSIGHTS & RECOMMENDATIONS: |
| 189 | + • Consider diversifying within tech sector |
| 190 | + • AI infrastructure companies show strong momentum |
| 191 | + • Monitor semiconductor sector for buying opportunities |
| 192 | +``` |
| 193 | + |
| 194 | +## Advanced Features |
| 195 | + |
| 196 | +### Custom Queries |
| 197 | + |
| 198 | +You can combine multiple topics for comprehensive analysis: |
| 199 | + |
| 200 | +```bash |
| 201 | +# Get news about multiple related topics |
| 202 | +./financial_news_tracker.py "NVIDIA AMD semiconductor AI chips" |
| 203 | + |
| 204 | +# Track geopolitical impacts on markets |
| 205 | +./financial_news_tracker.py "oil prices Middle East geopolitics" |
| 206 | + |
| 207 | +# Monitor economic indicators |
| 208 | +./financial_news_tracker.py "inflation CPI unemployment Federal Reserve" |
| 209 | +``` |
| 210 | + |
| 211 | +### JSON Output |
| 212 | + |
| 213 | +For integration with other tools or scripts: |
| 214 | + |
| 215 | +```bash |
| 216 | +./financial_news_tracker.py "bitcoin" --json | jq '.market_analysis.market_sentiment' |
| 217 | +``` |
| 218 | + |
| 219 | +## Tips for Best Results |
| 220 | + |
| 221 | +1. **Be Specific**: Include company tickers, sector names, or specific events |
| 222 | +2. **Combine Topics**: Mix company names with relevant themes (e.g., "TSLA electric vehicles") |
| 223 | +3. **Use Time Ranges**: Match the time range to your investment horizon |
| 224 | +4. **Regular Monitoring**: Set up cron jobs for daily market updates |
| 225 | + |
| 226 | +## Limitations |
| 227 | + |
| 228 | +- Results depend on available public information |
| 229 | +- Not financial advice - always do your own research |
| 230 | +- Historical data may be limited for very recent events |
| 231 | +- Structured output requires Tier 3+ Perplexity API access |
| 232 | + |
| 233 | +## Error Handling |
| 234 | + |
| 235 | +The tool includes comprehensive error handling for: |
| 236 | +- Invalid API keys |
| 237 | +- Network connectivity issues |
| 238 | +- API rate limits |
| 239 | +- Invalid queries |
| 240 | +- Parsing errors |
| 241 | + |
| 242 | +## Integration Examples |
| 243 | + |
| 244 | +### Daily Market Report |
| 245 | + |
| 246 | +Create a script for daily updates: |
| 247 | + |
| 248 | +```bash |
| 249 | +#!/bin/bash |
| 250 | +# daily_market_report.sh |
| 251 | + |
| 252 | +echo "=== Daily Market Report ===" > market_report.txt |
| 253 | +echo "Date: $(date)" >> market_report.txt |
| 254 | +echo "" >> market_report.txt |
| 255 | + |
| 256 | +./financial_news_tracker.py "S&P 500 market overview" >> market_report.txt |
| 257 | +./financial_news_tracker.py "top gaining stocks" >> market_report.txt |
| 258 | +./financial_news_tracker.py "cryptocurrency bitcoin ethereum" >> market_report.txt |
| 259 | +``` |
| 260 | + |
| 261 | +### Python Integration |
| 262 | + |
| 263 | +```python |
| 264 | +import subprocess |
| 265 | +import json |
| 266 | + |
| 267 | +def get_financial_news(query, time_range="24h"): |
| 268 | + result = subprocess.run( |
| 269 | + ["./financial_news_tracker.py", query, "--time-range", time_range, "--json"], |
| 270 | + capture_output=True, |
| 271 | + text=True |
| 272 | + ) |
| 273 | + |
| 274 | + if result.returncode == 0: |
| 275 | + return json.loads(result.stdout) |
| 276 | + else: |
| 277 | + raise Exception(f"Error fetching news: {result.stderr}") |
| 278 | + |
| 279 | +# Example usage |
| 280 | +news = get_financial_news("tech stocks", "1w") |
| 281 | +print(f"Market sentiment: {news['market_analysis']['market_sentiment']}") |
| 282 | +``` |
0 commit comments