Spaces:
Runtime error
Runtime error
Delete API_ENHANCEMENTS.md
Browse files- API_ENHANCEMENTS.md +0 -260
API_ENHANCEMENTS.md
DELETED
|
@@ -1,260 +0,0 @@
|
|
| 1 |
-
# API Enhancements Summary
|
| 2 |
-
|
| 3 |
-
## Overview
|
| 4 |
-
|
| 5 |
-
The MCP Server has been enhanced to include all important methods from `FinancialAnalyzer`, providing both basic and advanced financial data analysis capabilities.
|
| 6 |
-
|
| 7 |
-
## Total API Endpoints: 9
|
| 8 |
-
|
| 9 |
-
### Basic Endpoints (6) - Using `EdgarDataClient`
|
| 10 |
-
|
| 11 |
-
1. **POST /api/search_company**
|
| 12 |
-
- Search company by name
|
| 13 |
-
- Returns: CIK, name, ticker
|
| 14 |
-
|
| 15 |
-
2. **POST /api/get_company_info**
|
| 16 |
-
- Get detailed company information
|
| 17 |
-
- Returns: Full company details with SIC
|
| 18 |
-
|
| 19 |
-
3. **POST /api/get_company_filings**
|
| 20 |
-
- Get company SEC filings
|
| 21 |
-
- Supports: 10-K, 10-Q, 20-F, etc.
|
| 22 |
-
|
| 23 |
-
4. **POST /api/get_company_facts**
|
| 24 |
-
- Get complete XBRL financial facts
|
| 25 |
-
- Returns: Raw financial data
|
| 26 |
-
|
| 27 |
-
5. **POST /api/get_financial_data**
|
| 28 |
-
- Get financial data for specific period
|
| 29 |
-
- Supports: Annual (YYYY) and Quarterly (YYYYQX)
|
| 30 |
-
|
| 31 |
-
6. **GET /health**
|
| 32 |
-
- Health check endpoint
|
| 33 |
-
- Returns: Server status
|
| 34 |
-
|
| 35 |
-
### Advanced Endpoints (3) - Using `FinancialAnalyzer` ⭐
|
| 36 |
-
|
| 37 |
-
#### 7. POST /api/advanced_search
|
| 38 |
-
**Purpose**: Intelligent company search supporting both name and CIK
|
| 39 |
-
|
| 40 |
-
**From**: `FinancialAnalyzer.search_company()`
|
| 41 |
-
|
| 42 |
-
**Request**:
|
| 43 |
-
```json
|
| 44 |
-
{
|
| 45 |
-
"company_input": "Apple" // or "0000320193"
|
| 46 |
-
}
|
| 47 |
-
```
|
| 48 |
-
|
| 49 |
-
**Features**:
|
| 50 |
-
- Auto-detects input type (name vs CIK)
|
| 51 |
-
- Returns complete company information
|
| 52 |
-
- More intelligent than basic search
|
| 53 |
-
|
| 54 |
-
**Use Case**: When you don't know if user input is name or CIK
|
| 55 |
-
|
| 56 |
-
---
|
| 57 |
-
|
| 58 |
-
#### 8. POST /api/extract_financial_metrics
|
| 59 |
-
**Purpose**: Extract multi-year financial metrics (annual + quarterly)
|
| 60 |
-
|
| 61 |
-
**From**: `FinancialAnalyzer.extract_financial_metrics()`
|
| 62 |
-
|
| 63 |
-
**Request**:
|
| 64 |
-
```json
|
| 65 |
-
{
|
| 66 |
-
"cik": "0001045810",
|
| 67 |
-
"years": 3
|
| 68 |
-
}
|
| 69 |
-
```
|
| 70 |
-
|
| 71 |
-
**Response**:
|
| 72 |
-
```json
|
| 73 |
-
{
|
| 74 |
-
"metrics": [
|
| 75 |
-
{
|
| 76 |
-
"period": "2024",
|
| 77 |
-
"total_revenue": 60922000000,
|
| 78 |
-
"net_income": 29760000000,
|
| 79 |
-
"earnings_per_share": 12.04,
|
| 80 |
-
...
|
| 81 |
-
},
|
| 82 |
-
{
|
| 83 |
-
"period": "2024Q4",
|
| 84 |
-
...
|
| 85 |
-
},
|
| 86 |
-
{
|
| 87 |
-
"period": "2024Q3",
|
| 88 |
-
...
|
| 89 |
-
}
|
| 90 |
-
],
|
| 91 |
-
"count": 15
|
| 92 |
-
}
|
| 93 |
-
```
|
| 94 |
-
|
| 95 |
-
**Features**:
|
| 96 |
-
- Returns both annual and quarterly data
|
| 97 |
-
- Automatically formats data
|
| 98 |
-
- Sorted by period (newest first)
|
| 99 |
-
- Configurable years (1-10)
|
| 100 |
-
|
| 101 |
-
**Use Cases**:
|
| 102 |
-
- Historical trend analysis
|
| 103 |
-
- Multi-period comparison
|
| 104 |
-
- Financial modeling
|
| 105 |
-
- Data visualization
|
| 106 |
-
|
| 107 |
-
---
|
| 108 |
-
|
| 109 |
-
#### 9. POST /api/get_latest_financial_data
|
| 110 |
-
**Purpose**: Get the most recent annual financial data
|
| 111 |
-
|
| 112 |
-
**From**: `FinancialAnalyzer.get_latest_financial_data()`
|
| 113 |
-
|
| 114 |
-
**Request**:
|
| 115 |
-
```json
|
| 116 |
-
{
|
| 117 |
-
"cik": "0001045810"
|
| 118 |
-
}
|
| 119 |
-
```
|
| 120 |
-
|
| 121 |
-
**Response**:
|
| 122 |
-
```json
|
| 123 |
-
{
|
| 124 |
-
"period": "2024",
|
| 125 |
-
"total_revenue": 60922000000,
|
| 126 |
-
"net_income": 29760000000,
|
| 127 |
-
"earnings_per_share": 12.04,
|
| 128 |
-
"operating_expenses": 11822000000,
|
| 129 |
-
"operating_cash_flow": 28091000000,
|
| 130 |
-
"source_url": "https://www.sec.gov/...",
|
| 131 |
-
"source_form": "10-K"
|
| 132 |
-
}
|
| 133 |
-
```
|
| 134 |
-
|
| 135 |
-
**Features**:
|
| 136 |
-
- Automatically finds latest fiscal year
|
| 137 |
-
- No need to know the year
|
| 138 |
-
- Returns most recent 10-K or 20-F data
|
| 139 |
-
|
| 140 |
-
**Use Cases**:
|
| 141 |
-
- Quick company snapshot
|
| 142 |
-
- Current financial position
|
| 143 |
-
- Latest performance metrics
|
| 144 |
-
|
| 145 |
-
---
|
| 146 |
-
|
| 147 |
-
## Key Benefits
|
| 148 |
-
|
| 149 |
-
### 1. **Flexibility**
|
| 150 |
-
- Basic endpoints for precise queries
|
| 151 |
-
- Advanced endpoints for intelligent analysis
|
| 152 |
-
|
| 153 |
-
### 2. **Efficiency**
|
| 154 |
-
- `extract_financial_metrics` - Get multiple years in one call
|
| 155 |
-
- `get_latest_financial_data` - No need to determine fiscal year
|
| 156 |
-
- `advanced_search` - Flexible input handling
|
| 157 |
-
|
| 158 |
-
### 3. **Complete Coverage**
|
| 159 |
-
All important `FinancialAnalyzer` methods are now exposed:
|
| 160 |
-
- ✅ `search_company()` → `/api/advanced_search`
|
| 161 |
-
- ✅ `extract_financial_metrics()` → `/api/extract_financial_metrics`
|
| 162 |
-
- ✅ `get_latest_financial_data()` → `/api/get_latest_financial_data`
|
| 163 |
-
|
| 164 |
-
### 4. **Data Quality**
|
| 165 |
-
- Automatic data formatting
|
| 166 |
-
- Consistent response structure
|
| 167 |
-
- Comprehensive error handling
|
| 168 |
-
|
| 169 |
-
## Comparison: Basic vs Advanced
|
| 170 |
-
|
| 171 |
-
| Feature | Basic Endpoint | Advanced Endpoint |
|
| 172 |
-
|---------|---------------|-------------------|
|
| 173 |
-
| Company Search | `/api/search_company` | `/api/advanced_search` |
|
| 174 |
-
| Input Type | Name only | Name or CIK |
|
| 175 |
-
| Return Data | Basic (CIK, name, ticker) | Complete (includes SIC) |
|
| 176 |
-
| | | |
|
| 177 |
-
| Financial Data | `/api/get_financial_data` | `/api/extract_financial_metrics` |
|
| 178 |
-
| Period | Single period | Multiple years |
|
| 179 |
-
| Data Type | Annual OR quarterly | Annual AND quarterly |
|
| 180 |
-
| Request Count | 1 per period | 1 for all periods |
|
| 181 |
-
| | | |
|
| 182 |
-
| Latest Data | `/api/get_financial_data` | `/api/get_latest_financial_data` |
|
| 183 |
-
| Year Required | Yes (must specify) | No (auto-detects) |
|
| 184 |
-
| Convenience | Manual | Automatic |
|
| 185 |
-
|
| 186 |
-
## Usage Examples
|
| 187 |
-
|
| 188 |
-
### Example 1: Quick Company Analysis
|
| 189 |
-
|
| 190 |
-
```python
|
| 191 |
-
import requests
|
| 192 |
-
|
| 193 |
-
BASE_URL = "https://YOUR_SPACE.hf.space"
|
| 194 |
-
|
| 195 |
-
# Step 1: Advanced search (works with name or CIK)
|
| 196 |
-
response = requests.post(
|
| 197 |
-
f"{BASE_URL}/api/advanced_search",
|
| 198 |
-
json={"company_input": "NVIDIA"}
|
| 199 |
-
)
|
| 200 |
-
company = response.json()
|
| 201 |
-
cik = company['cik']
|
| 202 |
-
|
| 203 |
-
# Step 2: Get latest data (no year needed!)
|
| 204 |
-
response = requests.post(
|
| 205 |
-
f"{BASE_URL}/api/get_latest_financial_data",
|
| 206 |
-
json={"cik": cik}
|
| 207 |
-
)
|
| 208 |
-
latest = response.json()
|
| 209 |
-
print(f"Latest FY{latest['period']} Revenue: ${latest['total_revenue']:,.0f}")
|
| 210 |
-
```
|
| 211 |
-
|
| 212 |
-
### Example 2: Multi-Year Trend Analysis
|
| 213 |
-
|
| 214 |
-
```python
|
| 215 |
-
# Get 5 years of data in one call
|
| 216 |
-
response = requests.post(
|
| 217 |
-
f"{BASE_URL}/api/extract_financial_metrics",
|
| 218 |
-
json={"cik": cik, "years": 5}
|
| 219 |
-
)
|
| 220 |
-
data = response.json()
|
| 221 |
-
|
| 222 |
-
# Analyze trends
|
| 223 |
-
import pandas as pd
|
| 224 |
-
df = pd.DataFrame(data['metrics'])
|
| 225 |
-
annual_data = df[~df['period'].str.contains('Q')] # Filter annual only
|
| 226 |
-
print(annual_data[['period', 'total_revenue', 'net_income']])
|
| 227 |
-
```
|
| 228 |
-
|
| 229 |
-
### Example 3: Flexible Search
|
| 230 |
-
|
| 231 |
-
```python
|
| 232 |
-
# Works with either input type
|
| 233 |
-
def search_company(input_str):
|
| 234 |
-
response = requests.post(
|
| 235 |
-
f"{BASE_URL}/api/advanced_search",
|
| 236 |
-
json={"company_input": input_str}
|
| 237 |
-
)
|
| 238 |
-
return response.json()
|
| 239 |
-
|
| 240 |
-
# Both work!
|
| 241 |
-
result1 = search_company("Apple") # By name
|
| 242 |
-
result2 = search_company("0000320193") # By CIK
|
| 243 |
-
```
|
| 244 |
-
|
| 245 |
-
## Documentation
|
| 246 |
-
|
| 247 |
-
- **Complete API Examples**: See `mcp_client_examples.json`
|
| 248 |
-
- **Interactive Testing**: Visit `/docs` (Swagger UI)
|
| 249 |
-
- **Detailed Usage**: See `API_USAGE.md`
|
| 250 |
-
|
| 251 |
-
## Summary
|
| 252 |
-
|
| 253 |
-
The MCP Server now provides **9 comprehensive API endpoints** covering:
|
| 254 |
-
- ✅ Basic data retrieval (EdgarDataClient)
|
| 255 |
-
- ✅ Advanced analysis (FinancialAnalyzer)
|
| 256 |
-
- ✅ Flexible search options
|
| 257 |
-
- ✅ Multi-year data extraction
|
| 258 |
-
- ✅ Automatic latest data retrieval
|
| 259 |
-
|
| 260 |
-
All important functionality from both `edgar_client.py` and `financial_analyzer.py` is now accessible via RESTful APIs! 🎉
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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